Java Zero to All All questionsPractise free
Interview questions › Interview Rapid-Fire — Top Q&A › JVM Internals — Top Interview Q&A

G1 GC vs ZGC vs Serial GC?

Level III · MidJVM Internals — Top Interview Q&A
Short answer

The core trade-off is pause time vs throughput vs footprint.

Explanation

Serial is simplest with the least overhead but is single-threaded STW and pauses scale with heap size — good for small heaps/containers. G1 (default since Java 9) divides the heap into regions and balances a configurable pause target (e.g. 200ms) against throughput on large heaps. ZGC (and Shenandoah) are concurrent, do compaction with load/colored-pointer barriers, and target sub-millisecond pauses roughly independent of heap size (multi-terabyte heaps) at some throughput/CPU cost.

Common mistakes
  • Saying ZGC is always best.
  • Ignoring throughput versus latency trade-offs.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for JVM Internals — Top Interview Q&A.

Practise free

More on JVM Internals — Top Interview Q&A