Setting up the Java Development Kit (JDK)

The Java Development Kit (JDK) is a software development kit required to build and run Java applications. It includes essential components such as the Java compiler (javac), the Java Runtime Environment (JRE), and various development and debugging tools.

There are two main types of JDKs commonly used:

  • Oracle JDK – Officially provided by Oracle, includes enterprise-grade features.
  • OpenJDK – An open-source implementation of the Java Platform, Standard Edition, widely used and supported by the community.

Steps to Set Up Oracle JDK

  1. Download the Oracle JDK Visit the official Oracle JDK Downloads page and download the version suitable for your operating system.

  2. Install the JDK
    Run the installer and follow the setup instructions.

  3. Set Environment Variables

    • Add the JDK bin directory to the system PATH variable.
    • Set JAVA_HOME to the JDK installation directory (e.g., C:\Program Files\Java\jdk-21).
  4. Verify Installation
    Open a terminal or command prompt and run:

    java -version
    javac -version
    

Steps to Set Up OpenJDK

OpenJDK provides the same core functionality as Oracle JDK and is widely used in Linux distributions and open-source projects.

For Windows:

  1. Download OpenJDK
    Use trusted providers such as:

  2. Install or Extract
    Extract the ZIP file or run the MSI installer.

  3. Set Environment Variables

    • Set JAVA_HOME to the JDK directory.
    • Add %JAVA_HOME%\bin to the PATH.
  4. Verify Installation

    java -version
    javac -version
    

For Linux/macOS:

Install via a package manager:

  • Ubuntu/Debian:
    sudo apt install openjdk-21-jdk
    
  • Fedora:
    sudo dnf install java-21-openjdk
    
  • macOS (Homebrew):
    brew install openjdk@21
    

Set JAVA_HOME and update PATH in your shell config file.