Java / JVM Architecture (Java21) Interview questions
What are the types of garbage collectors available in Java 21?
Java 21 ships five HotSpot garbage collectors that a developer can select with a command-line flag.
| Collector | Enable flag | Focus |
| Serial GC | -XX:+UseSerialGC | Single-threaded, small heaps |
| Parallel GC | -XX:+UseParallelGC | Multi-threaded, throughput |
| G1 GC | -XX:+UseG1GC | Balanced pause/throughput (default) |
| ZGC | -XX:+UseZGC | Very low pause, large heaps |
| Shenandoah | -XX:+UseShenandoahGC | Low pause, concurrent compaction |
G1 remains the default collector, while ZGC runs in its new generational mode by default as of Java 21 (JEP 439), replacing the older single-generation ZGC behavior.
More Related questions...