Wednesday, 3 February 2016

Portability of JAVA


Java is considered as Platform independent because of many different reasons which are listed below
v  Output of a Java compiler is Non Executable Code i.e Byte-code.
v  Byte-code is a highly optimized set of instructions
v   Byte code is executed by Java run-time system, which is called the Java Virtual Machine (JVM). 
        Note: JVM is inside JRE
v  JVM is an interpreter.
v  JVM accepts Byte-code as input and execute it.
v  Translating a Java program into byte-code makes it much easier to run a program in a wide variety of environments because only the JVM needs to be implemented for each platform.
v  For a given System we have Run-time package, once JVM is installed for particular system then any java program can run on it.
v  However internal details of JVM will differ from platform to platform but still all understand the same Java Byte-code
Important Point: JAVA is platform independent. JVM is platform dependent

Explanation:

Figure 1: JAVA Portability

          
Case 1: If we created a simple C language program called Sample.C on 64 bit Windows XP operating system. It was successfully compiled the same platform and it generated Sample.obj file (which will have ASCII codes). On this same platform it was executed successfully.
Second time we are trying to execute already generated Sample.obj (which was generated on 64 bit Windows XP) on 128 bit Windows XP. This time it was not executed. Because C language is platform depended. On which platform .obj file generated, on the same platform only we can able to execute this program.

Case 2: If we created a simple JAVA language program called Sample.java on 64 bit Windows XP operating system. It was successfully compiled the same platform and it generated Sample.class file (which will have bite-code instructions). On this same platform it was executed successfully.
Second time we are trying to execute already generated Sample.class (which was generated on 64 bit Windows XP) on 128 bit Windows XP. This time it was executed. Because JAVA language is platform independent. Once we created the JAVA program on a platform we can able to execute this program irrespective of the platforms. This is called JAVA portability.

No comments:

Post a Comment