December 31, 2025
Preparing for a Java developer interview? Whether you're a junior developer or experienced professional, mastering these 30 common Java interview questions will dramatically improve your chances of landing the job.
Don't walk into your Java interview unprepared. WiseWhisper AI helps you practice technical questions in real-time with instant feedback on your answers. Practice Java interviews with AI assistance.
Core Java Fundamentals
1. What is Java and what are its main features?
Answer: Java is an object-oriented, platform-independent programming language. Key features include:
- Platform independence (Write Once, Run Anywhere)
- Object-oriented programming
- Automatic memory management (Garbage Collection)
- Multithreading support
- Rich API and extensive libraries
2. Explain the difference between JDK, JRE, and JVM
Answer:
- JVM (Java Virtual Machine): Executes Java bytecode and provides platform independence
- JRE (Java Runtime Environment): Includes JVM + libraries needed to run Java applications
- JDK (Java Development Kit): Includes JRE + development tools (compiler, debugger) for developing Java applications
3. What are the differences between == and .equals()?
Answer:
- == compares object references (memory addresses)
- .equals() compares object contents/values (must be overridden for custom comparison)
For strings: use .equals() to compare actual text content, not ==.
4. What is the difference between String, StringBuilder, and StringBuffer?
Answer:
- String: Immutable, thread-safe, creates new object on modification
- StringBuilder: Mutable, NOT thread-safe, faster for single-threaded operations
- StringBuffer: Mutable, thread-safe (synchronized), slower than StringBuilder
5. What is method overloading and overriding?
Answer:
- Overloading: Same method name, different parameters (compile-time polymorphism)
- Overriding: Subclass provides specific implementation of parent class method (runtime polymorphism)
Struggling to Remember Java Concepts During Interviews?
WiseWhisper provides real-time assistance during technical interviews, helping you recall key concepts and structure your answers professionally.
Start Practicing Java InterviewsObject-Oriented Programming (OOP)
6. Explain the four pillars of OOP
Answer:
- Encapsulation: Bundling data and methods, hiding internal details
- Inheritance: Creating new classes from existing ones, promoting code reuse
- Polymorphism: Objects taking multiple forms (overloading/overriding)
- Abstraction: Hiding implementation complexity, showing only essential features
7. What is the difference between abstract class and interface?
Answer:
- Abstract Class: Can have abstract and concrete methods, constructor, instance variables, single inheritance
- Interface: Only abstract methods (before Java 8), no constructor, constants only, multiple inheritance
- Java 8+: Interfaces can have default and static methods
8. What is the final keyword in Java?
Answer:
- final variable: Constant, cannot be reassigned
- final method: Cannot be overridden by subclasses
- final class: Cannot be inherited
9. What is a constructor and what are its types?
Answer: A constructor is a special method that initializes objects. Types:
- Default constructor: No parameters, provided by compiler if no constructor defined
- Parameterized constructor: Accepts parameters to initialize object with specific values
- Copy constructor: Creates object by copying another object
10. What is the difference between composition and inheritance?
Answer:
- Inheritance: "is-a" relationship, creates tight coupling, less flexible
- Composition: "has-a" relationship, creates loose coupling, more flexible, preferred over inheritance
Collections Framework
11. What is the difference between ArrayList and LinkedList?
Answer:
- ArrayList: Dynamic array, fast random access O(1), slow insertion/deletion O(n)
- LinkedList: Doubly-linked list, slow random access O(n), fast insertion/deletion O(1)
12. What is the difference between HashMap and Hashtable?
Answer:
- HashMap: NOT synchronized, allows one null key and multiple null values, faster
- Hashtable: Synchronized (thread-safe), no null keys or values, slower
13. Explain HashMap internal working
Answer: HashMap uses array + linked list/tree structure:
- Computes hash code for key
- Determines bucket index using hash {}rray length
- Stores key-value as Entry/Node in bucket
- Handles collisions using linked list (tree if > 8 entries in Java 8+)
14. What is the difference between Set and List?
Answer:
- List: Ordered, allows duplicates, accessed by index (ArrayList, LinkedList)
- Set: Unordered (or sorted), no duplicates, no index access (HashSet, TreeSet)
15. What is the fail-fast iterator?
Answer: Iterator that throws ConcurrentModificationException if collection is modified during iteration (except through iterator's own remove() method). Used by ArrayList, HashMap.
Multithreading and Concurrency
16. What is the difference between process and thread?
Answer:
- Process: Independent program with own memory space
- Thread: Lightweight subprocess sharing memory within a process
17. How do you create a thread in Java?
Answer: Two ways:
- Extend Thread class and override run() method
- Implement Runnable interface and implement run() method (preferred)
18. What is synchronization and why is it needed?
Answer: Synchronization controls access to shared resources by multiple threads, preventing race conditions and ensuring thread safety. Implemented using synchronized keyword or locks.
19. What is the difference between wait() and sleep()?
Answer:
- wait(): Releases lock, must be called within synchronized block, part of Object class
- sleep(): Holds lock, can be called anywhere, part of Thread class
20. What is a deadlock and how can you avoid it?
Answer: Deadlock occurs when two or more threads wait for each other to release locks. Avoid by:
- Lock ordering (always acquire locks in same order)
- Lock timeout (tryLock with timeout)
- Avoiding nested locks when possible
Exception Handling
21. What is the difference between checked and unchecked exceptions?
Answer:
- Checked: Must be caught or declared, checked at compile-time (IOException, SQLException)
- Unchecked: Not required to catch/declare, checked at runtime (NullPointerException, ArrayIndexOutOfBoundsException)
22. What is the finally block?
Answer: Finally block always executes after try-catch, regardless of whether exception occurred. Used for cleanup operations (closing resources).
23. What is try-with-resources?
Answer: Java 7 feature that automatically closes resources implementing AutoCloseable. No need for explicit finally block to close resources.
JVM and Memory Management
24. Explain Java memory model (Heap vs Stack)
Answer:
- Heap: Stores objects, shared by all threads, garbage collected
- Stack: Stores method calls and local variables, thread-specific, LIFO structure
25. What is Garbage Collection?
Answer: Automatic memory management that reclaims memory occupied by unreferenced objects. Major GC algorithms: Serial, Parallel, CMS, G1GC.
26. What is the difference between ClassNotFoundException and NoClassDefFoundError?
Answer:
- ClassNotFoundException: Exception thrown when trying to load class at runtime using Class.forName()
- NoClassDefFoundError: Error when class was present at compile-time but missing at runtime
Java 8+ Features
27. What are lambda expressions?
Answer: Anonymous functions for implementing functional interfaces. Syntax: (parameters) -> expression. Enables functional programming in Java.
28. What is the Stream API?
Answer: Java 8 feature for processing collections in a functional style. Provides operations like:
- filter(), map(), reduce()
- Lazy evaluation for better performance
- Parallel processing support
29. What is Optional class?
Answer: Container object that may or may not contain a non-null value. Helps avoid NullPointerException by forcing explicit handling of null cases.
30. What are default methods in interfaces?
Answer: Java 8 allows interfaces to have method implementations using "default" keyword. Enables adding new methods to interfaces without breaking existing implementations.
Master Your Java Interview with AI Assistance
Knowing the answers is just the start. WiseWhisper helps you practice delivering them confidently in real interview scenarios with instant feedback on your communication.
Stop losing opportunities because you froze on one question. Start showcasing the professional you actually are.
Download WiseWhisper Free →Key Takeaways
- Focus on core fundamentals: OOP, collections, multithreading
- Understand the "why" behind each concept, not just definitions
- Practice explaining complex topics in simple terms
- Know practical examples and real-world use cases
- Stay updated with Java 8+ features (lambdas, streams, Optional)
Success in Java interviews comes from understanding concepts deeply and communicating them clearly. Regular practice with realistic interview scenarios builds the confidence you need to excel.
Related Articles
STAR Method: Complete Interview Technique Guide
Learn the proven framework for structuring compelling interview answers that showcase your skills.
Common Interview Mistakes and How to Avoid Them
Avoid costly interview mistakes with practical tips for better performance.