Difference between JRE, JDK and JVM in Java [Interview Questions]
We often come across the difference between JRE, JDK and JVM when we are introduced to JAVA. In many interviews, you will be asked questions related to the JDK and JVM.
However, most of us are unable to establish that clear line of difference between these terms and the vagueness and similarities in names and definitions often confuses us.
Difference between JRE, JDK and JVM in Java?
So if you are one of those people, read on to get clarification of concepts and clear that long-lasting doubt from your mind.
What is the Java Virtual Machine (JVM)?
First of all, let us talk about the Java Virtual Machine. Before getting introduced to this term, we go through various features of Java like robustness, object-oriented, strongly typed, platform independence and so on.
Platform independence is the most important one among them, which means that once compiled, the bytecode can be executed on any machine.
But how is this achieved? How can machines with different architectures and operating systems run the same code?
This is possible because Java creates its own machine (virtual) to run on which makes it independent of other machines. This is JVM.
So what is the use of JVM?
JVM loads, verifies and executes code and gives the code a virtual machine or an environment to run on. It is a kind of interpreter. It also provides memory management and garbage collection functions.
What is the Java Run Time Environment (JRE)?
Java Run Time Environment provides everything that is needed to run a program. It mainly includes the environment to run the program along with the set of libraries or functions that are necessary for the execution of a program.
However, JRE cannot alone help us develop a program. It is physical (not virtual) and provides us with features to simply runs them.
What is the Java Development Kit (JDK)?
JDK is a kit, which means a collection of tools or a bundle of software components to compile as well as run the program.
It contains the environment to bytecode the program but also helps a programmer to develop applications. It consists of a compiler and debugger as well.
Java development kit is an implementation of Java SE, Java EE or Java ME. We often begin with Java SE to get a grip on the basic features of Java.
So, I hope this clarifies the difference between JRE, JDK and JVM in Java.
Difference between JVM, JRE and JDK
In case there’s still a doubt, I’d share with you three simple lines that my teacher asked me to always remember which assures that I do not get confused between these terms.
JVM: Virtual Machine for platform independence JRE: JVM + API JDK: Compiler + JVM + API (or JRE + API)
Here, API stands for Application Programming Interface, or simply stated, a set of functionalities or a library.
Understanding these differences is very important. If you are applying for a Java developer role, in interviews, you will be asked questions on this topics.
We may also come across a term, Just in Time Compiler (JIT).
What is Just in Time Compiler (JIT Compiler)?
It is simply a module or component or a subset of JRE. It compiles some part the byte code into machine code along with working to improve the efficiency of the program. Rest all parts of the bytecode are interpreted and executed.
Note if you are installing Java on your system. When we are working with Java, we need to install only two packages, JDK and JRE. All other functionalities and tools are available in them itself.
You may like to read:
- If you are new to Java programming, you can read the complete installation setup guide for Java. So what are you waiting for? Install JDK and start coding.
- Most common errors and fixes for JVM.
- You may come across different environment variable in Java. You can read the difference between path and classpath environment variable in Java.
Hope this is a quick guide for finding the difference between JRE, JDK and JVM and to start with Java. If you are Java developer, you can follow the Java programming sections to get updated with.