BreadcrumbHomeResourcesBlog Java 21: Uncover New Features In JDK 21 September 19, 2023 Java 21: Uncover New Features in JDK 21Enterprise DevelopmentBy Bleston WrightReleased on September 19, 2023, Java 21 is the latest long term support release of Java. This JDK release not only marks an increasing cadence in Java LTS releases from Oracle, but also includes several preview and permanent features in the language. Java 21 marks the first installment of Oracle’s commitment to increasing the cadence of Java LTS versions. Java 17 was released in September 2021, marking the start of a two-year span between long term support versions. Previously, Java LTS versions were released every three years, and prior to that even more sporadically. This means that new features are maturing over a much quicker period of time. 📚 Further reading: What is Java LTS and Why Does it Matter? But there’s more to Java 21 than simply a shifting release cadence. The latest JDK is packed with permanent, preview, and incubator features to help Java developers innovate. Keep reading to find out: What JDK programming languages developers are using What a JEP is and why it matters Hidden gems in Java 21 Expert insight on Java 21Final thoughts on Java 21 What JDK Languages are Java Developers Using?A new Java version isn’t impetus enough for many organizations to drop what they’re doing and upgrade to a new version. After all, upgrading is a lot of work and can cause disruption to mission-critical business applications. According to the 2024 Java Developer Productivity Report, 11% of developers said they had already upgraded to Java 21, 23% were using Java 17, and a combined 42% were using Java 8 or Java 11, for which Oracle no longer offers standard support. The burden of upgrading JDKs used to be very large due to large sets of features being released with each subsequent release. Today, many companies realize that it’s much easier to maintain support for the latest version of Java due to a smaller group of features introduced with each release. And the features introduced in Java 21 make the lift of upgrading JDK versions worth the effort. 📊 Curious about what your peers are using in their Java tech stack? Get your free copy of our 2024 Java Developer Productivity Report to dive into the data. Download Your Copy What’s a JEP and Why Does it Matter?JEP is a Java development kit enhancement proposal. JEPs are a formalized way by which new features are added to the Java language on a preliminary or permanent basis. Further, there are three different types of JEPs: Incubator JEPs are a means of putting not-yet-final tools and APIs in the hands of developers while those tools and APIs progress toward either finalization or permanent removal in a future release. Incubator JEPs are a good way to test new features today, but put them into production at your own risk. Preview JEPs are features for which the design, specification, and implementation is finalized but not yet permanent, which means that they may yet be changed or removed at a future release. Preview JEPs must also be specifically enabled to be used. All other JEPs are essentially permanent. While it’s not an official title, I’ll refer to them as “Permanent JEPs” to differentiate. Java 21 includes 15 JEPs: one is an incubator, five are previews and nine are permanent features. Here’s the full list: Incubator JEP The incubator JEP included in Java 21 is: JEP 448 - Vector API (Sixth Incubator) Preview JEPs The six preview JEPs included in Java 21 are: JEP 430 : String Templates JEP 442 : Foreign Function & Memory API (Third Preview) JEP 443 : Unnamed Patterns and Variables JEP 445 : Unnamed Classes and Instance Main Methods JEP 446 : Scoped Values JEP 453 : Structured Concurrency Permanent JEPs The eight permanent JEPs included in Java 21 are: JEP 431 : Sequenced Collections JEP 439 : Generational ZGC JEP 440 : Record Patterns JEP 441 : Pattern Matching for switch JEP 444 : Virtual Threads JEP 449 : Deprecate the Windows 32-bit x86 Port for Removal JEP 451 : Prepare to Disallow the Dynamic Loading of Agents JEP 452 : Key Encapsulation Mechanism API Hidden Gems in Java 21With definitions out of the way, here’s a look at some of our favorite features included in the latest Java LTS release. While not all of the JEPs qualify as “hidden gems” (some, like virtual threads, should be quite familiar unless you’ve been developing under a rock) they should all be on your list to test for production readiness. Here’s a closer look at 11 of our favorites. JEP 430: String Templates String templates couple literal text with embedded expressions and template processors to produce specialized results. This was theoretically possible prior to JEP 430 but the process was messy; now it’s much more straightforward and comparable to other programming languages, like in the example below: This feature makes it easier and more intuitive for Java developers to write strings. If you’d like to try string templates out yourself, you have to add compilation flags in order to do so. JEP 431: Sequenced Collections Sequenced collections represent collections with a defined encounter order. Using this feature, you should easily be able to get to the first and last elements, and process elements in reverse order. You might already be doing this today, but now the process is much easier. Prior to JEP 431, there wasn’t a common interface for these collections and the operations were different. The diagram below illustrates the SequencedSet, SequencedCollection, and SequencedMap interfaces. JEP 439: Generational Z Garbage Collector (ZGC) The Generational ZGC improves the Z Garbage Collector to maintain separate generations for young and old objects. It also allows the ZGC to collect young objects more frequently, and older objects less frequently. If you’re currently using the ZGC, you’ll see significantly improved performance. Right now Generational ZGC has to be specifically enabled, but in the future it will be enabled by default. JEP 440: Record Patterns Record Patterns enable Java developers to deconstruct record values; they can be nested with type patterns to enable a powerful, declarative, and composable form of data navigation and processing. Record patterns first appeared as a preview feature in Java 19 and were previewed for a second time with some tweaks in Java 20. JEP 442: Foreign Function & Memory API Foreign Function & Memory API allows Java programs to interoperate with code and data not managed by the JVM. JEP 442 enables foreign memory management for code outside of the JVM safely, without worrying about causing disruption to the underlying operating system. JEP 444: Virtual Threads Virtual threads could pose a significant time savings for Java programmers who are doing concurrent programming and dealing with threads. Instead of having to modify your code for concurrency and specify threads—a process that can quickly get messy—virtual threads enable the benefits of concurrency with greater performance and less complexity. That said, they may be complex to implement in existing large applications. They’re also not a panacea; you can’t substitute virtual threads for CPU threads and magically expect the same level of performance. Virtual threads are hardly a hidden gem—they've been previewed multiple times in previous JDK versions—but there’s excitement to see how the Java community can incorporate this feature into new applications. JEP 445: Unnamed Classes and Instance Main Methods This preview JEP poses the most potential for Java developers who are new to the language, or for more experience developers who are teaching others the language. This feature has some limitations, mainly that unnamed classes can’t reference named classes and vice versa. It’s also somewhat controversial, since while it may make Java easier to learn for individuals coming from other languages, it could potentially cause newcomers to learn some bad habits. JEP 448: Vector API (Sixth Incubator) Vectors have been in the Java development language nearly since the beginning, but until now there hasn’t been an API to utilize CPU hardware when doing so. That changes with JEP 448. Use cases for the Vector API include linear algebra, image processing, and character decoding, among others. As mentioned earlier, the main advantage of this API is that it’s hardware supported. Take a closer look at the documentation before you dive into testing this feature, however, because certain CPUs are not supported. JEP 449: Deprecate the Windows 32-bit x86 Port for Removal End of life for the final Windows 10 (Version 22H2) is October 14, 2025. That date is important because Windows 10 is the last version that supports 32-bit operations. With JEP 449, Java developers will get an error when they configure the 32-bit x86 port. JEP 451: Prepare to Disallow the Dynamic Loading of Agents This new feature will issue a warning when agents are loaded dynamically into a running JVM; in the future it will issue an error. The main benefit of this is increased security. Libraries that currently load agents dynamically will need to be changed to load them at startup with --javaagent/--agentlib options or enable dynamic loading with --XX:+EnableDynamicAgentLoading JEP 452: Key Encapsulation Mechanism API This API allows for creating of encryption keys using key encapsulation mechanisms (KEMs) to comply with the latest security regulations including those proposed in RSA Key Encapsulation Mechanism (RSA-KEM), the Elliptic Curve Integrated Encryption Scheme (ECIES), and candidate KEM algorithms for the National Institute of Standards and Technology (NIST) Post-Quantum Cryptography standardization process. JEP 453: Structured Concurrency Structured concurrency simplifies concurrent programming by introducing an API that treats groups of related tasks running in different threads as a single unit of work. This is a preview JEP that was first introduced as an incubator JEP in Java 19. Expert Insight on Java 21 Looking for more details on the aforementioned hidden gems in Java 21? We cover the details on Virtual threads, record patterns, generational Z Garbage Collector and more in this webinar. Final Thoughts on Java 21 As you can see, there are a wide range of features included in Java 21, many of which support faster and more efficient Java development. Tooling throughout the Java community will likely expedite adding support for Java 21 due to the fact that it is a long-term support version. Tools like JRebel have consistently been the first to add support for these releases (JRebel support expected to release on October 3rd). Compound those time savings by using JRebel by Perforce, eliminating time-consuming rebuilds and redeploys that disrupt your development workflow. Discover how much Java development time you could save during your 14-day free trial of JRebel. Try Free
Bleston Wright Senior Sales Engineer, Perforce Software Bleston Wright is a Sales Engineer at Perforce, and is passionate about helping software development teams to increase output while working more efficiently.