- Collections
- Data Structures and Algorithms
- Concurrency
- Phone interview
- Generics
- Frequently Asked Questions;
- Other Core Java Questions
- Top 10 Tricky Java interview questions and Answers (link)
Source: https://javarevisited.blogspot.com/2011/11/collection-interview-questions-answers.html
-
How does
HashMapwork in Java? (Variations: WhyHashMapkeys need to be immutable? what is race conditions onHashMapand howHashMapresize in Java?) (answer) -
What is the difference between
poll()andremove()method ofQueueinterface? -
What is the difference between fail-fast and fail-safe Iterators? (answer)
-
How do you remove an entry from a
Collection? and subsequently what is the difference between theremove()method of Collection andremove()method ofIterator, which one you will use while removing elements during iteration? -
What is the difference between Synchronized Collection and Concurrent Collection? (answer)
-
What is the difference between
IteratorandEnumeration? (answer) -
How does
HashSetis implemented in Java, How does it use Hashing? (answer) -
What do you need to do to use a custom object as a key in Collection classes like
MaporSet? -
The difference between
HashMapandHashtable? (answer) -
When do you use
ConcurrentHashMapin Java? (answer) -
What is the difference between
SetandListin Java? (answer) -
How do you Sort objects on the collection? What is the different between
ComparableandComparator. (answer) -
What is the difference between
VectorandArrayList? (answer) -
What is the difference between
HashMapandHashSet? (answer) -
What is
NavigableMapin Java? What is a benefit overMap? (answer) -
Which one you will prefer between
ArrayandArrayListfor Storing object and why? (answer). See "Effective Java", Item 28: Prefer lists to arrays. -
Can we replace
HashtablewithConcurrentHashMap? -
What is
CopyOnWriteArrayList, how it is different thanArrayListandVector? (answer) -
Why
ListIteratorhasadded()method but Iterator doesn't or Why toadd()method is declared inListIteratorand not on Iterator. (answer) -
When does
ConcurrentModificationExceptionoccur on iteration? (answer) -
Difference between
Set,ListandMapCollection classes? (answer) -
What is
BlockingQueue, how it is different than other collection classes? (answer) -
How does
LinkedListis implemented in Java, is it a Singly or Doubly linked list? Hint:LinkedListin Java is a doubly linked list. -
How do you iterator over Synchronized
HashMap, do you need to lock iteration and why? -
What is
Deque? when do you use it?
-
What is
Threadin Java? (answer) -
What is the difference between
ThreadandProcessin Java? (answer) -
How do you implement
Threadin Java? (answer) -
When to use
RunnablevsThreadin Java? (answer) -
What is the difference between
start()andrun()method of Thread class? (answer) -
What is the difference between
RunnableandCallablein Java? (answer) -
What is the difference between
CyclicBarrierandCountDownLatchin Java? (answer) -
What is Java Memory model?
-
What is volatile variable in Java? (answer)
-
What is thread-safety? is Vector a thread-safe class? (answer)
-
What is race condition in Java? Given one example? (answer)
-
How to stop a thread in Java?(answer)
-
What happens when an
Exceptionoccurs in a thread? -
How do you share data between two thread in Java? (Producer-consumer pattern)
-
What is the difference between
notifyandnotifyAllin Java? (answer) -
Why wait,
notifyandnotifyAllare not insideThreadclass? ([answer](What is ThreadLocal variable in Java?)) -
What is
ThreadLocalvariable in Java? (answer) -
What is
FutureTaskin Java? -
What is the difference between the
interrupted()andisInterrupted()method in Java? -
Why wait and notify method are called from synchronized block? (answer)
-
Why should you check condition for waiting in a loop? (answer)
-
What is the difference between synchronized and concurrent collection in Java?
-
What is the difference between Stack and Heap in Java? (answer)
-
What is thread pool? Why should you thread pool in Java?
-
Write code to solve Producer-Consumer problem in Java? (see)
-
How do you avoid deadlock in Java? Write Code? (answer)
-
What is the difference between livelock and deadlock in Java?
-
How do you check if a Thread holds a lock or not?
-
How do you take thread dump in Java?
-
Which JVM parameter is used to control stack size of a thread?
-
What is the difference between synchronized and ReentrantLock in Java? (answer)
-
There are three threads T1, T2, and T3? How do you ensure sequence T1, T2, T3 in Java? (answer)
-
What does yield method of
Threadclass do? (answer) -
What is the concurrency level of ConcurrentHashMap in Java? (answer)
-
What is Semaphore in Java?
-
What happens if you submit a task when the queue of the thread pool is already filled?
-
What is the difference between the submit() and execute() method thread pool in Java? (answer)
-
What is blocking method in Java? (answer)
-
How to create an Immutable object in Java? (answer)
-
What is
ReadWriteLockin Java? -
What is busy spin in multi-threading?
-
What is the difference between the volatile and atomic variable in Java?
-
What happens if a thread throws an Exception inside synchronized block?
-
How to create thread-safe Singleton in Java?
-
List down 3 multi-threading best practice you follow?
-
How do you force to start a Thread in Java?
-
What is the fork-join framework in Java? (answer)
-
What is the difference between calling
wait()andsleep()method in Java multi-threading? (answer)
Source: https://javarevisited.blogspot.com/2018/07/top-30-java-phone-interview-questions.html
-
Why is String immutable in Java? (answer)
-
Can abstract class have a constructor in Java?
-
Which two methods are overridden by an Object, intended to be used as a key in
HashMap? (answer) -
What is the difference between wait and sleep in Java? (answer)
-
Difference between List and Set in Java? (easy)
-
Difference between List and Set in Java? (answer)
-
Which data type you should use to represent currency in Java? (easy)
-
When to use abstract class and interface in Java? (easy)
-
Difference between Hashtable and HashMap in Java? (easy)
-
What is the difference between ArrayList and LinkedList in Java? (easy)
-
What is the difference between Overloading and Overriding in Java? (Compile time vs Runtime polymorphism. See this and this)
-
Difference between checked and unchecked exception in Java?
-
Difference between checked and unchecked exception in Java? (answer)
-
Does Java array is an instance of Object?
-
Does
List<Number>can hold Integers? (easy) -
Can we pass
ArrayList<Number>to a method which acceptsList<Number>in Java? -
Can we pass
ArrayList<Integer>to a method which acceptsList<Number>? -
What is a volatile variable in Java?
-
What is the difference between
CountDownLatchandCyclicBarrierin Java? -
Does
BlockingQueueis thread-safe in Java? -
Why wait and notify method should be called in a loop?
-
What is the difference between
"ABC".equals(unknown string)andunknown.equals("ABC")? (NullPointerException) -
What is a marker or tag interface in Java? (answer)
-
Can
Enumtypes implement interface in Java? (Yes) -
Can
Enumextend a class in Java? (No) -
How to prevent your class from being subclassed? (answer)
-
Can we override a static method in Java? Compilation error? (answer)
-
Which design pattern have you used recently?
-
What is the difference between
StringBufferandStringBuilderin Java?
Source: https://javarevisited.blogspot.com/2020/04/50-java-collection-and-generics-interview-questions-answers.html, https://javarevisited.blogspot.com/2020/04/50-java-collection-and-generics-interview-questions-answers.html
-
What is Generics in Java ? What are advantages of using Generics?
-
How Generics works in Java ? What is type erasure?
-
What is Bounded and Unbounded wildcards in Generics? What is the difference between bounded and unbounded wildcards in Java generics? What is difference between
List<? extends T>andList <? super T>? -
Write a program to implement LRU cache using Generics ?
-
Can you pass
List<String>to a method which acceptsList<Object>? -
Can we use Generics with Array?
-
Difference between
List<Object>and raw typeListin Java? -
Difference between
List<?>andList<Object>in Java? -
Difference between
List<String>and raw typeList? -
What is an "unchecked" warning?
-
What is a bridge method?
-
How can I avoid "unchecked cast" warnings?
-
What is the "diamond" operator?
-
Difference between
ArrayListandArrayList<?>in Java? (Raw type vs Wildcard)
Source: https://www.java67.com/2014/07/21-frequently-asked-java-interview-questions-answers.html
-
What are the types of Java Threads? (See)
-
What is a class loader?
-
What is volatile "happens-before" relationship - "A happens-before relationship is a guarantee that memory written to by statement A is visible to statement B, that is, that statement A completes its write before statement B starts its read."
-
Why multiple inheritance is not supported in Java? (answer)
-
Does Java Pass by Value or Pass by Reference? (answer)
-
Can You Run Java Program Without a Main Method? (answer)
-
Why main method is public static and void in Java? (answer)
-
Why character array is better than String for Storing password in Java? (See this and this answer)
-
Why Default or No Argument Constructor is Important in Java Class? (answer)
-
Can we have a static & final method? (Yes)
-
Can we have an abstract & final method? (No)
-
What are the implications of declaring a constructor private?
-
Can there be a private/constructor in an abstract class? (see)
-
new String(“str”);how many objects will be created? (see) -
Can a constructor be final? (No, see)
-
How to sort values in
HashMap? (answer)