Java 20
April 28, 2023

Java 20: What’s New in JDK 20

Java Tools

Java 20 was released in March 2023 and the features included are either incubator features that are not fully mature yet, or preview versions of various capabilities, including virtual threads and structured concurrency.

Although this release doesn’t come with major updates, we expect Java users to continue transitioning away from legacy Java versions and into the new technologies within the Java ecosystem. In fact, according to our Java Developer Productivity Report*, more than half of survey respondents indicated using newer versions of Java.

Let’s take a look at the new Java 20 features and what value they bring to Java development.

*The 2024 Java Developer Productivity Report is here. See what's new in Java trends. 

Back to top

New Features in Java 20

This short-term Java release will be supported for six months following the September 20, 2022 release of JDK 19. We anticipate the long-term support (LTS) release of Java 21, due in September, to provide even greater updates backed by years of support. Until then, let’s dive into what’s new in JDK 20.

Seven features have been officially marked for the Java 20 release, including: virtual threads, a vector API proposal, structured concurrency, scoped values, a foreign function and memory API, record patterns, pattern matching for switch statements and expressions, and a vector API proposal.

📚 Java 21 is here! Read about permanent and proposed enhancements in the JDK. 

Back to top

Virtual Threads as Preview Feature

Virtual Threads are a prerequisite for structured concurrency. Since the first preview in JDK 19, minor changes have been made, including a small number of API changes, as well as degradations to ThreadGroup. Now in the second preview stage, these lightweight threads reduce the effort of writing and maintaining concurrent applications. According to Oracle, this will radically change how Java applications are scaled. 

Back to top

Vector API Proposal

Previously, the Vector API was incubated in JDK 16JDK 17JDK 18, and JDK 19. This new API proposal was added a few weeks before the launch of Java 20 as a re-incubation, with no changes in the API relative to JDK 19. The implementation includes a small number of bug fixes and performance enhancements, including the ability to express vector computations that reliably compile at runtime and act as optimal vector instructions on supported CPUs.

Back to top

Structured Concurrency

Delivered in JDK 19 as an incubating API, Structured Concurrency works by treating multiple tasks running in different threads as a single unit of work. This helps streamline error handling and cancellation, thereby improving reliability and enhancing observability. The only change with its re-incubation is StructuredTaskScope being updated to support the inheritance of scoped values by threads created in a task scope. 

Back to top

Scoped Values

Scoped Values enable immutable data to be shared across and within threads. They’re preferred to thread-local variables, especially when used with a large number of virtual threads. Goals of this incubating API include ease of use, comprehensibility, robustness, and performance.

Back to top

Foreign Function and Memory API

The Foreign Function and Memory (FFM) API combines two earlier incubating APIs: the Foreign-Memory Access API and the Foreign Linker API. The FFM API was first incubated in JDK 17 before being re-incubated in JDK 18; it was then first previewed in JDK 19. Based on user feedback, JDK 20 re-previews the FFM API to include the following refinements: 

  • MemorySegment and MemoryAddress abstractions are unified (memory addresses are now modeled by zero-length memory segments)
  • Sealed MemoryLayout hierarchy is enhanced to facilitate usage with pattern matching in switch expressions and statements
  • MemorySession has been split into Arena and SegmentScope to facilitate sharing segments across maintenance boundaries
Back to top

Record Patterns

The main goals of the second preview of Record Patterns are to extend pattern matching to express more sophisticated, composable data queries, as well as to maintain the syntax or semantics of type patterns. Since the first preview of this language feature delivered in JDK 19, expect the following changes in Java 20: added support for inference of type arguments of generic record patterns, support for record patterns to appear in the header of an enhanced for statement, and removal of support for named record patterns.

Back to top

Pattern Matching for Switch Statements and Expressions

Pattern Matching was initially proposed as a preview and delivered in JDK 17, proposed for a second preview and delivered in JDK 18, and proposed for a third preview and delivered in JDK 19. This language feature’s fourth preview in JDK 20 enables its continued co-evolution with the Record Patterns preview feature, and includes basic updates to grammar around switch statements.

Back to top

Final Thoughts on Java 20

Java 20 features are moving toward becoming more standardized, and these features are determined by various Java research projects. While JDK 20 doesn't introduce any new JEPs or major updates, it still has multiple preview and incubator features worth testing and leaving feedback on. For a full list of all Java 20 features, check out the release notes.

When it comes to Java, JRebel is just what you need to help maximize your productivity. The latest JRebel release includes added support for new Java technology versions, including Java 20. See how much time your team could save during your 14-day free trial. 

TRY JREBEL

 

Back to top