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 Series
Part 3 of 6
Table of Contents
- 📚 Java Advanced Concepts (Q21–Q30)
- 21. 📦 Java Collections Framework
- 22. 🔁 ArrayList vs LinkedList
- 23. 🧠 HashMap Internal Working
- 24. 🧮 equals() vs hashCode()
- 25. 🔄 Comparable vs Comparator
- 26. 🧠 Java Memory Model (JMM)
- 27. 🗑️ Garbage Collection in Java
- 28. 🏷️ Java Annotations
- 29. 🔀 Lambda Expressions
- 30. 🌊 Stream API in Java
- 📌 What’s Next?
📚 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
Feature | ArrayList | LinkedList |
---|---|---|
Backed by | Dynamic array | Doubly-linked list |
Access time | Fast (O(1)) | Slow (O(n)) |
Insert/Delete | Slower (shifting required) | Faster (no shifting) |
Memory usage | Less overhead | More 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()
Method | Purpose |
---|---|
equals() | Checks logical equality of objects |
hashCode() | Returns hash value for use in hash-based collections |
25. 🔄 Comparable vs Comparator
Feature | Comparable | Comparator |
---|---|---|
Package | java.lang | java.util |
Method | compareTo() | compare() |
Use case | Natural ordering | Custom ordering |
Implementation | Implemented by class | Passed 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
Java Interview Guide - Part 1: Core Questions (1–10)
A comprehensive list of essential Java interview questions covering OOP, memory management, exceptions, collections
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 4: Advanced Java Concepts (Q31–Q40)
A comprehensive list of essential Java interview questions covering OOP, memory management, exceptions, collections, and Streams