JEP 495: Simple Source Files and Instance Main Methods (Fourth Preview)

Mainly for education but also for writing simple scripts

🔹 What JEP 495 Introduces

  1. Simple source file execution: Java can now run .java files without compiling them first, even if they're in a package or use preview features.

  2. Instance main() methods: You can now define the main() method as an instance method, not just static.

RUN:

JustSimpleSourceDemo

To see that instance method main will be run - it doesn't have to be static anymore.

RUN:

cd src/main/java/com/wlodar/jeeps/jep495simplesourcefiles/
java --enable-preview JustSimpleSourceDemo.java
-> This is an instance method without args not static and you can run it in IDEA

To see that you can run simple java programs

RUN:

java --enable-preview TheSimplestExampleWithJustMainFunction.java
-> As simple as that

the file is just :
public void main() {
    println("As simple as that");
}

Last updated