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 and Preview

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.

Some examples:

  • OpenJDK 19: Structured Concurrency (Incubator), JEP 428

  • OpenJDK 21: Vector API (Sixth Incubator), JEP 448

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:

  • OpenJDK 18: Pattern Matching for switch (Second Preview), JEP 420

  • OpenJDK 14: Text Blocks (Second Preview), JEP 368

  • OpenJDK 14: Records (Preview), JEP 359

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.