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

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
Then java helloworld to run it.

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


Run Java in terminal without an IDE
Share this