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.

OptionNotes
Oracle JDKThe 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.
Tip: If you're not sure which to choose, Adoptium's Temurin distribution is a great default — it's free, well-maintained, and works identically to Oracle's JDK for learning purposes.

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_HOME as a system environment variable pointing to your JDK folder (e.g. C:\Program Files\Java\jdk-17), then add %JAVA_HOME%\bin to your PATH.
  • macOS: export JAVA_HOME in your shell profile, typically using /usr/libexec/java_home to locate the installed JDK.
  • Linux: export JAVA_HOME in your shell profile (e.g. ~/.bashrc) pointing to your JDK's install directory, and add its bin folder to PATH.
Note: Many modern IDEs can detect and manage a JDK for you without a manual 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.

IDEWhy people choose it
IntelliJ IDEA Community EditionFree, feature-rich, and the most popular Java IDE among professional developers.
EclipseFree, mature, and widely used in enterprise and academic settings.
VS Code + Java Extension PackA 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 into HelloWorld.class bytecode.
  • java HelloWorld — runs the compiled class using the JVM (note: no .class or .java extension here).
  • If everything worked, you'll see Hello, World! printed to your terminal.
Next steps: Now that your environment is ready, head to Syntax & First Program to understand exactly what each part of that Hello World program means.