Explain Codes LogoExplain Codes Logo

What is the difference between JDK and JRE?

java
jdk
jre
java-development
Alex KataevbyAlex Kataev·Aug 5, 2024
TLDR

Using JDK equips developers with necessary tools such as compiler (javac) and several utilities aiding in building Java applications. It houses JRE, the right environment for running Java applications, which encompasses the core libraries and the JVM. In essence, leverage JDK when you're tasked to develop Java applications and JRE for running them.

Key Point: JDK = create apps, contains JRE + tools. JRE = run apps, includes JVM + libraries.

To break it down, JDK and JRE are crucial for any Java practitioner to configure the fitting environment for both development and execution. The JDK brings an impressive tooling ensemble including jdb for debugging, jshell for interactive Java sessions, and jar tool for clustering related class files. On the other hand, the JRE is responsible for providing a hassle-free run of Java applications to the end-users, keeping the development overhead at bay. Interestingly, the JRE packed within the JDK comes with extra debugging support. It's worth noting that the standalone JRE has gone extinct with OpenJDK on stage, as JRE is part of the JDK.

Diving Into JDK's Toolkit

Here's a little walkthrough:

javac MyClass.java // "*javac*, do your magic and make my code a bytecode!" javadoc MyClass.java // "Hey *javadoc*, create an API documentation out of comments in MyClass.java, will you?" jdb MyClass.java // "*jdb*, let's debug MyClass.java together today!" jar cvf MyJar.jar MyClass.class // "Dear *jar*, bundle up MyClass.class into MyJar.jar, ready for shipping!" jshell // "*jshell*, let's have a quick Java jam session!"

Running the Show: Java Applications

Here's how you undertake the different operations:

java MyClass // Run single-class applications like "*java MyClass* and see the magic unfold!" deploy app.war // Use JDK while deploying JSP Web applications. "*Dear deploy, prepare app.war for the real world*" java -version // Meet the magic lamp: JVM. "*java -version*, grant my wish - run on any platform!"

Knowing the correct variant of JDK to pick according to your Java development requirements is much like shopping for the right outfit for an occasion!