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
| Term | What it is |
|---|---|
| JVM | The Java Virtual Machine: runs compiled bytecode |
| JRE | Runtime environment: the JVM plus the standard library — enough to run programs |
| JDK | Development 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:
# 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
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:
void main() { System.out.println("It works!"); }
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
$ 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.