JDK 16: Records, Patterns, Ports & Garbage Collectors
What’s This About?
Another half a year has gone by, so here we go: Today, Oracle released JDK 16 or “Next Java LTS, final beta”. That release comes half a year after JDK 15. And JDK 17 will finally be here in September!
What’s in the Release?
Just like last time, Tech Geek Next has a good overview. So, what affects us Java developers day-in, day-out?
Records
First stop is probably records. They are “immutable value classes” and leave the preview status behind with Java 16. That’s the equivalence of Project Lombok’s @Value classes. So in Java 16, a record Point(int x, int y) { }
turns into this:
|
|
As I mentioned in last week’s issue of my newsletter, record serialization is easier to understand, has no magic, is more secure, and offers better performance. That’s a nice bonus over Lombok!
Pattern Matching
We often write this code:
With Java 16, we can now move the variable declaration of s
into the if
condition:
It’s not earthshaking, but it does save a few keystrokes.
OpenJDK Ports
OpenJDK is now available on Windows ARM64. What’s that? Well, it’s like Apple M1-powered MacBooks, but worse. So if you’re one of the few people who has a Windows on ARM device (like the Microsoft Surface Pro X, then you can now run Java natively on it!
OpenJDK is now also out on Alpine Linux. Alpine Linux the smallest Linux distribution with wide circulation. So this means that our Docker images can get smaller!
Garbage Collectors
Some customer, especially in the financial industry, want very small garbage collection pauses in Java. So they look alternate JDK distributions with specialized garbage collectors, like Azul’s Zing. Now in JDK 16, the ZGC garbage collector claims “pauses below a single millisecond”. And G1 is faster, too, shaving off possibly 50~100ms+ in some cases. This may get some folks to look at the regular JDK 16 again!
Should I Upgrade?
No. Wait for Java 17.
If you’re on the bleeding edge and need this release, you know it and don’t need my advice.
Still, Where Can I Get It?
The popular OpenJDK distributor AdoptOpenJDK has Java 16. As usual, get the HotSpot version, unless you’re sure that you need the OpenJ9 version.
When Will the Next JDK LTS Version Be Out?
JDK 17 will be out in September 2021. It’s the next release!
Developer job ads down 32% year over year, Stack Overflow questions dropped 55% since ChatGPT. I now recommend IntelliJ Community Edition because many AI code assistants don't run in Eclipse. Job ads for Quarkus hit an all-time high.
Read my newsletter