Java 23: What Developers Need to Know
Java 23 brings exciting features like implicit classes, improved ZGC, and VS Code integration. Learn what's new and how it impacts your development workflow.
Join the DZone community and get the full member experience.
Join For FreeAs Java implements its 23rd major release on September 17, 2024, developers are in for a treat with many new features and improvements. Oracle's latest release promises to make development more efficient and enjoyable while enhancing the platform's performance, stability, and security. Let's dive into the key aspects developers should be excited about in Java 23.
The Six-Month Release Cadence Continues
Oracle is sticking to its six-month release cycle for Java, now in its seventh year. This approach has successfully delivered regular updates and innovations to the Java ecosystem. A Long-Term Support (LTS) version is released every two years, providing stability for enterprises that prefer less frequent updates. Java 23 marks the 14th release in this six-month cadence.
Key Themes in Java 23
Java 23 focuses on several key areas:
- Language improvements
- Library enhancements
- Tool updates
- Runtime optimizations
- Integrity features
The release delivers 12 JDK Enhancement Proposals (JEPs) across these themes. Let's explore each of these areas in more detail.
1. Language Improvements
Java 23 continues to evolve the language itself, focusing on making Java more accessible for smaller programs and scripts while maintaining its strength in large-scale applications.
Primitive Types in Patterns, instanceof, and switch (Preview): JEP 455
This feature aims to increase Java programming productivity by making the language more uniform and expressive. It removes restrictions about primitive types in pattern matching, instance, and switch statements, enhancing pattern matching by allowing primitive type patterns in all contexts.
Module Import Declarations (Preview): JEP 476
This feature enables developers to quickly and easily import all the packages exported by a module without requiring the importing code to be in a module. This simplifies the reuse of modular libraries and helps beginners use third-party libraries and fundamental Java classes more easily.
Implicitly Declared Classes and Instance Main Methods (Third Preview): JEP 477
This feature continues to evolve, offering a smooth on-ramp to Java programming. It allows students and developers to write their first programs without needing to understand language features designed for large programs. For example, you can now write:
```java
void main() {
System.out.println("Hello, World!");
}
```
This change eliminates the need for explicit class declarations and access modifiers in simple programs, making Java more approachable for beginners and more convenient for experienced developers working on small scripts.
Flexible Constructor Bodies (Second Preview): JEP 482
This feature allows statements to appear before an explicit constructor invocation (such as super(..)
or this(..)
). This gives developers greater freedom to express the behavior of constructors and preserves the existing guarantee that constructors run in top-down order during class instantiation.
2. Library Enhancements
Java 23 includes several important library updates:
Class-File API (Second Preview): JEP 466
This provides a standard API for parsing, generating, and transforming Java class files, helping developers improve productivity in tasks involving bytecode manipulation.
Vector API (Eighth Incubator): JEP 469
This API allows developers to express vector computations that reliably compile at runtime to vector instructions on supported CPU architectures, potentially achieving superior performance compared to equivalent scalar computations.
Stream Gatherers (Second Preview): JEP 473
This enhancement to the Stream API supports custom intermediate operations, allowing stream pipelines to transform data in ways not easily achievable with existing built-in intermediate operations. This makes stream pipelines more flexible and expressive.
Structured Concurrency (Third Preview): JEP 480
This feature introduces a new API for structured concurrency, aiming to simplify multithreaded programming. Consolidating related tasks running in different threads into a single unit of work it helps eliminate common risks arising from cancellation and shutdown.
Scoped Values (Third Preview): JEP 481
This feature enables the sharing of immutable data within and across threads, aiming to increase concurrent programs' ease-of-use, comprehensibility, performance, and robustness.
3. Tool Updates
Markdown Documentation Comments: JEP 467
This feature enables Javadoc documentation comments to be written in Markdown rather than solely in HTML and Javadoc @-tags. This change makes it easier for developers to write and read API documentation comments in source form.
4. Runtime Optimizations
ZGC: Generational Mode by Default: JEP 474
Java 23 switches the default mode of the Z Garbage Collector (ZGC) to generational mode. This change reduces the resources and maintenance costs required to support two different modes and is expected to improve efficiency for many applications.
Graal JIT Compiler Integration
Starting with Java 23, Oracle is including the Graal JIT compiler as an option within the Oracle JDK. This integration allows developers to easily switch between JIT compilers easily, potentially gaining performance benefits for certain workloads, especially those requiring faster startup times.
5. Integrity Features
Deprecate the Memory-Access Methods in sun.misc.unsafe for Removal: JEP 471
This change helps developers understand when their applications rely, directly or indirectly, on the memory-access methods in sun.misc.Unsafe
, which is planned for removal in a future release. It's part of Oracle's ongoing efforts to improve the security and integrity of the Java platform.
Java and AI
While not specific to Java 23, it's worth noting the increasing importance of AI in the Java ecosystem. Oracle has outlined a three-pronged strategy for Java and AI:
- Integration with enterprise data and cloud services includes OCI AI Services and the OCI SDK for Java.
- Making the Java platform better for Native AI involves native Java frameworks such as Tribuo, LangChain4j, and CoreNLP.
- Connecting business logic to native AI libraries: This is facilitated through projects like Panama and GraalPy.
Many of Java's ongoing projects, such as Project Valhalla and Project Panama, align well with the needs of AI and machine learning workloads. These projects aim to improve Java's performance with value types, better native interoperability, and vector APIs, all of which are crucial for AI development.
Java Management Service and Oracle Java SE Universal Subscription
Alongside Java 23, Oracle has released Java Management Service (JMS) 9.0, an Oracle Cloud Infrastructure (OCI) native service that provides a unified console and dashboard to help organizations manage Java runtimes and applications on-premises or in any cloud.
The Oracle Java SE Universal Subscription offers best-in-class support, including triage support for the entire Java portfolio, entitlement to Oracle GraalVM, the Java SE Subscription Enterprise Performance Pack, access to the advanced features of JMS, and the flexibility to upgrade at the pace of customers' businesses.
Looking Ahead: JavaOne 2025
Oracle has announced the return of JavaOne, the flagship event for the global Java community. JavaOne 2025 will take place from March 17 to 20, 2025, in Redwood Shores, California. This event will allow developers to hear about the latest Java developments and interact with Oracle's Java experts and industry luminaries.
What This Means for Developers
Java 23 represents a significant step forward for the language and platform. Here's what developers should keep in mind:
- Simplified coding: Features like implicitly declared classes and instance main methods will make writing small Java programs and scripts easier.
- Improved performance: With ZGC improvements and the integration of the Graal JIT compiler, applications can expect better performance and more predictable behavior.
- Enhanced tools: The new Markdown support for documentation and ongoing improvements to development tools will make it easier to work with Java.
- Platform integrity: While deprecating unsafe APIs may require some code adjustments, it will ultimately lead to a more secure and stable platform.
- AI readiness: Java's ongoing improvements make it an increasingly viable platform for AI and machine learning workloads.
- Better Library Support: Enhancements to the Stream API and the introduction of the Vector API provide developers with more powerful tools.
- Improved Concurrency: The structured concurrency and scoped values features (although still in preview) promise to make concurrent programming in Java more manageable and less error-prone.
Conclusion
Java 23 continues the language's tradition of thoughtful evolution, balancing innovation with compatibility. The new features and improvements demonstrate Oracle's commitment to keeping Java relevant and influential in an ever-changing technological landscape. Whether you're working on large enterprise applications, small scripts, or cutting-edge AI projects, Java 23 offers something valuable for every Java developer.
As of the September 17, 2024 release date, developers are encouraged to experiment with the preview builds, provide feedback on new features, and prepare their codebases for upcoming changes. With its blend of innovation and stability, Java 23 is shaping up to be another significant milestone in the evolution of one of the world's most popular programming languages.
Opinions expressed by DZone contributors are their own.
Comments