Installing JDK

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

  1. Visit Oracle’s website: https://www.oracle.com/java/technologies/downloads/
  2. Select your operating system (Windows)
  3. Choose JDK version (Java 17 LTS or Java 21 LTS recommended)
  4. Download the installer (.exe file)
  5. Accept license agreement

Alternative: Download OpenJDK from https://adoptium.net/

Step 2: Run Installer

  1. Double-click the downloaded .exe file
  2. Click “Next” on welcome screen
  3. Choose installation location (default: C:\Program Files\Java\jdk-xx)
  4. Click “Next” to install
  5. Wait for installation to complete
  6. Click “Close” when finished

Step 3: Set Environment Variables

Why? So you can run Java commands from any directory.

Setting JAVA_HOME:

  1. Right-click “This PC” or “Computer”
  2. Select “Properties”
  3. Click “Advanced system settings”
  4. Click “Environment Variables”
  5. Under “System variables”, click “New”
  6. Variable name: JAVA_HOME
  7. Variable value: C:\Program Files\Java\jdk-17 (your JDK path)
  8. Click “OK”

Adding to PATH:

  1. In System variables, find “Path”
  2. Click “Edit”
  3. Click “New”
  4. Add: %JAVA_HOME%\bin
  5. 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

  1. Visit Oracle’s website or use Homebrew
  2. Download macOS installer (.dmg file)

Using Homebrew (Recommended):

brew install openjdk@17

Step 2: Install

Manual Installation:

  1. Open .dmg file
  2. Run the installer package
  3. Follow installation prompts
  4. 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)

# 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

  1. Download Linux tar.gz file
  2. Extract:
    tar -xzf jdk-17_linux-x64_bin.tar.gz
  3. Move to /opt:
    sudo mv jdk-17 /opt/
  4. Set JAVA_HOME in ~/.bashrc:
    export JAVA_HOME=/opt/jdk-17
    export PATH=$JAVA_HOME/bin:$PATH
  5. Reload:
    source ~/.bashrc
  1. IntelliJ IDEA

  2. Eclipse

  3. VS Code

  4. NetBeans

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) or which java (Mac/Linux)
  • Uninstall old versions

Issue 3: Permission Denied (Linux/Mac)

Problem: Insufficient permissions

Solution:

  • Use sudo for 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:

  1. Download new version installer
  2. Run installer
  3. Update JAVA_HOME if needed
  4. Verify new version

macOS (Homebrew):

brew upgrade openjdk

Linux:

sudo apt update
sudo apt upgrade openjdk-17-jdk

Uninstalling JDK

Windows:

  1. Control Panel → Programs → Uninstall
  2. Find Java (TM) Development Kit
  3. Click Uninstall
  4. 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

  1. Know the difference: JDK vs JRE vs JVM
  2. JDK contains: JRE + Development Tools (javac, jar, etc.)
  3. Environment variables: JAVA_HOME and PATH
  4. Verification commands: java -version and javac -version
  5. LTS versions: 8, 11, 17, 21 (Long Term Support)
  6. JDK types: Oracle JDK (commercial), OpenJDK (open source)
  7. Installation location: Usually in C:\Program Files\Java (Windows)
  8. 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)