2 Java Language Changes by Release
This section describes in detail the updated language features in Java SE 9 and subsequent releases.
Java Language Features for Java SE 24
| Feature | Description | JEP |
|---|---|---|
| First previewed in Java SE 23, this feature is re-previewed for this release. It is unchanged between Java SE 23 and this release. | JEP 488: Primitive Types in Patterns, instanceof, and switch (Second Preview) | |
| Flexible Constructor Bodies | First previewed in Java SE 22 as JEP 447: Statements before super(...) (Preview) and previewed again in Java SE 23 as JEP 482: Flexible Constructor Bodies (Second Preview). This feature is re-previewed for this release without any significant changes. | JEP 492: Flexible Constructor Bodies (Third Preview) |
| Module Import Statements | First previewed in Java SE 23, this feature is
re-previewed for this release.
In this release:
|
JEP 494: Module Import Declarations (Second Preview) |
| Simple Source Files and Instance Main Methods | First previewed in Java SE 21 as JEP 445: Unnamed Classes and Instance Main Methods (Preview) and previewed again in Java SE 23. This feature is re-previewed for this release with new terminology and a revised title but otherwise unchanged. | JEP 495: Simple Source Files and Instance Main Methods (Fourth Preview) |
Java Language Changes for Java SE 23
| Feature | Description | JEP |
|---|---|---|
| Introduced as a preview feature for this release.
In this release:
|
JEP 455: Primitive Types in Patterns, instanceof, and switch (Preview) | |
| Module Import Declarations | Introduced as a preview feature for this release.
In this release, you can succinctly import all of the packages exported by a module with a module import declaration. |
JEP 476: Module Import Declarations (Preview) |
| Implicitly Declared Classes and Instance Main Methods | First previewed in Java SE 21 as JEP 445: Unnamed
Classes and Instance Main Methods (Preview), this feature is
re-previewed for this release.
In this release:
|
JEP 477: Implicitly Declared Classes and Instance Main Methods (Third Preview) |
| Flexible Constructor Bodies | First previewed in Java SE 22 as JEP 447: Statements
before super(...) (Preview), this feature is re-previewed for
this release with a new title.
In this release, a
constructor body may initialize fields in the same class before
explicitly invoking a constructor. This enables a constructor in a
subclass to ensure that a constructor in a superclass never runs
code that sees the default value of a field in the subclass (for
example, |
JEP 482: Flexible Constructor Bodies (Second Preview) |
Note:
String Templates were first previewed in JDK 21 (JEP 430) and re-previewed in JDK 22 (JEP 459). String Templates were intended to re-preview again in JDK 23 (JEP 465). However, after feedback and extensive discussion, we concluded that the feature is unsuitable in its current form. There is no consensus on what a better design will be; therefore, we have withdrawn the feature for now, and JDK 23 will not include it.
See March 2024 Archives by thread and Update on String Templates (JEP 459) from the Project Amber amber-spec-experts mailing list for further discussion.
Java Language Changes for Java SE 22
| Feature | Description | JEP |
|---|---|---|
| Statements Before super(...) | Introduced as a preview feature for this release.
In constructors in the Java programming language, you may add statements that don't reference the instance being created before an explicit constructor invocation. |
JEP 447: Statements before super(...) (Preview) |
| Unnamed Variables and Patterns | First previewed in Java SE 21 as Unnamed Patterns and
Variables, this feature is permanent in this release. This means
that it can be used in any program compiled for Java SE 22 without
enabling preview features.
This feature remains unchanged since Java SE 21. |
JEP 456: Unnamed Variables & Patterns |
| String Templates | Preview feature from Java SE 21 re-previewed for this
release.
Except for a technical change in the types of template expressions, which is described in String Templates (Second Preview) in The Java Language Specification: Java SE 22 Edition, this feature remains unchanged since Java SE 21. |
JEP 459: String Templates (Second Preview) |
| Implicitly Declared Classes and Instance Main Methods | First previewed in Java SE 21 as JEP 445: Unnamed
Classes and Instance Main Methods (Preview), this feature is
re-previewed for this release as JEP 463: Implicitly Declared Classes
and Instance Main Methods (Second Preview).
In
this release:
|
JEP 463: Implicitly Declared Classes and Instance Main Methods (Second Preview) |
Java Language Changes for Java SE 21
| Feature | Description | JEP |
|---|---|---|
| Record Patterns | First previewed in Java SE 19, this feature is permanent
in this release. This means that it can be used in any program compiled
for Java SE 21 without enabling preview features.
In this
release, support for record patterns appearing in the header of an
enhanced |
JEP 440: Record Patterns |
| Pattern Matching for switch Expressions and Statements | First previewed in Java SE 17, this feature is permanent
in this release. This means that it can be used in any program compiled
for Java SE 21 without enabling preview features.
In this release:
|
JEP 441: Pattern Matching for switch |
| String Templates | Introduced as a preview feature for this release.
String templates complement Java's existing string literals and text blocks by coupling literal text with embedded expressions and template processors to produce specialized results. |
JEP 430: String Templates (Preview) |
| Unnamed Patterns and Variables | Introduced as a preview feature for this release.
Unnamed patterns match a record component without
stating the component's name or type. Unnamed variables are
variables that can be initialized but not used. You denote both with
the underscore character ( |
JEP 443: Unnamed Patterns and Variables (Preview) |
| Unnamed Classes and Instance Main Methods | Introduced as a preview feature for this
release.
Unnamed classes and instance main methods enable students to write streamlined declarations for single-class programs and then seamlessly expand their programs later to use more advanced features as their skills grow. |
JEP 445: Unnamed Classes and Instance Main Methods (Preview) |
Java Language Changes for Java SE 20
| Feature | Description | JEP |
|---|---|---|
| Pattern Matching for switch Expressions and Statements |
Preview feature from Java SE 17 re-previewed for this release. In this release:
|
JEP 433: Pattern Matching for switch (Fourth Preview) |
| Record Patterns |
Preview feature from Java SE 19 re-previewed for this release. In this release:
|
JEP 432: Record Patterns (Second Preview) |
Java Language Changes for Java SE 19
| Feature | Description | JEP |
|---|---|---|
| Pattern Matching for switch Expressions and Statements |
Preview feature from Java SE 17 re-previewed for this release. In this release:
|
JEP 427: Pattern Matching for switch (Third Preview) |
| Record Patterns |
Introduced as a preview feature for this release. A record pattern consists of a type, a record component pattern list used to match against the corresponding record components, and an optional identifier. You can nest record patterns and type patterns to enable a powerful, declarative, and composable form of data navigation and processing. |
JEP 405: Record Patterns (Preview) |
Java Language Changes for Java SE 18
| Feature | Description | JEP |
|---|---|---|
| Pattern Matching for switch Expressions and Statements |
Preview feature from Java SE 17 re-previewed for this release. In this release:
|
JEP 420: Pattern Matching for switch (Second Preview) |
Java Language Changes for Java SE 17
| Feature | Description | JEP |
|---|---|---|
| Sealed Classes |
First previewed in Java SE 15, this feature is permanent in this release. This means that it can be used in any program compiled for Java SE 17 without enabling preview features. A sealed class or interface restricts which classes or interfaces can extend or implement it. |
JEP 409: Sealed Classes |
| Pattern Matching for switch Expressions and Statements |
Introduced as a preview feature for this release. Pattern matching for |
JEP 406: Pattern Matching for switch (Preview) |
Java Language Changes for Java SE 16
| Feature | Description | JEP |
|---|---|---|
| Sealed Classes |
Preview feature from Java SE 15 re-previewed for this release. It has been enhanced with several refinements, including more strict checking of narrowing reference conversions with respect to sealed type hierarchies. A sealed class or interface restricts which classes or interfaces can extend or implement it. |
JEP 397: Sealed Classes (Second Preview) |
| Record Classes |
First previewed in Java SE 14, this feature is permanent in this release. This means that it can be used in any program compiled for Java SE 16 without enabling preview features. In this release, inner classes may declare members that are either explicitly or implicitly static. This includes record class members, which are implicitly static. A record is a class that acts as transparent carrier for immutable data. |
JEP 395: Records |
| Pattern Matching for instanceof |
First previewed in Java SE 14, this feature is permanent in this release. This means that it can be used in any program compiled for Java SE 16 without enabling preview features. In this release, pattern variables are no longer
implicitly final, and it's a compile-time error if a pattern
Pattern matching allows common logic in a program, namely the conditional extraction of components from objects, to be expressed more concisely and safely. |
JEP 394: Pattern Matching for instanceof |
Java Language Changes for Java SE 15
| Feature | Description | JEP |
|---|---|---|
| Sealed Classes |
Introduced as a preview feature for this release. A sealed class or interface restricts which classes or interfaces can extend or implement it. |
JEP 360: Sealed Classes (Preview) |
| Record Classes |
Preview feature from Java SE 14 re-previewed for this release. It has been enhanced with support for local records. A record is a class that acts as transparent carrier for immutable data. |
JEP 384: Records (Second Preview) |
| Pattern Matching for instanceof |
Preview feature from Java SE 14 re-previewed for this release. It is unchanged between Java SE 14 and this release. Pattern matching allows common logic in a program, namely the conditional extraction of components from objects, to be expressed more concisely and safely. |
JEP 375: Pattern Matching for instanceof (Second Preview) |
|
See also Programmer's Guide to Text Blocks |
First previewed in Java SE 13, this feature is permanent in this release. This means that it can be used in any program compiled for Java SE 15 without enabling preview features. A text block is a multiline string literal that avoids the need for most escape sequences, automatically formats the string in a predictable way, and gives the developer control over the format when desired. |
JEP 378: Text Blocks |
Java Language Changes for Java SE 14
| Feature | Description | JEP |
|---|---|---|
| Pattern Matching for the instanceof Operator |
Introduced as a preview feature for this release. Pattern matching allows common logic in a program, namely the conditional extraction of components from objects, to be expressed more concisely and safely. |
JEP 305: Pattern Matching for instanceof (Preview) |
| Records |
Introduced as a preview feature for this release. Records provide a compact syntax for declaring classes which are transparent holders for shallowly immutable data. |
JEP 359: Records (Preview) |
| Switch Expressions |
First previewed in Java SE 12, this feature is permanent in this release. This means that it can be used in any program compiled for Java SE 14 without needing to enable preview features. This feature extends
|
JEP 361: Switch Expressions |
|
See also Programmer's Guide to Text Blocks |
Preview feature from Java SE 13 re-previewed for this release. It has been enhanced with support for more escape sequences. A text block is a multiline string literal that avoids the need for most escape sequences, automatically formats the string in a predictable way, and gives the developer control over the format when desired. |
JEP 368: Text Blocks (Second Preview) |
Java Language Changes for Java SE 13
| Feature | Description | JEP |
|---|---|---|
| Text Blocks, see Programmer's Guide to Text Blocks |
Introduced as a preview feature for this release. A text block is a multi-line string literal that avoids the need for most escape sequences, automatically formats the string in a predictable way, and gives the developer control over format when desired. |
JEP 355: Text Blocks (Preview) |