Java 11 (LTS)

Changes

JEP 330: Launch Single-File Source-Code Programs (opens in a new tab)

  • Notes

    • Use java interpreter to execute source code directly, aka source-file mode

    • java HelloWorld.java

      is informally equivalent to

      javac -d <memory> HelloWorld.java java -cp <memory> hello.World

    • You can add as many public classes as you need in the single source file. The only thing that matters is that the main method should be defined in the first class in the source file.

    • The in-memory compiled code runs as part of an unnamed module with the option --add-modules=ALL-DEFAULT. This enables the code to use different modules without the need to explicitly declare dependency using the module-info.java.

    • Test with java --source <version> <script> first before using shebang approach, as there could be JVM compatibility issues. When used with shebang, specifying a compatible Java interpreter.

  • Cheatsheet

    • Run source code file with java extension

      java <Java-source-code-file.java> <arguments...>

    • If the file does not have the .java extension, the --source option must be used to force source-file mode.

      java --source <java-source-version> <Java-source-code-file> <arguments...>

    • Shebang files

      1. Add shebang line

        #!<java-interpreter-path> --source <java-source-version>

      2. Make the source code file executable.

        chmod +x <script>

      3. Run the source code file like any shell script

        ./<script>

  • Resources

JEP 320: Remove the Java EE and CORBA Modules (opens in a new tab)

  • java.xml.ws.annotation removed from JDK, use the following dependency instead:
<!-- https://mvnrepository.com/artifact/javax.annotation/javax.annotation-api -->
<dependency>
    <groupId>javax.annotation</groupId>
    <artifactId>javax.annotation-api</artifactId>
    <version>1.3.2</version>
    <scope>provided</scope>
</dependency>