--release flag

The javac option that compiles for an older Java release, checking against that release's library and writing its class file version.

In more detail

A newer compiler can build class files that an older JVM accepts; --release 17 makes the output load on Java 17. Unlike older options, it also stops you calling library methods that did not exist in that release. Maven sets it through the maven.compiler.release property, and Gradle through a toolchain or release setting.

Examples

javac --release 17 Hello.java
<maven.compiler.release>21</maven.compiler.release>

Related terms

Taught in

References