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 -versionChoose 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 MainExercise: Java Get Started
If a .java file contains a public class, what must the file name match?