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
- Top 25+ Fresher Java Interview Questions - March 9, 2023
- 25 Free Practice Questions – GCP Certified Professional Cloud Architect - December 3, 2021
- 30 Free Questions – Google Cloud Certified Digital Leader Certification Exam - November 24, 2021
- 4 Types of Google Cloud Support Options for You - November 23, 2021
- APACHE STORM (2.2.0) – A Complete Guide - November 22, 2021
- Data Mining Vs Big Data – Find out the Best Differences - November 18, 2021
- Understanding MapReduce in Hadoop – Know how to get started - November 15, 2021
- What is Data Visualization? - October 22, 2021
0 thoughts on “How Does A Java Virtual Machine Works?”
JVM allows Java portability to execute within platform and hardware-independent applications.Many thanks for sharing.