You can run Java like Python now

by: Ethan McCue

This is meant to be a brief PSA for the programming general public. All this is known to the people following Java closely, but I figure most are not.

As of Java 22, you can run Java code like you would an interpreted language such as Python, Ruby, JavaScript, etc. This means that ahead-of-time compilation is no longer strictly required.

Say you have the following files.

src/Main.java

class Main {
    public static void main(String[] args) {
        System.out.println(Example.text());    
    }
}

src/Example.java

class Example {
    static String text() {
        return "example";
    }
}

You can directly run this project with java src/Main.java.

This is very new. The Java ecosystem doesn't yet have an accepted equivalent of pip or npm that isn't also tied to a build tool. Now that a build tool isn't required I figure that will come around soon enough.1

As a sidenote, public static void main(String[] args) and System.out.println are also no longer going to be needed. Stay tuned.

1: There are two tools that most closely fit the mould today. The first is Coursier, a tool that has been around in the Scala community for a while. The second is jresolve, a tool I produced that has a few bugs and missing features, but that I think could be a better fit with more time and polish.


<- Index