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*, 40% of respondents are on Java 17 or a more recent version. 

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 the new features in Java 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 23 is here! Read about permanent and proposed enhancements in the JDK. 

Back to top

Virtual Threads in Java 20

Virtual Threads are a prerequisite for structured concurrency. Since the first preview in Java 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 in Java 20

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 Java 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 in Java 20

Delivered in Java 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 in Java 20

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 in Java 20

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 Java 17 before being re-incubated in Java 18; it was then first previewed in Java 19. Based on user feedback, Java 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 in Java 20

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 Java 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 in Java 20

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

⚠️  Java 20 is not a Java LTS version. Learn more about Java LTS. 

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 Java 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