Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
JDK(Java Development Kit) is one of the three core technology packages along with JRE(Java Runtime Environment) and JVM(Java Virtual Machine). It provides the tools and services required to develop software applications with ease.
What is Java Development Kit?
The JDK plays an essential role in the Java application development lifecycle. In short, it is a software package that contains the compiler and class libraries to create Java-based applications. The JDK consists of a JRE, a compiler, an interpreter, and an archiver. The JRE contains tools to run Java programs, so the JDK requires it.
The packages part of the JDK are kits targeted to work on different types of development. The Enterprise Edition (Java EE) contains tools for Enterprise application development and Object-relational mapping. It focuses on web-based applications with servlet specifications. Usually, all JDK versions include a Standard Edition(Java SE). The Micro Edition, Java ME is also an available JDK package.
How to Download and Install JDK?
The Java SE JDK can be downloaded from the official Oracle site. There are many types and versions of JDKs available. Choose the most suitable one for your use.
The JDK you install determines the Java version you will use to code. This means that to compile a Java 8 code, you may require at least a Java 8 JDK.
On running the JDK installer, you will be prompted to select the Development Tools, Source Code, and Public JRE. These are optional. Installing Development tools provides services for monitoring, troubleshooting, security, and deployment for Java applications. The Source code contains the public classes of the core Java API. Public JRE allows other programs to execute Java Programs.
You can verify installing JRE and JDK by running "java -version" on the command prompt after navigating to the default locations of your OS.
JDK 8 (March 2014): Introduced lambda expressions, Stream API, and new Date/Time API.
JDK 11 (September 2018): Long-Term Support (LTS) release. Features: var for local variables, HTTP Client API.
JDK 17 (September 2021): LTS release. Added sealed classes, pattern matching for switch, and improved random number generators.
JDK 21 (September 2023): Latest LTS release with performance and security improvements.
JDK 23 (September 2024): Focuses on modern APIs, performance optimizations, and language enhancements.
Working with Java Development Kit
Create a file using a text editor with .java as its extension. Open the file and type your java code in it.
Use the JDK to convert this file into an executable file. This can be done by using the javac command in the command prompt. Now, the file’s extension would be .class. This compiled code is the Java bytecode.
The above command will create the Program.class file in the same directory.
Run the file using the java command
"C:\Program Files\Java\jdk-10.0.1\bin\javac.exe"Program.java
C:\Users\Documents>java Program
The javac command is stored in the /bin directory that contains many other useful tools. One such tool is the jar tool. A jar file contains a set of Java classes generated by the compiler. Compressed and arranged in a specific way.
We can convert .class file to .jar by using the following command.
Add .jar to the classpath using the -cp option and run it. To execute the program inside it.
java -cp Program.jar Program
Frequently Asked Questions
What is the role of the javac command in the JDK?
The javac command is the Java compiler in the JDK. It translates Java source code (.java files) into bytecode (.class files), enabling the Java Virtual Machine (JVM) to execute the program.
How does the JDK support platform independence?
The JDK supports platform independence through the JVM, which executes Java bytecode. Bytecode is platform-neutral, and the JVM interprets or compiles it into machine code specific to the underlying operating system.
Can I use the JDK for Android development?
Yes, the JDK is essential for Android development. It provides tools like javac for compiling Java code, which is later converted into Dalvik bytecode by the Android SDK's tools to run on Android devices.
Is the JDK the same as the JVM?
No, the JDK is a development kit that includes the JVM, development tools (e.g., javac), and libraries. The JVM is part of the JDK and is responsible for executing Java bytecode on specific platforms.
What is the difference between JDK and JRE?
The JDK is a complete development environment, including tools like javac, jar, and the JRE. The JRE is a subset of the JDK containing only the JVM and libraries needed to execute Java programs.
Conclusion
To build scalable and reliable Java-based applications, a deep understanding of JDK is essential. This blog highlights the basics of JDK, its components, and its uses. It also explains how to install and work with JDK to compile and execute Java application programs.