View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All

JDK in Java: Comprehensive Guide to JDK, JRE, and JVM

Updated on 16/05/20253,110 Views

The Java Development Kit (JDK) is the foundation of Java programming, providing all the tools, executables, and binaries needed to develop, compile, and run Java applications.If you're wondering "what is JDK in Java," it's essentially a software development environment that contains everything you need to develop Java-based applications. This guide explains JDK, its relationship with JRE and JVM, and provides practical examples of how to install and use JDK across different operating systems.

Turn your Java passion into a profession with upGrad’s expert-led, practical software engineering program.

What is JDK in Java?

The Java Development Kit (JDK) is a software development environment used for developing Java applications and applets. It includes the Java Runtime Environment (JRE), an interpreter/loader (Java), a compiler (javac), an archiver (jar), a documentation generator (Javadoc), and other tools needed for Java development.

The JDK enables developers to create Java programs that can be executed by the Java Virtual Machine (JVM). It serves as the primary platform for Java development, providing all the necessary tools to develop, compile, debug, and run Java applications.

Upgrade your skills with these high-impact tech programs:

Full Stack Development Bootcamp – upGrad

AI Full Stack Development – IIIT Bangalore

Master of Design in User Experience  by Jindal Global School

Components of JDK

The JDK includes several key components:

  1. Development Tools: A collection of tools including:
    • javac: The Java compiler that converts Java source code into bytecode
    • java: The Java launcher that executes Java applications
    • jar: The archiver tool that packages related class libraries into a single JAR file
    • javadoc: The documentation generator
    • jdb: The Java debugger
    • jconsole: A monitoring tool
  2. Java Runtime Environment (JRE): Provides the libraries, JVM, and other components to run Java applications.
  3. Additional Libraries: Extra class libraries and support files needed for Java application development.
  4. Java Virtual Machine (JVM): The runtime engine that executes Java bytecode.

Also read: Exploring Java Architecture: A Guide to Java's Core, JVM and JDK Architecture

Let's examine what is JDK in Java with a simple example:

// HelloWorld.java
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World! This is a JDK example.");
    }

Expected Output

Demonstrating JDK Features: JDK includes: Compiler (javac), Launcher (java), Archiver (jar), Documentation Generator (javadoc)

System Properties: Java Version: 17.0.2 Java Home: /usr/lib/jvm/java-17-openjdk OS Name: Linux

Accessing Compiler API: Java Compiler is available in this JDK

Using Java NIO (part of JDK): Current directory: /home/user/java-projects

Explanation:

This example demonstrates multiple JDK features including:

1. Core libraries for collections and streams

2. Access to system properties provided by the JRE within the JDK

3. The Compiler API which is available only in the JDK (not in the JRE)

4. File operations using Java NIO libraries

Also read: How to Install Java in Windows 10

JDK JRE JVM in Java: Architecture and Workflow

The JDK, JRE, and JVM form a three-layer architecture that enables Java's "write once, run anywhere" capability. Let's explore how they work together:

JDK (Top Layer)

- Development tools for creating, compiling, and debugging Java code

- Includes JRE and additional development utilities

- Provides the development ecosystem for Java programmers

JRE (Middle Layer)

- Provides runtime libraries needed to execute Java applications

- Contains class libraries, JVM, and support files

- End-users only need JRE to run Java applications

JVM (Bottom Layer)

- Executes bytecode and provides memory management

- Handles platform-specific operations

- Makes Java platform-independent

The workflow from code to execution follows these steps:

1. Development: Write Java code using JDK tools

2. Compilation: JDK's compiler (javac) compiles source code (.java) to bytecode (.class)

3. Distribution: Package application (often in JAR files)

4. Runtime: JRE loads the application

5. Execution: JVM interprets/executes the bytecode

Let's illustrate this with a simple example:

// JDKWorkflowExample.java
public class JDKWorkflowExample {
    public static void main(String[] args) {
        System.out.println("Step 1: Developer writes this Java code using an IDE or text editor (part of JDK)");
        
        // The compiled bytecode (JDKWorkflowExample.class) is created by javac (part of JDK)
        System.out.println("Step 2: JDK's javac compiler converts this source code to bytecode");
        
        // The application is run with 'java JDKWorkflowExample'
        System.out.println("Step 3: JRE provides runtime environment for execution");
        
        // The bytecode is executed by the JVM
        System.out.println("Step 4: JVM executes the bytecode instructions");
        
        // Demonstrate platform independence
        System.out.println("Running on: " + System.getProperty("os.name") + 
                           " " + System.getProperty("os.arch"));
    }
}

Expected Output:

Step 1: Developer writes this Java code using an IDE or text editor (part of JDK)

Step 2: JDK's javac compiler converts this source code to bytecode

Step 3: JRE provides runtime environment for execution

Step 4: JVM executes the bytecode instructions

Running on: Windows 10 amd64

Explanation: This example demonstrates the entire workflow from code writing to execution, highlighting the roles of JDK, JRE, and JVM at each step.

Checkout: Jar file in Java

This guide has covered the essential aspects of Java's development environment, from installation across different operating systems to understanding the complex relationship between JDK, JRE, and JVM. As you continue your journey in Java development, remember that the JDK is your primary toolkit for bringing Java applications to life. 

To compile and run this program, you would use the JDK's tools:

# Compile the Java source file using javac (JDK compiler)
javac HelloWorld.java

# Run the compiled bytecode using java (JDK launcher)
java HelloWorld

Expected Output:

Hello, World! This is a JDK example.

Explanation: The JDK's javac compiler converts the Java source code into bytecode (HelloWorld.class), and then the java launcher executes this bytecode using the JVM included in the JDK.

Must Explore: Packages in Java

Visual representation of their relationship

Given below is a relationship between the three:

Understanding JVM JDK JRE in Java is crucial for Java developers. Let's see how they interact in practice:

// Class to demonstrate JDK, JRE, and JVM interaction
public class JavaComponentsDemo {
    public static void main(String[] args) {
        // JDK: Used to compile this code with javac
        // JRE: Provides the runtime environment to run this program
        // JVM: Executes this code and manages memory
        
        // Get JRE version
        String jreVersion = System.getProperty("java.version");
        System.out.println("JRE Version: " + jreVersion);
        
        // Get JVM name
        String jvmName = System.getProperty("java.vm.name");
        System.out.println("JVM Name: " + jvmName);
        
        // Get class path (set by the JRE)
        String classPath = System.getProperty("java.class.path");
        System.out.println("Class Path: " + classPath);
    }
}

Expected Output:

JRE Version: 17.0.2

JVM Name: OpenJDK 64-Bit Server VM

Class Path: .

Explanation: This program demonstrates how JDK, JRE, and JVM work together:

  1. The developer uses the JDK's compiler (javac) to compile the source code
  2. The JRE provides the runtime environment and necessary libraries
  3. The JVM executes the bytecode and provides system properties that reveal details about the runtime environment

How to Install Java JDK in Operating System

Installing the JDK is the first step to start Java development. Let's look at the installation process for windows.

How to Install Java JDK in Windows 10

Installing JDK in Windows 10 involves the following steps:

1. Download the JDK installer from Oracle's website or adopt OpenJDK

2. Run the installer and follow the installation wizard

3. Set up JAVA_HOME environment variable

4. Add JDK bin directory to the PATH environment variable

5. Verify the installation

Here's a more detailed guide:

  1. Download JDK: Visit the Oracle website or adopt OpenJDK website and download the appropriate JDK installer for Windows.
  2. Run the Installer: Double-click the downloaded file and follow the installation wizard.
  3. Set Environment Variables:
    • Right-click on "This PC" or "My Computer" and select "Properties"
    • Click on "Advanced system settings"
    • Click the "Environment Variables" button
    • Under "System variables", click "New"
    • Add a variable named "JAVA_HOME" with the value pointing to your JDK installation directory (e.g., C:\Program Files\Java\jdk-17)
    • Edit the "Path" variable and add %JAVA_HOME%\bin

Verify Installation: Open Command Prompt and type: java -version

javac -version

  1. If the installation was successful, you should see the installed Java version information.

What is JDK in Java with Example

To better understand what the JDK does, let's create a more comprehensive example that demonstrates some key JDK functionalities:

// JDKFeaturesDemo.java
import java.util.List;
import java.util.ArrayList;
import java.util.stream.Collectors;
import javax.tools.*;
import java.io.File;
import java.nio.file.*;

public class JDKFeaturesDemo {
    public static void main(String[] args) {
        System.out.println("Demonstrating JDK Features:");
        
        // 1. Using core libraries (part of JDK)
        List<String> jdkComponents = new ArrayList<>();
        jdkComponents.add("Compiler (javac)");
        jdkComponents.add("Launcher (java)");
        jdkComponents.add("Archiver (jar)");
        jdkComponents.add("Documentation Generator (javadoc)");
        
        // Using streams API (introduced in Java 8)
        String components = jdkComponents.stream()
                .collect(Collectors.joining(", "));
        System.out.println("JDK includes: " + components);
        
        // 2. Accessing system properties (provided by JRE within JDK)
        System.out.println("\nSystem Properties:");
        System.out.println("Java Version: " + System.getProperty("java.version"));
        System.out.println("Java Home: " + System.getProperty("java.home"));
        System.out.println("OS Name: " + System.getProperty("os.name"));
        
        // 3. Using compiler API (a JDK tool)
        try {
            System.out.println("\nAccessing Compiler API:");
            JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
            if (compiler != null) {
                System.out.println("Java Compiler is available in this JDK");
            } else {
                System.out.println("Java Compiler is not available (you might be using JRE only)");
            }
            
            // 4. File operations using NIO (part of JDK)
            System.out.println("\nUsing Java NIO (part of JDK):");
            Path currentPath = Paths.get(".");
            System.out.println("Current directory: " + currentPath.toAbsolutePath().normalize());
            
        } catch (Exception e) {
            System.out.println("Exception: " + e.getMessage());
        }
    }
}

Conclusion

The Java Development Kit (JDK) is the cornerstone of Java development, providing all the tools needed to create, compile, and run Java applications. Understanding the differences between JDK, JRE, and JVM is crucial for both developers and users of Java applications.

With JDK, developers can harness the full power of Java's "write once, run anywhere" philosophy, creating applications that can run on any platform with a JVM. Whether you're developing a small utility or enterprise-level software, the JDK provides the foundation you need to build cross-platform Java applications.

FAQs

1. What is the difference between JDK, JRE, and JVM in Java?

The JDK (Java Development Kit) is a complete development package containing JRE plus development tools like compilers and debuggers. The JRE (Java Runtime Environment) is a subset of JDK that provides libraries and resources to run Java applications. The JVM (Java Virtual Machine) is a component of both JDK and JRE that executes Java bytecode and provides memory management.

2. What is JDK used for in Java?

JDK is used for developing, compiling, debugging, and running Java applications. It provides the essential tools, executables, and binaries that developers need throughout the Java application development lifecycle, from writing code to testing and deployment.

3. Do I need JDK or JRE to run Java applications?

End-users only need the JRE to run Java applications as it contains the necessary runtime libraries and JVM. Developers need the JDK to create and compile Java programs. If you're only running Java applications and not developing them, JRE is sufficient.

4. What are the main components of JDK?

The main components of JDK include development tools (javac compiler, java launcher, jar archiver, javadoc documentation tool), the Java Runtime Environment (JRE), additional libraries, and the Java Virtual Machine (JVM).

5. Which JDK should I use for my project?

The choice of JDK depends on your project requirements. For long-term support, consider using LTS (Long Term Support) versions like JDK 8, 11, or 17. For cutting-edge features, use the latest version. Consider OpenJDK for open-source projects or Oracle JDK for commercial use (note Oracle's licensing changes after JDK 8).

6. How do I check which JDK version I have installed?

You can check your JDK version by opening a command prompt or terminal and typing java -version (for runtime version) and javac -version (for compiler version). This will display the version information of your installed Java.

7. Can I have multiple JDK versions installed?

Yes, you can have multiple JDK versions installed on the same system. Tools like SDKMAN (Linux/macOS) or JEnv can help manage multiple Java versions and switch between them as needed. On Windows, you can manually modify the PATH and JAVA_HOME environment variables.

8. What is the difference between Oracle JDK and OpenJDK?

Oracle JDK and OpenJDK are implementations of the Java Platform Standard Edition. OpenJDK is the open-source reference implementation, while Oracle JDK is Oracle's commercial distribution based on OpenJDK. Since JDK 11, Oracle JDK requires a commercial license for production use, while OpenJDK remains free and open source.

9. How do I set the JAVA_HOME environment variable?

On Windows, set JAVA_HOME through System Properties > Environment Variables. On Linux/macOS, add export JAVA_HOME=/path/to/jdk to your shell configuration file (.bashrc, .zshrc, etc.). The JAVA_HOME variable should point to the JDK installation directory.

10. What is the difference between JDK 8 and newer versions like JDK 11 or 17?

JDK 8 introduced lambda expressions and the Stream API. JDK 11 introduced the HTTP Client API, local variable type inference with var, and removed some deprecated components. JDK 17 added sealed classes, pattern matching for switch, and improved random number generators. Each version also includes performance improvements and security updates.

11. Is JDK free to use?

OpenJDK is free and open-source for both personal and commercial use. Oracle JDK is free for development and testing but requires a paid license for commercial deployment since Java 11. AdoptOpenJDK (now Eclipse Temurin) provides free, production-ready OpenJDK builds.

image

Take the Free Quiz on Java

Answer quick questions and assess your Java knowledge

right-top-arrow
image
Join 10M+ Learners & Transform Your Career
Learn on a personalised AI-powered platform that offers best-in-class content, live sessions & mentorship from leading industry experts.
advertise-arrow

Free Courses

Explore Our Free Software Tutorials

upGrad Learner Support

Talk to our experts. We are available 7 days a week, 9 AM to 12 AM (midnight)

text

Indian Nationals

1800 210 2020

text

Foreign Nationals

+918068792934

Disclaimer

1.The above statistics depend on various factors and individual results may vary. Past performance is no guarantee of future results.

2.The student assumes full responsibility for all expenses associated with visas, travel, & related costs. upGrad does not provide any a.