This Specification defines version 18 of the Java Platform, Standard Edition (“Java SE 18”). The Reference Implementation of this Specification is the Java Development Kit, version 18 (“JDK 18”).
|4||Component JSR Specifications|
|8||APIs proposed for removal|
|A1||Complete API Specification|
|A2||API Specification differences|
|A3||Java Language & Virtual Machine Specifications|
|A4||JAR File Specification|
|A5||Java AWT Native Interface (JAWT) Specification & Guide|
|A6||Java Debug Wire Protocol (JDWP)|
|A7||Java Native Interface (JNI) Specification|
|A8||Java Object Serialization Specification|
|A9||Java Remote Method Invocation (RMI) Specification|
|A10||Java Security Standard Algorithm Names|
|A11||JVM Tool Interface (JVM TI)|
This release continues the evolution of the Platform to ensure the
broadest possible success of the core Java technology. It previews
pattern matching for
switch statements and
switch expressions, specifies UTF-8 as the default charset of
the standard Java APIs, and defines a service provider interface (SPI) for
host name and address resolution. Finally, it deprecates finalization for
removal in a future release.
This document directly specifies API features, enhancements, clarifications, and bug fixes. It also specifies features by reference to other Specifications which are revised in Maintenance Releases of existing JSRs. The specifications of these changes are contained in two accompanying documents: Annex 1 is the complete Java SE 18 API Specification and Annex 2 is an annotated API specification showing the exact differences relative to Java SE 17. Informative background for these changes may be found in the list of approved Change Specification Requests for this release.
This Specification includes the Java SE 18 Editions of The Java Language Specification and The Java Virtual Machine Specification in Annex 3. The Java SE 18 Editions contain all corrections and clarifications made since the Java SE 17 Editions, as well as additions for new features. Annex 3 also presents changes to The Java Language Specification and The Java Virtual Machine Specification in connection with preview features in Java SE 18.
This Specification includes the Java SE 18 versions of additional narrative specifications in Annexes 4 — 11. The Java SE 18 versions contain all corrections and clarifications made since the Java SE 17 versions, as well as additions for new features.
Changes to the Java SE Platform Specification are categorized as either features or enhancements. A feature is, roughly speaking, a change of which at least one of the following statements is true:
Any addition that is not a feature is considered an enhancement.
There is, obviously, room for judgment when interpreting this definition. In order to maximize the visibility of Platform revisions we generally tend to consider borderline items to be features rather than enhancements.
Some Component JSR Specifications previously incorporated into the Platform are still available separately or have significant Specifications themselves. Changes to their Specifications are therefore made in separate Maintenance Releases. The following existing component JSRs may have Maintenance Releases. These will be incorporated by reference before the Final Release of this Specification as necessary:
JSR 199: Java Compiler API [MR 6] JSR 269: Pluggable Annotation-Processing API [MR 12]
Each Component JSR Specification, or revision thereto, may be related to one or more features in the detailed list below.
Work on features in the Java SE 18 Reference Implementation is organized in terms of JDK Enhancement Proposals (JEPs). Each feature description gives a link to the corresponding JEP document as a convenience, but that document is not a normative part of this Specification. Some features are included in the Java SE 18 Reference Implementation on a preview basis, to gain exposure before achieving permanent status in a later release of the Java SE Platform.
Deprecate finalization for removal in a future release. Finalization remains enabled by default for now, but can be disabled to facilitate early testing. In a future release it will be disabled by default, and in a later release it will be removed. Maintainers of libraries and applications that rely upon finalization should consider migrating to other resource management techniques such as the
try-with-resources statement and cleaners.
Define a service-provider interface (SPI) for host name and address resolution, so that
java.net.InetAddress can make use of resolvers other than the platform's built-in resolver.
Specify UTF-8 as the default charset of the standard Java APIs. With this change, APIs that depend upon the default charset will behave consistently across all implementations, operating systems, locales, and configurations.
Enhance the Java programming language with pattern matching for
expressions and statements, along with extensions to the language of patterns.
Extending pattern matching to
switch allows an expression to be tested against
a number of patterns, each with a specific action, so that complex data-oriented
queries can be expressed concisely and safely.
Preview features A preview language or VM feature is a new feature of the Java SE Platform that is fully specified, fully implemented, and yet impermanent. This Specification incorporates the Java SE 12 Platform Specification (JSR 386), subsection Preview features by reference.
Preparing for removal of finalization An Implementation must support the finalization of objects, as described in The Java Language Specification, section 12.6. However, this Platform Specification deprecates finalization, for removal. To aid preparations for the removal of finalization, an Implementation may provide a means to invoke its run-time system with finalization disabled. If finalization is disabled, the effect is that the Java Virtual Machine never invokes an object’s finalizer before the storage for the object is reclaimed by the garbage collector. An Implementation must not, by default, disable finalization.
(The Reference Implementation provides the ability to disable
finalization via the command-line option
Future revisions of this Platform Specification are expected to disable finalization by default and, eventually, to remove finalization from the Java Language Specification.
A module is a named set of packages designed for reuse. A specification governed by the JCP defines standard packages, and may group them into one or more standard modules.
This Specification groups the standard packages of the Java SE Platform into 21 standard modules, which we refer to as the Java SE modules. The name of a Java SE module always starts with the string "java.". The complete list of such modules is:
Compared to Java SE 17, this Specification does not add or remove any modules.
The module graph The Java SE modules depend upon each other as stated in their specifications, which are part of the overall API Specification. The corresponding complete Java SE module graph has too many edges to be displayed easily in visual form; here is the transitive reduction of the directed acyclic graph, in which redundant edges are omitted (click to enlarge):
Here is how to read this visualization of the module graph:
If one module depends upon another, and it grants implied readability to that module via a requires transitive directive, then there is an edge from the first module to the second.
At the very bottom is the java.base module, which contains essential classes such as java.lang.Object and java.lang.String. The base module depends upon no module, and every other module depends upon the base module.
At the top is the java.se module, which gathers together all of the modules that comprise the Java SE Platform. This is an example of an aggregator module, which logically gathers the content of other modules by granting implied readability to them, but adds no content of its own. A run-time system configured to contain the java.se module will contain all of the packages of the Java SE Platform.
A module is a Java SE module — that is, considered part of the Java SE Platform Specification — if and only if it is a standard module reachable from the java.se module.
Relaxing strong encapsulation As an aid to migration, previous versions of this Specification permitted an Implementation to provide a means to invoke its run-time system with one or more packages of one or more of its modules open to code in all unnamed modules, i.e., to code on the class path. This is no longer permitted.
(The Reference Implementation provided this capability via the
An Implementation must not relax the strong encapsulation of any of its modules, either by default or upon request. That is, its run-time system must not behave as if some packages in the Implementation’s modules are open when they are not open according to their module declarations. A package, or an entire module, is open to code in all unnamed modules if and only if:
This section may be compared to the corresponding section that appeared in Java SE 16.
Incorporated subsections This Specification incorporates the following subsections by reference from Java SE 9 Platform Specification (JSR 379), “Modules”:
The following APIs were removed from the Java SE Platform by this Platform Specification. The number in parentheses indicates the Java SE Platform Specification which first proposed its removal.
The following APIs were proposed for removal from the Java SE Platform by the Platform Specifications for Java SE 9, Java SE 10, Java SE 13, Java SE 14, Java SE 16, and Java SE 17. They are not removed in this release of the Java SE Platform. They continue to be eligible for removal in a future release.
The following APIs are proposed for removal from the Java SE Platform
by this Platform Specification. They are annotated as
forRemoval=true, following the
convention established by
This makes them eligible for removal in a future release.
Additional details about deprecations, including potential alternatives, may be found in the Deprecated API list of the API Specification. Migration away from deprecated APIs is strongly encouraged.