Difference Between JDK, JVM & JRE: After Learning about the history of Java, we came to know about the terminology like JDK, JVM & JRE. So let’s go a little bit in-depth to learn more about the JDK, JVM and JRE and the Difference between them. If you are visiting our SoftwareTestingO blog for the first time, then you can check our series of posts on the Core Java tutorial by following the link.
As we know that Java is a high-level programming language. So if you try to run a high-level programming language in any machine, then the computer can not run that. So if you try to run the high programming language, then you need to convert the high-level language to machine understandable language.
So when you compile the java program, then the java compiler can take the java program as the input and then convert that program to machine understandable code, which is byte code. After the conversion, the machine takes the byte code and runs that code, and then only the machines can understand that byte code and perform the operation.
What is JVM & Architecture?
So you can understand that the primary function of JVM is to execute the byte code, which is generated by the compiler. Each operating system has different JVM, but when JVM executes the byte code, they all produce the same output across all different operating systems. That means the byte code can be run in any environment. Because of this feature of java, Java called a platform-independent or a robust language.
In the above diagram, you can see the JVM architecture. Let’s go step by step and try to learn how things are happening internally:
ClassLoader: First of all, the .java program is converted into a .class file, which is a byte code, and the java compiler generates this. Now when the JVM gets the .class file then there is a module or program called class loader system which doing the below functions:
- First, it loads the .class file into memory
- After loading it, verify that the byte code is proper or not. If JVM found anything suspicious, then the execution is rejected immediately.
- If the byte code is proper, then it allocates memory to execute the program.
Java Memory Area
The memory area categorized into five parts, which called run-time data areas; it can contain the result and data while running the program. These five different data areas are:
- Method area: This area stores the class code like variables and code of methods in the java program.
- Heap Area: This is the area where objects are created. So when JVM loads a class, a method and heap area is created immediately
- Java Stacks: Method code are stored in the method area, but when we are executing those methods, you need some more memory to store the data and results at that time memory is allocated in Java stack. So, Java Stacks is the memory area where the Java methods are executed. JVM Create a separate thread to implement each method.
- Program Counter (PC) registers: This memory area contains the memory address of the instructions of the methods. if there are four methods, then 4 PC registers will be used to track the instructions of the methods
- Native Method Stacks: Java methods are executed on java stack; similarly, native methods are performed in native method stacks. To execute the native methods generally, we required native method libraries. These header files are located and connected to JVM by a program called Native method interface.
Java Execution engine contains an interpreter and JIT (Just in time) compiler, which is responsible for converting the byte code to machine code so that the processor will execute them. Most of the JVM implements both interpreter and JIT compiler to convert the byte code. This technique is called an adaptive optimizer.
Difference between JDK VS JRE VS JVM
I hope these words like JDK (Java Development Kit), JVM(Java Virtual Machine), and JRE(Java Runtime Environment) all are looks similar. Still, these are the core concepts of the Java programming language. These are different and are used for a specific purpose. you may face this in most of the interviews, so lets me explain this.
What is JDK?
its full Form is JDK ( Java Development Kit) of Java, which provides all the tools which are required for compile, debug and execute the java program. It’s a platform-specific software that’s why different versions are available according to the platform-specific like windows, Mac, Linux. Mainly JDK include two things
- Development tools (it provides an environment to develop Java programs)
- JRE (It Helps to Execute your Java program)
What is JVM (Java Virtual Machine)?
It is the most critical thing in java, which is responsible for converting byte code to the machine-specific code and also provide the core java functions like memory management, garbage collection, and security.
What Is JRE (Java Runtime Environment)?
JRE is providing us the platform to execute the java program. JRE is a combination of JVM and Java binaries and other classes, which helps us to execute our java program successfully. If you want to run a java program on your machine, then on your computer, JRE should be installed, and JDK is not required to run the java program.
- For Develope Java program we need JDK, but for successfully run the java program we required JRE
- JDK and JRE have the JVM so that we can run the java program.
- Because of the JVM, java is a platform-independent language so that we can write the java program once, and we can run on any other platforms.
If you want to add something or update something in the post, then feel free to mention that in the comment section.