Java 17 arrives with long-term support: What's new, and is it falling behind Kotlin?

Text blocks, sealed classes, switch expressions, records, and more


JDK (Java Development Kit) 17 was released today, the first long-term support release since JDK 11 three years ago.

A new version of Java appears every six months, in March and September. According to the Oracle Java SE support lifecycle, these are supported only for six months until the next one appears, whereas LTS releases are supported for eight years.

Java 8 (the last before a major revamp of the JDK in Java 9 with many breaking changes) has extended support until December 2030, while extended support for Java 11 runs up to September 2026.

Suppliers of free OpenJDK editions of Java generally match and may sometimes exceed these support dates, but it is only the LTS editions that are intended for long-term use.

What's new in Java 17?

The feature list is nothing huge. One big thing is sealed classes, which were first previewed in Java 15. Sealed classes restrict the types that can inherit from them. In Java, a sealed class has a permits clause which specifies permitted subclasses, as in:

public abstract sealed class Shape
  permits Circle, Rectangle, Square { ... }

Native macOS support has been improved, including a new rendering pipeline for Java 2D using macOS Metal, and a port to AArch64 (Apple Silicon).

A new random number generator in the release offers enhanced features including better randomization algorithms, though the feature also has a goal to "carefully preserve existing behaviour of class java.util.Random."

Some things are being removed. Top of the list is the Applet API. "That goes right back to the very beginning of Java," said Azul Systems deputy CTO Simon Ritter at a press roundtable for Java 17.

"Applets really are on the way out. The applet browser plug-in was removed in JDK 11… and they've decided to actually get rid of the applet API. In Java 17 it's been deprecated for removal, probably in JDK 18."

Also removed was the experimental Java ahead-of-time (AOT) compiler, with the documentation saying that "this compiler has seen little use since its introduction and the effort required to maintain it is significant" and that "these features were not included in the JDK 16 builds published by Oracle, and no one complained."

The HotSpot Just-in-time compiler still exists and those who want to use AOT compilation were pointed towards Graal.

The jpackage tool is not an AOT compiler but does wrap Java applications as a native application; this was part of Java 16.

Strong encapsulation of JDK internals is another new feature, ending the easy way to bypass the block on access to internal APIs. The widely used sun.mic.Unsafe remains available for compatibility reasons.

In preview in Java 17 is an enhanced switch statement with pattern matching. Another key preview (in incubator) is the Foreign Function and Memory API, also known as Project Panama. This API aims to provide a safer and easier to use alternative to the Java Native Interface (JNI). "The API enables Java programs to call native libraries and process native data without the brittleness and danger of JNI," according to the docs.

Switch pattern matching is not as big of a deal as switch expressions, previewed in JDK 12 and fully released in Java 14 – but then again, because of the short support cycle many developers will be coming to Java 17 from Java 11, or even from Java 8, so all this will be new.

Moving on

"A lot of developers are still on 8," said Trisha Gee, a member of the Executive Committee for the JCP (Java Community Process) and lead developer advocate at JetBrains, told The Register.

"The 8 to 11 transition looked a bit scary because of the migration pain, because of the way that the JVM got restructured. When you look at the difference in terms of the language features from 8 to 11, well we got var and we don't really get much more. There's some nice things in 9, 10 and 11, but nothing really compelling."

Between 11 and 17 is more interesting, said Gee. "Now that 17 has come out, you've got all these lovely language features which have come in since 11. We've got sealed classes, pattern matching for instanceof, which came in 16, records, which are my favourite feature, just a data holder without any ceremony and it's so much more readable.

"Text block is nice too because the reality of a lot of Java development is you are going to have strings of other languages inside your Java code, probably SQL and sometimes JavaScript. And the other one is switch expressions."

Text blocks are strings that span multiple lines, surrounded by three quote marks.

We, JetBrains, haven't left a comment on a Yes vote or voted no against anything since Java 9

Was there anything contentious in Java 17 or other recent releases on the JCP Committee? "We, JetBrains, haven't left a comment on a Yes vote or voted no against anything since Java 9," Gee told us. She said that the six-monthly release process is smooth and that with new features, "usually by the time it gets to JCP it's not contentious because those discussions have been had with the community."

Is Java falling behind Kotlin, the JetBrains JVM language developed by JetBrains and adopted by Google for Android? "There are criticisms from both sides," said Gee. "Java developers see stuff in Kotlin that they want in Java, and criticism from the Kotlin world saying it would be nice if the JVM or Java supported something... so yes, there is tension, but I think it's positive tension, like an arms race but in a good way. The backwards compatibility story has always been the most important thing from an Oracle point of view."

"One of the the biggest challenges [JDK developers] have is that, sure it would be nice to add lots of features to Java, but they have to do it in a very controlled way to make sure that backwards compatibility is not radically affected… the reason that Java does evolve a little bit slower than languages like Kotlin is a lot to do with making sure that we don't break stuff," said Ritter.

How hard is migration to Java 17? Dalia Abo Sheasha, Java Developer Advocate at JetBrains, said: "I think the biggest thing is going to be the strong encapsulation, because previously my advice was to keep the illegal access flag on, and the strong encapsulation means it's no longer there. The move from 8 to 11 was a bigger issue than the move from 11 to 17."

It appears that the move from Java 8 has accelerated recently. The Eclipse Jakarta EE survey, for which the 2021 edition has just appeared, has 940 participants from enterprise developer communities. Java 11 use increased from 28 per cent in 2020 to 58 per cent this year.

The survey also showed the dominance of the Spring/Spring Boot framework for enterprise Java, with a market share of 60 per cent up from 44 per cent in 2020. This was a smallish survey, so some changes may be accounted for by differences in the group participating.

Why has Java endured?

"Backward compatibility… some applications written in Java 10, 15, 20 years ago are still running, and still run the backbone of organisations that make money," said Gee. "On top of that, it's a very high performance language, and yet it's fairly easy to write, so you don't have to write low-level code… the JVM will make that run fast for you."

Most language surveys agree: Java remains popular and its usage is stable. "The language once created to run cable set-top boxes continues to be a workhorse, and importantly one that has consistently been able to find new work to do. Java's performance on these rankings continues to impress, all these years later, and as it's shown a remarkable ability to adapt to a rapidly changing landscape," said Redmonk analyst Stephen O'Grady. ®

Similar topics


Other stories you might like

Biting the hand that feeds IT © 1998–2021