JVM Knowledge

A preview feature is:

  • a new feature of the Java programming language ("preview language feature"), or
  • a new feature of the Java Virtual Machine ("preview VM feature"), or
  • a new module, package, class, interface, field, method, constructor, or enum constant in the java.* or javax.* namespace ("preview API")

that is fully specified, fully implemented, and yet impermanent. It is available in implementations of a given release of the Java SE Platform to provoke developer feedback based on real world use; this may lead to it becoming permanent in a future release of the Java SE Platform.

The preview features defined by a given release of the Java SE Platform are enumerated in the Java SE Platform Specification for that release. The preview features are specified as follows:

  • Preview language features are specified in standalone documents that indicate changes ("diffs") to The Java® Language Specification for that release. The specifications of preview language features are incorporated into The Java® Language Specification by reference, and made a part thereof, if and only if preview features are enabled at compile time.
  • Preview VM features are specified in standalone documents that indicate changes ("diffs") to The Java® Virtual Machine Specification for that release. The specifications of preview VM features are incorporated into The Java® Virtual Machine Specification by reference, and made a part thereof, if and only if preview features are enabled at run time.
  • Preview APIs are specified within the Java SE API Specification for that release.

1.5.1. Restrictions on the Use of Preview Features

Implementations of the Java SE Platform disable, at both compile time and run time, the preview features defined by a given release, unless the user indicates via the host system, at both compile time and run time, that preview features are enabled. Implementations do not provide a way to enable only some of the given release's preview features.

A class file depends on the preview features of Java SE N (N ≥ 12) if:

  • the class file's major version number is the latest major version number supported by Java SE N in Table 1.2-A, and
  • the class file's minor version number is 65535

For example, a class file with version number 66.65535 depends on the preview features of Java SE 22, because 66 is the latest major version number supported by Java SE 22.

Compilers may need to emit class files that depend on the preview features of a given release even if the class files do not use any preview VM features. For example, a Java source file that uses a preview language feature of the release must be compiled to a class file that depends on the preview features of the release.

At run time, the rules for loading a class file that depends on the preview features of a given Java SE Platform release are specified in §4.1. Such a class file is tied to that release of the Java SE Platform, and cannot be loaded on any other release (even if preview features are enabled) because the preview features it depends on may be different or missing in the other release.

1.5.2. Current Preview VM Features

Java SE 26 does not define any preview VM features.