Java Interview Questions for Experienced Professionals
Interviews for experienced Java developers lean less on syntax and more on judgement: how the JVM behaves under load, how you diagnose a production problem, and why you chose one design over another.
Below are senior-level topics with the reasoning interviewers usually want to hear. If you need a refresher on the basics, start with the core Java questions.
JVM internals and performance
How do the main garbage collectors differ?
Parallel GC favours throughput and accepts longer stop-the-world pauses. G1 (the default in modern JDKs) splits the heap into regions and tries to meet a pause-time goal. ZGC and Shenandoah do most of their work concurrently to keep pauses very short, trading some CPU and memory overhead. Choose from measured GC logs and latency targets, not by habit.
How would you investigate a suspected memory leak in production?
Confirm the trend first: heap usage after full GCs keeps climbing. Capture GC logs and a heap dump (jcmd or jmap, or on OutOfMemoryError with -XX:+HeapDumpOnOutOfMemoryError), then open it in a tool such as Eclipse MAT or VisualVM and look at the dominator tree and what holds references. Common culprits are unbounded caches or static collections, listeners never deregistered, ThreadLocals on pooled threads and classloader leaks.
Explain class loading and the delegation model.
A class loader first asks its parent to load a class and only loads it itself if the parent cannot. This keeps core classes (java.lang.*) from being replaced. Application servers and plugin systems use separate loaders for isolation, which is also why a leaked reference to a class from a redeployed application can prevent its loader from being collected.
Concurrency and the Java Memory Model
What does happens-before mean?
It is the Java Memory Model's guarantee about visibility and ordering: if action A happens-before action B, A's effects are visible to B. Examples are unlocking a monitor before a later lock of the same monitor, a volatile write before a later volatile read of the same variable, and Thread.start() before anything in the started thread. Without such a relationship, one thread may never see another's writes.
What are virtual threads and when should you use them?
Virtual threads (final in Java 21) are lightweight threads scheduled by the JVM onto a small pool of carrier threads. They suit workloads with many tasks that mostly block on I/O, letting you write simple thread-per-request code. They do not speed up CPU-bound work. In JDK 21 to 23, blocking inside a synchronized block can pin the carrier thread, so prefer ReentrantLock there.
Design and data
How do you design an immutable class?
Make the class final (or use a record), make all fields private and final, set them only in the constructor, and defensively copy any mutable inputs and outputs. Immutable objects are inherently thread-safe and safe as map keys.
public record Money(java.math.BigDecimal amount, String currency) {
public Money {
java.util.Objects.requireNonNull(amount);
java.util.Objects.requireNonNull(currency);
}
}Optimistic vs pessimistic locking?
Pessimistic locking locks the row up front (SELECT ... FOR UPDATE) and suits high contention. Optimistic locking lets everyone read, then detects conflicting writes at commit time using a version column (@Version in JPA) and retries or fails. Optimistic locking scales better when conflicts are rare.
A request that used to take 200 ms now takes 2 s. How do you find out why?
Measure before changing anything: check traces or logs to see which layer slowed down, compare against a recent deploy, then profile (thread dumps, a sampling profiler or flight recorder) and inspect slow queries, connection pool waits, GC pauses and downstream calls. Fix the bottleneck you measured and verify the improvement.
What interviewers look for at senior level
- Trade-offs explained out loud, not just a "right" answer.
- Evidence-driven troubleshooting: logs, metrics, dumps and profiles before guesses.
- Clear reasoning about concurrency, failure modes and data consistency.
- Examples from systems you have actually built or operated.
Practice this on Quick Tech Learners
Reading answers is only the first step. Quick Tech Learners lets you turn senior-level Java topics into active practice once you create an account and sign in.
- Interview Insights: browse interview questions shared by the community and filter them by topic tag.
- Practice Quiz: choose the concepts you want to revise, answer questions, and review how you did.
- Coding Practice: write and run code in a browser editor against test cases. Pick a language, a difficulty band from Beginner to Expert, and either Practice mode (with hints) or Interview mode.
- Study Plan and reports: set the topics you are preparing, then check performance, mastery and readiness reports to see where the gaps are.
- Share Interview Question: add a question you were asked so other learners can practise it.