Run Java in terminal without an IDE

Simplest way to run a Java hello world in terminal.

Make sure you've installed the Java Development Kit first.

I'm going to assume you're in your home directory from now on.

Then create a new file helloworld.java.

Paste the code below into it.

public class helloworld {
  public static void main(String[] args) {
    System.out.println("hello world");
  }
}

Now to run, first compile it with javac helloworld.java.
Then java helloworld to run it.

Note: the class name has to be the same as the file name.

ref: https://introcs.cs.princeton.edu/java/11hello/

Run Java in terminal without an IDE
Share this