What contains inside Java Virtual Machine with the explanation

As you know in any machine, we have different components like hardware (physical machine call it as hardware(CPU, RAM.. etc) and software (Operating System).

if you want to perform any operation from another machine, we need to write some code (say in c language) which will open a socket connection, that is a remote network call to another machine and make an OS call i.e native call.

Each machine should have different ways to handle this situation. Here the code is tightly coupled means dependent on the target machine. if the target machine is changed or a new machine. The existing code would not work in this case. so that means platform dependent.

After the Java virtual machine is introduced, many problems are solved. write once deploy to any machine.

what is inside Java Virtual machine?

as the name suggests it is a virtual machine run as a java process that talks to a physical machine. JVM is dependent on the physical machine, but it gives independence to different machines in the form of Java code. It is a virtual platform on top of your physical processor.JVM is one of a component of the Java runtime environment.

JRE contains a set of Java-based APIs as well as JVM. The following are responsibilities of the JVM

  • Compiling your java code java bytecode which is understood by the physical machine.
  • Interpret the java bytecode and covert this bytecode into the corresponding native calls i.e Operating system calls.
  • Object management handlings such as object creation and garbage collection.

JVM has different components.

JVM Components

  • Heap memory

Heap memory is one of the components of the JVM machine which stores the object. here object means which holds the member variables, constructors, and methods. By default heap size is 64 MB. We can increase the size using -Xmx(maximum heap size) and -Xms(initial heap size) options.

a lifetime of an object is as long as it is referenced.

whenever an object is unreferenced, the Garbage collector using some algorithm will destroy the object.

  • Stack Memory

Stack Memory holds the local variables. The lifetime of the local variables is temporary as long as a method is executed.

Once the function/method execution is over, these variables are removed. This follows the Last In First Out model.

  • Method section

Method section holds the current bytecode that is executed presently. once the bytecode is executed, it will point to the next bytecode.

  • registers

registers are used by the stack variable.

There are multiple different JRE by different vendors

  • JRockit JVM is developed by BEA Systems.
  • Java HotSpot VM developed by Sun Microsystems.

Related Posts: