The Java Development Kit (JDK) is a software package that helps you build Java
programs. It includes tools and libraries needed to create Java applications
and applets. The JDK is important for developing Java software, along with the
Java Virtual Machine (JVM) and Java Runtime Environment (JRE).
If you just want to run Java programs, you only need the JRE. But if you're
planning to develop Java software, you'll need the JDK, which includes the JRE
plus extra tools.
JDK=JRE+Development Tools
A Java SDK is an implementation of one of the following Java platforms:
What's Inside the Java Development Kit (JDK)?
The JDK includes a private Java Virtual Machine (JVM) and several other
essential tools needed for Java Application development.
Contents of JDK:
- Java Runtime Environment (JRE)
- Interpreter/loader (Java)
- Compiler (javac)
- Archiver (jar) and more.
The Java Runtime Environment in the JDK, known as the Private Runtime, is
separate from the regular JRE. It includes a JVM and all class libraries
found in the production environment, along with additional libraries useful
for developers, such as internationalization and IDL libraries.
Popular JDKs:
Oracle JDK: Leading JDK and main distributor of Java 11.
OpenJDK: Versions 15, 14, and JMC are ready for use.
Azul Systems Zing: Efficient and low-latency JDK for Linux.
Azul Systems Zulu: Available for Linux, Windows, and Mac OS X.
IBM J9 JDK: For AIX, Linux, Windows, and more.
Amazon Corretto: The newest option, offering a no-cost build
of OpenJDK with long-term support.
Setting Up JDK:
Installing the JDK in your development environment is straightforward. Just
follow these simple steps:
1. Installation of JDK
- Visit Oracle's official download page [link] and select the latest JDK version.
- Download and add it to your classpath.
- Verify the JDK installation at the correct location on your computer, e.g., `C:\Program Files\Java\jdk11.0.9`.
2. Set JAVA_HOME for Windows:
- Right-click My Computer and select Properties.
- Go to the Advanced tab, select Environment Variables, and edit JAVA_HOME to point to the JDK software's location, e.g., `C:\Program Files\Java\jdk11.0.9`.
Java maintains backward compatibility, so downloading the latest release
ensures you get all old and new features. After installing the JDK and JRE,
add the `java` command to your command line. You can verify this by
running
java -version
in the command
prompt. In some cases, you may need to restart your system after installing
the JDK.
You can convert your Java text file into an executable program using the
Java Development Kit (JDK), to do that just follow these steps:
1. Create Java File: Write your Java code in a text file and save it
with a `.java` extension. For example, you can name it
`Hello.java`.
class Hello{
public static void main (String[] args) {
System.out.println("Hello Trick!");
}
}
2. Compile Java Code: Open your command prompt and use the
javac
command to compile your Java file. Make sure to provide the full path to
your Java file. For example:
"C:\Program Files\Java\jdk-11.0.9\bin\javac.exe" Hello.java
This will create a `Hello.class` file in the same directory as your
Java file.
3. Run Java Code: To run your compiled Java program, use the
java
command followed by the name of your Java file (without the `.class`
extension). For example:
java Hello
This will execute your Java program and display the output: `Hello Trick!`.
Remember to replace `C:\Program Files\Java\jdk-11.0.9\bin\javac.exe` with
the correct path to your `javac.exe` file and ensure that your Java file
name matches the one you're compiling.
The Jar component:
The JDK includes many useful tools, the most popular of which, after javac,
is the jar tool. A jar file is nothing but a complete package of Java
classes. Once you have created .class files, you can combine them into a
.jar to compress and structure them in a predictable way. Next, let's
convert Hello.class into a jar file.
Please note that you must be in the same directory where the Hello.java file
was saved before proceeding. Then enter the following command in the command
prompt.
Creating a .jar file
C:\Users\Pinaki\Documents>”c:\Program Files\Java\jdk-11.0.9\bin\jar.exe” –create –file Hello.jar Hello.class
You can see that the Hello.jar file was created in the same directory with
the Hello.class and jar.exe files. You can use jar files by adding them to
your classpath and running your program within them. Here -cp indicates the
classpath and will allow you to add jar files to the same classpath.
Run the .jar file
java -cp hello_world.jar hello_world
Important Components of JDK
Below is a complete list of the most commonly used Jdk components that are
very useful for developing Java applications.
Component | Use |
---|---|
javac | Java compiler converts source code into Java bytecode |
java | The loader of the java apps. |
javap | Class file disassembler, |
javadoc | Documentation generator, |
jar | Java Archiver helps manage JAR files. |
appletviewer | Debugging of Java applets without a web browser, |
xjc | Accepts an XML schema and generates Java classes, |
apt | Annotation-processing tool, |
jdb | Debugger, |
jmc | Java Mission Control, |
JConsole | Monitoring and Management Console, |
pack200 | JAR compression tool, |
extcheck | Utility tool to detects JAR file conflicts, |
idlj | IDL-to-Java compiler, |
keytool | The keystore manipulating tool, |
jstatd | jstat daemon (experimental) |
jstat | JVM statistics monitoring tool |
jshell | jshell introduced in java 9. |
jstack | Prints Java stack traces(experimental) |
jrunscript | Java command-line script shell. |
jhat | Java Heap Analysis Tool (experimental) |
jpackage | Generate self-contained application bundles. |
javaws | Web Start launcher for JNLP applications, |
javah | C header and stub generator, |
jarsigner | jar signing and verification tool |
jinfo | configuration information(experimental) |
javafxpackager | Package and sign JavaFX applications |
Conclusion
The Java Development Kit (JDK) provides essential tools like `javac` for compiling Java code and `jar` for packaging classes into a JAR file. Compiling Java code converts it into bytecode, which can then be executed using the Java Virtual Machine (JVM). Creating a JAR file allows you to bundle your classes for easier distribution and execution. These tools are fundamental for Java developers to build, compile, and distribute Java applications efficiently.