Java Development Kit (JDK) is the essential software development environment required for developing Java applications. It contains the Java Runtime Environment (JRE), an interpreter/loader (Java Virtual Machine), a compiler (javac), and various tools to help developers create, compile, and run Java programs.
If you’re just getting started with Java, this guide will help you install and set up the JDK on your computer and configure your environment so you can start coding right away.
What is the Java JDK?
The Java Development Kit is a software package used to develop Java applications. It includes:
- Java Compiler (javac): Converts your Java source code into bytecode.
- Java Runtime Environment (JRE): Allows you to run Java applications.
- Java Virtual Machine (JVM): Executes Java bytecode.
- Various tools and utilities for debugging and monitoring.
Step 1: Download the Java JDK
Oracle provides the official JDK distribution, but there are other builds like OpenJDK which is free and open source. For beginners, Oracle JDK or OpenJDK both work well.
- Visit the official Oracle JDK download page: https://www.oracle.com/java/technologies/downloads/
- Alternatively, download OpenJDK from https://jdk.java.net/
- Choose the latest stable version (e.g., JDK 20 or JDK 17 LTS) suitable for your operating system (Windows, macOS, or Linux).
- Download the installer or compressed archive depending on your platform.
Step 2: Install the JDK
Windows
- Run the downloaded
.exe
installer. - Follow the installation wizard by clicking Next.
- Choose the installation path or leave the default.
- Finish the installation.
macOS
- Open the downloaded
.dmg
file. - Drag and drop the JDK into the Applications folder.
- Alternatively, use Homebrew:
brew install openjdk
Linux
- For Debian/Ubuntu-based distros:
sudo apt update
sudo apt install openjdk-17-jdk
- For Fedora/CentOS:
sudo dnf install java-17-openjdk-devel
Step 3: Set JAVA_HOME Environment Variable
Setting the JAVA_HOME
variable helps your system and development tools locate your Java installation.
Windows
- Open Start Menu, search for “Environment Variables”.
- Click “Edit the system environment variables”.
- In the System Properties window, click “Environment Variables”.
- Under System variables, click “New” and enter:
- Variable name:
JAVA_HOME
- Variable value: path to your JDK installation (e.g.,
C:\Program Files\Java\jdk-20
)
- Variable name:
- Find the
Path
variable, click Edit, then Add a new entry%JAVA_HOME%\bin
. - Click OK to save.
macOS / Linux
Add these lines to your shell profile file (~/.bash_profile
, ~/.zshrc
, or ~/.bashrc
):
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/bin:$PATH
Then reload your profile:
source ~/.bash_profile
Or replace the $JAVA_HOME
path with your actual JDK installation path if necessary.
Step 4: Verify the Installation
Open a terminal or command prompt and run:
java -version
You should see the installed Java version printed out, like:
java version "20.0.1" 2025-05-20
Java(TM) SE Runtime Environment (build 20.0.1+9)
Java HotSpot(TM) 64-Bit Server VM (build 20.0.1+9, mixed mode)
Also check the compiler:
javac -version
This should show your Java compiler version.
Step 5: Writing and Running Your First Java Program
Create a simple Java file HelloWorld.java
:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, Java World!");
}
}
Save it in a directory. Open your terminal or command prompt and navigate to that directory, then compile and run it:
javac HelloWorld.java
java HelloWorld
Output:
Hello, Java World!