Monday, 7 March 2016

Java's platform independence explained

One of the most talked about point about java is it's platform independent nature.

Believe me this nature makes java really special as a programming language. So let's explore this platform independent term.

Platform independent means write once and run anywhere. It implies that it doesn't matter on what operating system(lets say,Windows OS) the code was written, it could be run on the other operating system(lets say Linux) conveniently and without any issue.

The only requirement is installation of JVM (Java Virtual Machine) in the system. JVM is the interpreter of the bytecode.

* JVM and bytecode's magic is the hand behind this platform independent concept of java.

How is this possible?

Whenever we write a program, say HelloWorld.java and compile it then a .class file is created with name HelloWorld.class.
This .class file contains bytecode instructions for JVM. Now you can run on the same system or you can happily port this bytecode on other operating system that has JVM and leave all your worries of completing your task of running the code on JVM.

Thus making java a portable in nature programming language.

Interesting!

Advantages of JVM

  • Portability - The bytecode could be ported to other system without any worry if JVM is present in the system.
  • Re-compilation not needed - bytecode doesn't need to be recompiled again in case the code is to be ported on to other operating system.
  • JVM uses JIT(just in time) compiler - Java uses a JIT compiler to compile Java bytecode to native machine code at runtime. The JIT compiler can do sophisticated optimizations for the specific CPU that the program is running on and it can use profiling information that wouldn't be available to an ahead-of-time compiler - in principle, a JIT compiler can therefore produce more optimal code than a "normal" compiler.

You may read:



No comments:

Post a Comment

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If you are looking for a reference book on java then we recommend you to go for → Java The Complete Reference
Click on the image link below to get it now.