Press "Enter" to skip to content

JDK 20: The new features in Java 20

Java 20, or Java Development Kit (JDK) 20, the next planned version of standard Java, has reached the release candidate stage, having completed phase-down phases. All six features officially marked for release are either in incubation or at a preview stage. These include scoping values, registration patterns, pattern matching for switch statements and expressions, an external function and memory API, virtual threads, and structured concurrency.

Java 20 moved into the release candidate phase on February 9, according to a newsletter from Oracle’s Mark Reinhold, chief architect of the Java Platform Group. A second release candidate is scheduled for February 23. The version reached an initial phase-down on December 8 and a post-phase-down on January 19, with the developers looking to fix bugs and possibly add late improvements, with approvals required. The JDK is scheduled for general availability on March 21, 2023, as part of Oracle’s six-month release cadence for standard editions of Java. JDK 20 would follow the September 20 release of JDK 19. Early Access builds of JDK 20 can be found at jdk.java.net.

Here are the six features slated for JDK 20:

  • Scoped Values, an API at an incubator stage of development, allows immutable data to be shared within and between threads. These are preferable to thread-local variables, particularly when using a large number of virtual threads. A scoped value allows data to be shared securely and efficiently between components of a large program without resorting to method arguments. Goals include ease of use, understandability, robustness, and performance.
  • Registry Patterns, in a second preview, enhances the Java programming language with patterns to deconstruct registry values. Record patterns and type patterns can be nested to enable a powerful, composable, declarative way of browsing and processing data. The goals include extending pattern matching to express more sophisticated composable data queries, and not changing the syntax or semantics of type patterns. Major changes from the first preview in JDK 19 include the addition of support for inferring type arguments from generic registration patterns, support for registration patterns to appear in the header of a for and removing support for named registration patterns.
  • The External Memory and Function API introduces an API through which Java programs can interoperate with code and data outside of the Java runtime. The API allows Java programs to call native libraries and process native data without the fragility and danger of JNI (Java Native Interface). The API was previously incubated in JDK versions 17 and 18 and previewed in JDK 19. Enhancements added since JDK 19 include unification of MemorySegment and MemoryAddress abstractions, an improvement MemoryLayout hierarchy and division of MemorySession in Arena and SegmentScope to promote segment sharing across maintenance boundaries.
  • Virtual Threads, in a second preview, are lightweight threads that reduce the effort of writing, maintaining, and observing high-performance concurrent applications. Minor changes since the first preview in JDK 19 include a small number of API changes (permanent in JDK 19) and downgrades to ThreadGroup (also made permanent in JDK 19).
  • Structured concurrency introduces an API to simplify multithreaded programming and treats multiple tasks running on different threads as a single unit of work. Error management and cancellation are simplified, improving reliability and visibility. The only change since it was incubated in JDK 19 is that StructuredTaskScope updated to support inheritance of scope values ​​by threads created in a task scope. This feature is being reincubated.
  • Pattern matching for switch statements and expressions enables concise and safe expression of complex data-oriented queries. Previously previewed in JDK 17, JDK 18, and JDK 19, this fourth preview would allow for continued co-evolution with Record Patterns, allowing for continuous improvements based on experience and feedback. Major changes to pattern matching for switch since the third preview include simplified grammar for switch labels and support for type argument inference for generic patterns and registration patterns in switch statements and expressions. Also, a comprehensive change on an enum class now returns MatchException instead of IncompatibleClassChangeError if no change tag is applied at runtime.
Also Read:  Optimize Apache Kafka by understanding consumer groups

Capabilities that were not included in JDK 20 but are still being considered for Java include universal generics, string templates, sequenced collections, and an asynchronous stack trace VM API.

JDK 20 is set to be a short-term feature release, with only six months of Premier level support from Oracle. JDK 21, scheduled for September 2023, will be a long-term support release, backed by multiple years of support.

Copyright © 2023 IDG Communications, Inc.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *