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 5: Advanced Java Concepts (Q41–Q50)

🧠 Java Concepts (Q41–Q50)


41. 🧩 What are Inner Classes?

Inner classes are classes defined within another class. They help logically group classes and increase encapsulation.

🔸 Types:

  • Static Nested Class
  • Non-static Inner Class
  • Local Inner Class
  • Anonymous Inner Class

42. 🔒 Use of the synchronized Keyword

The synchronized keyword is used to lock a method or block so that only one thread can access it at a time.

synchronized void update() {
  // critical section
}

📌 Synchronized Keyword Guide

43. 🔁 String vs StringBuilder vs StringBuffer

Feature String StringBuilder StringBuffer Mutability Immutable Mutable Mutable Thread-safe Yes (by design) No Yes Performance Slower Faster (single-threaded) Slower (multi-threaded) 📌 String Comparison

44. 🧱 Immutability in Java

Immutable objects cannot be modified after creation.

✅ Example: String is immutable.

Benefits: Thread safety, cache efficiency, predictability.

📌 Immutability Explained

45. 🧠 Memory Leaks in Java

Java uses garbage collection, but memory leaks can still occur if:

Objects are referenced but unused.

Listeners or caches are not cleared.

📌 Detecting Memory Leaks

46. 🔧 Functional Interfaces

A functional interface has exactly one abstract method.

✅ Examples: Runnable Callable Comparator

📌 Functional Interfaces Guide

47. 🧩 default Keyword in Interfaces

Introduced in Java 8, default allows interfaces to have method implementations.

interface MyInterface {
  default void show() {
    System.out.println("Default method");
  }
}

📌 Default Methods in Interfaces

48. 📅 Enum Type in Java

Enums define a fixed set of constants.

enum Day {
  MONDAY, TUESDAY, WEDNESDAY
}

📌 Java Enum Tutorial

  1. 🔍 Reflection in Java Reflection allows runtime inspection and modification of classes, methods, and fields.

✅ Use Cases: Frameworks (e.g., Spring) Debugging tools Serialization libraries

50. 📦 Java Modules

Introduced in Java 9, modules improve:

Encapsulation Dependency management Packaging

module com.example.myapp {
  requires java.sql;
}

📌 What’s Next?

👉 Explore detailed answers, code samples, use cases, and illustrations in upcoming parts of this series:

Related Posts