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 Guide - Part 2: Advanced Java Concepts (Q11–Q20)

🔍 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.
FeatureInterfaceAbstract Class
MethodsAbstract (default), static, defaultAbstract + Concrete
Multiple InheritanceYes (via implements)No (only single inheritance)
ConstructorNot allowedAllowed

12. 🔐 Access Modifiers in Java

ModifierScope
publicAccessible from anywhere
protectedAccessible within same package and subclasses
defaultAccessible within same package only
privateAccessible within the same class only

13. 📦 Encapsulation in Java

Encapsulation is the process of wrapping data and methods into a single unit (class).

✅ Implementation:

  1. Declare variables as private.
  2. 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

StateDescription
NewThread is created
RunnableReady to run
RunningActively executing
BlockedWaiting for a resource
TerminatedExecution 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

KeywordPurpose
throwUsed to explicitly throw an exception
throwsDeclares exceptions a method might throw

19. ✅ Checked vs Unchecked Exceptions

TypeChecked atExamples
CheckedCompile-timeIOException, SQLException
UncheckedRuntimeNullPointerException, 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