JVM JRE JDK Program Exe Flow
JVM JRE JDK Program Exe Flow
JVM JRE JDK Program Exe Flow
The .class file is input to the JVM which loads & execute the .class file.
Class Loader System loads, links & initializes the class at the runtime, not at
compile time.
The output from the class loader will be delegated to the Linking :
The output of the loading block will be delegated to the Initialization block.
Initialization: This is the final phase of class loading, here all static
variables will be assigned with the original values & static block will be
executed.
1. Method Area : All the class level data will be stored here including
static variables. Method area is one per JVM & it is a shared resource.
2. Heap Area : All the objects & it’s corresponding instance variable &
arrays will be stored here. Heap area is also one per JVM since
Methods Area & Heap Area shares memory for multiple threads, the
data stored is not thread safe.
3. Stack Area : For every thread, a separate run-time stack will be
created. For every method call, one entry will be made in stack
memory which is called as stack frame.
All local variables will be created in stack memory. Stack area is
thread-safe since it is not shared resource.
Stack frame is divided into 3 sub entities as:
a) Local variable Array : Related to method, how many local
variables are involved & the corresponding values will be stored
here.
b) Operand Stack : If any intermediate operation is required to
perform, operand stack acts as a runtime workspace to perform
the operation.
c) Frame data : All symbols corresponding to the method will be
stored here. In the case of any exception, the catch block
information will be maintained in the frame data.
4. PC Registers :Each thread will have a separate register, to hold the
address of current executing instruction. Once the execution is
executed the PC register will be updated with the next instruction.
5. Native Method stack : It holds native method information. For every
thread, a separate native method stack will be created.
Execution Engine
It will be interacting with the native method libraries & provides the Native
libraries required for the execution engine.
It is open source.
Interview Questions :
1. What is difference between JVM, JRE & JDK?
2. What is the purpose of JVM?
3. Is JDK platform independent or dependent?
4. How java ensures high performance?
5. What is JIT compiler?
Program execution flow in Java
Program execution happen in following 4 steps:
▪ Load : In this step class loader loads the .class file which contains
bytecode and stores it in memory.
▪ Verify : In this step the bytecode is checked by bytecode verifier to
validate whether the bytecode is valid or not.
▪ Execute : In this step java interpreter interprets the bytecode one at a
time and converts the bytecode to native code which is more likely to
understand by machine. Finally, it runs the program.