What Is New in Java 16
Java 16 delivers a mix of finalized preview features, performance upgrades, and new tooling. This release solidifies changes that were incubating in previous versions, making them standard.
| Category | Key Changes |
|---|---|
| Language Features | Records, Pattern Matching for instanceof, Sealed Classes (Second Preview) |
| JVM Improvements | Elastic Metaspace, ZGC Concurrent Thread Stack Processing, Unix-Domain Socket Channel |
| Tools & APIs | Packaging Tool, Vector API (Incubator), Foreign Linker API (Incubator) |
| Security | Stronger Algorithms for JDK Internals |
| Deprecations & Removals | Deprecate the Solaris and SPARC Ports, Remove the Experimental AOT and JIT Compiler |
What are the finalized language features in Java 16?
Records and pattern matching for instanceof are now final and ready for production use. These features reduce boilerplate code and make common coding patterns more concise and less error-prone.
Records provide a compact syntax for declaring classes that are transparent holders for immutable data. Pattern matching simplifies the all-too-common practice of conditional extraction of components from objects.
Records Example
public record Point(int x, int y) { }
// Instead of a full class with constructors, getters, equals, hashCode, toString
Pattern Matching Example
if (obj instanceof String s) {
//å¯ä»¥ç›´æŽ¥ä½¿ç"¨å˜é‡ 's'
System.out.println(s.length());
}
How does Java 16 improve JVM performance and management?
Elastic Metaspace is a significant upgrade that returns unused HotSpot class-metadata memory to the OS more efficiently. This reduces metaspace footprint and minimizes fragmentation, which is crucial for containerized environments where memory is a constrained resource.
ZGC gets faster with concurrent thread stack processing, moving this activity from safepoints to a concurrent phase. This cuts down pause times even further, making ZGC an ultra-low-latency option for more applications.
What new tools and APIs are introduced?
The jpackage tool is now production-ready, letting you package self-contained Java applications into native formats like MSI, DMG, and DEB. This fills a major gap for developers needing simple distribution mechanisms.
Incubator modules continue to evolve. The Vector API allows expressing vector computations that reliably compile at runtime to optimal hardware instructions. The Foreign Linker API offers a pure-Java way to access native code, which is a cornerstone of the ongoing Project Panama work to simplify native interop.
What has been deprecated or removed?
The experimental Java-based Ahead-of-Time (AOT) and Just-In-Time (JIT) compilers, introduced in JDK 9 and JDK 10, have been removed. Their maintenance cost was high, and they saw little adoption compared to the mature C++-based compilers.
The Solaris and SPARC ports are now officially deprecated for removal, reflecting the diminished relevance of that hardware and OS ecosystem in the modern Java world.
FAQ
Are Records just like Lombok?
They solve similar boilerplate problems but are a language feature, not an annotation-based hack. Records are part of the type system, which means the JVM understands their semantics, leading to better performance and tooling support.
Should I use the new Packaging Tool for my applications?
Absolutely. jpackage is a game-changer for distributing standalone Java apps, especially to clients who expect native installers. It simplifies the entire packaging process significantly.
Why were the experimental JIT and AOT compilers removed?
They were complex to maintain and didn't offer a clear advantage over the existing, highly optimized C++ compilers (C1, C2). The effort is better spent on projects like GraalVM.
Is ZGC production-ready now?
Yes, ZGC has been production-ready since Java 15. The improvements in Java 16 further solidify its position as a top-tier, ultra-low-pause garbage collector for demanding applications.
What's the status of Sealed Classes?
They are in their second preview in Java 16. This allows for further community feedback based on real usage before the feature is finalized in a future release.