Java Virtual Machine

Sachintha Punchihewa
2 min readSep 28, 2021

Before going to learn about Java Virtual Machine we have to learn about what is the meaning of “Virtual”. Simply “Virtual” means it is not real but still we can use it. But when it comes to “Java Virtual Machine” it is also a machine that is not exsisting but still we can use it for a purpose.

When before developing a java program we usually download the JDK which has JRE, JVM both. but it is not true. cause we can also download JRE separately and run a program. the truth is when we download JRE it simply keeps the implementation of the JVM according to the different platform that’s what we call JVM is platform dependent and JRE is platform independent. JRE keeps all the implementation of the JRE and JVM has all the specifications that the program need to run.

We can divide virtual machines into two categories.

  1. System Based Virtual Machine
  2. Application based Virtudal Machine

When we take the System based Virtual machine we can take some example as hypervisor, Xen like wise and also those have one or more hardware. It creates multiple environment to work and completely independent.

JVM is fallen into the Application Virtual Machine category cause JVM is an instence that creates by JRE according to the platform. It doesn’t have any hardware creates and it only creates a software that a application can be run. mainly it makes a platform/environment to run a software that creates from a high level language like Java.

JVm is completely a specifications and it says how this should be done. ( how this program should be run )

ex: when we run a Java program we need a java version like 1.8 or some version. Before we run a java program we neet to compile the java program to make the compilation of the code we cannot do it from the JRE so to do that we need the JDK specifications like (Java I/O, Arrays, Math, Reflection) like wise otherwise we cannot compile a java program. after compilation then only we need to use the JRE, and JVM in runtime. and the other thing in a one computer we can create a java program and compiled java class files wen can run using only JRE because we need JRE to run a compiled java program.

When we type javaHelloWorld.class we ask the OS through the JRE “Hey gimme a instance of a JVM”. and It begins to start run the coding and by that time also it creates a Deamon thread that needs run the application. and that main deamon thread can make other non-deamon threads also. that thread is gonna die after all the non-deamon thread dies and if we call System.exit() code.

--

--