Hey Guys!!!!! Do you really think that you know the basics about JVM??

Roshni Silva
5 min readNov 28, 2021

So, your answer would be either ‘YES’ or ‘NO’… No worries let’s try to figure it out also remember I am not going to discuss the entire information about JVM but let’s give a START.

Most people think that they know about Java Fundamentals including myself. Hey, guys please don’t be angry about me note that I am not talking about everyone but of course about a few or more people. When we talk about Java fundamentals, we can’t forget about JVM, JRE and JDK. So here I mainly take you guys through a bit about JVM.

Let’s take look at the below conversation which is a small part of the JAVA Software Engineer interview session.

Interviewer: …. Hey, so let me take you through some of JAVA fundamentals. Can you explain to me what is JVM?

Interviewee: JVM standard for Java Virtual Machine and it executes java byte codes further it converts compiled bytecode into machine code.”

I am not trying to say each and everyone would come up with an above answer but a few or more use the above answer when someone asked about JVM also I’m not trying to tell that the above answer is completely wrong but of course above answer is not fair. Here I used a term called ‘fair’ instead of wrong. Now, let’s see why I used ‘fair’. Assume someone comes and asks you to explain about your mother so what if you just tell, she is the one who prepares your meal every day so now you might feel ‘Okay this is somewhat true. Yes of course this is somewhat true but this is not a fair answer why because out of 1000 + tasks, preparing your meal is just one task that your mother does for you. If you give such an answer this is not really fair RIGHT??

As similarly, the above answer regarding JVM is just one point that you trying to show.

Ooopsss!!! I forgot to tell you. When someone answers the above mentioned JVM question, a few or more people sometimes tell that it is inside the JRE. So, guys what do you think is that really TRUE??? Let’s see. Now let me put full stop storytelling session and walk you guys through to the real flow.

???????

JVM these three letters standard for Java Virtual Machine so the name itself tells that it is a virtual machine. Now some of you might think what does it really mean. It means this is a machine that does not exist in the reality or is not available physically further you cannot go and touch or find this machine in the real environment/ in your computer. Do you ever try to download and install this so-called JVM on your computer? Obviously, the answer would be NO because this JVM is nothing that exists physically or entity-wise.

Let’s go a little bit more with virtual machines then you can easy to find what is JVM.

I hope now you have somewhat an idea about what is a virtual machine. There are two types of virtual machines which are System based Virtual Machines (SVM) and Application based Virtual Machines (AVM).

· SVM — This type of virtual machine is used one or more hardware and it creates multi environments which are totally independent from each other.

Examples: Hypervisor, XEN

· AVM — This type of virtual machine has not involved any type of hardware instead it may have software to create a platform to run the programs. Since these types of virtual machines are applications, we can consider this as a process so we can call this a Process based Virtual Machine as well.

Examples: JVM, CRL (Common Runtime Language)Now back JVM

Now back to JVM

So JVM is a virtual machine that does not exist in reality and fallen under Application or Process based virtual machine and this JVM is completely a specification that tells what needs to be done in order to run a java program also you need to remember when the time you install JRE (Java Runtime Environment) which is an implementation which illustrates how the things need to be done, it deploys all the code which required to create JVM. When the time we start running our Java program, it will create a JVM instance, in another word if you are not executing any program on your computer at that time remember you don’t have any JVM instance on your computer. Assume now you are running a ’n’ number of different java programs, at that time there are ’n’ number of JVM instances are available on your computer. So, the point to remember is that JVM is not static or constant on the computer. Now we are aware of at what time this JVM instance gets created and let’s see how this JVM instance gets destroyed. We have two ways of destroying this JVM instance. First, in java, we have daemon and non-daemon threads. When a java program started it creates a JVM instance and that JVM instance creates a non-daemon thread. When the time the last non-daemon thread gets dies, at that time JVM also gets destroyed. Second, the program itself has to call the system exit() method.

JVM is platform-dependent because the JVM instance takes care of reading class files and converting that into machine language which is your operating system understands.

JVM topic is kind of huge range topic so there are many things that you need to aware of JVM but above I have discussed simple and very basic points about JVM and hope to cover some more points in JVM in upcoming stories.

Finally, I hope now you guys can come up with a fair answer to the question ‘Can you explain about JVM?’

--

--