Core Java

The Java fundamentals every interview starts with — OOP, Strings & Collections, Java 8+ features, exception handling, multithreading, JVM internals, and the DSA problems that show up alongside them.

Inner Classes

JVM Internals & Memory

Q

What is the difference between Minor GC, Major GC, and Full GC?

intermediate

Tests whether you know exactly which memory regions each GC type actually sweeps.

Q

What is an OutOfMemoryError vs StackOverflowError?

intermediate

Tests whether you know these are triggered by two completely different memory regions filling up.

Q

G1 GC vs ZGC vs Shenandoah — when would you choose each?

advanced

Tests whether you know the pause-time and throughput tradeoffs across modern collectors, not just their names.

Q

Heap keeps growing even after a Full GC runs. How do you debug it?

advanced

Tests whether you recognize this as the classic memory-leak signature and know the heap-dump workflow to isolate it.

Q

Production throws OutOfMemoryError: Metaspace. What could cause it?

advanced

Tests whether you know Metaspace exhaustion usually points to classloader leaks, not regular object allocation.

Q

Java heap is stable, but overall process memory keeps growing. Why?

advanced

Tests whether you know to look past the heap entirely — direct ByteBuffers, Netty off-heap memory, or JNI leaks.

Q

Your application pauses frequently, but GC logs look completely normal. What's going on?

advanced

Tests whether you know JVM safepoints (biased lock revocation, deoptimization) can freeze threads independently of GC.

Q

What is Escape Analysis? Why is it useful?

advanced

Tests whether you know the JIT can allocate objects on the stack instead of the heap when it proves they never escape a method.

Q

What is the Parent Delegation Model in class loading, and why is it important?

intermediate

Tests whether you know why a class request always goes up the classloader hierarchy first, and what that prevents.

Q

How do you capture and analyze a heap dump using Eclipse MAT — what do you actually look for?

advanced

Tests whether you know the practical workflow: dominator tree, retained size, and finding the actual leak suspect.

Q

What is TLAB (Thread Local Allocation Buffer) and how does it improve allocation performance?

advanced

Tests whether you know how the JVM avoids lock contention on every single object allocation.

Q

What is GC ergonomics and how does the JVM auto-tune GC settings?

intermediate

Tests whether you know the JVM picks sensible defaults based on hardware and heap size without any flags at all.

Q

What are the different memory areas in JVM?

beginner

Tests whether you know the heap, stack, metaspace, and PC register layout and what lives where.

Q

What is Garbage Collection and how does it work?

intermediate

Tests whether you understand generational GC, reachability, and why Java doesn't need manual memory management.

Q

What is ClassLoader? Explain the delegation model.

intermediate

Tests whether you know why a class request is always delegated upward first, and what that prevents.

Q

What is the difference between WeakReference, SoftReference, and PhantomReference?

advanced

Tests whether you know these three reference types and how each affects when the GC is allowed to reclaim an object.

Q

How does the JIT compiler work?

advanced

Tests whether you understand how the JVM detects hot code paths and compiles them to native machine code at runtime.

Java Basics & OOP

Q

What is the difference between JDK, JRE, and JVM?

beginner

Tests whether you understand the three nested layers of the Java platform and what each one is actually responsible for.

Q

Explain the 4 pillars of OOP with real-world examples.

beginner

Checks whether you can explain encapsulation, abstraction, inheritance, and polymorphism with concrete examples, not just definitions.

Q

What is the difference between == and .equals() in Java?

beginner

Tests your understanding of reference equality versus logical equality, and where each one silently trips people up.

Q

What is method overloading vs method overriding?

beginner

Tests whether you know compile-time vs runtime polymorphism and the rules that govern each.

Q

What is the difference between abstract class and interface?

beginner

Tests whether you know when to use each, especially after Java 8 added default and static methods to interfaces.

Q

Explain the 'static' keyword — static variable, method, block, class.

beginner

Tests whether you understand what 'belongs to the class, not the instance' actually means in memory and execution order.

Q

What is the difference between pass-by-value and pass-by-reference in Java?

beginner

A classic trick question — tests whether you know Java is always pass-by-value, even for objects, and why that still confuses people.

Q

What is autoboxing and unboxing?

beginner

Tests whether you know how Java silently converts between primitives and wrapper classes, and where that costs performance.

Q

What is the diamond problem and how does Java 8 solve it with default methods?

advanced

Tests whether you understand multiple inheritance ambiguity and the specific resolution rules Java applies for default methods.

Q

Explain how 'instanceof' works and what pattern matching for instanceof (Java 16) does.

advanced

Tests whether you know the classic instanceof check plus the newer syntax that eliminates the redundant cast afterward.

File I/O & NIO

String & StringBuilder

Multithreading & Concurrency

Q

Why do Virtual Threads become pinned and lose scalability?

advanced

Tests whether you know synchronized blocks and native calls can pin a virtual thread to its carrier thread.

Q

What is structured concurrency in Java 21+ and why is it better than raw CompletableFuture chains?

advanced

Tests whether you know how it ties a group of subtasks' lifetimes together for cleaner cancellation and error handling.

Q

Why are exceptions inside CompletableFuture chains often missed silently?

advanced

Tests whether you know an unhandled exception in a chain just completes the future exceptionally, with nothing logged unless you check.

Q

ConcurrentHashMap is thread-safe, yet race conditions can still exist in code that uses it. Why?

advanced

Tests whether you know thread-safety of individual operations doesn't make compound check-then-act sequences atomic.

Q

Why can increasing the thread pool size actually reduce application performance?

advanced

Tests whether you know excessive threads can increase context-switching overhead and contention beyond a certain point.

Q

What is the difference between synchronized, ReentrantLock, and StampedLock?

advanced

Tests whether you know the tradeoffs in fairness, interruptibility, and read/write optimization across the three.

Q

What is the difference between CountDownLatch, CyclicBarrier, and Semaphore?

advanced

Tests whether you know these three synchronization tools solve genuinely different coordination problems.

Q

How does ForkJoinPool differ from a regular ThreadPoolExecutor?

advanced

Tests whether you know work-stealing is what makes ForkJoinPool efficient for divide-and-conquer tasks specifically.

Q

What happens when you submit too many tasks to a ThreadPoolExecutor — what are the rejection policies?

advanced

Tests whether you know the four built-in RejectedExecutionHandler strategies and when each is appropriate.

Q

What is a race condition and how is it different from a data race?

advanced

Tests whether you know these overlapping-sounding terms actually describe two distinct classes of concurrency bug.

Q

A ThreadLocal variable in your app is causing a memory leak. How does that happen, and how do you fix it?

advanced

Tests whether you know pooled threads never die, so a ThreadLocal never cleared keeps leaking across every reused thread.

Q

What is the difference between a Thread and a Process?

beginner

Tests whether you understand shared vs isolated memory space and why threads are cheaper to create.

Q

What is the difference between wait(), notify(), and notifyAll()?

intermediate

Tests whether you understand Java's low-level thread coordination primitives and the monitor lock they require.

Q

What is a deadlock? How can you detect and prevent it?

intermediate

Tests whether you know the four necessary conditions for deadlock and practical strategies to avoid them.

Q

What is the volatile keyword in Java?

intermediate

Tests whether you know volatile guarantees visibility, not atomicity — one of the most commonly misunderstood keywords.

Q

What is ExecutorService? How is it better than creating raw threads?

intermediate

Tests whether you know why managed thread pools beat manually creating and managing Thread objects in production code.

Q

What is a thread-safe Singleton? Implement double-checked locking.

advanced

Tests whether you can correctly write the volatile + double-checked-locking pattern, a classic concurrency coding question.

Q

What is the Java Memory Model (JMM)? Explain happens-before.

advanced

Tests whether you understand the formal rules that govern visibility and ordering across threads — deep concurrency territory.

Q

What is CompletableFuture? How does it differ from Future?

advanced

Tests whether you know how to chain and combine async operations rather than blocking with Future.get().

Arrays & Matrices

Collections Framework

Q

Explain the Collections hierarchy — List, Set, Map, Queue.

beginner

Tests whether you have a clear mental map of Java's core collection interfaces and how they relate to each other.

Q

How does HashMap work internally? (hashing, buckets, collision)

intermediate

One of the most-asked Java questions — tests whether you actually understand hashing, bucket placement, and collision resolution, not just usage.

Q

What is the difference between HashMap and Hashtable?

intermediate

Tests whether you know the thread-safety, null-key, and performance differences between these two legacy-adjacent classes.

Q

A HashMap has millions of entries and suddenly becomes slow. How would you investigate?

advanced

Tests whether you know to check hashCode() quality, load factor, and whether entries are treeifying due to collisions.

Q

How does ConcurrentHashMap differ from HashMap?

intermediate

Tests whether you understand segment/bucket-level locking and why it beats simply synchronizing a whole HashMap.

Q

What is fail-fast vs fail-safe iterator?

intermediate

Tests whether you know why ConcurrentModificationException happens and which collections avoid it, and how.

Q

You insert a mutable object as a HashMap key and later modify it. What can go wrong?

advanced

Tests whether you know a changed hashCode() after insertion makes the entry effectively unfindable at its original bucket.

Q

Your CopyOnWriteArrayList is creating high memory usage and GC pressure. Why?

advanced

Tests whether you know every single write copies the entire underlying array, which is brutal for write-heavy or large lists.

Q

Implement an LRU cache using LinkedHashMap.

advanced

A very common coding-round question testing whether you know LinkedHashMap's access-order mode and removeEldestEntry hook.

Q

What happens when HashMap capacity exceeds load factor? Explain rehashing.

advanced

Tests whether you understand the resize trigger, the doubling behavior, and why rehashing is expensive.

Q

A ConcurrentModificationException occurs in a single-threaded application. How is that possible?

advanced

Tests whether you know this exception is about structural modification during iteration, not literally about concurrent threads.

Q

You're reviewing production code using Collections.synchronizedMap(). Would you keep it or replace it? What factors decide?

advanced

Tests whether you can weigh whole-map locking against ConcurrentHashMap's finer-grained concurrency for the actual access pattern.

Q

Why can a poor hashCode() implementation destroy HashMap performance?

advanced

Tests whether you know a constant or low-quality hashCode collapses lookups from O(1) toward O(n) by funneling everything into one bucket.

Q

Two threads call computeIfAbsent() for the same key on a ConcurrentHashMap at the same time. What behavior do you expect?

advanced

Tests whether you know ConcurrentHashMap guarantees the mapping function runs atomically per key, avoiding duplicate computation.

Q

What is EnumMap and why is it more performant than HashMap for enum keys?

intermediate

Tests whether you know EnumMap uses ordinal-based array indexing instead of general-purpose hashing.

Q

You need the top 10 most frequent items out of millions of events. Which collections would you combine to solve this efficiently?

advanced

Tests whether you know to pair a frequency HashMap with a bounded PriorityQueue instead of sorting everything.

Q

A cache should automatically release entries when their keys are no longer strongly referenced elsewhere. What would you use?

advanced

Tests whether you know WeakHashMap lets the garbage collector reclaim entries whose keys have become otherwise unreachable.

Java 8+ Features

Exception Handling

Modern Java (11-25)

Q

Are Java Records truly immutable? What are their limitations?

intermediate

Tests whether you know records give you shallow immutability for their own fields, not deep immutability of referenced objects.

Q

What are Sealed Classes in Java 17 — how do they enforce domain modeling?

intermediate

Tests whether you know sealed types let you declare an exhaustive, closed set of permitted subtypes at compile time.

Q

What is Pattern Matching for switch (Java 21) and how does it improve type-safe branching?

intermediate

Tests whether you know how it eliminates the manual instanceof-and-cast boilerplate switch statements used to require.

Q

What are Sequenced Collections in Java 21?

intermediate

Tests whether you know this new interface finally gives a consistent way to access first/last elements across ordered collection types.

Q

How does Java 21's virtual thread implementation handle blocking I/O internally — what is carrier thread pinning?

advanced

Tests whether you understand the mechanism that lets thousands of virtual threads share a small pool of OS carrier threads.

Q

What is the difference between var (Java 10) and explicitly typed declarations — when does var hurt readability?

intermediate

Tests whether you know var is fine when the type is obvious from context, but can obscure intent when it isn't.

Q

Java 25 Compact Object Headers (JEP 519) — what does it mean for production workloads?

advanced

Tests whether you're current on recent JVM changes and know what shrinking object headers actually saves in practice.

DSA — Problem-Solving Patterns

Q

What is the Sliding Window pattern in DSA, and what class of problems does it solve efficiently?

intermediate

Tests whether you can recognize when a shrinking/growing window beats a brute-force nested loop.

Q

What is the two-pointer pattern? Give an example problem where it turns an O(n²) solution into O(n).

intermediate

Tests whether you know how converging pointers from both ends of a sorted structure eliminate redundant comparisons.

Q

What is the fast & slow pointers pattern? How does it detect a cycle in a linked list?

intermediate

Tests whether you know Floyd's algorithm and why two pointers moving at different speeds must eventually meet in a cycle.

Q

What is the merge intervals pattern? Walk through merging a list of overlapping intervals.

intermediate

Tests whether you know to sort by start time first, then merge in a single linear pass.

Q

What is the Top K Elements pattern using a heap, and why is it more efficient than sorting the entire dataset?

advanced

Tests whether you know a bounded heap gets you the top K in O(n log k) instead of paying for a full O(n log n) sort.

Q

What is the 0/1 Knapsack dynamic programming pattern, and what other problems share its structure?

advanced

Tests whether you can recognize the include-or-exclude decision structure that generalizes to many DP problems.

Q

What is the topological sort graph pattern? How does it apply to a course-scheduling / build-order problem?

advanced

Tests whether you know how to order nodes in a DAG so every dependency is processed before what depends on it.

Q

Find the Kth largest element in a stream of numbers, where new numbers keep arriving.

advanced

Tests whether you know to maintain a fixed-size min-heap instead of re-sorting on every new element.

Q

Implement an LFU (Least Frequently Used) Cache with O(1) get and put.

advanced

Tests whether you can design a harder variant of LRU that also tracks access frequency, not just recency.

Q

Find the median from a data stream — numbers keep arriving one at a time, and you must return the median at any point.

advanced

Tests whether you know the two-heap technique (a max-heap and a min-heap balanced against each other) for this classic problem.

Q

Solve the Word Ladder problem — find the shortest transformation sequence from one word to another, changing one letter at a time.

advanced

Tests whether you know to model this as a graph shortest-path problem and solve it with BFS.