How Does A Java Virtual Machine Works?

Even an amateur Java programmer knows that a given Java byte code is executed in Java Runtime Environment. JRE plays an important role in Java as it composes of Java APIs and JVM. Java Virtual Machine (JVM) is known for analyzing and executing the byte code of Java and it is not necessary to know, as a developer, how JVM works. But learning and understanding the architecture of JVM helps you to gain knowledge on the overall insight of a virtual machine.

Not only Java, but Java Virtual Machine (JVM) also supports a set of languages which are high-level languages. You can use a set of languages to develop your projects. There are three different categories of languages that are supported by JVM. This set of languages which is supported by Java Virtual Machine constitutes the JVM languages.

Let us understand how JVM works?

You have learnt that in high level languages like C and C++ the source code is directly converted to the machine understandable code called the binary code by a compiler. This binary code thus generated is understandable by the computer and is executed. Coming to Java, this process of compiling and execution of a program slightly varies. This exception is because of the fact that Java programs are machine independent. This very well suits the Java slogan ‘Write Once, Run anywhere.’

Initially, a Java program is compiled with the help of a compiler which generates the byte code of the source program. This compiled byte code can be run on any computer that has JRE installed on it. As JRE consists of JVM, it now converts this byte code to the machine executable code with the help of an interpreter. This machine executable code is portable which is why Java is called platform independent.

Is JVM Platform Independent?

No, Java Virtual Machine is not platform independent. Whenever a program is compiled, JVM does two things.

  • Firstly, it converts the byte code to a machine understandable code for a particular computer.
  • Secondly, to execute the machine code instructions as well.

And this machine code is dependent of the operating system which implies that JVM is OS dependent. This proves that different platforms or precisely saying different operating systems have different JVMs and that JVM is platform dependent.

Why Java Architecture is Neutral?

By now, you have understood that JVM exists only in the memory of our computer. It means that there is a possibility of fooling the compiler by generating a byte code for some virtual (imaginary) machine which is quite ingenious. This makes Java architecture neutral. It is the responsibility of the interpreter to see that it acts as the intermediary between the Virtual machine and the real machine.

Advantages and Disadvantages of JVM

The primary advantage of Java JVM is code compatibility as it eases a programmer’s job to write code only once and run anywhere. Once the application is built it can be run on any device that has JVM. Apart from this it provides security. A program running in virtual machine is likely to suffer less from any malicious activity.

Speed and its platform specific features can be considered as the disadvantages of JVM. As a program needs to be translated from source code to byte code and then from byte code to executable code, the speed of execution of a program is decreased when compared to other high level languages. JVM should be free of errors as a Java program depends on JVM. Any failure of JVM leads to the failure of the program.


  • Java is Platform Independent
  • JVM is Platform Dependent

About Aditi Malhotra

Aditi Malhotra is the Content Marketing Manager at Whizlabs. Having a Master in Journalism and Mass Communication, she helps businesses stop playing around with Content Marketing and start seeing tangible ROI. A writer by day and a reader by night, she is a fine blend of both reality and fantasy. Apart from her professional commitments, she is also endearing to publish a book authored by her very soon.

0 thoughts on “How Does A Java Virtual Machine Works?”

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top