Tuesday, December 10, 2013

WHAT IS JVM - JAVA VIRTUAL MACHINE

JVM - JAVA VIRTUAL MACHINE


Albeit this topic is such that you can dig deeper and deeper,I will try to keep it simple.But if you have the understanding of inner working of machines and experience in Java programming ,it will be helpful in understanding the topic better.

Although we will be discussing about JVM(Java Virtual Machine) here but please note that this VIRTUAL MACHINE concept is not specific to Java only. In fact,there are many other languages which make use of virtual machine.Here we will discuss what JVM does for you,it's benefits and it's disadvantages.Let's start from the top:

HIGH LEVEL LANGUAGES:

The semantics of a high level language are designed in such a way that it is easily understood by us and at the same time it's easy for a machine to interpret it.And as we all know that higher level programming language is totally different from machine level language or machine level code that the machine actually uses to construct and run the program.Thus high level languages are at multiple levels of abstraction from the machine code.

Before the program/code written in higher level is able to run,it should be interpreted first.Many programming interfaces have the capability to Compile In Advance(AOT compilation).This makes the execution of program efficient during run-time but it is generally platform specific.So you have to sacrifice portability!!!! Not a good option,right???

Java actually converts the high level code into Java bytecode which is interpreted by the JVM (Java Virtual Machine).


WHAT JVM DOES WITH JAVA BYTECODE:


When we build our Java project then the Source Code(i.e. *.java source files) is converted to Java Bytecode(generally contained in *.class files).The Java Bytecode is a set of compact micro-instructions that are easy to understand/interpret by the machine but less readable as compared to machine code.We can say that Java Bytecode is somewhat very near to Machine code but not exactly machine code.Phew!!!!!

When we run the Java code on any Java enabled platform(e.g. on computers,mobile phones,etc),the Java code is actually passed to JVM which starts interpreting the entire bytecode at run-time,following the principles called JUST-IN-TIME-COMPILATION.This makes the Java program that we try to open work faster and increases the performance compared to normal interpreted compilation.


How JVM works?



The main advantage which is very evident is the increased compatibility.So basically you have to write the code once and you can run it on any platform having JVM. This is possible because Java applications run on the Virtual machine rather than on actual hardware.This clearly indicates that java application doesn't have to bother about the underlying hardware or platform. JVM takes of everything which is basically a software that can be written for different platforms.Therefore,the world says about java that-

WRITE ONCE, RUN EVERYWHERE!!!

BENEFITS:

  • Compatibility
  • Security
As already mentioned and explained - Compatibility.The other most important advantage of JVM is - Security.Due to the fact that Java applications run on JVM,there are less chances that they would disrupt the user's operating system.But this does not mean JVM is like another virtual computer(i.e. It's not something like VMware or VirtualBox).In fact Java applications do have read and write access to various data available on your machine but the simple point is that there are less chances that your data files would be corrupted if any error occurs.For a complete list of advantages,go to - JAVA ROCKS!!! 


DISADVANTAGES:

  • Slower - It has been overcome by using special code analysis features like Just-in-time-compilation.
  • Different Implementations of JVM - Basically JVM is not a single piece of software.So basically your code may run correctly on a JVM but may crash on another JVM. Nevertheless practically it's true that write your code once and run it everywhere.But more complex and larger codes may need debugging in different JVMs to ensure that they are working correctly.

If you have any queries with respect to to what's mentioned in the article or need help with any computer issue - Leave a comment!!! If you feel that something more can be added to this article,please tell us :D


  



  

  

No comments:

Post a Comment

Thanks for your valuable comment