DEV Community

Adhi sankar
Adhi sankar

Posted on

JDK in Java

Introduction

JDK stands for Java Development Kit. It is a software package used to develop, compile, debug, and run Java applications.

If you want to create a Java program, you need tools that can convert your Java source code into something the computer can execute. The JDK provides these tools.

For example, when we write:

class Main {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}
Enter fullscreen mode Exit fullscreen mode

the JDK provides the tools required to compile and run this program.


What is JDK?

JDK (Java Development Kit) is a collection of software tools required for Java application development.

It contains:

  • JRE (Java Runtime Environment)
  • JVM (Java Virtual Machine)
  • Java compiler
  • Debugging tools
  • Other development utilities

In simple words:

JDK = Tools needed to develop Java applications


Main Components of JDK

1. JDK

JDK is the complete development kit.

It is mainly used by Java developers to write and develop applications.

JDK
 ├── JRE
 │    └── JVM
 └── Development Tools
Enter fullscreen mode Exit fullscreen mode

2. JRE

JRE stands for Java Runtime Environment.

It provides the environment required to run Java applications.

JRE
 └── JVM
Enter fullscreen mode Exit fullscreen mode

JRE contains the JVM and Java libraries required for running Java programs.


3. JVM

JVM stands for Java Virtual Machine.

It is responsible for executing Java bytecode.

For example:

Java Code
    ↓
Compiler
    ↓
Bytecode (.class)
    ↓
JVM
    ↓
Program Output
Enter fullscreen mode Exit fullscreen mode

The JVM helps Java achieve its famous feature:

Write Once, Run Anywhere

A Java program can run on different operating systems as long as a compatible JVM is available.


Java Compiler

One of the most important tools in the JDK is the Java compiler.

The Java compiler is called:

javac
Enter fullscreen mode Exit fullscreen mode

Suppose we have a file:

Main.java
Enter fullscreen mode Exit fullscreen mode

We can compile it using:

javac Main.java
Enter fullscreen mode Exit fullscreen mode

This creates:

Main.class
Enter fullscreen mode Exit fullscreen mode

The .class file contains Java bytecode.

We can then run it using:

java Main
Enter fullscreen mode Exit fullscreen mode

JDK Compilation Process

The basic process is:

Main.java
    ↓
   javac
    ↓
Main.class
    ↓
   JVM
    ↓
Output
Enter fullscreen mode Exit fullscreen mode

For example:

Step 1: Write Java code

class Main {
    public static void main(String[] args) {
        System.out.println("Hello Java");
    }
}
Enter fullscreen mode Exit fullscreen mode

Save the file as:

Main.java
Enter fullscreen mode Exit fullscreen mode

Step 2: Compile

javac Main.java
Enter fullscreen mode Exit fullscreen mode

Step 3: Run

java Main
Enter fullscreen mode Exit fullscreen mode

Output:

Hello Java
Enter fullscreen mode Exit fullscreen mode

Important JDK Commands

javac

Used to compile Java source code.

javac Main.java
Enter fullscreen mode Exit fullscreen mode

java

Used to run a Java application.

java Main
Enter fullscreen mode Exit fullscreen mode

javadoc

Used to generate documentation from Java source code.

javadoc Main.java
Enter fullscreen mode Exit fullscreen mode

jar

Used to create and manage Java archive files.

jar
Enter fullscreen mode Exit fullscreen mode

jdb

Used for debugging Java applications.


JDK vs JRE vs JVM

JDK JRE JVM
Used for development Used for running Java programs Executes bytecode
Contains JRE Contains JVM Part of JRE
Contains development tools Contains runtime libraries Converts bytecode into machine-level instructions
Used mainly by developers Used to run applications Executes Java programs

The relationship can be remembered as:

JDK
 ↓
JRE
 ↓
JVM
Enter fullscreen mode Exit fullscreen mode

Why Do We Need JDK?

JDK is needed when we want to develop Java applications.

For example, if you want to create:

  • Web applications
  • Desktop applications
  • Backend applications
  • Android-related Java projects
  • Enterprise applications
  • Java-based tools

you need a Java development environment.

The JDK provides the compiler and other tools required for development.


How to Check JDK Installation

After installing the JDK, open Command Prompt or Terminal and type:

java -version
Enter fullscreen mode Exit fullscreen mode

You can also check the compiler:

javac -version
Enter fullscreen mode Exit fullscreen mode

Example:

java version "21..."
javac 21...
Enter fullscreen mode Exit fullscreen mode

The exact version depends on the JDK installed on your computer.


JDK Versions

Java has many versions, such as:

  • Java 8
  • Java 11
  • Java 17
  • Java 21
  • Java 25

Some Java versions are LTS (Long-Term Support) releases.

For learning Java, it is useful to understand that the JDK version determines which Java language features and tools are available.


Advantages of JDK

1. Complete Development Environment

JDK provides the tools needed to develop Java applications.

2. Platform Independent

Java bytecode can run on different platforms using a compatible JVM.

3. Development Tools

It provides tools such as:

javac
java
javadoc
jar
jdb
Enter fullscreen mode Exit fullscreen mode

4. Supports Large Applications

Java and the JDK are widely used for developing large-scale applications.

5. Debugging and Documentation

JDK provides tools that help developers debug programs and create documentation.


Simple Real-Life Example

Think of JDK like a complete workshop for a mechanic.

  • JDK → Complete workshop
  • Compiler → Tool that prepares the program
  • JRE → Environment where the program can operate
  • JVM → Machine that executes the program

Therefore, if you want to build Java applications, you need the JDK.


Conclusion

JDK is an important part of Java development. It provides the compiler, runtime environment, JVM, libraries, and various development tools required to create Java applications.

The most important concept to remember is:

JDK → Development
JRE → Running
JVM → Execution
Enter fullscreen mode Exit fullscreen mode

Top comments (0)