Introduction
Before you can start writing and running Java programs, you need to install the Java Development Kit (JDK) on your computer. The JDK is the official toolkit that provides everything required to develop Java applications, including the Java compiler, Java Runtime Environment (JRE), debugging tools, and other utilities.
Whether you’re learning Java for the first time or setting up a new development environment, installing the JDK is the first and most important step. Once installed, you’ll be able to compile Java source code, run Java applications, and use popular IDEs like IntelliJ IDEA, Eclipse, or Visual Studio Code.
What is Java JDK?
The Java Development Kit (JDK) is a software development kit used to create, compile, debug, and run Java applications.
The JDK includes:
- Java Compiler (javac)
- Java Runtime Environment (JRE)
- Java Virtual Machine (JVM)
- Java Debugger (jdb)
- Java Documentation Tool (javadoc)
- Java Archive Tool (jar)
- Other development utilities
Without the JDK, you cannot compile Java source code into bytecode.
Prerequisites
Before installing the JDK, make sure:
- You have administrator privileges on your computer.
- Your operating system is updated.
- You have a stable internet connection to download the installer.
- You choose the correct installer for your operating system and processor architecture (64-bit is recommended for most modern systems).
Download the Java JDK
The recommended way to install Java is to download the latest Long-Term Support (LTS) version from Oracle or use an OpenJDK distribution.
Popular JDK distributions include:
- Oracle JDK
- Eclipse Temurin (OpenJDK)
- Amazon Corretto
- Microsoft Build of OpenJDK
Choose an LTS version if you’re learning Java or developing production applications.
Install Java JDK on Windows
Follow these steps to install Java on Windows.
Step 1: Download the Installer
Download the Windows installer (.exe or .msi) for your preferred JDK distribution.
Step 2: Run the Installer
Double-click the downloaded installer.
The setup wizard will open.
Click:
Next → Next → Install
Step 3: Choose Installation Folder
The default installation path is typically:
C:\Program Files\Java\jdk-XX
Replace XX with the installed version number.
You may keep the default location or choose another folder.
Step 4: Complete Installation
Click Finish after installation completes.
The JDK is now installed on your system.
Configure JAVA_HOME on Windows
Setting the JAVA_HOME environment variable allows many tools and IDEs to locate your JDK installation.
Step 1
Open:
Control Panel → System → Advanced System Settings
Step 2
Click:
Environment Variables
Step 3
Under System Variables, click New.
Variable Name:
JAVA_HOME
Variable Value:
C:\Program Files\Java\jdk-XX
Step 4
Locate the Path variable.
Click Edit.
Add:
%JAVA_HOME%\bin
Click OK to save the changes.
Verify Installation on Windows
Open Command Prompt and execute:
java -version
Example output:
Java(TM) SE Runtime Environment
Java HotSpot(TM) 64-Bit Server VM
Now verify the compiler:
javac -version
Example:
javac 21
If both commands display version information, the installation was successful.
Install Java JDK on macOS
Installing Java on macOS is straightforward.
Step 1
Download the macOS installer (.dmg or .pkg) for your preferred JDK distribution.
Step 2
Open the downloaded installer.
Follow the installation wizard.
Click:
Continue → Install
Step 3
Enter your administrator password if prompted.
Step 4
After installation completes, open the Terminal and verify:
java -version
Then verify the compiler:
javac -version
If both commands return version details, Java is installed correctly.
Install Java JDK on Linux
Installation steps vary slightly depending on the Linux distribution.
Ubuntu/Debian
Update package information:
sudo apt update
Install the default JDK:
sudo apt install default-jdk
Verify:
java -version
Compiler:
javac -version
Fedora
Install OpenJDK:
sudo dnf install java-latest-openjdk
Verify:
java -version
CentOS/RHEL
Install OpenJDK:
sudo yum install java-latest-openjdk
Verify:
javac -version
Check the JAVA_HOME Variable
To display the JAVA_HOME value:
Windows
echo %JAVA_HOME%
macOS/Linux
echo $JAVA_HOME
Create Your First Java Program
Once the JDK is installed, you can write your first Java program.
Create a file named:
HelloWorld.java
Add the following code:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
Compile the Program
Open the terminal or command prompt.
Navigate to the folder containing the file.
Compile:
javac HelloWorld.java
A new file is generated:
HelloWorld.class
This is the compiled Java bytecode.
Run the Program
Execute:
java HelloWorld
Output:
Congratulations! You have successfully installed Java and executed your first Java program.
Understanding the Installation Components
When you install the JDK, several important tools become available.
| Tool | Purpose |
|---|---|
| java | Runs Java applications |
| javac | Compiles Java source code |
| jar | Creates and extracts JAR files |
| javadoc | Generates API documentation |
| jdb | Debugs Java programs |
| jshell | Interactive Java shell (Java 9+) |
IDEs for Java Development
Although Java programs can be written in a text editor, using an IDE improves productivity.
Popular Java IDEs include:
- IntelliJ IDEA
- Eclipse IDE
- Apache NetBeans
- Visual Studio Code (with Java extensions)
These IDEs provide features such as:
- Syntax highlighting
- Code completion
- Debugging
- Refactoring
- Build automation
- Project management
Real-Life Example
Imagine you’re joining a software company as a Java developer.
Before contributing to a project, you must:
- Install the Java JDK.
- Configure JAVA_HOME.
- Install an IDE.
- Clone the project repository.
- Compile and run the application.
Without the JDK, none of these development tasks would be possible.
Common Installation Errors
Beginners often encounter a few common issues during installation.
1. ‘java’ is not recognized as an internal or external command
Cause: The Path environment variable is not configured correctly.
Solution: Add the JDK’s bin directory to the system Path.
2. ‘javac’ is not recognized
Cause: The compiler is missing from the Path, or only a runtime environment is installed.
Solution: Install the JDK and ensure its bin directory is included in the Path.
3. Incorrect JAVA_HOME Value
Cause: JAVA_HOME points to the wrong folder.
Solution: Set it to the JDK installation directory, not the bin folder.
Correct example:
C:\Program Files\Java\jdk-XX
4. Multiple Java Versions
Installing multiple JDK versions can lead to version conflicts.
Solution: Verify which version is active using:
java -version
Update your environment variables if necessary.
5. Restart Not Performed
Environment variable changes may not take effect in already-open terminals.
Solution: Close and reopen the command prompt or terminal after updating the environment variables.
Best Practices
Follow these recommendations when installing Java.
- Install the latest Long-Term Support (LTS) version for stability.
- Keep the JDK updated with security patches.
- Configure JAVA_HOME correctly.
- Verify the installation using both java -version and javac -version.
- Avoid installing unnecessary duplicate JDK versions unless required.
- Use a modern IDE for development.
- Learn basic command-line compilation before relying entirely on an IDE.
Conclusion
Installing the Java Development Kit (JDK) is the first step toward becoming a Java developer. The JDK provides the compiler, runtime environment, debugging tools, and utilities needed to build and execute Java applications. By configuring the JAVA_HOME environment variable and verifying the installation with the java and javac commands, you can ensure your development environment is ready.
Whether you’re using Windows, macOS, or Linux, the installation process is straightforward. Once the JDK is installed, you can begin writing, compiling, and running Java programs, as well as using powerful IDEs to build larger applications.