JVM, JRE, JDK and JIT explained

Java is not just a programming language, it is also a contained program execution environment. It is also a platform. Many beginners are overwhelmed when they encounter terms JDK, JRE, JVM and JIT for the first time. The surprise is understandable and attributable to the fact that Java is a platform and a language at the same time.

There exists a hierarchical relationship. JDK is superset of JRE, JRE has an implementation of JVM (called java) and JIT is inside JVM. Perhaps, the figure below can summarize.

codingraptor.com
JDK, JRE, JVM, JIT inter-relationship

Let’s begin dissecting and expanding all these 3 letter acronyms.

JVM

JVM stands for Java Virtual Machine. Guessing, like gambling, is a dangerous game. Don’t think that JVM is abstract or virtual. Far from it. JVM  is as real as Java, because JVM is Java itself. If that leaves you confused, don’t worry.

JVM, simply put, is a program that converts bytecodes to machine code. In case of Oracle JVM, this happens to be implemented in C++. JVM plays the role of interpreter. It reads the bytecode line by line and runs the bytecode. Therefore, it is the JVM layer that makes Java architecture neutral.

JVM is instantiated/ invoked using the ‘java’ program contained in JRE and JDK.

JRE

JRE stands for Java Runtime Environment. JRE contains everything it takes to run a Java program. Therefore, one of the components of JRE is the ‘java’ program which is one of way on instantiating a JVM.

But in addition to JVM, JRE also contains other tools. Some of them are –

  1. java-rmi, rmid and rmiregistry – to provide support for RMI
  2. javaws – Java Web Start – to run standalone applications over network
  3. javacpl – Java Control Panel – allows you to enable Java in browser, update your JRE and manage security settings.
  4. policytool – allows to edit user policies. Refer to this official documentation on editing policy file through policytool.
  5. jjs – Nashorn JavaScript implementation. This was introduced in Java 8 and signifies the growing importance of JavaScript. Further, it is extremely interesting to see one language implementation to contain another.
  6. keytool – utility for management of keys and X.509 certificates.

JDK

JDK stands for Java Development Kit. This is a set of programs for compilation, debugging, monitoring and running of Java programs. The key program in JDK is javac. javac is a shorthand for ‘Java Compiler’.

Some of the other useful programs that are a part of JDK are –

  1. jconsole – used to monitor local and remote JVMs.JConsole in Action
  2. jvisualvm – similar to jconsole in functionality. Can be used to monitor JVMs.jvisualvmJvisualvm
  3. appletviewer – used to run applets outside a browser environment.
  4. apt – Annotation processing tool. Is totally unrelated to Ubuntu apt.
  5. jar – the Java archiver. It is used to gather class files into a single zip file with .jar extension. A jar file is the Java equivalent of a library.
  6. jarsigner – jar security tool. It is used to digitally sign a jar so that no one tempers with the class or manifest files.
  7. javah – used to generate C headers for use in Java native methods.
  8. jdb – the java debugger. Draws inspiration from gdb debugger, but architecturally is very different.
  9. jstack – prints stacktraces of all Java threads
  10. xjc – given a XML schema, generates JAXB compatible Java files.

JIT Compiler

JIT stands for Just in Time. JIT compilation is a technique for enhancing performance of bytecode interpretation. The JIT compiler stores the bytecode of methods. So when a method is called for second time, there is no need to re-generate the bytecode. There are thresholds for levels of optimization. Methods which are most frequently called are most aggressively optimized. This results in enhanced speed of bytecode execution.

Unlike JVM, JRE and JDK, JIT is a part of JVM. It is enabled by default and most of the times the user does not need to know about JIT.

Leave a comment

Your email address will not be published. Required fields are marked *