Java Get Started

To start coding in Java you install the JDK, choose an editor, then compile and run your first program.

Install the JDK

The Java Development Kit (JDK) contains the compiler and everything else you need to build Java programs. Download a current long-term-support version, such as JDK 21, from Oracle or an open distribution like Adoptium, and follow the installer for your operating system.

After installing, open a terminal or command prompt and check that Java is available by asking it for its version number.

Check the installed version

java -version
Note: If the command reports a version number, the JDK is installed correctly. If you see "command not found", the JDK may not be on your system PATH yet.

Choose an editor

  • A plain text editor with a terminal, which is great for learning the fundamentals
  • Visual Studio Code with the Java extension pack for a lightweight setup
  • IntelliJ IDEA or Eclipse for full-featured, professional development

Write your first program

Create a file named Main.java. The file name must match the public class name exactly, including capitalization. Type the following code into it.

Main.java

public class Main {
  public static void main(String[] args) {
    System.out.println("Hello, World!");
  }
}

Compile and run

From the folder that contains your file, compile it with javac to produce Main.class, then run it with java. Notice that you compile using the file name but run using the class name without any extension.

Build and execute

javac Main.java
java Main
CommandWhat it does
javac Main.javaCompiles the source file into Main.class bytecode
java MainRuns the compiled class on the JVM
Note: A common mistake is running java Main.java in older setups or typing the wrong capitalization. The class name and file name must match, and Java is case-sensitive.

Exercise: Java Get Started

If a .java file contains a public class, what must the file name match?