JDK 14: What’s new?

Max Di Franco
Devjam
Published in
5 min readApr 14, 2020
Photo by Ales Nesetril on Unsplash

Hello folks, as many of you know the JDK 14 is available since March 2020 as it was announced in the roadmap both in the JDK 14 and Open JDK 14 (to see the differences between the two versions please visit this link).

This non-LTS (long term support) version will receive a minimum of 2 quarterly updates before being followed by the JDK 15.

Some enhancements are introduced in incubator features (non-final APIs and non-final tools to get feedback from developers) and similarly some others are introduced as preview features (fully specified, fully implemented, which might become permanent on future releases).

Important! Preview features must be enabled in order to be used with the arg:

--enable-preview

In this article, I’m going to go over many of the newly included features such as:

  • Pattern matching for instanceof
  • Records
  • Switch expressions
  • Improved NullPointerException messages
  • Java packaging tool
  • Memory, metrics and garbage collection enhancements

As well as the items that were removed or deprecated on this version.

Pattern matching for instanceof (preview feature)

This feature enhances Java with pattern matching for the instanceof operator, improving productivity by eliminating the need to write boilerplate, and having more concise type-safe code.

Records (preview feature)

With the constant need of writing objects to transport data out, primarily having getters and a constructor, Java 14 record classes become very handy as they provide a very simplified way of creating an immutable class with less boilerplate (constructors, accessors, toString, etc).

Similar to already existing implementations in languages such as Scala (case classes), Kotlin (data classes) and C# (record classes).

Last but not least, this feature comes with several limitations:

  • Components of a record are implicitly final.
  • Therefore record classes cannot be extended by another class.

Switch expressions (standard feature)

This was previously included in Java 12 and 13 has now become a standard feature; therefore I’m including a recap:

Improved NullPointerException messages

With the goal of improving the usability of NullPointerExceptions generated by the JVM, this enhancement adds more details to the exception message by specifying the variable that is null.

This feature is disabled by default, in order to use it, the following needs to be added to the VM options:

-XX:+ShowCodeDetailsInExceptionMessages

As an example we are going to use the following code:

Before Java 14 with the details in exception feature disabled, it would show:

Exception in thread “main” java.lang.NullPointerException
at NullPointerExceptionDemo.main(NullPointerExceptionDemo.java:5)

Java 14 version with details in exception feature enabled:

Exception in thread “main” java.lang.NullPointerException: Cannot read field “name” because “user” is null
at NullPointerExceptionDemo.main(NullPointerExceptionDemo.java:5)

As we can see, this feature is very helpful in order to debug and find the cause of the NullPointerExceptions. It’s disabled in this version by default, but it is intended to be enabled in future releases.

Java packaging tool (incubator feature)

Photo by Kelli McClintock on Unsplash

As a replacement for the JavaFX packaging tool, this new incubator feature called jpackage comes in handy to generate native installer images (deb and rpm for Linux, pkg and dmg for macOS, msi and exe for Windows).

A disadvantage worth mentioning is that cross-platform creation is not supported by this tool.

To read more about this tool, please refer to the official documentation.

Memory, metrics and garbage collection enhancements

NUMA-Aware Memory Allocation for G1

This feature improves the overall performance of the G1 garbage collector on Non-uniform memory access (NUMA) systems. Only available on Linux, this improvement is for large server deployments and applies to machines where the memory might not be equidistant from every socket or core. For more information please visit this link.

Java Flight Recorder Event Streaming

This feature exposes JDK Flight Recorder (JFR) data for continuous monitoring, which simplifies access to JFR data to various tools and applications. For more information please refer to the official documentation.

ZGC: A Scalable Low-Latency Garbage Collector (Experimental)

Introduced in Java 11 for Linux operative systems, it’s now available both for Windows and macOS platforms

Deprecations

Have you tried any of these features? Do you have any questions? Please feel free to comment on this story!

I want to thank you for your attention. If you enjoyed reading this story, clap for me by clicking the icon below so other people can see this here on Medium!

This version certainly includes some cool features that lead to continuous improvements in Java developer’s life. The cadence change to have a new release every 6 months, is definitely excellent.

That’s it for now!

I work at Sytac.io; We are a consulting company in the Netherlands, we employ around ~100 developers across the country at A-grade companies like KLM, ING, ABN-AMRO, TMG, Ahold Delhaize, and KPMG. Together with the community, we run DevJam check it out and subscribe if you want to read more stories like this one. Alternatively, look at our job offers if you are seeking a great job!

--

--

Max Di Franco
Devjam
Writer for

Software developer living in Amsterdam, passionate about technology, music and sports