Java / Java 17 Garbage Collection Interview Questions
Why is G1 GC the default collector since Java 9?
G1 replaced Parallel GC as the default in JDK 9 (JEP 248) because it offers a better all-around balance for the majority of modern workloads without requiring heavy manual tuning.
Its region-based heap layout lets it collect only the regions with the most reclaimable garbage first rather than being locked into fixed young/old boundaries, and it exposes a soft, configurable pause-time goal (-XX:MaxGCPauseMillis, 200ms by default) that it actively tries to honor by adjusting how much work it does per pause.
This made it a safer default than Parallel GC, which optimizes purely for throughput and can produce long, unpredictable old-gen pauses on larger heaps, and than the now-removed CMS, which was concurrent but non-compacting and prone to heap fragmentation over time.
More Related questions...