Sixteen Going on Seventeen!

Today, Java 17 is being released. It is a “long term support” release. I've been updating the Core Java books for this momentous occasion. Maybe not that momentous since the best (Valhalla, Panama, Loom) is still ahead of us. But still nice. And with a ton of bug fixes and security patches. You should upgrade.


The Release Cadence

In the early years of Java, there was a new release every couple of years, and two of them (1.2 and 5) had significant advances of the API and/or language.

Then came a long dry spell. It took five years for Java 7 (meh) and three years each for Java 8 (default methods and streams, yeah!) and 9 (modules, ugh).

In order to put things on a more predictable footing, Oracle switched to a new release model. Rain or shine, there is a release every 6 months. Releases every three years get long term support, starting with Java 11. That makes Java 17, released today, the second LTS release. Followed by 23, 29, 35, 41, 47, 53, and so on. Like clockwork.

Except today's press release seems to indicate that the next LTS release may be Java 21. Which would actually be fine. A two year LTS cycle is pretty common elsewhere.

NB. The Oracle JDK has a free-to-use license that was just extended from a paltry 6 months to a full year. Other vendors (IBM, Red Hat, Azul, Amazon, ...) have more generous terms. I like to use the Adoptium (previously AdoptOpenJDK) version.

I think it is fair to say that the non-LTS releases don't get much uptake. Only the most hardened Java enthusiasts will want to update so frequently.

Nothing wrong with that, of course. It's like with Ubuntu. Most users stick with the LTS versions, but if you absolutely need a new feature or if it's your job to keep up to date with the most current version, you have that option.

So, now that there is a new LTS release, you are probably asking yourself if you should switch to it.

What's in the Box?

Here is my completely unbiased cheat sheet of what's interesting and new(ish) in Java 17, starting from the previous LTS release, Java 11.

I am not rating “preview features” at all. They give a glimpse of what may come, but the details are subject to change. Interesting for enthusiasts, but not something you would want to touch in production.

I am not giving brownie points for future promise. Sure, switch expressions, instanceof patterns, records, and sealed classes lay the ground work for robust pattern matching in the future. I only rate them for the utility they have today.

Feature Example Momentousness rating Why care?
record Point(double x, double y)
Nice Constructor, accessors, toString, hashCode automatically provided
Switch expressions without fallthrough
int numConsonants = switch (season) {
   case "Fall" -> 3;
   case "Summer", "Winter" -> 4;
   case "Spring" ->  5;
   default -> -1;
Nice More compact than if/else, safer than classic switch
Two other switch constructs
int numVowels = switch (season) { // Expression with fallthrough
   case "Spring": System.out.println("Spring time!");
   case "Fall": yield 1;
   case "Summer", "Winter": yield 2;
   default: yield -1;

switch (season) { // Statement without fallthrough
   case "Fall" -> numConsonants = 3;
   case "Summer", "Winter" -> numConsonants = 4;
   case "Spring" ->  numConsonants = 5;
Ugh I never asked for four kinds of switch
Pattern matching for instanceof
if (obj instanceof String s) process(s.strip());
Nice No need to cast
Sealed types
public sealed class JSONValue
   permits JSONObject, JSONArray, JSONPrimitive { ... }
public sealed class JSONPrimitive extends JSONValue
   permits JSONString, JSONNumber, JSONBoolean, JSONNull { ... }
public final class JSONObject extends JSONValue { ... }
Ok Can accurately model closed hierarchies
Text blocks
var query = """
Meh Nice for multiline strings, but must still escape \ and some "
New file and stream methods
   .filter(s -> s.contains("ava"))
Nice Dozens of new and useful methods
Alpine port, ChaCha20 and Poly1305 Cryptographic Algorithms, NUMA-Aware Memory Allocation for G1, JFR Event Streaming, many more YMMV Depends on how badly you need the particular feature

Should You Switch?

Are you using one of the removed features (CORBA, Nashorn, Java FX, others)? Then you obviously have some work ahead of you.

Are you using Java 8? Then you may have some work ahead of you, depending how much the Java platform module system of Java 9 puts sticks and stones in your way. But it's not going to get any easier. Standing still is not a long-term option. Java is alive and well, and exciting improvements lie ahead. And the grass isn't greener on the other side. Better get moving.

Are you using Java 11? Why not move along to the next LTS? It's unlikely to break anything, you get a few nice features, and you are ready for a smooth move next time.

Far more importantly, you get bug fixes and security patches galore.

I am a bit baffled that organizations don't think twice about keeping their OS current and patched, but don't do the same thing with their JDK. I guess it is the hump of Java 9 and modules. For the first time in the history of Java, it was genuinely difficult to move forward. Get past that hump and stay on the LTS train!

Comments powered by Talkyard.