You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Java Core/Java Basics.txt
+12-7Lines changed: 12 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,7 @@ Java Basics
44
44
45
45
5. What is an abstract class?
46
46
47
-
An abstract class is a java class that has one or more absract methods (no body). Abstract classes cannot be instantiated. Abstract class defines an interface that has to be implemented by all its subclasses.
47
+
An abstract class is a java class that has one or more abstract methods (no body). Abstract classes cannot be instantiated. Abstract class defines an interface that has to be implemented by all its subclasses.
48
48
49
49
6. What is static in java?
50
50
@@ -86,8 +86,12 @@ Java Basics
86
86
87
87
13. What are different types of inner classes?
88
88
89
-
if declared with static -- it's nested class. Nested classes are fairly independent and treated as top-level classes. But the constructor call is different.
89
+
if declared with static -- it's nested class. Nested classes are fairly independent and treated as top-level classes. But the constructor call is different.
90
+
To construct one: new OuterClassNeme.InnerClassName().
91
+
90
92
if declared without static -- inner class. Each instance of inner class can only exist within an instance of the outer class.
93
+
To construct one: instanceOfOuterClass.new InnerClassName()
94
+
91
95
local class -- declared and visible only within a block of code
92
96
anonymous -- same, but they don't even have a name.
93
97
@@ -170,7 +174,7 @@ Java Basics
170
174
171
175
33. What is the default value of the local variables?
172
176
173
-
No default value. Default values are assigne to instance fields. Local variables have to be explicitly initialized.
177
+
No default value. Default values are assigned to instance fields. Local variables have to be explicitly initialized.
174
178
175
179
34. Does garbage collection guarantee that a program will not run out of memory?
176
180
@@ -182,7 +186,7 @@ Java Basics
182
186
183
187
36. Can a public class MyClass be defined in a source file named YourClass.java?
184
188
185
-
no. Unless it is a nested public class.
189
+
no. Unless it is a nested class public class.
186
190
187
191
37. What will be the output of the following statement? System.out.println ("1" + 3);
Copy file name to clipboardExpand all lines: Java Core/Java Collections.txt
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,7 @@ Collections
44
44
45
45
List -- storing values in specified order. Provides methods to get the element by its position get(i), finding element, ListIterator. Known implementations: ArrayList, Vector, LinkedList. List should be used when the order in which the elements are stored matters.
46
46
47
-
Set -- storing only different objects and at most one null element. Known implementations: TreeSet (iterate over the elements in order defined by Comparator, or if the elements implement comparable; provides log(n) performance for basic operations), HashSet -- stores values in buckest defined by their hashcodes. Each bucket is a singly linked list. Provides constant time performance for basic operations. LinkedHashSet
47
+
Set -- storing only different objects and at most one null element. Known implementations: TreeSet (iterate over the elements in order defined by Comparator, or if the elements implement comparable; provides log(n) performance for basic operations), HashSet -- stores values in buckets defined by their hashcodes. Each bucket is a singly linked list. Provides constant time performance for basic operations. LinkedHashSet
48
48
49
49
Map -- for storing key-value pairs. Map cannot contain duplicate keys. Provides three collection views: set of keys, collection of values, set of key-value mappings. Know implementations HashMap, EnumMap, TreeMap, LinkedHashMap, WeakHashMap.
50
50
@@ -62,19 +62,19 @@ Collections
62
62
63
63
9. What are relationships between equals and hash codes?
64
64
65
-
See above.
65
+
See in Java Basics.
66
66
67
67
10. What are the advantages of ArrayList over arrays ?
68
68
69
69
1. ArrayList comes with a number of utility methods (e.g. contains, remove, addAll)
70
70
2. Type safety
71
71
3. Dynamic sizing
72
-
On the other hand arrays are a little bit faster and take less memory (packing)
72
+
On the other hand arrays are a little bit faster and take less memory (packing). Arrays are also able to contain values of primitive types while ArrayList can only contain Objects.
73
73
74
74
11. Principle of storing data in a hashtable
75
75
76
-
HashSet. add(element) -> element.hashCode() -> mod bucketsNumber -> store
77
-
HashMap. add(key, value) -> key.hashCode() -> mod bucketsNumber -> store(value)
76
+
HashSet. add(element) -> element.hashCode() -> mod bucketsCount -> store
77
+
HashMap. add(key, value) -> key.hashCode() -> mod bucketsCount -> store(value)
78
78
79
79
12. Differences between Hashtable, ConcurrentHashMap and Collections.synchronizedMap()
Copy file name to clipboardExpand all lines: Java Core/Java Concurrency.txt
+70-4Lines changed: 70 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ Concurrency
16
16
17
17
Not exactly a correct question.
18
18
19
-
A scheduler can be preemptive (it's capable to force a process to interrupt its execution and resume it in some time) and non-preemptive (which is unable to interrupt a process and relies on the processes themselves that voluntarily give control to other tasks). Time slicing is a usual technique to that is used in a preemptive multitasking system. The scheduler is run every time slice to choose the next process to run (it may happen that it's the same process during few time slices in a row, or it may happen that every time slice a different process is executed )
19
+
A scheduler can be preemptive (it's capable to force a process to interrupt its execution and resume it in some time) and non-preemptive (which is unable to interrupt a process and relies on the processes themselves that voluntarily give control to other tasks). Time slicing is a usual technique that is used in a preemptive multitasking system. The scheduler is run every time slice to choose the next process to run (it may happen that it's the same process during few time slices in a row, or it may happen that every time slice a different process is executed )
20
20
21
21
To apply these terms to Java world -- replace the "process" with "thread", since the ideas behind scheduling processes in OS are the same as scheduling threads in an application.
22
22
@@ -77,7 +77,7 @@ Concurrency
77
77
notifyAll( ) wakes up all the threads that called wait( ) on the same object.
78
78
79
79
80
-
9. What does it mean Volatile keyword?
80
+
9. What does Volatile keyword mean?
81
81
82
82
The volatile keyword guarantees that reads and from a variable will see the changes made by the last write to this variable (and of course all other writes that happened earlier). Java documentation states that volatile establishes a "happens-before" relationship between a write to a variable and all subsequent reads from it.
Differences in JMM before Java 5 and after Java 5?
222
+
What is the difference between Runnable and Callable?
223
+
What is the difference between java.util.concurrent.Atomic*.compareAndSwap() and java.util.concurrent.Atomic*.weakCompareAndSwap()?
224
+
What is the difference between Collections.synchronizedMap(new HashMap()) and ConcurrentHashMap?
225
+
What is the difference between Thread.isInterrupted() and Thread.interrupted()?
226
+
What is the difference between CountDownLatch and CyclicBarrier?
227
+
What is the difference between ReenetrantLock and synchronized{}
228
+
Can you list all the reasons when InterruptedException can be thrown?
229
+
In SynchronousQueue what is unique for BlockingQueue?
230
+
In the String class all the fields are final. Could we remove the final keyword, since the class doesn't have any setters and thus the fields cannot be changed.
231
+
What happens when you call Thread.interrupt()?
232
+
What are advantages of ScheduledThreadPool over java.util.Timer?
233
+
Thread.getState() returns an instance of Thread.State. What are the possible values?
234
+
ReentrantLock created with a true flag (fair) one of the methods to get the lock is not fair. Which one? When to use or not use it?
235
+
Which of the following calls creates a happens-before relationship? Thread.sleep(), Thread.join(), Thread.yield(), Thread.start(), Thread.run(), Thread.isAlive(), Thread.getState()?
236
+
Some of the following methods are deprecated, some have never been implemented. Which of them fall into which category? Thread.interrupt(), Thread.stop(), Thread.yield(), Thread.suspend(), Thread.resume(), Thread.join(), Thread.start(), Thread.run(), Thread.sleep()
237
+
What are ordering, visibility, atomicity, happens-before, mutual exclusion? Which of the listed properties are retained when using volatile, AtomicInteger and synchronized{}? How?
238
+
What do you know about asynchronous method calls? Do they exist in Java? If yes, how they are implemented? If no, how would you implement them?
239
+
What is rendez-vous? Which Java classes can help?
240
+
What is a "green thread"? Are they used in Java (in HotSpon JVM.6)?
241
+
What is cooperative multitasking? Is it used in Java? If not then which type of multitasking is used in Java? What are the advantages.
242
+
What is false sharing? Could it happen in Java? If yes, how could you fight it? If no, how the JVM developers have overcome it?
243
+
244
+
Explain safe publication.
245
+
Explain recursive parallelism.
246
+
Explain iterative parallelism.
247
+
Tell something about Reactor/Proactor patterns.
248
+
What does reentrant property mean?
249
+
List the ways to fight priority inversion. Name the types of systems where they are extremely dangerous.
250
+
Name the ways to a) avoid b) overcome a deadlock (imagine you're writing a RDBMS kernel)
251
+
252
+
What is monitor?
253
+
What is private mutex?
254
+
What is priority inheritance?
255
+
What is back-off protocol (exponential back-off)?
256
+
What is task-stealing?
257
+
What is spin lock?
258
+
What is sequential consistency?
259
+
What is ABA problem?
260
+
What is "test and set"?
261
+
What is "test and set and set"?
262
+
What is "sense reversing barrier"?
263
+
What is pipeline?
264
+
What is poison message?
265
+
What is mutual exclusion? Examples.
266
+
What is condition waiting? Examples.
267
+
268
+
Implement a simple nonblocking stack (only push() and pop())
269
+
Implement a simple copy-on-write ArrayList (void add(int index, T item), T get(int index), void remove(int index), int size())
270
+
Implement a simple buffer for multiple producers / multiple consumers using synchronized{}
271
+
Implement a simple buffer for multiple producers / multiple consumers using ReentrantLock
Copy file name to clipboardExpand all lines: Java Core/Java Exceptions.txt
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -43,7 +43,7 @@ Exceptions
43
43
44
44
10. When should you use which approach?
45
45
46
-
As I understand one should handle the exception if he/she has all the knowledge and resources to do so. And the exception has to be handled as soon as this knowledge is aquired. However if you are writing a library you may consider declaring the exceptions that are thrown and force the user of the library to decide how to react to a specific situation. The downside of this approach is that declared exceptions become the part of the API which has to be fixed after being published.
46
+
As I understand one should handle the exception if he/she has all the knowledge and resources to do so. And the exception has to be handled as soon as this knowledge is aquired. However if you are writing a library you may consider declaring the exceptions that are thrown and force the user of the library to decide how to react to a specific situation. The downside of this approach is that declared exceptions become the part of the API which has to be frozen after being published.
47
47
48
48
11. Is it necessary that each try block must be followed by a catch block?
Copy file name to clipboardExpand all lines: Java Core/Java Generics.txt
+57-5Lines changed: 57 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -148,7 +148,6 @@ Questions
148
148
15. Difference between List<?> and raw type List.
149
149
150
150
The raw type and the unbounded wildcard parameterized type have a lot in common. Both act as kind of a supertype of all instantiations of the corresponding generic type. Both are so-called reifiable types. Reifiable types can be used in instanceof expressions and as the component type of arrays, where non-reifiable types (such as concrete and bounded wildcard parameterized type) are not permitted.
151
-
152
151
In other words, the raw type and the unbounded wildcard parameterized type are semantically equivalent. The only difference is that the compiler applies stricter rules to the unbounded wildcard parameterized type than to the corresponding raw type. Certain operations performed on the raw type yield "unchecked" warnings. The same operations, when performed on the corresponding unbounded wildcard parameterized type, are rejected as errors.
153
152
154
153
16. Is <T> List<? extends T> x() a useful signature?
@@ -166,26 +165,79 @@ Questions
166
165
167
166
18. Examples of a valid generic type that cannot be expressed with the Java type system and will lead to compiler warnings.
168
167
168
+
from http://stackoverflow.com/questions/12254897/a-bug-in-java-type-system
169
169
170
+
interface IProducer<T extends Comparable<T>> {
171
+
public Map<Integer, T> getResults();
172
+
}
170
173
171
-
19. Examples where the java compiler will/will not infere the generic type? (examples of code where the compiler will infere the wrong type)
174
+
interface IEvaluator {
175
+
public <T extends Comparable<T>> double evaluate(Map<Integer, T> results,
21. What's APT (use cases when not to use reflection)?
226
+
It means that the type argument for enum has to derive from an enum which itself has the same type argument. How can this happen? By making the type argument the new type itself. So if I've got an enum called StatusCode, it would be equivalent to:
180
227
228
+
public class StatusCode extends Enum<StatusCode>
181
229
230
+
Now if you check the constraints, we've got Enum<StatusCode> - so E=StatusCode. Let's check: does E extend Enum<StatusCode>? Yes! We're okay.
182
231
183
-
22. What does the Class Enum<E extends Enum<E>> ensure?
232
+
You may well be asking yourself what the point of this is :) Well, it means that the API for Enum can refer to itself - for instance, being able to say that Enum<E> implements Comparable<E>. The base class is able to do the comparisons (in the case of enums) but it can make sure that it only compares the right kind of enums with each other.
184
233
234
+
22. If the compiler erases all type parameters at compile time, why should you use generics?
185
235
236
+
While the compiler erases all type parameters it still performs all the checks on generic code at compile time. Additionally generics enable you to implement generic algorithms.
186
237
187
-
23. If the compiler erases all type parameters at compile time, why should you use generics?
2. Design a Vending Machine which can accept different coins, deliver different products?
94
-
3. You have a Smartphone class and will have derived classes like IPhone, AndroidPhone,WindowsMobilePhone can be even phone names with brand, how would you design this system of Classes.
95
-
4. Design ATM Machine ?
96
-
5. You are writing classes to provide Market Data and you know that you can switch to different vendors overtime like Reuters, wombat and may be even to direct exchange feed , how do you design your Market Data system.
87
+
15. What is FrontController design pattern in Java ? Give an example of front controller pattern ?
0 commit comments