Interview prep

Java Interview Questions

Java interviews lean on collections, concurrency and JVM behaviour. Enterprise employers also probe Spring Boot patterns.

Questions and answers

01What is the difference between HashMap and ConcurrentHashMap?

HashMap is unsynchronised and can corrupt or infinite-loop under concurrent writes. ConcurrentHashMap uses per-bin locking and CAS so reads are lock-free and writes contend only on the affected bin.

02Explain the Java memory model in terms of heap and stack.

Each thread has its own stack holding frames and primitives; objects live on the shared heap. Escaping references, not allocation size, are what force objects to survive across frames.

03What does the volatile keyword guarantee?

Visibility and ordering, not atomicity. A volatile read sees the latest write from any thread, but compound operations such as i++ still need synchronisation or an atomic class.

04Checked vs unchecked exceptions — when do you use each?

Checked exceptions model recoverable, caller-actionable conditions; unchecked exceptions model programming errors. Modern codebases lean unchecked and wrap at boundaries rather than propagating checked types everywhere.

05How does garbage collection work on the JVM?

Generational collectors split the heap into young and old regions, collecting the young generation frequently and cheaply. G1 and ZGC add region-based, mostly-concurrent collection to keep pause times bounded.

How to answer these well

Interviewers are not grading recall — they are checking whether you've hit the failure mode the question describes. Anchor every answer to something you actually shipped or debugged with Java.

Say the trade-off out loud. "I'd use X here, but it costs Y under Z conditions" scores higher than a clean textbook definition every time.

Roles asking for Java

Related prep