If you're just getting started with Java programming on Windows, the very first step is to set up your
Java development environment. Don’t worry—it's easier than you might think! Once you’ve set it up properly, you’ll be ready to compile and run your Java code smoothly.
In this guide, we’ll walk you through how to
install Java, set up the
JAVA_HOME environment variable, and verify everything works using the
Command Prompt. No previous experience required—just follow the steps!
What You'll Learn
- How to download and install the Java Development Kit (JDK)
- How to set environment variables (
JAVA_HOME
and Path
)
- How to verify the setup using the terminal
- Tips for running your first Java program
Step 1: Download the Java JDK
Java programs need the
Java Development Kit (JDK) to compile and run. The JDK includes everything you need—compiler, tools, and runtime.
Where to Download
You can get the latest JDK from Oracle or other providers like OpenJDK:
For beginners, the Adoptium distribution (Temurin) is open-source, stable, and widely used.
Choose the Right Version
Pick a
Long-Term Support (LTS) version like
Java 17 or Java 21. These are stable and supported for years.
Download the Installer
- Choose Windows x64 as your platform.
- Download the .msi installer file (recommended for Windows).
- Run the installer and follow the steps to install Java on your system.
Step 2: Find Your JDK Installation Path
Once installed, your JDK will be in a directory like:
C:\Program Files\Java\jdk-17
Copy this path—you’ll need it to set up your environment variables.
Step 3: Set JAVA_HOME Environment Variable
Setting
JAVA_HOME
tells your system where Java is installed. Many tools (like Maven or Gradle) use this to find Java.
How to Set JAVA_HOME
- Press Windows + S, search for Environment Variables, and select "Edit the system environment variables".
- In the System Properties window, click on the "Environment Variables…" button.
- Under System variables, click New.
- For Variable name, enter:
JAVA_HOME
- For Variable value, paste the JDK path you copied earlier:
C:\Program Files\Java\jdk-17
- Click OK to save.
Step 4: Add Java to the Path Variable
Now, you want to make sure you can run Java from any terminal window (like Command Prompt). To do this, add the JDK's
bin
folder to your system
Path
.
How to Update the Path
- In the same Environment Variables window, under System variables, find and select the
Path
variable.
- Click Edit.
- Click New, and add:
%JAVA_HOME%\bin
- Click OK to save and close all windows.
Now your system knows where to find Java commands like
java
and
javac
.
Step 5: Verify the Installation
Command Prompt window and check your installation:
Check Java Version
java -version
You should see output like:
java version "17.0.8"
Check the Compiler
javac -version
You should see:
javac 17.0.8
If you get errors like “command not recognized,” make sure the
JAVA_HOME
and
Path
variables were added correctly.
image quote pre code