Getting Started · Lesson 2 of 42
Install the JDK and Set Up an IDE
To write Java you need the JDK and an editor. This lesson gets both working on Windows, macOS or Linux in about fifteen minutes, and shows how to fix the two errors almost everyone hits on the first day.
In this lesson
- Choose and install a JDK
- Set
JAVA_HOMEandPATH - Verify with
java -versionandjavac -version - Set up IntelliJ IDEA or VS Code, and try JShell
Step 1: Download a JDK
Java is open source, and several organisations publish free builds of the same OpenJDK code. Any of these is fine:
- Eclipse Temurin (adoptium.net) – the most popular free build. Recommended.
- Oracle JDK (oracle.com/java) – free to use for development.
- Amazon Corretto, Microsoft Build of OpenJDK – also free.
Pick JDK 21 (LTS) or a newer LTS, and the installer for your system. On a Mac with an M-series chip choose aarch64 / ARM64; on most Windows laptops choose x64.
Step 2: Install
Windows
- Run the
.msiinstaller. - On the "Custom Setup" screen enable Set JAVA_HOME variable and Add to PATH.
- Finish and open a new Command Prompt (old windows don't see the new PATH).
macOS
Run the .pkg installer, or use Homebrew:
brew install --cask temurin@21
Linux (Ubuntu / Debian)
sudo apt update
sudo apt install openjdk-21-jdk
Step 3: Verify
java -version
javac -version
openjdk version "21.0.5" 2024-10-15 LTS OpenJDK Runtime Environment Temurin-21.0.5+11 (build 21.0.5+11-LTS) javac 21.0.5
If both commands print version 21 or higher, you are ready.
Common mistake: "'javac' is not recognized…"
The JDK's bin folder is not on your PATH. On Windows search for Environment Variables, add a system variable JAVA_HOME = C:\Program Files\Eclipse Adoptium\jdk-21…, then add %JAVA_HOME%\bin to Path. Close and reopen the terminal.
Common mistake: java and javac show different versions
An older Java installed earlier is first on the PATH. Remove the old one (or move the new bin folder to the top of the Path list) so both commands come from the same JDK.
Step 4: Choose an editor
| Editor | Why choose it |
|---|---|
| IntelliJ IDEA Community | The professional standard for Java. Excellent auto-complete, refactoring and debugging. Free. |
| VS Code + "Extension Pack for Java" | Lightweight; good if you already use VS Code for other languages. |
| Eclipse | Still common in older company projects. |
In IntelliJ: New Project → Java → JDK 21 → Create. Right-click the src folder, choose New → Java Class, name it Main, and you have a file ready for the next lesson.
Try code instantly with JShell
The JDK includes JShell, an interactive shell (REPL). Type jshell in a terminal and test single lines without writing a class:
jshell> 24 * 60 * 60
$1 ==> 86400
jshell> "Learn".length() + "Frenzy".length()
$2 ==> 11
jshell> /exit
JShell is perfect for checking how an operator or method behaves before you use it in a program.
How the folders look
A simple Java project
java-course/
- src/your .java source files (Main.java…)
- out/ or target/compiled .class files (created by the IDE or build tool)
- pom.xml / build.gradlelater: Maven or Gradle build file listing libraries
Practice
Try it yourself
Open JShell and calculate how many minutes are in a week.
Show solution
jshell> 7 * 24 * 60 $1 ==> 10080Find out where your JDK is installed.
Show solution
On macOS run
/usr/libexec/java_home; on Windows runwhere java; on Linux runreadlink -f $(which java).
Quick check
Which command shows the compiler version?
javac -version
What should JAVA_HOME point to?
The JDK's installation folder (the one that contains bin).
What is JShell?
An interactive shell included with the JDK for running Java snippets without a class or main method.
Summary
- Install a free JDK 21+ build such as Eclipse Temurin.
- Make sure
java -versionandjavac -versionboth work and match. - Use IntelliJ IDEA Community (or VS Code) and try ideas quickly in JShell.
Finished this lesson?
Mark it complete to track your progress, then carry on with the next lesson.