Java11: Run Java code in a single file as is

Java 11 has been released.

The official version of Java 11 has been released, and support for the Oracle JDK will be charged from this version. Expectations for free long-term support provided by OpenJDK are low at this time https://www.publickey1.jp/blog/18/java_11oracle_jdkopenjdk.html

"Execute Java code in a single file as it is" in it

JEP 330: Launch Single-File Source-Code Programs http://openjdk.java.net/jeps/330

I tried.

Installation

I tried the Windows version. ~~http://openjdk.java.net/~~ I followed the link from ~~, but ... I followed the link to the Oracle JDK and installed it. ~~ ~~ OpenJDK 11 is here (look for later). ~~

You can download it from the following. https://jdk.java.net/11

Install it for the time being and check the java version. I updated from java 8 on Windows The environment variables remained unchanged at java 8, so I manually rewrote the PATH and JAVA_HOME paths to java 11.

$ java -version
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)

Run Java code in a single file as is

And a single java file

test.java

class Test {
    public static void main(String[] arg) {
        System.out.println("Hello World");
    }
}

Run without compiling

$ java test.java
Hello World

I was able to execute it. ..

Of course you can compile and run

$ javac test.java
$ ls
Test.class  test.java
$ java Test
Hello World

Obviously, When using .class files, there is no first intermediate compilation, so execution is faster.

Recommended Posts

Java11: Run Java code in a single file as is
What is a class in Java language (3 /?)
What is a class in Java language (1 /?)
What is a class in Java language (2 /?)
Memo: [Java] If a file is in the monitored directory, process it.
Read a string in a PDF file with Java
Run a Spring Boot project in VS Code
Code to escape a JSON string in Java
[Java] Something is displayed as "-0.0" in the output
Studying java8 (such as reading a file using Stream)
How to convert a file to a byte array in Java
Work as a team! Face Null head-on in Java
What is a jar file?
Find a subset in Java
What is a Java collection?
[Windows] Java code is garbled
Java in Visual Studio Code
Write Java8-like code in Java8
Read WAV data as a byte array in Android Java
Activate Excel file A1 cell of each sheet in Java
Guess the character code in Java
3 Implement a simple interpreter in Java
I created a PDF in Java.
Java Spring environment in vs Code
[For beginners] Run Selenium in Java
Run Java application in Azure Batch
Upload a file using Java HttpURLConnection
How slow is a Java Scanner?
Log output to file in Java
A simple sample callback in Java
What is a snippet in programming?
Get the public URL of a private Flickr file in Java
Java Calendar is not a singleton.
[Java] Returns a Japanese name file in filename of HTTP header
About file copy processing in Java
What is a lambda expression (Java)
Read items containing commas in a CSV file without splitting (Java)
Get stuck in a Java primer
Determining if a custom keyboard is enabled in Android Studio (Java)
Run an external process in Java
Even though the property file path is specified in the -cp option, it is not recognized as a classpath.
For the time being, run the war file delivered in Java with Docker
To create a Zip file while grouping database search results in Java
Sample program that returns the hash value of a file in Java
About returning a reference in a Java Getter
What is a Spring Boot .original file?
What is the best file reading (Java)
Java creates a pie chart in Excel
Why does Java call a file a class?
Create a TODO app in Java 7 Create Header
What is the main method in Java?
Try making a calculator app in Java
All same hash code string in Java
Implement something like a stack in Java
Split a string with ". (Dot)" in Java
Creating a matrix class in Java Part 1
[Mac] Install Java in Visual Studio Code
Sample to unzip gz file in Java
Build by specifying docker as a file
File output bean as JSON in spring
[Deep Learning from scratch] 2. There is no such thing as NumPy in Java.