Java Developer Interview Questions & Answers
1. Core Java & OOPs Concepts
Q1. What is Java?
Answer:
Java is a high-level, object-oriented, platform-independent programming language. It follows the principle
of Write Once, Run Anywhere (WORA) through the JVM.
Q2. What are the four pillars of OOP?
Answer:
• Encapsulation
• Inheritance
• Polymorphism
• Abstraction
Q3. What is Encapsulation?
Answer:
Wrapping data and methods into a single unit and restricting direct access using private variables.
Q4. What is Inheritance?
Answer:
Inheritance allows one class to acquire properties and methods from another class using the extends
keyword.
Q5. What is Polymorphism?
Answer:
The ability of an object to take multiple forms.
• Compile Time → Method Overloading
• Runtime → Method Overriding
Q6. What is Abstraction?
Answer:
Hiding implementation details and showing only essential functionality using abstract classes and
interfaces.
Q7. Difference between Abstract Class and Interface?
Abstract Class Interface
Can have constructors Cannot have constructors
Supports partial abstraction Supports full abstraction
Uses extends Uses implements
2. Collections Framework & HashMap Internals
Q1. What is Collection Framework?
Answer:
A set of classes and interfaces used to store and manipulate groups of objects.
Q2. Difference between ArrayList and LinkedList?
ArrayList LinkedList
Fast retrieval Fast insertion/deletion
Uses Dynamic Array Uses Doubly Linked List
Q3. Difference between HashMap and Hashtable?
HashMap Hashtable
Not synchronized Synchronized
Allows null key No null key
Q4. How does HashMap work internally?
Answer:
1. Key's hashCode() is generated.
2. Hash value determines bucket index.
3. Entry stored in bucket.
4. If collision occurs, Linked List/Tree is used.
5. equals() verifies correct key.
Q5. What is Hash Collision?
Answer:
When multiple keys generate the same bucket index.
3. Exception Handling
Q1. What is an Exception?
Answer:
An unexpected event that interrupts normal program execution.
Q2. Difference between Checked and Unchecked Exceptions?
Checked Exceptions
• Checked at compile time
• Example: IOException
Unchecked Exceptions
• Occur at runtime
• Example: NullPointerException
Q3. Difference between throw and throws?
throw
throw new Exception();
throws
public void test() throws Exception
Q4. Can we have multiple catch blocks?
Answer:
Yes, but specific exceptions should come before generic exceptions.
4. Multithreading, Concurrency & Synchronization
Q1. What is a Thread?
Answer:
A lightweight process used for parallel execution.
Q2. Ways to create a thread?
1. Extending Thread class
2. Implementing Runnable interface
Q3. Difference between start() and run()?
start()
• Creates new thread
run()
• Executes like normal method
Q4. What is Synchronization?
Answer:
A mechanism that allows only one thread to access a shared resource at a time.
Q5. What is Deadlock?
Answer:
A situation where two threads wait indefinitely for each other's resources.
5. JVM, JDK, JRE & Garbage Collection
Q1. Difference between JVM, JRE and JDK?
JVM
• Executes Java bytecode
JRE
• JVM + Libraries
JDK
• JRE + Development tools
Q2. What is Garbage Collection?
Answer:
Automatic memory cleanup process that removes unused objects from heap memory.
Q3. What are JVM Memory Areas?
• Heap
• Stack
• Method Area
• PC Register
• Native Method Stack
Q4. What causes Memory Leaks?
Answer:
• Static references
• Unclosed resources
• Improper caching
6. String & Memory Management
Q1. Why is String immutable?
Answer:
• Security
• Thread Safety
• Performance
Q2. Difference between String, StringBuilder and StringBuffer?
String StringBuilder StringBuffer
Immutable Mutable Mutable
Thread Safe No Yes
Q3. What is String Pool?
Answer:
A special memory area where string literals are stored and reused.
Q4. Difference between == and equals()?
==
• Compares references
equals()
• Compares content
7. Java 8 Features, Stream API & Lambda
Q1. What are Java 8 features?
• Lambda Expressions
• Stream API
• Functional Interfaces
• Method References
• Optional Class
Q2. What is Lambda Expression?
(a,b) -> a+b
Short way to implement functional interfaces.
Q3. What is Functional Interface?
Answer:
An interface containing exactly one abstract method.
Example:
Runnable
Comparator
Callable
Q4. What is Stream API?
Answer:
Used for processing collections in a functional way.
Q5. Difference between map() and filter()?
map()
• Transforms data
filter()
• Filters data
8. Serialization, Comparable vs Comparator
Q1. What is Serialization?
Answer:
Converting object into byte stream.
Q2. What is Deserialization?
Answer:
Converting byte stream back to object.
Q3. Why use Serializable Interface?
Answer:
To persist or transfer objects.
Q4. Difference between Comparable and Comparator?
Comparable Comparator
Natural Sorting Custom Sorting
compareTo() compare()
9. Scenario-Based & Tricky Questions
Q1. Why is String immutable?
Answer:
Security, caching, thread safety.
Q2. Why is HashMap not thread-safe?
Answer:
Multiple threads can modify data simultaneously causing inconsistency.
Q3. Can we override static methods?
Answer:
No. Static methods are class-level methods.
Q4. Can constructor be final?
Answer:
No.
Q5. Can main method be overloaded?
Answer:
Yes.
10. Rapid Fire Round (10 One-Liners)
1. Default value of int?
0
2. Parent class of all classes?
Object
3. Size of int?
4 bytes
4. Can interface have methods?
Yes
5. Is Java pass-by-reference?
No, pass-by-value
6. Can abstract class have constructor?
Yes
7. Can final class be inherited?
No
8. Can we create object of interface?
No
9. Can we create object of abstract class?
No
10. Which package is imported automatically?
[Link]
11. Top 20 Frequently Asked Java Interview Topics
1. OOPs Concepts
2. JVM Architecture
3. JDK vs JRE vs JVM
4. String Pool
5. StringBuilder vs StringBuffer
6. Exception Handling
7. Collection Framework
8. HashMap Internal Working
9. ArrayList vs LinkedList
10. HashSet vs TreeSet
11. Comparable vs Comparator
12. Multithreading
13. Synchronization
14. Deadlock
15. Java 8 Features
16. Stream API
17. Lambda Expressions
18. Serialization
19. Garbage Collection
20. Memory Management
12. Final Interview Tips
Explain concepts with examples
Speak confidently and clearly
If you don't know an answer, admit it honestly
Focus on OOPs, Collections, Multithreading, JVM, and Java 8
Practice coding questions daily
Learn real project examples using Java and Spring Boot
Revise top 20 topics before the interview
Be ready to explain your project end-to-end
Final Formula for Java Interviews
OOPs + Collections + Exception Handling + Multithreading + JVM + Java 8 + Projects = Interview Success