What are the default garbage collectors in different Java versions?

The default Garbage Collector in Java has evolved over different releases to improve performance, scalability, and pause-time behavior. Earlier Java versions prioritized throughput, while modern versions focus on balancing throughput and low-latency requirements for enterprise applications.

Key Points: • Java 8 uses Parallel GC as the default collector, focusing on maximum throughput. • Starting from Java 9, G1 GC became the default collector due to its predictable pause times and better performance on large heaps. • Modern Java versions continue to use G1 GC by default, while ZGC and Shenandoah are available as alternatives for ultra-low latency applications.

Default Garbage Collectors by Version:

Java 5 – Java 8 • Default GC: Parallel GC (Throughput Collector) • Optimized for high throughput. • Suitable for batch processing and server applications.

Java 9 – Java 10 • Default GC: G1 GC (Garbage First) • Introduced as the default collector. • Provides a balance between throughput and pause times.

Java 11 – Java 17 (LTS) • Default GC: G1 GC • Improved memory management and pause-time predictability. • Widely used in enterprise applications.

Java 18 – Java 24+ (Latest Stable Releases) • Default GC: G1 GC • Continues to be the default collector. • Enhanced through continuous performance improvements.

Other Available Garbage Collectors: • Serial GC - Small applications and low-memory environments. • Parallel GC - High throughput workloads. • G1 GC - General-purpose and enterprise applications. • ZGC - Ultra-low latency with very large heaps. • Shenandoah GC - Low pause times and predictable performance. • Epsilon GC - No-op collector used for testing and benchmarking.

Example: A Java 8 application will use Parallel GC by default unless configured otherwise. The same application running on Java 17 will automatically use G1 GC, benefiting from better pause-time management and scalability.

Interview Tip: A concise interview answer is: Parallel GC was the default collector from Java 5 through Java 8. Starting with Java 9, G1 GC became the default and remains the default in modern Java releases because it provides a good balance between throughput, scalability, and predictable pause times. For specialized low-latency workloads, ZGC and Shenandoah are available as alternatives.