Java 12 was a short-term release (March 2019). Still, it introduced a few developer-friendly improvements—especially around switch, JVM performance, and tooling.
1) Switch Expressions (Preview) ✅ (Biggest highlight)
Java 12 added switch expressions as a preview feature. Unlike classic switch statements, you can return a value from a switch.
✅ Old style (Java 11 and below)
int day = 3;
String name;
switch (day) {
case 1: name = "Mon"; break;
case 2: name = "Tue"; break;
case 3: name = "Wed"; break;
default: name = "Unknown";
}
System.out.println(name);
✅ Java 12 switch expression (preview)
int day = 3;
String name = switch (day) {
case 1 -> "Mon";
case 2 -> "Tue";
case 3 -> "Wed";
default -> "Unknown";
};
System.out.println(name);
✅ Multi-line case with yield
Use yield when a case needs multiple statements.
int marks = 85;
String grade = switch (marks / 10) {
case 10, 9 -> "A+";
case 8 -> {
System.out.println("Good score!");
yield "A";
}
case 7 -> "B";
default -> "C";
};
System.out.println(grade);
Why it matters
- Cleaner, less error-prone (no missing
break) - Easier to assign values directly
Note: It’s a preview in Java 12, stabilized later (Java 14).
2) Shenandoah GC (Experimental)
Java 12 introduced Shenandoah as an experimental garbage collector in OpenJDK builds to reduce pause times (low-latency GC).
When useful
- Large heaps
- Applications sensitive to GC pauses (trading systems, real-time APIs)
Enable it (example)
java -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -version
3) Default CDS Archives
CDS (Class Data Sharing) helps JVM startup by sharing common class metadata between JVM runs. In Java 12, creating a default CDS archive became easier (improved out-of-the-box usage).
Why it matters
- Faster startup for repeated runs (CLI tools, microservices, serverless)
(This is mostly a JVM/runtime improvement—no code change needed.)
4) JVM Constants API (JEP 334)
Java 12 added an API for describing and working with constants (especially helpful for tools and advanced frameworks that manipulate bytecode / class files).
Who benefits
- Library authors
- Bytecode tools
- Frameworks (instrumentation, codegen)
Most application developers won’t directly use it daily.
5) Improved AArch64 (ARM64) Support (JEP 340)
Better support for AArch64 on Linux, useful for ARM servers and devices.
Where it helps
- Running Java on ARM servers (cloud ARM instances)
- Performance/compatibility improvements
6) Microbenchmark Suite (JEP 230)
Java 12 shipped a microbenchmark suite to help OpenJDK developers measure performance changes more reliably. Not typically used directly by application developers, but it improves JVM quality over time.
How to compile/run Java 12 preview features (switch expressions)
Because switch expressions were preview in Java 12, you must enable preview mode.
Compile
javac --release 12 --enable-preview Main.java
Run
java --enable-preview Main
Quick Summary (for your blog “TL;DR” box)
- Switch Expressions (Preview): cleaner
switch, can return values, supports->andyield - Shenandoah GC (Experimental): low-pause GC option
- CDS Improvements: better startup performance
- JVM Constants API: mainly for framework/tool authors
- ARM64 improvements: better AArch64 support
- Benchmarks suite: improves JVM performance testing