In Java11, you can launch the source code file
directly using java launcher.
Hello.java
public class Hello{ public static void main(String args[]){ System.out.println("Welcome to Java11 Programming"); } }
You can run ‘Hello.java’ application by executing
below command ‘java Hello.java’.
$java Hello.java Welcome to Java11 Programming
You can use this feature to quickly test the
applications and to write the scripts using shebang (#!) file.
More details
Till Java10, Java launcher operates in three modes.
a.
Launching a class file
b.
Launching main class of jar file.
c.
Launching main class of a module.
From Java11 onwards, 4th mode is added,
‘source-file mode’ it launch a class from source file.
In source file mode, class is compiled into memory and
executed.
For example,
java Hello.java
is informally equivalent to
javac -d <memory> Hello.java
java -cp <memory> Hello
Referencehttps://openjdk.java.net/jeps/330
No comments:
Post a Comment