Interview replay
Full round replay — heap and stack
Timed verbal replay with pass/fail criteria per follow-up.
How to run this
The opener
“What lives on the heap and what lives on the stack?”
Budget: 45 seconds. Going long here is itself a fail signal.
Follow-ups
1. “Are primitives always on the stack?”
Testing: The single most common half-learned rule in Java.
Scoring
Pass: Only locals. A primitive field lives inside its object on the heap, and an int[] is a heap object. The split is locals vs the object graph, not primitives vs objects.
Fail: 'Yes' — or 'yes, unless boxed', which is a different fact.
2. “So is every object on the heap?”
Testing: Do they know escape analysis exists, and that it is measurable?
Scoring
Pass: Not necessarily. C2 can prove an object never escapes and scalar-replace it, so the allocation never happens. Names it as a JIT optimisation, not a guarantee, and notes it needs warm-up.
Fail: 'Yes, always' stated as a language rule.
3. “StackOverflowError or OutOfMemoryError — how do you tell them apart, and what do you change?”
Testing: Region, knob, blast radius.
Scoring
Pass: Different regions: one thread's frames vs the shared heap. -Xss vs -Xmx. Reads the OOM message, because 'Java heap space' and 'Requested array size exceeds VM limit' need different responses.
Fail: Treats them as the same 'out of memory' problem, or reaches straight for a bigger flag.
4. “A service is OOMKilled by its container, with no OutOfMemoryError in the log. What happened?”
Testing: Does -Xmx cover the whole process? Separates people who have run a JVM in Kubernetes from people who have not.
Scoring
Pass: The memory that ran out was not the heap. Stacks, Metaspace, code cache, direct buffers and GC structures are outside -Xmx but inside the container limit. Leave headroom; turn on native memory tracking.
Fail: 'Raise the memory limit' with no mechanism, or assumes the heap dump would show it.
5. “Where do static fields live?”
Testing: Almost everyone says Metaspace. JEP 122 moved statics to the heap.
Scoring
Pass: The slot is on the heap, inside the java.lang.Class mirror — JEP 122 moved static variables and interned strings there when PermGen went. Only the metadata is in Metaspace. Connects it to why a static collection leaks: the class is a GC root.
Fail: 'Metaspace' with no qualification, 'on the stack', or 'PermGen' without noticing that went away in 8.
6. “Where does a virtual thread's stack live?”
Testing: Java 21 awareness, and whether they know why it matters.
Scoring
Pass: On the heap, as a chunked continuation that grows on demand and is copied back on unmount. That is why a million virtual threads is affordable where a million platform threads is not.
Fail: 'Same as a normal thread' or 'virtual threads don't have stacks'.
Score yourself
← Back to What lives on the heap and what lives on the stack?