Java interviews test depth: the JVM, the garbage collector, the memory model, and modern language features. These 25 questions cover what interviewers actually ask in 2026 — including JDK 21 features (records, sealed classes, virtual threads).
JVM & memory (Q1–Q8)
- What is the JVM? The Java Virtual Machine — executes bytecode, manages memory, JIT, GC, threads.
- What is the JIT? Just-in-time compiler compiles hot bytecode paths to native code at runtime.
- What is the GC? Garbage collection — automatic memory management. G1 is default since JDK 9; ZGC and Shenandoah are low-pause.
- Stack vs heap — stack holds local references + primitives; heap holds objects.
- What is the JMM? Java Memory Model — defines happens-before. `volatile`, `synchronized`, `final` guarantee visibility.
- What are the classloaders? Bootstrap → Platform → Application. Custom loaders for OSGi / hot reload.
- What is bytecode? Intermediate .class format. `javap` disassembles; ASM manipulates.
- What is the metaspace? Native memory for class metadata (replaced PermGen in Java 8).
Language features (Q9–Q17)
- `==` vs `.equals()` — `==` compares references; `.equals()` compares contents.
- Generics + erasure — type parameters are erased at runtime; `List` and `List` share bytecode.
- PECS — Producer Extends Consumer Super. Use `? extends T` for read, `? super T` for write.
- `Optional` — represents a value-or-absent. Avoid as a method parameter.
- Streams — lazy intermediate ops + eager terminal ops. Use parallel streams carefully.
- Records — `record Point(int x, int y)` — auto-generates accessors, equals, hashCode, toString.
- Sealed classes — `sealed interface Shape permits Circle, Square`. Enables exhaustive switch.
- Pattern matching switch — `case Integer i when i > 0 -> ...`. JDK 21.
- Virtual threads — JDK 21 lightweight threads (millions per JVM). Eliminates thread-pool sizing for I/O.
Concurrency (Q18–Q25)
- `synchronized` vs `ReentrantLock` — `ReentrantLock` supports timed waits, interruptible locks, condition variables.
- `volatile` guarantees — visibility + prevents instruction reordering. Not atomic.
- `ConcurrentHashMap` — fine-grained locking; allows concurrent reads + structured concurrent writes.
- `CompletableFuture` — composable async. `thenApply`, `thenCompose`, `thenCombine`, `allOf`.
- Thread pools — `ExecutorService`, `ForkJoinPool`, structured concurrency (preview in JDK 21+).
- Deadlock detection — `jstack`, `jcmd`, thread dumps, ThreadMXBean.
- Structured concurrency — treat related threads as a unit; failure in one cancels the others.
- Atomic classes — `AtomicInteger`, `AtomicReference`. Lock-free CAS operations.
How to structure answers — the SAAR-Java template
Strong Java answers follow a four-part template: definition, mechanism, code, pitfall. The interviewer cares less about the exact words and more about whether you can explain trade-offs and write idiomatic code on the board. Practise writing 10-line snippets on a whiteboard or paper before the interview — muscle memory matters more than screen-completion speed.
- Definition — one sentence stating what the concept is.
- Mechanism — one or two sentences on how it works internally (JMM, GC, lock contention).
- Code — 5–10 lines showing idiomatic usage.
- Pitfall — the one mistake candidates make (e.g., `volatile` is not atomic, `==` vs `.equals()` on Strings).
Modern Java: JDK 17, 21, and what's next
JDK 21 is the release interviewers ask about most in 2026. LTS (Long-Term Support) releases come every two years; JDK 17 (2021) and JDK 21 (2023) are the current LTS. JDK 25 will be the next LTS (September 2025). Know the headline features of each so you can pick the right tool.
- JDK 17 (LTS) — sealed classes (finalised), records (finalised), pattern matching for switch (preview), strong encapsulation of JDK internals.
- JDK 21 (LTS) — virtual threads (finalised, Project Loom), structured concurrency (preview), scoped values (preview), pattern matching for switch (finalised), string templates (preview).
- JDK 25 (next LTS) — finalisation of scoped values, structured concurrency, and string templates; further Project Loom integration.
- Performance — generational ZGC (JDK 21) cuts allocation pause times for large heaps; the JIT continues to improve with each release.
Performance and JVM tuning — what interviewers care about
Senior Java interviews go beyond language features into JVM tuning. Know the flags, know the GC algorithms, and know what to look at first when an application is slow.
- Heap sizing — `-Xms`/`-Xmx`; ratio of young to old generation; metaspace sizing.
- GC choice — G1 (default), ZGC (low pause), Parallel (throughput), Shenandoah (low pause, Red Hat). Match GC to SLO.
- Profiling — JFR + JDK Mission Control; async-profiler for flame graphs; JITWatch for inlining analysis.
- Memory leaks — heap dumps via `jmap`, analysis in Eclipse MAT or VisualVM; native leaks via `jemalloc` / `libunwind`.
- Threading — thread dumps via `jstack`, contention analysis with `fastthread.io` or `console-threads`.
Resources for deeper study
These 25 questions cover the surface. To go deeper, read the JLS (Java Language Specification), JEP (JDK Enhancement Proposal) index, and at least one book on concurrency and one on performance.
- Books — "Effective Java" (3rd edition) by Joshua Bloch, "Java Concurrency in Practice" by Brian Goetz, "Optimizing Java" by Benjamin Evans.
- Online — Baeldung (tutorials), Inside Java (podcast + talks), the OpenJDK mailing lists.
- Practice — LeetCode for algorithms, HackerRank for Java-specific exercises, Advent of Code for end-to-end problems.
- Certifications — Oracle Certified Professional: Java SE 11 Developer, OCP Java SE 21 Developer (newer track).






