Installing the JDK
To write Java you need a JDK and an editor. This takes about ten minutes.
On this page · 5 min · Beginner
On this page
- In simple words
- Learning objectives
- Explanation
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Beginner
- Updated
- Oct 30, 2026
Related tutorials
In simple words#
The JDK is your full workshop (tools + engine). JAVA_HOME is the signboard telling every other tool where the workshop is.
- JDK distribution
- Temurin, Oracle, Microsoft Build of OpenJDK — all Java.
- JAVA_HOME
- Environment variable pointing to the JDK folder.
- jshell
- Interactive Java console for quick experiments.
Learning objectives#
- Install a JDK
- Set JAVA_HOME and PATH
- Verify the installation
- Run code in jshell and an IDE
Explanation#
Download a JDK 21 or 25 LTS build (e.g. Eclipse Temurin from adoptium.net) or install with a package manager.
The installer usually sets PATH; set JAVA_HOME to the JDK folder for build tools like Maven and Gradle.
java -version and javac -version confirm the install.
IntelliJ IDEA Community (free) is the most popular Java IDE; VS Code with the Extension Pack for Java also works well.
Code example: Install and verify#
# Windows (winget)
winget install EclipseAdoptium.Temurin.21.JDK
# macOS (Homebrew) brew install --cask temurin@21
# Ubuntu sudo apt install openjdk-21-jdk
java -version
javac -version
echo $JAVA_HOME # Windows PowerShell: $env:JAVA_HOME
jshell
jshell> 2 + 3 * 4
jshell> "Java".repeat(3)
jshell> /exit
openjdk version "21.0.5" 2024-10-15 LTS javac 21.0.5 $1 ==> 14 $2 ==> "JavaJavaJava"
This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.
Step-by-step explanation#
- A package manager installs the JDK.
- java/javac -version confirm the tools are on PATH.
- JAVA_HOME is used by Maven and Gradle.
- jshell evaluates Java expressions instantly.
Real-world use case#
New team members install the same JDK version so builds behave identically on every laptop.
Common mistakes#
You need the JDK to compile code.
Check which java runs: where java (Windows) / which java (macOS/Linux).
Best practices#
- Use an LTS version
- Set JAVA_HOME
- Keep one default JDK
- Use jshell for quick experiments
Remember this#
Install a JDK, not just a JRE.
java -version / javac -version.
jshell = Java playground.
Practice exercise#
Your task: Use jshell to calculate how many seconds are in a day.
Show solution
jshell> 24 * 60 * 60
$1 ==> 86400
Mini quiz#
Which variable do Maven and Gradle use to find the JDK?
Want more? Practise all Java MCQs · Java interview questions
My notes#
Saved in this browser.