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 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
  1. Switch Expressions (Standard) - JEP 361 - after two previews, switch expressions are a permanent part of Java: switch can return a value, case X -> labels do not fall through, a case can list several constants, and yield returns a value from a block. Read the tutorial on switch expressionsClick to read tutorial: Java Switch Expressions: Arrow Labels and yield.
  2. 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.
  3. 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.
  4. 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 \s for a single space. Standard in Java 15 - read the tutorial on text blocksClick to read tutorial: Java Text Blocks: Multi-line Strings with Examples.
Developer experience and monitoring
  1. 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.
  2. 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.
  3. 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).
Garbage collection and JVM
  1. Remove the Concurrent Mark Sweep (CMS) Garbage Collector - JEP 363 - CMS, deprecated in Java 9, was removed. Applications which used -XX:+UseConcMarkSweepGC should 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.
  2. ZGC on macOS and Windows - JEPs 364 and 365 - ZGC, until now available only on Linux, was ported to macOS and Windows (still experimental).
  3. 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.
  4. Deprecate the ParallelScavenge + SerialOld GC Combination - JEP 366 - a rarely used combination of garbage collectors was deprecated.
Other changes
  1. 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.
  2. Non-Volatile Mapped Byte Buffers - JEP 352 - MappedByteBuffer can map files on non-volatile (persistent) memory.
  3. Remove the Pack200 Tools and API - JEP 367 - Pack200, deprecated in Java 11Click to read: Java 11, was removed.
  4. Deprecate the Solaris and SPARC Ports - JEP 362 - the ports for Solaris and SPARC were deprecated, and they were removed in Java 15.
Summary In this article we went through the new features of Java 14. Switch expressions became standard, records and pattern matching for 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.