14.0.2

Latest release in branch Java SE 14
Released 5 years ago (July 14, 2020)

Software Java/Java SE
Branch Java SE 14
Status
End of life
End of premier support September 2020
First official release version 14
First official release date 6 years ago (March 17, 2020)
Release notes https://www.oracle.com/java/technologies/javase/14-0-2-relnotes.html
Documentation https://docs.oracle.com/javase/14
Download https://www.oracle.com/java/technologies/javase/jdk14-archive-downloads.html
Java/Java SE Java SE 14 Releases View full list

What Is New in Java 14

Java 14 delivers a mix of finalized preview features, productivity enhancements, and performance improvements. This release continues the pattern of introducing features in preview status for real-world feedback before they become permanent.

Category Key Changes
New Features Pattern Matching for instanceof (Preview), Records (Preview), Text Blocks (Second Preview)
Improvements Helpful NullPointerExceptions, Packaging Tool, NUMA-Aware Memory Allocation
Deprecations & Removals Parallel Scavenge + SerialOld GC combo deprecated, Solaris/SPARC ports deprecated
Security Security-related bug fixes and enhancements

What are the headline features in Java 14?

The standout features are preview versions of Records and Pattern Matching for instanceof. Records provide a compact syntax for declaring classes that are transparent holders for shallowly immutable data, reducing a ton of boilerplate code.

Pattern Matching enhances the instanceof operator by allowing you to declare a binding variable right in the expression. This eliminates the need for an explicit cast after the instanceof check, making code cleaner and less error-prone.

Pattern Matching for instanceof Example

// Old way
if (obj instanceof String) {
    String s = (String) obj;
    System.out.println(s.length());
}

// New way (Preview)
if (obj instanceof String s) {
    System.out.println(s.length());
}

How do Text Blocks improve in this release?

Text Blocks enter their second preview with two new escape sequences. This feature simplifies writing multi-line strings for JSON, HTML, SQL, and other formats without a mess of concatenation and escape characters.

The new \s escape signifies an obligatory space that won't be stripped by the compiler's whitespace removal process. Additionally, the new \ escape at the end of a line prevents the insertion of a newline character, allowing you to break up a long string for readability without adding the line break.

Text Block Escape Sequences

String text = """
    {
        "name": "John",\s
        "age": 30\
    }
    """;

What makes the new NullPointerExceptions better?

The JVM now provides detailed messages telling you exactly what was null when a NullPointerException (NPE) is thrown. This is a huge time-saver during debugging, as you no longer have to dissect a line of code to figure out which variable or method call caused the failure.

This feature is enabled by default. Instead of a generic error line number, you get a message like "Cannot invoke 'String.length()' because the return value of 'foo.getBar()' is null". It precisely pinpoints the source of the null value in a chain of method calls or field accesses.

Are there any new garbage collection features?

Java 14 introduces a new experimental garbage collector called ZGC (Z Garbage Collector) for macOS and Windows, joining its existing availability on Linux. ZGC is designed for low-latency applications with very large heaps.

Additionally, the combination of the Parallel Scavenge and SerialOld garbage collection algorithms has been deprecated. This is a signal to developers using this combination to begin migrating to other GC combinations, as it will likely be removed in a future release.

What tools are new for Java developers?

The jpackage tool is now a standard feature. It allows you to package a Java application into a platform-specific native package, such as a DMG for macOS, MSI for Windows, or DEB/RPM for Linux. This simplifies application distribution significantly.

Beyond packaging, the JDK also includes a new NUMA-aware memory allocation mode for the G1 garbage collector. On Non-Uniform Memory Access (NUMA) systems, this can lead to improved performance by optimizing memory access patterns.

FAQ

Are Records and Pattern Matching safe to use in production since they are preview features?
Preview features are not intended for production use. They are provided for testing and feedback. You must explicitly enable them at compile time (javac --enable-preview --release 14) and runtime (java --enable-preview) to use them.

How do I get the new helpful NullPointerMessages?
They are enabled by default. You don't need to do anything. The JVM will generate them automatically when an NPE occurs. This is a JVM enhancement, not a language change.

What should I use instead of the deprecated Parallel Scavenge + SerialOld GC combination?
The recommendation is to use the G1 garbage collector (-XX:+UseG1GC), which is the default since Java 9. For low-latency scenarios, you could also evaluate the experimental ZGC or Shenandoah collectors.

Is the jpackage tool a replacement for tools like Launch4j or JPackager?
Yes, jpackage is now the standard, integrated tool for creating native installers directly from the JDK. It aims to replace the need for third-party packaging tools for basic to moderate use cases.

Why are the Solaris and SPARC ports being deprecated?
The ports for Oracle Solaris and SPARC-based systems are deprecated due to the declining use of both the operating system and the hardware architecture in the Java ecosystem. This allows the JDK team to focus resources on more widely used platforms.

Releases In Branch Java SE 14

Version Release date
14.0.2 5 years ago
(July 14, 2020)
14.0.1 6 years ago
(April 14, 2020)
14 6 years ago
(March 17, 2020)