Definition
The Java heap is split into two main generations based on object age. The Young Generation holds newly created objects and is itself divided into Eden and two Survivor spaces (S0 and S1). Objects are born in Eden, and the ones that survive repeated Minor GCs are copied between Survivor spaces and have their age counter increased. Once an object's age crosses a tenuring threshold, it is promoted into the Old Generation, which holds long-lived objects and is collected far less often. This design is based on the generational hypothesis: most objects die young.
Understanding the Concepts
What is Young Generation vs Old Generation?
When you create an object with new, the JVM places it in Eden, the largest part of the Young Generation. Eden fills quickly because programs allocate constantly. When Eden is full, a Minor GC runs. It uses a copying collector: it finds the live objects (reachable ones) and copies them into one of the two Survivor spaces, then wipes all of Eden at once. Because most objects in Eden are already dead by the time GC runs, copying only a few survivors is very fast.
How do Survivor spaces work?
The two Survivor spaces, S0 and S1, work as a pair. At any moment one is empty. During a Minor GC, live objects from Eden and from the currently-occupied Survivor space are copied into the empty one, and then the roles swap. Each time an object survives a copy, its age counter increments. This back-and-forth copying compacts the survivors and avoids fragmentation.
Before Minor GC: After Minor GC: ┌──────────────┐ ┌──────────────┐ │ Eden (FULL) │ │ Eden (EMPTY) │ │ A B C D E F │ │ │ └──────────────┘ └──────────────┘ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ │ S0 │ │ S1 │ │ S0 │ │ S1 │ │ G │ │(empty)│ │(empty)│ │ A G │ └──────┘ └──────┘ └──────┘ └──────┘ (B,C,D,E,F are dead) (only A,G survived)
When does promotion happen?
When an object's age reaches the tenuring threshold (often 15, tunable with -XX:MaxTenuringThreshold), it is promoted to the Old Generation. Large objects may be allocated directly in the Old Generation if they do not fit well in the Young Generation. The Old Generation holds objects that have proven they live long, like caches and connection pools. It is collected by a Major or Full GC, which is slower because it scans a much larger region.
Why is this split efficient?
The weak generational hypothesis says the vast majority of objects die very young. By keeping new objects in a small region and collecting it frequently, the JVM reclaims most garbage with tiny, fast pauses, and it only pays the cost of scanning the big Old Generation occasionally.
package com.bank.service;
import java.math.BigDecimal;
public class TransferService {
// This method creates many short-lived objects per call
public void transfer(String fromId, String toId, BigDecimal amount) {
// These objects are born in Eden and die before the next Minor GC
String logMessage = "Transfer " + amount + " from " + fromId + " to " + toId;
BigDecimal fee = amount.multiply(new BigDecimal("0.001"));
BigDecimal netAmount = amount.subtract(fee);
// logMessage, fee, netAmount all become garbage after this method returns
}
}
In a banking service handling thousands of transfers per second, each call creates temporary objects (the log message, the fee calculation, the net amount) that are born in Eden and die within milliseconds. The Minor GC sweeps them cheaply.
What is premature promotion?
Excessive promotion – objects surviving to Old Gen that then die shortly after – is called premature promotion. It causes more expensive Old Gen collections. This happens when the Young Generation is too small (objects get promoted before they have a chance to die) or when Survivor spaces are too small to hold all survivors, forcing early promotion.
# Tune Young Generation size to reduce premature promotion
java -Xmn1g -Xmx4g -XX:MaxTenuringThreshold=10 -jar bank-app.jar
# Monitor promotion rate
jstat -gcutil <pid> 1000
What are the key JVM flags for generation sizing?
| Flag | Purpose |
|---|---|
| -Xmn | Young Generation size |
| -XX:NewRatio | Ratio of Old to Young (default 2, meaning Old is 2x Young) |
| -XX:SurvivorRatio | Ratio of Eden to each Survivor space (default 8) |
| -XX:MaxTenuringThreshold | Age at which objects are promoted (default 15) |
Key Takeaway
The Java heap is divided into the Young Generation and the Old Generation based on how long objects live. New objects are always created in the Young Generation, specifically in a region called Eden, with two Survivor spaces called S0 and S1 beside it. When Eden fills up, a Minor GC runs. It copies the few objects that are still alive into a Survivor space and wipes everything else in one shot. Each time an object survives, its age increases, and once it has survived enough collections it is promoted into the Old Generation, which holds long-lived objects and is collected only rarely by a slower Major or Full GC.
The reason this split exists is the generational hypothesis, which observes that in almost every real program the overwhelming majority of objects die very young. By keeping new objects in a small region and collecting it frequently, the JVM reclaims most garbage with tiny, fast pauses, and it only pays the expensive cost of scanning the large Old Generation once in a while. This is dramatically more efficient than scanning the entire heap every time.
In my banking work at National Bank of India, this plays out exactly as the theory predicts. Every transfer request creates a burst of short-lived objects – the request body, parsed amounts, validation results – that are born in Eden and swept away by a quick Minor GC within milliseconds. Meanwhile our long-lived account cache and connection pool get promoted to the Old Generation and stay there, barely touched by the collector. When I size the JVM, I deliberately make the Young Generation large enough to absorb our high allocation rate so Minor GCs stay cheap, and I watch promotion rate closely, because if request objects start leaking into the Old Generation we call that premature promotion and it triggers costly Full GCs that hurt our transfer latency.
Remember one sentence: What is Young Generation vs Old Generation: new objects are created in Young Gen (Eden + Survivor spaces S0/S1), objects that survive multiple GC cycles are promoted to Old Gen: and why is this split efficient (most objects die young, so young GC is fast and frequent) is fundamental knowledge for Java interviews and production banking work.
---