Monday 31 August 2015

What is JVM (Java Virtual Machine)

JVM-BY NAREN
Many of them work with Java but they do not known what is a JVM which is an important to be known as a Java Programmer. So let we see in detail about What is a JVM is with a detailed discussion .
 
To execute any program written in any programming language on a microprocessor it has to be converted into machine language instructions understood by that microprocessor. This process is known compilation.

Machine language instructions of different microprocessor are different. Thus instructions of an Intel microprocessor is different than an ARM microprocessor.

Therefore any program being executed on a specific microprocessor needs to be  converted into machine language instructions that the microprocessor understands.

The machine language instructions for one microprocessor differs from one to another.

Hence if a program is compiled for one microprocessor it may not work on the another
microprocessor it would have to be compiled for that microprocessor again.

compilation-in-c 

This is a “Write once, Compile anywhere” scenario. It means to make the same program work on different microprocessor we are not required to rewrite the program, but are required to recompile the program for different microprocessors.

But the Java is different in this approach

“ Compile once, run anywhere ” .

This implemented through  a program called JAVA VIRTUAL MACHINE (JVM) .

When we compile Java Programs they are not converted into machine language instructions for a specific microprocessor, but a bytecode instructions are similar to machine code, but are intended to be interpreted by JVM. A JVM provides an environment in which JAVA BYTECODE can be executed.

Different JVMs are written specifically for different host hardware and operating systems.

For example, there is JVM for Windows and different JVM for Linux.

A JVM is distributed along with a set of standard class libraries that implement the Java Application Programming Interface (API) .

The JAVA APIs and JVM together form the JAVA RUNTIME ENVIRONMENT (JRE).
All these components of JAVA platform are shown in the below diagram

java-platform

  During execution the JVM runtime executes the bytecode by interpreting it or compiling it using just-in-time compiler (JIT) .

JIT Compilers are preferred as they work faster than interpreters.

During interpretation JIT compilation the bytecode is converted into machine language instructions for the microprocessor on which the program is being executed.

The java program is stored in .java file. The bytecode is usually stored in a .class file. A complex program may consists of many .class files .

For easier distribution these multiple class files may be packaged together in a .jar file ( java archive file ).

jre&jvm

This is how the JVM is used

detailed-jvm

I think you have understood what is a JVM is.
Keep visiting…. Thank you…..
Related Post: How to run a Java Program

No comments :

Post a Comment