What is JDK?
JDK (Java Development Kit) is a software development environment used to develop Java applications. It includes:
- Java Compiler (javac): Converts Java code to bytecode
- JRE (Java Runtime Environment): To run Java programs
- Development Tools: Debugger, JavaDoc, jar, etc.
- Java API Libraries: Pre-written code
Why Install JDK?
You need JDK to:
- Write Java programs
- Compile Java code (.java to .class)
- Run Java applications
- Debug and test Java programs
JDK vs JRE vs JVM
JDK (Java Development Kit):
- For developers
- Contains JRE + development tools
- Used to develop Java applications
JRE (Java Runtime Environment):
- For end users
- Contains JVM + libraries
- Used to run Java applications
JVM (Java Virtual Machine):
- Executes bytecode
- Part of JRE
- Platform-specific
Relationship:
JDK = JRE + Development Tools
JRE = JVM + Library Classes
Types of JDK
1. Oracle JDK
- Official JDK from Oracle
- Commercial license for production
- Free for development and personal use
- Best support and updates
2. OpenJDK
- Open source version
- Free for all uses
- Community-driven
- Same features as Oracle JDK
3. Other Distributions
- Amazon Corretto: AWS distribution
- AdoptOpenJDK: Community builds
- Azul Zulu: Enterprise JDK
- IBM Semeru: IBM distribution
System Requirements
Minimum Requirements:
- Operating System: Windows 7+, macOS 10.8+, Linux
- RAM: 128 MB (minimum), 512 MB recommended
- Disk Space: 200 MB
- Processor: Pentium 2 or higher
Recommended:
- RAM: 2 GB or more
- Disk Space: 500 MB
- Modern processor
Installing JDK on Windows
Step 1: Download JDK
- Visit Oracle’s website: https://www.oracle.com/java/technologies/downloads/
- Select your operating system (Windows)
- Choose JDK version (Java 17 LTS or Java 21 LTS recommended)
- Download the installer (.exe file)
- Accept license agreement
Alternative: Download OpenJDK from https://adoptium.net/
Step 2: Run Installer
- Double-click the downloaded .exe file
- Click “Next” on welcome screen
- Choose installation location (default: C:\Program Files\Java\jdk-xx)
- Click “Next” to install
- Wait for installation to complete
- Click “Close” when finished
Step 3: Set Environment Variables
Why? So you can run Java commands from any directory.
Setting JAVA_HOME:
- Right-click “This PC” or “Computer”
- Select “Properties”
- Click “Advanced system settings”
- Click “Environment Variables”
- Under “System variables”, click “New”
- Variable name:
JAVA_HOME - Variable value:
C:\Program Files\Java\jdk-17(your JDK path) - Click “OK”
Adding to PATH:
- In System variables, find “Path”
- Click “Edit”
- Click “New”
- Add:
%JAVA_HOME%\bin - Click “OK” on all windows
Step 4: Verify Installation
Open Command Prompt and type:
java -version
Expected output:
java version "17.0.1" 2021-10-19 LTS
Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39)
Check compiler:
javac -version
Expected output:
javac 17.0.1
Installing JDK on macOS
Step 1: Download JDK
- Visit Oracle’s website or use Homebrew
- Download macOS installer (.dmg file)
Using Homebrew (Recommended):
brew install openjdk@17
Step 2: Install
Manual Installation:
- Open .dmg file
- Run the installer package
- Follow installation prompts
- Enter admin password when prompted
Step 3: Set JAVA_HOME
Add to ~/.bash_profile or ~/.zshrc:
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/bin:$PATH
Reload:
source ~/.zshrc
Step 4: Verify
java -version
javac -version
Installing JDK on Linux (Ubuntu/Debian)
Method 1: Using APT (Recommended)
# Update package list
sudo apt update
# Install OpenJDK 17
sudo apt install openjdk-17-jdk
# Verify installation
java -version
javac -version
Method 2: Manual Installation
- Download Linux tar.gz file
- Extract:
tar -xzf jdk-17_linux-x64_bin.tar.gz - Move to /opt:
sudo mv jdk-17 /opt/ - Set JAVA_HOME in ~/.bashrc:
export JAVA_HOME=/opt/jdk-17 export PATH=$JAVA_HOME/bin:$PATH - Reload:
source ~/.bashrc
Setting Up IDE (Optional but Recommended)
Popular Java IDEs:
-
IntelliJ IDEA
- Most popular
- Smart code completion
- Download: https://www.jetbrains.com/idea/
-
Eclipse
- Free and open source
- Large plugin ecosystem
- Download: https://www.eclipse.org/
-
VS Code
- Lightweight
- Install Java Extension Pack
- Download: https://code.visualstudio.com/
-
NetBeans
- Official Java IDE
- Good for beginners
- Download: https://netbeans.apache.org/
Common Installation Issues
Issue 1: “java is not recognized”
Problem: PATH not set correctly
Solution:
- Check JAVA_HOME is set correctly
- Ensure %JAVA_HOME%\bin is in PATH
- Restart Command Prompt/Terminal
- Restart computer if necessary
Issue 2: Wrong Java Version
Problem: Multiple Java versions installed
Solution:
- Check JAVA_HOME points to correct version
- Use
where java(Windows) orwhich java(Mac/Linux) - Uninstall old versions
Issue 3: Permission Denied (Linux/Mac)
Problem: Insufficient permissions
Solution:
- Use
sudofor installation - Check file permissions
- Run terminal as administrator
Choosing the Right JDK Version
For Learning (2024):
- Java 17 LTS: Widely used, stable
- Java 21 LTS: Latest LTS with modern features
For Production:
- Java 11 LTS: Stable, mature
- Java 17 LTS: Recommended for new projects
- Java 21 LTS: Latest features
LTS (Long Term Support):
- Java 8, 11, 17, 21
- Receive updates for 3+ years
- Recommended for production
Updating JDK
Windows:
- Download new version installer
- Run installer
- Update JAVA_HOME if needed
- Verify new version
macOS (Homebrew):
brew upgrade openjdk
Linux:
sudo apt update
sudo apt upgrade openjdk-17-jdk
Uninstalling JDK
Windows:
- Control Panel → Programs → Uninstall
- Find Java (TM) Development Kit
- Click Uninstall
- Remove JAVA_HOME from environment variables
macOS:
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-xx.jdk
Linux:
sudo apt remove openjdk-17-jdk
Testing Your Installation
Create a simple test program:
HelloWorld.java:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("JDK installed successfully!");
}
}
Compile:
javac HelloWorld.java
Run:
java HelloWorld
Output:
JDK installed successfully!
Exam Tips
- Know the difference: JDK vs JRE vs JVM
- JDK contains: JRE + Development Tools (javac, jar, etc.)
- Environment variables: JAVA_HOME and PATH
- Verification commands:
java -versionandjavac -version - LTS versions: 8, 11, 17, 21 (Long Term Support)
- JDK types: Oracle JDK (commercial), OpenJDK (open source)
- Installation location: Usually in C:\Program Files\Java (Windows)
- Why JAVA_HOME?: So tools can find Java installation
Important Points
- JDK is required for development, JRE for running only
- Always verify installation with
java -version - Set environment variables for command-line access
- Choose LTS version for stability
- Keep JDK updated for security
- One JDK can compile for older Java versions (backward compatibility)