codegurukool.com · Free coding tutorials & online compiler

Home › Java Tutorial › Java get started

Java get started

Install the JDK, compile and run.

Install the JDK (Java Development Kit), for example from adoptium.net. Save your code as Main.java, compile with javac Main.java and run with java Main. The file name must match the public class name. Since Java 11 you can also run a single file directly with java Main.java.

Example code

/* Terminal:
   javac Main.java
   java Main
*/
public class Main {
  public static void main(String[] args) {
    System.out.println("It works");
  }
}

Run this code in the online editor

← Java installationJava syntax →