What is JDK (Java Development Kit)?

What is JDK (Java Development Kit)?

If you are an aspiring Java Developer or a professional, one of the very first components you have encountered is the Java Development Kit (JDK). Although Java is a powerful programming language, the JDK is what helps developers to create, compile, and run Java applications. JDK is used with JVM (Java Virtual Machine) and JRE (Java Runtime Environment).

In this blog, we will discuss what JDK is, what it includes, and why it is an important tool for Java developers. So let’s get started!

Table of Contents:

What is JDK?

The Java Development Kit (JDK) is basically a software development environment that is provided by Oracle and other vendors who are responsible for building Java applications. It consists of a package of tools that are necessary for developing, debugging, and running programs in Java. For writing a Java application, the JDK is the first component to be installed.

Unlike Java Runtime Environment (JRE), which is used to run Java programs, the JDK provides everything that is required for development, from writing the source code to converting it to bytecode and then executing it on the Java Virtual Machine (JVM).

Why is JDK Important?

JDK is important for developers for the following reasons:

  • Code compilation: Without using javac, you cannot convert your source code into an executable format.
  • Application Development: The JDK consists of important APIs and tools that are required for building, packaging, and documenting applications.
  • Debugging and Monitoring: Various tools like jdb and jconsole help you to track down issues and monitor performance.
  • Flexibility: By using JDK, you can develop Java applications ranging from desktop utilities to large-scale applications.
Boost your tech career with Java – Sign up now!
Practical projects, job-ready skills, and expert guidance.
quiz-icon

How Does Java Work?

Working of Java

The working of Java defines the process by which Java programs are written, compiled, and executed. The above image provides a visual representation of the step-by-step execution of a Java program. The detailed explanation of how Java works is given below:

  1. Source Code: The first step in the architecture of Java involves writing the source code. You can do this using a text editor or IDE, which is responsible for defining the logic and architecture of the program.
  1. Java Compiler: The Java compiler then converts the source code into a platform-independent bytecode. That can be executed by any device having a compatible JVM.
  1. Bytecode: Bytecode is a compiled Java code that is platform-independent. It runs on any device having a compatible JVM. This feature makes Java a platform-independent language.
  1. Java Virtual Machine (JVM): The Java Virtual Machine (JVM) is responsible for converting the bytecode into machine code. This allows Java programs to run on any platform. This supports the “Write Once, Run Anywhere” feature in Java.
  1. Operating System (OS): The JVM hands over the machine code to the operating system. After that, it interacts with the hardware for the execution of tasks in the source code.

Architecture of JDK

Now, let us look into the architecture of Java and discuss the 3 important software modules of JDK. They are: JVM (Java Virtual Machine), JRE (Java Runtime Environment), and JDK (Java Development Kit). JDK is the superset that contains the JRE, which in turn contains the JVM inside it.

Each of the 3 components is elaborated below:

Java Development Kit (JDK)

It is a software package that is used to create Java applications and applets. It includes the JRE along with several tools that are required for development. These tools include a compiler (javac), which is used to convert source code into bytecode, an interpreter/loader (java) for running programs, an archiver (jar) for bundling files, and a documentation generator (javadoc). The JDK provides everything that is needed by a developer for writing, compiling, and running Java programs.

JDK Architecture

In the above diagram, the blue area represents the JDK. 

Java Runtime Environment (JRE)

The JRE (Java Runtime Environment) provides the environment that is needed to run Java programs. It includes everything that is required to run your Java code, such as the JVM and important libraries. When you run a Java program, the JRE combines your code with the libraries. After that, it starts the JVM to execute the code. Although JRE is a part of the JDK, it can be downloaded and used separately if you only need to run Java programs and not use it for development.

Java Virtual Machine (JVM)

Java applications work on the feature called “Write Once Run Anywhere” because of the ability to run the code on any platform. This is done by the JVM. The JVM is a platform component in Java that consists of an environment for executing programs in Java. JVM is responsible for the interpretation of the bytecode into machine code.

To summarize everything, the JVM performs the following functions:

  • At first, it loads the code.
  • After that, code verification is performed.
  • Then it executes the code.
  • At last, it provides a runtime environment.

Now, let us talk about the architecture of the JVM.

JVM Architecture

The explanation of the architecture of JVM with reference to the above image is given below:

  • Class Loader: It is a part of the Java Virtual Machine (JVM) that loads the class files into memory. When you run a Java program, the class loader is the first component that loads the required classes so that the program can start to execute.
  • Method area: It is one of the memory areas in the JVM where information related to classes is stored. The information includes static variables, static blocks, static methods, and instance methods.
  • Heap: A heap is basically a memory location that is created when the JVM starts running. After the Java program starts running, the size of the heap can grow or shrink depending on the memory needs of the application.
  • Stack: Stack in JVM is also called the thread stack. It is a part of the JVM memory that is created for each individual thread when it starts running. It is used by that thread for storing important data such as local variables, temporary results, and information that is needed to call methods and return from them. Each thread consists of its own separate JVM stack.
  • Native Method Stack: It is a part of the JVM memory that is responsible for handling all the native methods used in a Java application. Native methods are the methods written in languages like C or C++ instead of Java. The native stack keeps a track of those methods during the time of execution.
  • Execution engine: The execution engine consists of the JIT compiler and Garbage collector.
  • JIT compiler: The JIT (Just-In-Time) compiler is a part of the Java runtime environment. It helps you improve the performance of the programs in Java. The working process involves converting the bytecode into machine code while the program is running. This process takes place only when it is needed. That is why it is called a “just-in-time” application. By default, the JIT compiler is turned on, and after a method is compiled, the JVM runs faster.
  • Garbage collector: The Garbage Collector in the JVM is responsible for finding and removing the unused or unwanted objects from the memory. The working process involves keeping track of all the objects in the heap space of the JVM and getting rid of those that are not used by the program anymore. The process of garbage collection consists of two main steps:
    • Mark: In this step, the garbage collector checks the objects that are still being used by the program and the ones that are not.
    • Sweep: In this step, it clears out the objects that are not used. This helps to free up the memory for future use.

Get 100% Hike!

Master Most in Demand Skills Now!

Components of JDK

Some of the important components of JDK are mentioned below:

  • java: It is the launcher that is used for all the applications in Java.
  • javac: It is the compiler used for the Java programming language.
  • javadoc: It is used to generate the API documentation.
  • jar: It is used to create and manage all the JAR files.
  • jps: It stands for Java Virtual Machine Process Status Tool. It is used to manage the active JVMs for the program that is currently executing.
  • idlj: It is used to generate Java bindings from a given Java IDL file.
  • javap: It is used to disassemble files.
  • JConsole: It is used as a Java Management and Monitoring unit.
  • javac -h: It is a stub generator, where a C header is employed to write native methods.
  • javaws: It is used as the Web Start launcher for JNLP applications, but it is deprecated now in recent JDK versions.
  • jhat: It is a heap analysis tool.
  • jmc: It is used as an abbreviation for Java Mission Control.
  • xjc: It accepts an XML schema and generates the classes in Java.
  • apt: It is an abbreviation for Annotation-processing tool.
  • jdb: It is a debugging tool.
  • extcheck: It is a utility tool used for detecting conflicts in JAR files.
  • keytool: It is a keystore manipulation tool.
  • jstatd: It is a background tool used for monitoring JVM performance and usage of resource.
  • jstat: It is a statistics monitoring tool in JVM.
  • jshell: It was introduced in Java 9.
  • jstack: It is a tool that is used to print Java thread stack traces for debugging purposes.
  • jrunscript: It is a Java command-line script shell.
  • jpackage: It is used to generate self-contained bundles of applications.
  • jarsinger: It is a jar signing and verification tool.
  • jinfo: It displays configuration and system properties of a Java running process.

Set-up and Installation of JDK

It is very easy to set up the JDK in your development environment. Kindly follow the steps given below:

  1. At first, visit the Official Oracle JDK page to download the JDK.
JDK Official Page
  1. Select the latest version of the JDK. Currently, the latest version of JDK is JDK 24. Click on download and add it to your classpath. Download the .exe file for Windows.
JDK Download Page
  1. After the .exe file is downloaded, you will be redirected to the page given below.
JDK Installation
  1. Press Next. Set your file location where you want to store JDK-24 on your computer. After that, you will be redirected to the page given below.
JDK Installation
  1. For setting the JAVA_HOME variable, at first go to the control panel, then click on System, then go to Advanced System Settings, then Environment Variables. In Environment variables, just add a new system variable named JAVA_HOME with the installation path of the JDK as its value.
JDK Installation
JDK Installation
JDK Installation

Congratulations, you have successfully downloaded and installed JDK-24 on your computer.

After the installation of JDK, JRE adds the Java command to your command line. You can verify this by typing java -version on the command line. 

java -version on the command line

Compiling and Running Java Code using JDK

Now, after the JDK is installed on your computer, you can use it to convert your Java text file to a program that can be executed. Here, your Java text gets converted into bytecode after compiling the code. That bytecode carries the .class extension.

You can try this by writing the code given below in VSCode, and naming the text file as index.java

Example:

Java

Output:

Compiling and Running Java Code using JDK

To ensure the smooth running of the above code on VSCode, make sure to install the recommended extension packs for Java. 

Oracle JDK vs. Open JDK vs. Other Distributions

JDK Distribution License Type Commercial Support Key Features Ideal For
Oracle JDK Oracle NFTC (No-Fee Terms and Conditions) Optional (Paid LTS available) Java Flight Recorder, Java Mission Control, Performance Enhancements Enterprises needing advanced monitoring tools and optional paid support
OpenJDK GPL v2 + Classpath Exception Community-driven only Pure open-source reference implementation Open-source projects, education, general development
Amazon Corretto Open Source (GPL + CE) Yes (Free LTS from AWS) Multi-platform support, LTS, regular updates Production environments on AWS or cross-platform systems
Azul Zulu Free & Commercial Yes (Flexible Plans) Broad OS support, embedded systems compatibility Developers needing cross-platform or embedded JDKs
Eclipse Temurin Open Source Community-led support Maintained by Eclipse Adoptium, frequent security and performance updates Developers seeking stable, consistent open-source JDK
Red Hat OpenJDK Open Source (Red Hat Subscription for LTS) Yes (via RHEL Subscription) Optimized for Red Hat ecosystems, secure updates Enterprises using RHEL or Red Hat infrastructure
SAP SapMachine Open Source Community + SAP-focused Optimized for SAP software, enterprise-grade runtime SAP-based enterprise applications, stability-focused systems

The Jar Component

There are many useful tools in JDK, and one of the most popular ones after javac (the Java compiler) is the jar tool. A JAR (Java ARchive) file is a bundle of compiled Java classes that are packaged together in a single compressed file. Once you combine your Java program into .class files, you can use the jar tool to combine them into a .jar file. This makes it easier for you to distribute, manage, and run your Java application in a structured way. For example, you can take your HelloWorld.class file and convert it into a .jar file for ease of use.

Creating a JAR File

The steps to create a JAR file are given below:

  1. First, you have to write your Java code and save it. For example,

Example:

Java

Compile it using the following javac command.

javac HelloWorld.java

This command will generate the file HelloWorld.class

  1. After you have created the .class file, you have to create a file named manifest.txt by using the following line:
Main-Class: HelloWorld
  1. After that, use the jar tool that is provided by the JDK. Write the following command on the terminal:
jar cfm HelloWorld.jar manifest.txt HelloWorld.class

Where, 

  • c = create
  • f = specify filename
  • m = include manifest file

This command creates the file HelloWorld.jar.

  1. You can run the JAR file by using the following command:
java -jar HelloWorld.jar
Learn Java for Free – Start Coding Today!
Dive into Java with our beginner-friendly course
quiz-icon

Conclusion

The Java Development Kit (JDK) is the most important part of Java programming. It encapsulates everything when you try to develop, compile, debug, and run Java applications. Java development is not possible without the JDK. It is important for you to have a good understanding of its components and purpose for using its capabilities and building robust, scalable Java applications.

Installing JDK is the first step in your journey into Java development. Only then will you get to know about the potential of one of the most powerful languages in the software industry.

What is a Java Development Kit (JDK) – FAQs

Q1. What is the difference between JDK, JRE, and JVM?

JDK is used for installing Java programs, JRE is used for running those programs, and JVM is responsible for executing the bytecode.

Q2. Why do I need the JDK to run Java programs?

For developing and compiling Java code, the JDK is used. For just running the code, using JRE is enough.

Q3. How do I create a JAR file in Java?

To create a JAR file in Java, you have to compile the code with javac, then create a manifest file, and then use the jar cfm command.

Q4. What tools come with the JDK?

The tools that come with JDK are: javac, java, javadoc, jar, jdb, jshell, and jconsole.

Q5. Can I install JRE without JDK?

Yes, if you want to just run the Java applications and not for development purposes, you can install JRE without JDK.

About the Author

Technical Research Analyst - Full Stack Development

Kislay is a Technical Research Analyst and Full Stack Developer with expertise in crafting Mobile applications from inception to deployment. Proficient in Android development, IOS development, HTML, CSS, JavaScript, React, Angular, MySQL, and MongoDB, he’s committed to enhancing user experiences through intuitive websites and advanced mobile applications.

Full Stack Developer Course Banner