
During the Oracle CloudWorld conference in Las Vegas, Oracle has lifted the curtain on its latest innovation: Java 21. The newest iteration of the globally dominant programming language aims to offer an enhanced user experience with thousands of improvements in performance, stability, and security.
Java, renowned for its robustness, scalability, and security, sits firmly at the heart of countless applications utilized by organizations and individuals worldwide. With Java 21, developers can expect amplified productivity and the ability to foster innovation within their teams, making the coding process “smoother and more efficient.”
"Java's unyielding dominance in the programming ecosystem stems from its adaptability, making it the primary choice for building applications that stand the test of time," said Georges Saab, the Senior Vice President of Oracle Java Platform. “As the chair of the OpenJDK governing board, Java 21 is designed to empower developers to craft superior applications at a faster rate. To ensure seamless transitions, we've committed to a minimum of eight years of commercial support, granting our users the freedom to migrate as they see fit."
Digging deeper into the technical improvements, Java 21 comes loaded with 15 Java Development Kit Enhancement Proposals (JEPs). Among these advancements are language enhancements from the OpenJDK project Amber, which include String Templates and Pattern Matching for Switch, among others. Further enhancements stem from Project Panama, which introduces features such as the Foreign Function & Memory API. Java 21 also embraces elements of Project Loom, most notably Virtual Threads and Structured Concurrency. The Generational ZGC would offer performance boosts, while other features focus on maintenance and deprecation, with one of the major moves being the deprecation of the 32-bit x86 Port for Removal.
Stephen O'Grady, a principal analyst and co-founder of RedMonk, echoed the sentiment regarding Java's omnipresence. "Despite the plethora of languages on offer, Java's universality is unparalleled. Its inherent ability to evolve ensures it remains invaluable to developers in our rapidly changing world."
Oracle's extended support strategy signals its commitment to the Java community. The tech giant has pledged to provide long-term support for Java 21 for a minimum of eight years. This gesture grants businesses the flexibility to maintain and run applications longer with fewer disruptions. Taking customer feedback to heart, Oracle has also extended Java 11's long-term support until at least January 2032.
Among the notable changes included in Java 21 are:
Project Loom Features
- JEP 444: Virtual Threads: By adding lightweight virtual threads to the Java Platform, this course greatly simplifies the process of creating, managing, and monitoring high-throughput, concurrent applications. Virtual threads contribute to applications development speed by making it easier for developers to scale, troubleshoot, debug, and profile concurrent applications using pre-existing JDK tools and methodologies.
- JEP 446: Scoped Values (Preview): Allows immutable data to be shared both inside and across threads. This improves the projects' performance, robustness, comprehensibility, and simplicity of use for developers.
- JEP 453: Structured Concurrency (Preview): Prevents common risks associated with cancellation and shutdown, like thread leaks and cancellation delays, and enhances the observability of concurrent code by streamlining concurrent programming through the introduction of an API for structured concurrency. This facilitates error handling and cancellation for developers and increases observability and dependability.
Updates on Performance - JEP 439: Generational ZGC: By expanding the Z Garbage Collector (ZGC) to preserve distinct generations for new and old objects, this feature enhances application performance. By decreasing the overhead of heap memory and garbage collection CPU needed by apps, as well as the possibility of allocation pauses, generational ZGC helps increase developer productivity.
Language Revisions and Enhancements
- JEP 430: String Templates (Preview): Enhances the security of programs that create strings from user-supplied data and send them to other systems, while also simplifying the creation of Java applications by facilitating the expression of strings that include values calculated at runtime. Furthermore, non-string values calculated from literal text and embedded expressions may be formed without passing through an intermediary string representation, improving the readability of expressions that combine text and expressions. By improving the readability, writability, and maintainability of the Java language, this aids in boosting developer productivity.
- JEP 440: Record Patterns (Third Preview): This release adds nested patterns support and expands pattern matching to include destructuring record class instances. This boosts productivity by allowing developers to use pattern matching to more complex and modular data searches.
- JEP 441: Pattern Matching for Switch: By allowing patterns to occur in case labels, this technique increases the expressiveness and practicality of switch expressions and statements. Furthermore, switch statements become more secure since pattern switch statements must cover every potential input value. Additionally, any switch expressions and statements that already exist can be built and run with the same semantics without any modifications. By making the Java language more semantic, this aids developers in streamlining and improving the dependability of their projects by enabling the safe and succinct expression of complicated data-oriented queries.
- JEP 443: Unnamed Patterns and Variables (Preview): This adds functionality to the Java language by allowing unnamed variables to be initialized but not utilized, and unnamed patterns to match a record component without specifying the type or name of the component. This makes record patterns easier to understand and makes all code more maintainable, which streamlines the development process.
- JEP 445: Main Methods for Instances and Unnamed Classes (Preview): aids in making the Java language more approachable and straightforward so that teachers may gradually introduce programming ideas. Student programs can be compiled and run with the same tools that compile and run any Java program, saving the introduction of a separate beginner's dialect of Java and beginner's toolchain. This enables students to write basic programs succinctly and to grow their code gracefully as their proficiency grows. By allowing students to construct their initial programs without having to comprehend language features intended for huge projects, this increases student developer productivity.
Project Panama Preview Features
Third preview of JEP 442: Foreign Function & Memory API: This API allows Java applications to communicate with code and data that are not part of the Java runtime. The new API allows Java applications to contact native libraries and handle native data without using the Java Native Interface. It does this by securely accessing foreign memory, which is memory not controlled by the Java Virtual Machine (JVM), and by efficiently launching foreign functions, which are code outside the JVM. For developers, this improves performance, safety, flexibility, and simplicity of use.
JEP 448: Vector API (Sixth Incubator): This introduces an API for expressing vector calculations that, on supported CPU architectures, consistently compile at runtime to vector instructions. By giving developers access to an API that can describe a broad variety of vector calculations succinctly and explicitly, this enhances the performance of their applications.
Through OpenJDK and the Java Community Process (JCP), Oracle engineers and other global Java developers collaborated extensively to produce the Java 21 release. Java Management Service (JMS), an Oracle Cloud Infrastructure (OCI) native service, supports Java 21 in addition to the new features. It offers a uniform interface and dashboard to assist enterprises in managing Java runtimes and applications on-premises or on any cloud.