The Java Development Kit (JDK) is a development environment for building applications and components using the Java programming language. It includes tools useful for developing, testing, and monitoring such programs written in Java and running on the Java platform.
The available versions of the JDK can be checked on the official oracle website, where there's detailed information about each specific release, along with instruction for their installation, and their download url. Speaking of instructions for installation, there are some nice tutorials in dev.java that walk us through each specific step we must follow from the very beginning to get our first program up and running.
When we download the JDK archive, we can find inside configuration files, C header files, compiled Java modules, copyright and license files and additional libraries.
The JDK provides several commands to work with our Java programs. Some of them are:
javac
This command converts .java source files into .class bytecode files.
Let's suppose we have the following Java class inside a file called MyClass.java:
public class MyClass {
}
Now, if we run javac MyClass.java
, in the command line (at the same level the .java file is located at
), we'll see that a file MyClass.class is created.
java
This one is used to execute the Java program we write.
Following along with the previous example, let's now add some code that prints "Hello world" in console and exits. First, let's modify the class to look like this:
public class MyClass {
public static void main(String[] args) {
System.out.println("Hello world");
}
}
Now let's re-compile it to get the new changes into the bytecode file (javac MyClass.java
).
Now we're ready to run it. Let's execute java MyClass.class
from the command line (notice we provided
the compiled file as the argument —the .class file—). You should see "Hello world" printed in console.
As a side note, starting with Java 11, Java applications can be run without going through the compilation step, as
long as the program is written in a single file. So in the previous example, this would have worked as well:
java MyClass
.
jar
This one is used mainly to package files together.
In our example, we could use it to create an archive called MyProgram.jar, that contains one class file,
MyClass.class, and set MyClass
as the entry point. Like this:
jar --create --file MyProgram.jar --main-class MyClass MyClass.class
If you feel curious, you can run the program, as a jar file now, with java -jar MyProgram.jar
and you
should see the exact same "Hello world" printed in console.
javadoc
This command is used to generate the API documentation from Java source files as HTML pages.
If we add a documentation comment to our previous main
method like this:
public class MyClass {
/**
* Entry point for our application.
*
* @param args Program arguments.
*/
public static void main(String[] args) {
System.out.println("Hello world");
}
}
And now run javadoc MyClass.java
, we can see all the HTML files created by the tool to include
our documentation.
All of these commands and more are documented in details in the official documentation website. You should definitely check it to get to know all the details about how to use them in you program.
JRE stands for Java Runtime Environment. It is a subset of the JDK that is not distributed anymore ( starting with Java11 ). It only contained the tools needed to run a Java application.