The JDK is a key platform component for building Java applications. At its core is the Java compiler

The Java Development Kit (JDK) is one of three core technology packages used in Java programming, along with the JVM (Java Virtual Machine) and JRE (Java Runtime environment). It’s important to distinguish these three technologies and understand how they connect:

  • The JVM is a Java platform component that executes programs.
  • The JRE is the disk part of Java that is used to create the JVM.
  • The JDK allows developers to create Java programs that can be executed and run by the JVM and JRE.

Developers unfamiliar with Java often confuse the Java development kit with the Java runtime environment. The difference is that the JDK is a toolkit for developing Java-based software, while the JRE is a toolkit for running Java code.

The JRE can be used as a standalone component to simply run Java programs, but it is also part of the JDK. The JDK requires a JRE because running Java programs is part of developing them.

Figure 1 shows how the JDK fits into the Java application development lifecycle.

Figure 1. High-level view of the JDK

As with our recent introduction to the Java Virtual Machine, let’s consider the JDK’s technical and everyday definitions:

  • Technical definition: The JDK is an implementation of the Java platform specifications, including a compiler and class libraries.
  • Everyday Definition: A JDK is a software package you download to create Java-based applications.

JDK and Java compiler

Each JDK includes a Java compiler in addition to the JRE (the environment used to run Java applications). The compiler is capable of photographing software programs in raw.java files – which are plain text – and rendering them into executable.class files. We’ll see the compiler in action shortly. First, I’ll show you how to download and set up the JDK in your development environment

Start using JDK

Setting up Java in your development environment is as simple as downloading the JDK and adding it to your classpath. When downloading the JDK, you need to choose which version of Java to use. Java 8 is the most commonly used version, but At the time of this writing, Java 11 is the long term support (LTS) version. Java remains backward compatible, so we will only download the latest version.

The JDK package

In addition to selecting your Java version, you also need to select a Java package. Packages are Java development kits for different types of development. The available packages are Java Enterprise Edition (Java EE), Java Standard Edition (Java SE), and Java Mobile Edition (Java ME).

Novice developers are sometimes unsure which package is right for their project. Typically, every JDK version includes Java SE. If you download Java EE or Java ME, you’ll get the standard edition. For example, Jave EE is a standard platform with additional tools that are useful for Enterprise application development, such as Enterprise JavaBeans or support for object-relational mapping.

It’s not hard to switch to a different JDK in the future if you find it necessary. Don’t worry too much about choosing the right Java version and JDK package at first.

JDK version Compatibility

Since the JDK provides a compiler for your Java programs, the JDK you use determines which version of Java you can code. For example, if you want to use the newer functional programming features in Java 8 (such as the arrow Lambda operator), then you need at least the Java 8 JDK to compile. Otherwise, the Javac command will reject code with syntax errors.

Download the JDK

We’ll stick with Java SE throughout this tutorial so we can focus on the core JDK classes and technologies. To download the Java SE JDK, visit Oracle’s official download page. You’ll see the various JDK packages available, as shown in Figure 2.

Figure 2. Available JDK packages

Take a moment to look at the other options before choosing Java SE download. Lots of good food in the Java Kitchen!

On Java EE

If you’re primarily interested in building Java-based Web applications, you can download the Java EE JDK. The Java EE JDK includes the Java Servlet specification, which supports HTTP request processing. Each Java EE JDK implementation also requires a container, which is a server where Java EE applications run. Glassfish is Oracle’s Java EE server reference implementation. Other popular implementations are Tomcat and Jetty.

For now, proceed to download the Java Standard JDK.

Install the JDK

When you run the JDK installer, you have a choice of three components: development tools, source code, and a common JRE. You can install one or all of them. In this case, just select the default value.

Installing the Development Tools option will provide you with the correct JDK. The installation “source code” contains the source code for the public classes in the core Java API. Including this option allows you to reference source code when building your application. The third option, “Public JRE,” indicates that the JDK and JRE are separate entities: the public JRE can be used by other programs to execute Java programs, and can be installed separately from the JDK.

Go ahead and install all three components and accept the default values for each. Doing so means that your JDK and JRE will be installed at the default location of your operating system. On Windows, it is C:\Program Files\Java, as shown in Figure 3.

Figure 3. Java installed

JDK on the command line

Installing the JDK and JRE adds Java commands to the command line. You can verify this by going into the command shell and typing java-version, which will return the Java version you installed. (In some cases, you will have to restart the system to fully adopt this change to the system path.)

Java is already installed, but what about Javac? You will need this JDK element to compile your Java files.

Javac command

The javac command is in the/JDK directory, but is not automatically added to the system path during installation. We can choose to install Javac ourselves, or we can install an IDE that includes this command. We’ll start by compiling and running Java programs the old-fashioned way.

A simple Java program

Step 1. Write a simple Java program

Create a new text file called intro.java and place it somewhere on your computer, such as in your Documents folder.

Next, add the code in Listing 1, which is a very simple Java program.

Listing 1. Intro. Java


public class Intro {

    public static void main(String[] args) {
        System.out.println("Welcome to the JDK!"); }}Copy the code

Step 2. Compile with JDK

Next, use the JDK compiler to convert your text file into an executable program. Compiled code in Java is called bytecode and has a.class extension.

You’ll use the javac command, which stands for the Java compiler. Type the full path to the command in the command shell and pass the intro.java file as the command. On my system, it looks like Listing 2.

Listing 2. Compile with JDK

"C: \ Program Files \ Java \ JDK - 10.0.1 \ bin \ javac exe" Intro.java
Copy the code

This should result in a successful compilation. The Javac will not respond to a successful message; It just prints out new files. Any errors will result in console output.

Step 3. Run the.class file

You should now have intro. class in with intro. Java.

You can run it Java Intro by typing:, which yields Listing 3. Note that.class does not include when typing this command.

Listing 3. Running intro.class


C:\Users\mtyson\Documents>java Intro
Welcome to the JDK!
Copy the code

The jar command

This Javac is the star of the JDK, but the /bin directory contains the other tools you need. Perhaps the most prominent Javac is the JAR tool.

A.JAR file is a package group Java class. Once the compiler has created the.class files, developers can put them together as.jars to compress and build them in a predictable way.

Let’s convert intro. class into a JAR file.

Navigate back to the directory you placed in, intro.java, and type the command you saw in Listing 4.

Listing 4. Creating a JAR file

C:\Users\mtyson\Documents>"C: \ Program Files \ Java \ JDK - 10.0.1 \ bin \ jar exe" --create --file intro.jar Intro.class
Copy the code

Perform the jar

Now you will see a file in the directory with intro.jar. You can use.jar by adding it to your classpath and executing programs in it, as follows:

java -cp intro.jar Intro
Copy the code

The -cp switch tells Java to add jars to the classpath. The.jar files are unnecessary for this small program, but they are essential as the program grows in size and depends on third-party packages.

IDE of the JDK

Reviewing the JDK download page, you may have noticed the option to download the JDK using Netbeans IDE. An IDE, or integrated development environment, is software that provides a cohesive set of tools for developing applications. Think of an IDE as a visual operating system with a set of tools, such as a file browser and text editor, and development-specific additional features, such as code completion and formatting.

One of the key things an IDE does in Java development is manage the build for you. That is, the IDE runs the compilation process automatically in the background, so you don’t have to do it yourself. The IDE also provides play-by-play feedback at any time to catch coding errors in real time.

There are several reliable ides for Java. Now that you’ve seen how the JDK works on the command line, let’s take a quick look at how it works in the Eclipse IDE.

Eclipse and the JDK

Installing Eclipse is outside the scope of this guide, but it is a simple process. Eclipse includes an installer, and just like any other program, you can find one here for your operating system.

After installing Eclipse, open the Window menu item from the menu bar and select the preferences.

In the Preferences window, you will see the Java item. If you open it, you should see the Compiler item. Clicking this button will display some of the OPTIONS for the JDK.

Figure 4 shows a screen shot of the JDK options in Eclipse.

Figure 4. Eclipse JDK options

conclusion

Based on the silly white sweet school sister to help her summarize some knowledge/learning planning/learning materials

This article is the second in a short series covering the three core Java platform components: the JVM, JDK, and JRE.