JVM( Java Virtual Machine)


What is JVM?
  • JVM stands for Java Virtual Machine.
  • It’s an abstract computing machine which helps to run a java program.
  • JVM helps to convert java byte code to machine level language.
  • JVM helps to load the code, verifies and execute the code and also it’s providing a run time environment which is known as JRE (Java Runtime Environment).

How JVM works?
  • When we execute a class using java command, In RAM a memory has been allocated for java program execution.
  • That memory is divided in to two parts
  1. Stack
  2. Heap
  • Stack holds local variable and partial results and also it's stores frames.
  • Heap is the runtime data area where objects are allocated.
  • So, Stack is use for method execution while Heap is use for storage purpose..
  • JRE enters into Stack and invokes class loader.
  • Class loader is a program which loads all static members of a class into Heap.
  • After class loading JRE searches for a main method in static pool and if it is exist then JRE invokes main method.
  • Now, main method enters into Stack and starts the execution.
  • When main method encounters an object creation statement using new keyword, all non-static members of class are loaded into Heap and the address is stored into a reference variable.
  • By using reference variable we can access any non-static members of a specific object.
  • When main method execution is over, main method comes out from Stack.
  • At last JRE invokes garbage collector which cleans the entire memory.





Copyright © 2017 qatoolsguide.blogspot.com || ALL RIGHTS RESERVED