Loading lessons...
Get Started with Java
Get Started with Java
To run Java programs on your computer you need the JDK (Java Development Kit). It includes the compiler and the runtime needed to build and run Java code.
Install the JDK
- Go to the Oracle or OpenJDK website and download the JDK for your system.
- Install it like any other program.
- Verify it works by opening a terminal and running:
java -version
Write your first program
Create a file named Main.java. In Java, the file name should match the class name:
public class Main {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
Compile and run
First compile the file with the javac compiler:
javac Main.java
This creates a file called Main.class containing bytecode. Then run it with the java command:
java Main
The output is:
Hello World
Compile vs run
| Step | Command | What it does |
|---|---|---|
| Compile | javac Main.java | Turns source code into bytecode |
| Run | java Main | Runs the compiled class on the JVM |
TL;DR
- Install the JDK and check it with
java -version. - Save your code in a file that matches the class name.
- Compile with
javac Main.java. - Run with
java Main.