Java JDK 20, what can we expect?

Prateek Nima
3 min readMar 1, 2023
Photo by Michiel Leunens on Unsplash

Oracle Java release cycle is every 6 months and Java JDK 20 is set to release on March 21, 2023. Currently, there are six features that are official to be released and can be seen in this official OpenJDK specification. The following are the new features:

Scoped Values(Version: Incubator):

Scoped values enable us to share immutable data across threads. It is the preferred way and alternative to ThreadLocal in a multithreading environment. It helps components share data without resorting to method arguments. This feature is being incubated.

Virtual Threads(Version: Second Preview):

Virtual threads were introduced in Java 16 and helped us to create and manage threads. It is an alternative to the traditional threads which offer better performance. They are lightweight and not directly mapped to the operating system. They share single pool memory space with other virtual threads thereby making creation, destruction, and context switching of threads much quicker. There are minor API changes to this in JDK 20 including degradations to ThreadGroup.

Structured Concurrency(Version: Second Incubator):

Structured Concurrency provides control over the execution of code blocks in the multithreaded environment. It provides control over execution. It treats tasks running in different threads as a single unit of work. This feature is being incubated.

Vector API(Version: Fifth Incubator):

Vector API was introduced in Java 16 to provide parallel processing of numerical computation of data. Stream.parallel() introduced in Java 8 would sound similar to vector API but the latter was specifically provided for numerical computation at a low-level mechanism. In normal processing, it adds two pieces of data in one go also called Single Instruction, Single Data(SISD), while in the case of Vector API, it takes two chunks of data and processes it simultaneously also called Single Instruction Multiple Data(SIMD). The JDK 20 update includes bug fixes and improved performance.

Record Patterns(Second Preview):

Record patterns and type patterns can be nested to enable a powerful, declarative, and composable form of data navigation and processing. The main changes for this preview are support for an inference of type arguments of generic record patterns, support for record patterns to appear in the header of an enhanced statement, and removal of support for named record patterns.

One of the examples for record pattern is in the if statement we can directly store the value into a variable as follows:

if (o instanceof String str)

{

System.out.println(str);

}

Pattern matching for switch(Version: Fourth Preview):

Pattern matching for switch statements is a new feature introduced in Java 16, that along with value matching, also allows switch statements to match values based on their type, and structure, and further perform different actions based on the match condition.

The changes since the last preview include

As per the documentation, the main changes since the third preview are:

  • An exhaustive switch (i.e., a switch expression or a pattern switch statement) over an enum class now throws MatchException rather than IncompatibleClassChangeError if no switch label applies at run time.
  • The grammar for switch labels is simpler.
  • Inference of type arguments for generic record patterns is now supported in switch expressions and statements, along with the other constructs that support patterns.

This release version of JDK is a short-term feature release. You can register for the release event from this link. Thanks for reading this article, if you have any questions please feel free to comment down below. I hope you have a great day ahead :)

--

--