top

Search

Java Tutorial

.

UpGrad

Java Tutorial

JDK in Java

Introduction

In the early 1990s, under the leadership of James Gosling (a Canadian computer scientist), a group of developers at Sun Microsystems began developing a novel programming language called "Oak." Oak was designed for embedded systems, which initially encompassed consumer electronics. However, as the days passed, Sun Microsystems realized that Oak had a higher calling.

Sun Microsystems formally renamed the language "Oak" to Java, as the name Oak was already owned by another company.

The Java Development Kit, or JDK in Java, is a set of tools and libraries that programmers use to create Java-based applets, and that’s why it is called a Development Kit.
We will examine JDK in this tutorial. You will learn about the JDK composition and architecture and how to install it on your system. Read on to learn more.

Overview

The JDK was initially released on January 23, 1996.
The JVM and JRE are responsible for executing and running Java programs, and the JDK supplies the necessary tools. If you are new to Java, then you might get the Java Runtime Environment (JRE), the Java Development Kit (JDK), and the Java Virtual Machine(JVM) mixed up. 

What Is JDK in Java?

JDK full form in Java is Java Development Kit. It contains the JRE, an amalgamation of the JVM and libraries. It also contains the Java developer tools, i.e., javac, javadoc, and the Java debugger.

The Architecture of JDK in Java

JDK is used to develop Java applications and create executable programs using the Java programming language. The architecture of JDK is designed to support the Java programming language. The JDK includes the following components:

  • The JRE contains the JVM and the library tools.

  • The development tools (javac, javadoc, and the debugger)

Java Runtime Environment

You'd know what layers are if you've read a bit about operating systems. So, what is JRE?

JRE or Java Runtime Environment is a software layer that provides the essential libraries and resources a Java Program requires. It runs on top of your machine's OS (Operating System).

The JRE is responsible for combining the Java code created by the JDK with the libraries required to run the program and then creates an instance of the JVM, where the program executes.

Java Virtual Machine

Java Virtual Machine or JVM is, just as the name suggests, a virtual or abstract machine that enables users to run their Java applications. Java programs or applications have a trait called WORA or ‘Write Once Run Anywhere.’ So you can write a program on your system, then send it to another system where Java is enabled and expect it to run there.

When you write a program in Java, the source code is automatically saved as a file with a ‘.java’ extension. When you compile this code, the computer uses the Java compiler to convert this ‘.java’ file into a ‘.class’ file, which is machine-readable bytecode.

This ‘.class’ file is processed through an array of steps when we execute it, which is what the JVM enables.

Contents of the JDK

The JDK contains a wide variety of tools, each having its own unique feature. These tools are mentioned down below:

Tool

Description

java

Java interpreter or loader


javac

Java compiler used to compile Java source code into bytecode.

javadoc

Java documentation generator used to generate documentation from Java source code.


jar 

Java archive tool used to package Java applications and libraries into a single file.

jps

Java process status tool used to list the Java processes running on a system.

appletviewer

Tool used to view Java applets.

idlj

IDL-to-Java compiler is used to generate Java code from CORBA Interface Definition Language (IDL) files.

javap

Java class file disassembler used to display the contents of Java class files.

JConsole

Java monitoring and management console used to monitor and manage Java applications.

javah

Java header file generator used to generate C header files from Java classes.

javaws 

Java web start tool used to launch Java applications from the web.

jhat

Java heap analysis tool used to analyze heap dumps generated by Java applications.

jmc

Java mission control tool used to monitor and manage Java applications.

JDK contains

The JDK in Java contains a wide variety of tools. The main components of JDK are mentioned below:

  • JRE: It is the Java Runtime Environment that allows you to run your program. It acts as an abstract machine for your program to run on.

  • java: This is the Java interpreter/ loader. Once you write a program in Java, the interpreter/ loader reads your program and then executes it

  • javac: The ‘javac’ or Java compiler is responsible for compiling your program into machine-readable bytecode.

  • jar: Java ARchive or jar is similar to your ‘.zip’ file. It aggregates the necessary metadata, files and classes to run a Java application. The jar files help save storage space as they are compressed, and it speeds up the process of running a Java-based application.

  • jdb: The Java Debugger or jdb is a utility in the JDK that allows you to debug your Java program in the CLI(Command-Line-Interface).

Most Popular JDKs

Java Development Kits have come a long way since its first release. However, some versions are used more than the others. Here are the most popular JDKs:

JDK 8

Release Year: 2014

It is a Java version with long-term support (LTS) that remains widely used today. It includes features like the Stream API, lambda expressions, and the Date-Time API.

JDK 11

Release Year: 2018

JDK 11 is also an LTS version of Java. It introduced new features such as the HttpClient API, the VarHandle API, and improvements to the garbage collector.

JDK 14

Release Year: 2020

JDK 14 introduced features such as switch expressions, NIO2 enhancements, and the new packaging tool ‘jpackage’.

JDK 15

Release Year: 2020

JDK 15 introduced features such as sealed classes, hidden classes, and improvements to the garbage collector.

JDK 16

Release Year: 2021

Features such as record classes, pattern matching for instanceof, and enhancements to the garbage collector were among the new additions this release included.

Set-Up

Coming to setting up JDK on your system, you need to adhere to the following steps to ensure that JDK is successfully installed and runs on your machine without any hindrance:

Installation of JDK

  • Visit the Oracle website and download the version of the JDK you want. 

  • Double-click the installer file or icon in the downloads folder to launch the JDK setup process.

  • After you’ve followed the instructions provided by the installer and finished the installation process, you will need to set the JAVA_HOME environment variable.

Set JAVA_HOME for Windows

To set the JAVA_HOME environment variable, follow the steps mentioned below:

  • Go to your search bar and type in “Edit the system environment variables.”

  • Once you click the Environment Variables button, you will be directed to the “Environment Variables” window.

  • Click on the button “New” and enter "JAVA_HOME" for the variable name and the directory or PATH you have installed JDK in as the value.

  • Click on “OK” to save the variable.

You have now successfully set the JAVA_HOME variable for your Windows system.

Compile and Run code using JDK

To compile and run code using JDK, follow the steps below:

  • Navigate to your Windows search bar, type “cmd,” and press Enter.

  • This should open up the command prompt.

  • Now, navigate to the PATH where your Java source code is located.

  • Type “javac <your filename without the .java extension>.java.”

  • This will create a “.class” file in the same PATH where your source code is located.

  • To run the code, type “java <the class filename without the .class extension>.class.”

  • After pressing Enter, a new command prompt should open, executing your Java code and producing the output.

The JAR Component

Let’s say you have a Java-based application created on your system and want to share it with your fellow developers. You would want to compress the files to save on storage. To do this, you must create a “.jar” file containing all the files in your Java-based application. Follow the steps below to create a “.jar” file:

  • Navigate to your Windows search bar, type “cmd” and press Enter.

  • Navigate to the PATH of your Java-based application.

  • Type "jar -cvf <filename>.jar *.class", where <filename> is what you want to name your JAR file.

  • This will create the JAR file in the same directory.

Latest Version of JDK

JDK 20, the most recent release, was circulated on March 21, 2023. JDK 20 was released as a “patch release,” while JDK 17 is the current Long Term Support (LTS) release.

JDK 20 comes with a lot of new features and improvements, such as:

  • Support for the Java 10 language features, such as records and text blocks.

  • Enhanced performance for startup time, garbage collection, and more.

  • New security features, such as support for the JCE 7 standard, i.e., Java Cryptography Extension 7.

  • It has improved compatibility with Android and the Java EE platform.

Getting started with JDK

The most credible source to start using JDK is the official JDK documentation. Understanding the elements of a Java program is easier when you have the documentation by your side. 

You can start by creating your first class and typing the source code in a “.txt” file. Rename the file extension as “.java” from “.txt” and then use JDK from the command prompt to compile and execute your Java program. 

Conclusion

The JDK in Java was one of their best and long-lasting creations of all time. JDK is still widely used by the IT industry, especially JDK 8. JDK provides many tools to compile, run, test, and debug Java applications. Creating Java applications without the JDK would be extremely difficult, so it is still being worked on and updated with new features at every single release.

FAQs

1. What is JDK and JRE?

is Java Development Kit, while JRE stands for Java Runtime Environment. They both necessitate the development of Java-based applications along with the JVM(Java Virtual Machine).

2. Is JDK only available for Windows?

JDK is available for Windows, Mac, and Linux. You can go to the downloads page and download the installer suitable for your Operating System.

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

The JDK is a set of tools for creating a complete Java-based application, while the JRE lets you execute Java code correctly. JVM is a virtual machine that enables you to run the code on your system. 

Leave a Reply

Your email address will not be published. Required fields are marked *