<<< Prev

Next >>>

Class Loader Sub System

  • The class loader sub system will take a .class file as the input and performance the following operations. 
  • The class loader sub system is responsible for loading the .class file (Byte code) into the JVM.
  • Before loading the Byte code into the JVM it will verify where there the Byte code is valid      or   not. This verification will be done by Byte code verifier.
  • If the Byte code is valid then the memory for the Byte code will be allocated in different areas.
  • The different areas into which the Byte code is loaded are called as Run Time Data Areas. The various run time data areas are.


1. Method Area: 

  • Java Virtual Machine Method Area can be used for storing all the class code and method code.
  • All classes bytecode is loaded and stored in this run time area , and all static variables are created in this area.

2. Heap Memory:

  • JVM Heap Area can be used for storing all the objects that are created.
  • It is the main memory of JVM , all objects of classes :- non static variables memory are created in this run time area.
  • This runtime area memory is finite memory.    
  • This area can be configured at the time of setting up of runtime environment using non standard option like
  • java -xms <size> class-name.
  • This can be expandable by its own , depending on the object creation.
  • Method area and Heap area both are sharable memory areas.
  • 3. Java Stack area:

    • JVM stack Area can be used for storing the information of the methods. That is under execution. The java stack can be considered as the combination of stack frames where every frame will contain the stat of a single method.
    • In this runtime area all Java methods are executed.
    • In this runtime JVM by default creates two threads. they are
    • 1.main method
    • 2.Garbage Collection Thread
    •  main thread responsible to execute java methods starts with main method.
    • Also responsible to create objects in heap area if its finds new keyword in any method logic.
    • Garbage collection thread is responsible to destroy all unused objects from heap area.

    4. PC Register (program counter) area:

    • The PC Register i Java Virtual Machine will contain address of the next instruction that have to be executed.

    5. Java Native Stack:   

    • Java native stack area is used for storing non-java coding available in the application. The non-java code is called as native code.


    Execution Engine:

    The Execution Engine of JVM is Responsible for executing the program and it contains two parts.

    1. Interpreter.
    2. JIT Compiler (just in time compiler).
  • The java code will be executed by both interpreter and JIT compiler simultaneously which will reduce the execution time and them by providing high performance. The code that is executed by JIT compiler is called as HOTSPOTS (company).

Java Variable and Types of Variables

  • Definition

    Variable is a named memory location used to store data temporarily. During program execution we can modify that data.

    How can a variable be created?

    A variable can be created by using Datatype. As we have two types of datatypes we can create two types of variables.

    1. Primitive variables- These variables are created by using primitive datatypes.
    2. Referenced variables- These variables are created by using referenced datatypes.

    The difference between primitive and referenced variables is “primitive variables stores data directly, where as referenced variables stores reference of the object, not direct values”.

    Note: As per compiler and JVM we do not have a separate name called” reference variable”. It means, the variables created by using referenced datatype are also considered d as like normal variable only.

  • Referenced variables are initialized with object reference that “new keyword,shown in the right diagram.

Limitation of variable

  • It can only store single value at a time. If we assign new value, old value is replaced with new value. It means, always it returns latest modified value.


    • If we modify primitive value previous value is replaced with new value.
    • If we modify referenced variable previous object’s reference is replaced with new object’s reference and now this referenced variable is referencing to this new object.


    • The value of primitive variable is mathematical data based on its data types.
    • The value of referenced variable is its class object’s reference.

variables are initialized with object reference that “new" keyword



Class Example

{           int x = 10

            int y = 20;



Class Test {

       Public static void main(String[] args) {

                           //primitive variables

                                int p= 50;

                               int  q =m1();

                         //referenced variables

                               String s1 =”a”;

                                 String s2=new String (“a”);

                                  Example e= new Example();


             Static int m1() {

                    return 60;



Class simple {

      Public static void main(String[] args) {

              int a =50;

                 System.out.prtinln(“a: “ +a);


                  System.out.prtinln(“a: “ +a);

             Example e1=new Example();

               System.out.prtinln(“e1: “ +e1);

                  e1 = new Example ();