JVM, JDK, JRE
In the previous topic, you learned about the basic java program. But the question is what is helping Java to compile and execute this code?
There is something in java that helps in the compilation and execution of a program.
Let’s start with source code and byte code. The program which you write in the text editor is called as source code. The source code is saved with .java extension. The written code is converted by the java compiler into byte code with extension .class. This byte code can be run into any system that contains Java software. After that, java machine interprets the code and executes the program.
This is just like human digestive system.
The food you eat is the source code. Mouth acts as the compiler and converts the food by chewing into the byte code so that the food can pass through the throat.
Stomach stores the food and digests it which can be considered as interpret and execute.
- Source code: the one user saves with .java extension like Hello.java
- Byte code: java compiler compiles the source code and generates byte code. This byte code can be run on any kind of Operating System having java software. That is why it is called as platform-independent. Byte code contains the .class file.
JVM (JAVA INTERPRETER)
- JVM (Java Virtual Machine) acts as a run-time engine to run java applications. JVM is the part of JRE.
- JVM calls the main method after the execution of the program starts.
- JVM contains JIT(Just In Time) that converts byte code into machine code just before the execution of the program.
- JRE stands for Java Runtime Environment and can be also written as Java RTE.
- JRE contains JVM, other classes, and libraries that are required during the program execution.
JDK (JAVA COMPILER)
- JDK allows developers to create Java programs that can be executed and run by JVM and JRE.
- JDK contains JRE, java compiler, and other java tools.