Overview of New Features in Java 14
Introduction
Java 14 was released on 17th March 2020, with sixteen JDK Enhancement Proposals (JEPs) - a much bigger release than Java 12 and 13. It made switch expressions a standard language feature, gave NullPointerExceptions messages which actually say what was null, let programs stream Flight Recorder events as they happen, and previewed two features which changed how Java code is written: records and pattern matching for
Garbage collection and JVM
Other changes
instanceof. It also removed the CMS garbage collector and Pack200. This article gives an overview of the new features in Java 14, with links to detailed tutorials.
Language features
- Switch Expressions (Standard) - JEP 361 - after two previews, switch expressions are a permanent part of Java:
switchcan return a value,case X ->labels do not fall through, a case can list several constants, andyieldreturns a value from a block. Read the tutorial on switch expressionsClick to read tutorial: Java Switch Expressions: Arrow Labels and yield. - Records (Preview) - JEP 359 - a compact syntax for classes which are simple carriers of data. Finalized in Java 16 - read the records tutorialClick to read tutorial: Java 16 Records Tutorial with Examples.
- Pattern Matching for instanceof (Preview) - JEP 305 -
if (obj instanceof String s)tests and casts in one step. Finalized in Java 16 - read about pattern matching for instanceofClick to read tutorial: Java 16 Pattern Matching for instanceof. - Text Blocks (Second Preview) - JEP 368 - text blocks were previewed again, with two new escape sequences:
\at the end of a line to join it with the next, and\sfor a single space. Standard in Java 15 - read the tutorial on text blocksClick to read tutorial: Java Text Blocks: Multi-line Strings with Examples.
- Helpful NullPointerExceptions - JEP 358 - a
NullPointerException's message now names exactly what was null, such as Cannot invoke "String.length()" because "user.name" is null. Read about helpful NullPointerExceptionsClick to read tutorial: Java 14 Helpful NullPointerExceptions Explained. - JFR Event Streaming - JEP 349 - programs can subscribe to Java Flight Recorder events while they are recorded, for continuous monitoring. Read the JFR event streaming tutorialClick to read tutorial: Java 14 JFR Event Streaming Tutorial with Examples.
- Packaging Tool (Incubator) - JEP 343 - the first version of
jpackage, which creates native installers for Java applications. Standard in Java 16 - read the jpackage tutorialClick to read tutorial: jpackage Tutorial: Packaging Java Apps (Java 16).
- Remove the Concurrent Mark Sweep (CMS) Garbage Collector - JEP 363 - CMS, deprecated in Java 9, was removed. Applications which used
-XX:+UseConcMarkSweepGCshould move to G1, the default, or to ZGC or ShenandoahClick to read tutorial: ZGC and Shenandoah: Low-Pause GCs in Java 15 for low pauses. - ZGC on macOS and Windows - JEPs 364 and 365 - ZGC, until now available only on Linux, was ported to macOS and Windows (still experimental).
- NUMA-Aware Memory Allocation for G1 - JEP 345 - on large machines with several processor sockets, G1 allocates memory close to the processor that uses it, improving performance.
- Deprecate the ParallelScavenge + SerialOld GC Combination - JEP 366 - a rarely used combination of garbage collectors was deprecated.
- Foreign-Memory Access API (Incubator) - JEP 370 - the first step of a safe API for working with memory outside the Java heap, which grew into the Foreign Function & Memory APIClick to read: Foreign Function & Memory API of Java 22.
- Non-Volatile Mapped Byte Buffers - JEP 352 -
MappedByteBuffercan map files on non-volatile (persistent) memory. - Remove the Pack200 Tools and API - JEP 367 - Pack200, deprecated in Java 11Click to read: Java 11, was removed.
- Deprecate the Solaris and SPARC Ports - JEP 362 - the ports for Solaris and SPARC were deprecated, and they were removed in Java 15.
instanceof were previewed, and text blocks got a second preview. Helpful NullPointerExceptions and JFR event streaming improved debugging and monitoring, and the first version of jpackage appeared. On the JVM side, the CMS collector was removed and ZGC came to macOS and Windows. Continue with the helpful NullPointerExceptions tutorialClick to read tutorial: Java 14 Helpful NullPointerExceptions Explained.Continue Reading Java 12 to 17 Tutorials
Java Switch Expressions: Arrow Labels and yieldClick to read tutorial: Java Switch Expressions: Arrow Labels and yield Java 14 Helpful NullPointerExceptions ExplainedClick to read tutorial: Java 14 Helpful NullPointerExceptions Explained Java 14 JFR Event Streaming Tutorial with ExamplesClick to read tutorial: Java 14 JFR Event Streaming Tutorial with Examples Overview of New Features in Java 13Click to read tutorial: Overview of New Features in Java 13 Overview of New Features in Java 12Click to read tutorial: Overview of New Features in Java 12 Overview of New Features in Java 15Click to read tutorial: Overview of New Features in Java 15 Overview of New Features in Java 16Click to read tutorial: Overview of New Features in Java 16 Overview of New Features in Java 17Click to read tutorial: Overview of New Features in Java 17 Java 12 API Additions: String.indent, teeing, mismatchClick to read tutorial: Java 12 API Additions: String.indent, teeing, mismatch
Java Switch Expressions: Arrow Labels and yieldClick to read tutorial: Java Switch Expressions: Arrow Labels and yield Java 14 Helpful NullPointerExceptions ExplainedClick to read tutorial: Java 14 Helpful NullPointerExceptions Explained Java 14 JFR Event Streaming Tutorial with ExamplesClick to read tutorial: Java 14 JFR Event Streaming Tutorial with Examples Overview of New Features in Java 13Click to read tutorial: Overview of New Features in Java 13 Overview of New Features in Java 12Click to read tutorial: Overview of New Features in Java 12 Overview of New Features in Java 15Click to read tutorial: Overview of New Features in Java 15 Overview of New Features in Java 16Click to read tutorial: Overview of New Features in Java 16 Overview of New Features in Java 17Click to read tutorial: Overview of New Features in Java 17 Java 12 API Additions: String.indent, teeing, mismatchClick to read tutorial: Java 12 API Additions: String.indent, teeing, mismatch