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.
Let’s begin dissecting and expanding all these 3 letter acronyms.
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 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 –
- java-rmi, rmid and rmiregistry – to provide support for RMI
- javaws – Java Web Start – to run standalone applications over network
- javacpl – Java Control Panel – allows you to enable Java in browser, update your JRE and manage security settings.
- policytool – allows to edit user policies. Refer to this official documentation on editing policy file through policytool.
- keytool – utility for management of keys and X.509 certificates.
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 –
- jconsole – used to monitor local and remote JVMs.
- jvisualvm – similar to jconsole in functionality. Can be used to monitor JVMs.
- appletviewer – used to run applets outside a browser environment.
- apt – Annotation processing tool. Is totally unrelated to Ubuntu apt.
- 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.
- jarsigner – jar security tool. It is used to digitally sign a jar so that no one tempers with the class or manifest files.
- javah – used to generate C headers for use in Java native methods.
- jdb – the java debugger. Draws inspiration from gdb debugger, but architecturally is very different.
- jstack – prints stacktraces of all Java threads
- xjc – given a XML schema, generates JAXB compatible Java files.
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.
We are socialSpread the word