Java Interview Guide - Part 2: Advanced Java Concepts (Q11–Q20)
A comprehensive list of essential Java interview questions covering OOP, memory management, exceptions, collections, Streams, JDBC.
Java Interview Series
Part 2 of 6
Table of Contents
- 🔍 Advanced Java Concepts (Q11–Q20)
- 11. 🧩 Interface vs Abstract Class in Java
- 12. 🔐 Access Modifiers in Java
- 13. 📦 Encapsulation in Java
- 14. 🗂️ Packages in Java
- 15. ⚙️ Static Variables and Methods
- 16. 🔄 Thread Lifecycle in Java
- 17. ⚠️ Exception Handling in Java
- 18. 🧨 throw vs throws
- 19. ✅ Checked vs Unchecked Exceptions
- 20. 🔒 Synchronization in Java
- 📌 What’s Next?
🔍 Advanced Java Concepts (Q11–Q20)
11. 🧩 Interface vs Abstract Class in Java
🔹 Interface
- A collection of abstract methods and static constants.
- Can include default and static methods (since Java 8).
- A class can implement multiple interfaces.
🔸 Abstract Class
- Can have both abstract and concrete methods.
- A class can extend only one abstract class.
Feature | Interface | Abstract Class |
---|---|---|
Methods | Abstract (default), static, default | Abstract + Concrete |
Multiple Inheritance | Yes (via implements) | No (only single inheritance) |
Constructor | Not allowed | Allowed |
12. 🔐 Access Modifiers in Java
Modifier | Scope |
---|---|
public | Accessible from anywhere |
protected | Accessible within same package and subclasses |
default | Accessible within same package only |
private | Accessible within the same class only |
13. 📦 Encapsulation in Java
Encapsulation is the process of wrapping data and methods into a single unit (class).
✅ Implementation:
- Declare variables as
private
. - Provide
public
getter and setter methods.
class Person {
private String name;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}
14. 🗂️ Packages in Java
Packages are namespaces that group related classes and interfaces.
✅ Benefits:
- Avoids name conflicts
- Improves code organization
- Supports modular development
15. ⚙️ Static Variables and Methods
- Static Variable: Shared across all instances of a class.
- Static Method: Belongs to the class, not instances.
class Example {
static int count = 0;
static void display() {
System.out.println("Count: " + count);
}
}
16. 🔄 Thread Lifecycle in Java
State | Description |
---|---|
New | Thread is created |
Runnable | Ready to run |
Running | Actively executing |
Blocked | Waiting for a resource |
Terminated | Execution completed |
17. ⚠️ Exception Handling in Java
Java handles runtime errors using:
try {
// risky code
} catch (Exception e) {
// handle error
} finally {
// cleanup code
}
Keywords:
try
,catch
,throw
,throws
,finally
18. 🧨 throw vs throws
Keyword | Purpose |
---|---|
throw | Used to explicitly throw an exception |
throws | Declares exceptions a method might throw |
19. ✅ Checked vs Unchecked Exceptions
Type | Checked at | Examples |
---|---|---|
Checked | Compile-time | IOException , SQLException |
Unchecked | Runtime | NullPointerException , ArithmeticException |
20. 🔒 Synchronization in Java
Synchronization ensures that only one thread accesses a critical section at a time.
synchronized void updateBalance() {
// critical section
}
📌 What’s Next?
👉 Explore detailed answers, code samples, use cases, and illustrations in upcoming parts of this series:
Related Posts
Java Interview Guide - Part 4: Advanced Java Concepts (Q31–Q40)
A comprehensive list of essential Java interview questions covering OOP, memory management, exceptions, collections, and Streams
Java Interview Guide - Part 5: Advanced Java Concepts (Q41–Q50)
A comprehensive list of essential Java interview questions covering OOP, memory management, exceptions, collections, and Streams
Java Interview Guide - Part 3: Advanced Java Concepts (Q21–Q30)
A comprehensive list of essential Java interview questions covering OOP, memory management, exceptions, collections, and Streams