Setting Up Java

To write and run Java you need a JDK (Java Development Kit) and something to edit code with. This lesson walks through installing a JDK, running your first file from the terminal, and the tools you'll use as your programs grow: an IDE and JShell.

JDK, JRE and JVM

TermWhat it is
JVMThe Java Virtual Machine: runs compiled bytecode
JRERuntime environment: the JVM plus the standard library — enough to run programs
JDKDevelopment kit: the JRE plus tools such as the javac compiler — what you need to write programs

Installing a JDK

Java itself is open source (OpenJDK), and several organisations publish free, production-ready builds. Popular choices are Eclipse Temurin (adoptium.net), Oracle OpenJDK, Amazon Corretto, Microsoft Build of OpenJDK and Azul Zulu. Install version 25 or later:

$ install
# macOS (Homebrew)
brew install openjdk@25

# Windows (winget)
winget install EclipseAdoptium.Temurin.25.JDK

# Ubuntu / Debian
sudo apt install openjdk-25-jdk

# Any system: SDKMAN! (lets you switch between versions)
sdk install java 25-tem

Check that it worked:

$
java -version
Output
openjdk version "25.0.4.1" 2026-08-18 LTS
OpenJDK Runtime Environment Temurin-25.0.4.1+1 (build 25.0.4.1+1-LTS)
OpenJDK 64-Bit Server VM Temurin-25.0.4.1+1 (build 25.0.4.1+1-LTS, mixed mode, sharing)

Your exact version numbers will differ. If the command isn't found, the JDK's bin folder isn't on your PATH yet; the installer's instructions explain how to add it.

Running a single file

Create a file called Main.java:

JAVA Main.java
void main() {
    System.out.println("It works!");
}
Output
It works!

Then, in a terminal in the same folder:

$
java Main.java

The java launcher compiles the file in memory and runs it. This is perfect for learning and small scripts, and it's how every example in this course was run.

Compiling and running separately

$
javac Main.java     # creates Main.class
java Main           # runs the compiled class (no .java extension)

For larger programs, code is compiled once into .class files (usually packaged into a .jar) and then run many times. Build tools such as Maven and Gradle (lesson 55) automate this.

Choosing an editor or IDE

  • IntelliJ IDEA — the most popular Java IDE; the free Community Edition covers everything in this course.
  • Visual Studio Code with the "Extension Pack for Java" — lightweight and popular with beginners.
  • Eclipse and NetBeans — long-established, free IDEs.

An IDE compiles as you type, highlights errors, completes code, and has a Run button and a debugger. It's worth installing one early.

JShell: try code instantly

TXT jshell
$ jshell
jshell> 2 + 3 * 4
$1 ==> 14

jshell> String name = "Ana"
name ==> "Ana"

jshell> name.toUpperCase()
$3 ==> "ANA"

jshell> /exit

JShell (included with the JDK) runs Java one line at a time and shows each result immediately — ideal for experimenting with a method or checking how something behaves.

Online options

If you can't install software, online Java compilers let you paste and run code in the browser. Check that they use a recent Java version — the compact void main() style used in this course needs Java 25 or newer (use the traditional class form from lesson 3 on older versions).

Try it yourself

Copy this into Main.java, run it, then change the message.

Try it yourself · Main.java
Edit the code, copy it into Main.java and run java Main.java (Java 25+). How to set up Java