Installation & Setup
Before you can write and run Java programs, you need the JDK (Java Development Kit) installed on your
machine, along with a place to write code. This page walks through downloading the JDK, verifying it works, setting up
JAVA_HOME, picking an IDE, and compiling your first program from the command line.
Downloading the JDK
You have a few good options for getting a JDK. Any recent version (JDK 17 or later is a safe pick for beginners) will work fine for this tutorial.
| Option | Notes |
|---|---|
| Oracle JDK | The official build from Oracle. Free to download and use, with commercial licensing terms for some use cases at scale. |
| OpenJDK / Adoptium (Temurin) | Free, open-source builds of the JDK. Adoptium's Temurin builds are a very popular no-fuss choice for beginners. |
Verifying Your Installation
Once the JDK is installed, open a terminal (Command Prompt, PowerShell, or a Unix shell) and check that both the compiler and the runtime are available:
java -version
javac -version
java -version checks the Java Runtime used to execute programs, while javac -version
checks the compiler used to build them. If both print a version number, your JDK is installed correctly.
Setting JAVA_HOME
Many build tools and IDEs look for an environment variable named JAVA_HOME that points to your JDK's
installation folder. The exact steps to set it differ by operating system:
- Windows: set
JAVA_HOMEas a system environment variable pointing to your JDK folder (e.g.C:\Program Files\Java\jdk-17), then add%JAVA_HOME%\binto yourPATH. - macOS: export
JAVA_HOMEin your shell profile, typically using/usr/libexec/java_hometo locate the installed JDK. - Linux: export
JAVA_HOMEin your shell profile (e.g.~/.bashrc) pointing to your JDK's install directory, and add itsbinfolder toPATH.
JAVA_HOME setup, so don't worry if this feels fiddly at first.Choosing an IDE
You can write Java in any text editor, but an IDE (Integrated Development Environment) makes life much easier with auto-completion, error highlighting, and built-in run/debug buttons.
| IDE | Why people choose it |
|---|---|
| IntelliJ IDEA Community Edition | Free, feature-rich, and the most popular Java IDE among professional developers. |
| Eclipse | Free, mature, and widely used in enterprise and academic settings. |
| VS Code + Java Extension Pack | A lighter-weight editor that becomes a capable Java environment once you add Microsoft's Java Extension Pack. |
Compiling and Running from the Command Line
Even if you plan to use an IDE day-to-day, it's worth knowing how to compile and run Java directly from a terminal —
it's exactly what your IDE is doing behind the scenes. Save the following as HelloWorld.java:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Then, from the same folder, run these two commands:
javac HelloWorld.java
java HelloWorld
What just happened:
javac HelloWorld.java— compiles your source file intoHelloWorld.classbytecode.java HelloWorld— runs the compiled class using the JVM (note: no.classor.javaextension here).- If everything worked, you'll see
Hello, World!printed to your terminal.