5. JDK 11 Launch Single-Source-File New Feature

In JDK 11, you can compile/run a single-file program in one step, without explicit compilation.

  1. Write a "Hello.java" (see previous section).
  2. Delete "Hello.class", if it exists.
  3. You can compile/run "Hello.java" in one command as follows:
    // Change directory to the directory containing Hello.java
    
    // Compile and Run
    java Hello.java

Notes:

  • This is applicable to single source-file only.
  • No need to use javac to compile the program.
  • It compiles in memory (without producing a .class file), and run.
  • This feature is introduced for beginners to learn Java, and for professionals to test a Java feature.
  • The filename and classname need not be the same.