Sun Microsystems’s Java Virtual Machine is one of the best-known examples of application virtual machine.
In this article we will discuss about Java Virtual Machine and how it works.
As we know java has come up as powerful computer programming language, which has got its own benefits over conventional languages.
Main advantage of java programming language is platform independence, which means any application written in java can be operated on any of the platform, instead of having to produce separate versions of the application for each computer and operating system.
Now the question arises how it's possible for a Java application to run on many different machines?
From the figure given below you can get the flow of java program execution.
- Java Programmer writes Java Program
- Java Compiler generates the byte code that corresponds to the instructions in the program
- The JVM interprets the stream of bye code and executes the instructions.
- The System receives instruction from JVM and displays desired output.
The key to Java's portability and security is the Java Virtual Machine on which java relies, because of this simulated machine computer programmer does not communicate with system, in turn it it directly communicates with virtual machine, in this way programmer utilizes functions that are built into the JVM and not the operating system.
JVM does not have any information regarding the programming language. It knows only the binary format of the byte code. The java compiler from which you compile java program does not produce native executable code for a particular machine like C compiler would do. Instead it produces a special format called byte code, in other words byte code can be thought of as the machine language for JVM.
The JVM interprets a stream of byte-codes as a sequence of instructions and then execute to produce desired output.
JVM depends on operating system, it must have a possible mapping for its instruction on every operating system or machine that it is installed in order to work.
Once the byte-codes are interpreted by the JVM the instructions are mapped to the instructions in the operating system or on the hardware. JVM actually uses operating system and machine instructions to carry out the instructions it has been given.
It is possible that the instruction which JVM has can be carry out by one operating system and while with another it is not. This is one of the reason why Java has not achieved 100% portability.
The main purpose of the Java Virtual Machine is to solve the problem with creating portable computer programs. The question which still comes to the mind does the JVM completely solved the problem and made Java 100% portable?
The answer is no. It does not completely solve the problem, there is no doubt that it has provided a good solution that is most part effective but not 100% effective. Java has still achieved a relatively high degree of portability. Java has allowed people to develop many cross-platform applications and has proven to be useful and powerful interpretation of a virtual machine.