Visit Azul.com Support

Incubator and Preview Features in OpenJDK

With the introduction of the six-months release cycle in the OpenJDK project in 2018 (since OpenJDK 10), the evolution of the Java programming language and runtimes is managed with incubator and preview features, introduced by JEP 12. These features are only available during compilation and runtime when additional flags are used, and can be used for experiments and to try out these new features. This way, the Java community helps to evaluate new evolutions, provide feedback to the developers, and discover problems and inconsistencies.

Difference Between Incubator, Preview, and Experimental

Incubator Feature

Incubator (or experimental) features are not mature yet but allow early adopters and enthusiasts to use them in experiments. You can expect them to be buggy or unstable as they need to further mature in the next releases. But they can even be removed again, based on the feedback and the evolution of their development.

An example from the 24 release:

  • Vector API (Ninth Incubator), JEP 489

Preview Feature

Preview features have been fully specified, developed, and implemented, but are still being evaluated and can further change. They can be used in development to experiment with upcoming new features and can be expected to become available in a future version, although this is still not guaranteed.

Some examples from the 24 release:

  • Scoped Values (Fourth Preview), JEP 487

  • Primitive Types in Patterns, instanceof, and switch (Second Preview), JEP 488

  • Simple Source Files and Instance Main Methods (Fourth Preview), JEP 495

Experimental Feature

Some examples from the 24 release:

  • Generational Shenandoah (Experimental), JEP 404

  • Compact Object Headers (Experimental), JEP 450

How to Use These Features

During Compilation

When compiling code that uses incubator and/or preview features, you need to provide the additional flags --release and --enable-preview. For instance, for version 21:

 
javac --release 21 --enable-preview MyClass.java

During Runtime

To enable incubator and/or preview features during runting, only the additional flag --enable-preview is needed. For instance:

 
java --enable-preview -jar MyApp.jar

Conclusion

Incubator and preview features allow the Java-ecosystem to continuously evolve while getting feedback from the users about usability, consistency, and stability. You should never use these in production as they are not stable yet and can still evolve before they become generally available, or even get removed, in one of the next releases.