Top Java Intermediate Interview Questions and Answers
A collection of intermediate-level Java interview questions including collections, multithreading, exception handling, memory management, and JVM internals — ideal for 2–5 years experienced developers.
1. What is the difference between ArrayList and LinkedList?
- ArrayList: Fast access, slow insertion/deletion.
- LinkedList: Slow access, fast insertion/deletion.
2. What is the difference between HashMap and Hashtable?
| Feature | HashMap | Hashtable |
| Thread-safe | No | Yes |
| Null keys/values | Allowed | Not allowed |
| Performance | Faster | Slower |
3. What is a ConcurrentHashMap?
A thread-safe map that divides data into segments to improve performance in multi-threaded applications.
4. What is the difference between List, Set, and Map?
- List: Ordered, allows duplicates
- Set: No duplicates
- Map: Key–value pairs
5. What is the difference between throw and throws?
- throw: Used to throw an exception manually
- throws: Declares exceptions that a method may throw
6. What is the difference between final, finally, and finalize()?
- final: Keyword for restriction
- finally: Block always executes
- finalize(): Method called before garbage collection
7. What is the use of the super keyword?
Used to access parent class methods and constructors.
8. What is the this keyword?
Refers to the current class object.
9. What is the difference between abstract class and interface?
- Abstract class → can have both abstract and concrete methods
- Interface → only abstract methods (Java 7), default & static methods added in Java 8
10. What is the difference between equals() and hashCode()?
Objects that are equal using equals() must have the same hashCode().
11. What is the Java Stream API?
A functional-style API to process collections using operations like map, filter, reduce, sorted, etc.
12. What are Lambda Expressions?
Short-hand syntax to implement functional interfaces.
Example:
(a, b) -> a + b
13. What is Functional Interface?
An interface with exactly one abstract method (like Runnable, Callable, Comparable).
14. What is Method Reference in Java 8?
A compact way to refer to methods using ::.
15. What is Optional in Java?
A container object used to prevent NullPointerException.
16. What is the difference between Comparator and Comparable?
- Comparable: Natural sorting using compareTo()
- Comparator: Custom sorting using compare()
17. What is a Deadlock in Java?
A situation where two or more threads are waiting for each other, causing the program to freeze.
18. What is Synchronization in Java?
A mechanism to control multiple threads’ access to shared resources.
19. What is the Thread Lifecycle?
New → Runnable → Running → Blocked/Waiting → Terminated
20. What is a Daemon Thread?
A background thread that runs behind the application (e.g., garbage collector).
21. What is ExecutorService?
A framework for managing threads (thread pools).
22. What is Serialization in Java?
Converting an object into a byte stream.
23. What is Deserialization?
Converting byte stream back to an object.
24. What is the transient keyword?
Prevents a variable from being serialized.
25. What is the volatile keyword?
Ensures visibility of changes across threads.
26. What is Immutable Class?
A class whose objects cannot be changed after creation.
Example: String class.
27. What is the difference between String Pool and Heap?
- String Pool stores unique string literals
- Heap stores new String objects created using new
28. What is ClassLoader?
It loads Java classes into the JVM.
Types: Bootstrap, Extension, System
29. What is Reflection in Java?
Allows examining or modifying class behavior at runtime.
30. What is the difference between Stack and Heap memory?
- Stack: Stores method calls and local variables
- Heap: Stores objects and instance variables