Java
Core Java Interview Questions
Top Core Java interview questions on OOP, Immutability, Exceptions, and more.
By TechCoder TeamLast updated: 2026-06-02
In a Nutshell
Top Core Java interview questions on OOP, Immutability, Exceptions, and more. This hands-on tutorial focuses on practical implementation of core java interview questions concepts.
Core Java Interview Questions
Object-Oriented Programming
1. What are the four pillars of OOP?
- Encapsulation: Wrapping data (variables) and code (methods) together as a single unit. Data hiding using
private. - Inheritance: Mechanism where a new class inherits properties and behavior from an existing class.
- Polymorphism: Ability to perform a single action in different ways (Overloading & Overriding).
- Abstraction: Hiding internal details and showing only functionality.
2. Difference between Abstract Class and Interface?
| Feature | Abstract Class | Interface |
|---|---|---|
| Methods | Can have abstract & concrete methods | All methods abstract (before Java 8) |
| Variables | non-final, non-static allowed | public static final by default |
| Inheritance | Class can extend only one | Class can implement multiple |
| Constructor | Can have constructors | Cannot have constructors |
String & Immutability
3. Why is String immutable in Java?
- Security: Strings are used for passwords, URLs, db connections.
- Synchronization: Immutable objects are thread-safe.
- String Pool: Saves heap memory by reusing literals.
- Caching HashCode: Since it doesn't change, hashcode is cached (great for HashMap keys).
4. String vs StringBuilder vs StringBuffer?
- String: Immutable. Slow for concatenation.
- StringBuilder: Mutable. Not thread-safe. Fast.
- StringBuffer: Mutable. Thread-safe (synchronized). Slower than StringBuilder.
5. Difference between == and .equals()?
==compares references (memory address)..equals()compares content (values).
Exceptions & JVM
6. Checked vs Unchecked Exceptions?
- Checked: Checked at compile-time (e.g.,
IOException,SQLException). Must be handled. - Unchecked: Runtime exceptions (e.g.,
NullPointerException,ArrayIndexOutOfBoundsException). Not enforced.
7. Does finally block always execute?
Yes, except when:
System.exit()is called.- Power failure / JVM crash.
- Infinite loop in try/catch.
8. Use of static keyword?
- Variable: Shared copy for all instances.
- Method: Called without instance. Can't access instance members.
- Block: Runs once when class loaded.
- Class: Only nested classes can be static.
AI Mentor
Confused about "Core Java interview questions and concepts"? Ask our AI mentor for a simplified explanation.
Quiz
Quiz
Question 1 of 3Which of the following creates an immutable object?
StringBuilder
String
StringBuffer