Java Virtual Machine : Its features & internal structure

Java virtual machine is a machine within a machine which enables java byte code to be executed as action or operating system calls any other process regardless of the operating system being used. JVM basically translates the programming code so that two machines that may be on different platforms are able connect.

Other way to define virtual machine is that it is a layer of abstraction that gives a program one simplified interface for interacting with a variety of physical computers and its operating system.
Java virtual machine is software which resides in the computer. JVM has flexibility to execute the program’s byte code into executable code and execute it in any platform. It is not real hardware machine but a software layer which resembles an hardware platform.

JAVA COMPILER converts the source code into byte code .Suppose a program consist of class, function and variable then it will convert the program into byte code and JVM will execute the byte code on any operating system. So the input the JVM will be BYTE code and the output will be executable code.

Some important features of JVM

  • Platform Independence
    Java codes are written once and can be executed and can be run on any platform. Java source codes are converted into byte code and that byte can be executed on any of the system irrespective of the operating system used. JVM converts the source code to byte code and once the program is executed it will get converted into machine code.
  • Security
    Java Virtual machines have high built in security features which allow programmers to write highly secure java programs which will not harm any of the operating system on which the byte code will be executed.
  • Performance
    The performance of the java program is high as the codes are converted into system neutral language which byte code. The executable codes are converted into byte code which can run on any system and the execution of byte code to machine code takes very less time.
  • Correctness
    A program which executed through Java virtual Machines are error free and operate correctly .The java virtual machines are reliable and are not prone to any error. The Java virtual Machine is produced with high standard and therefore the chances to find the error is very few.
  • Java virtual Machine uses Java IN TIME (JIT) to convert Java code into low level machine code that runs quickly.
  • If nobody has installed Java Runtime Environment on your computer then we cannot use the Java program. This is one of the disadvantages of Java Virtual machine.

The structure of JVM

JVM consist of several components. The list of components is as follow:
  1. Local Variable
    They are all the local variables being used by the current method invocation while executing the program. It is pointed to by the vars register in the memory.
  2. Execution environment
    The execution environment is used to maintain the operations of the stack itself. Each of the operation is maintained in the stack and execution environment keep track of it. It is pointed to by the frame register in the memory.
  3. Operand Stack
    The operand stack is used as a work space by byte code instructions. It is used for holding parameters for byte code instructions and results of byte code instructions are also kept in operand stack. The top of the operand stack is pointed to by the optop register in the memory.
  4. Method Area
    This is the area where the byte code actually resides and the program counter points to some byte in the method area. It always keeps track of the current instruction which is being executed. After execution of an instruction, the JVM sets the PC to next instruction. Method area is shared among all the threads of a process.
  5. Garbage collected stack
    The garbage collected stack is where the objects of the java program are saved. Whenever any of the objects are created with the help of new operator then heaps are created and memory is allocated for each of the object being created.

Read More:
Difference between method Overloading and Overriding in OOPs
Advantages and Disadvantages of Inheritance in OOPS
How does inheritance work in Java?
Different features of OOPs

Copyright © ianswer4u.com