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

Java Interview Guide - Part 3: Advanced Java Concepts (Q21–Q30)

📚 Java Advanced Concepts (Q21–Q30)


21. 📦 Java Collections Framework

The Java Collections Framework (JCF) is a unified architecture for storing and manipulating groups of objects.

🔑 Core Interfaces:

  • List: Ordered collection (e.g., ArrayList, LinkedList)
  • Set: No duplicate elements (e.g., HashSet, TreeSet)
  • Map: Key-value pairs (e.g., HashMap, TreeMap)

22. 🔁 ArrayList vs LinkedList

FeatureArrayListLinkedList
Backed byDynamic arrayDoubly-linked list
Access timeFast (O(1))Slow (O(n))
Insert/DeleteSlower (shifting required)Faster (no shifting)
Memory usageLess overheadMore overhead (node pointers)

23. 🧠 HashMap Internal Working

  • Stores key-value pairs using a hash table.
  • Key is hashed → index is calculated → value is stored.
  • Collisions are handled using LinkedList or Red-Black Trees (Java 8+).

24. 🧮 equals() vs hashCode()

MethodPurpose
equals()Checks logical equality of objects
hashCode()Returns hash value for use in hash-based collections

25. 🔄 Comparable vs Comparator

FeatureComparableComparator
Packagejava.langjava.util
MethodcompareTo()compare()
Use caseNatural orderingCustom ordering
ImplementationImplemented by classPassed as argument

26. 🧠 Java Memory Model (JMM)

The Java Memory Model defines how threads interact through memory:

  • Ensures visibility and ordering of shared variables.
  • Prevents race conditions and inconsistent reads.

27. 🗑️ Garbage Collection in Java

Garbage Collection (GC) automatically reclaims memory by:

  • Identifying unreachable objects.
  • Deallocating memory in the heap.
  • Using algorithms like Mark-and-Sweep, G1, etc.

28. 🏷️ Java Annotations

Annotations provide metadata about code.

Common Annotations:

  • @Override: Indicates method overrides a superclass method.
  • @Deprecated: Marks method as outdated.
  • @SuppressWarnings: Suppresses compiler warnings.

29. 🔀 Lambda Expressions

Lambda expressions provide a concise way to implement functional interfaces.

List<Integer> list = Arrays.asList(1, 2, 3);
list.forEach(n -> System.out.println(n));

Benefits: Less boilerplate Enables functional programming

30. 🌊 Stream API in Java

The Stream API processes collections in a functional style.

Key Operations: filter(): Filters elements

map(): Transforms elements

reduce(): Aggregates elements

List<String> names = Arrays.asList("Alice", "Bob", "Charlie");
names.stream().filter(n -> n.startsWith("A")).forEach(System.out::println);

📌 What’s Next?

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

Related Posts