Saturday, 21 January 2012

Is Java Platform Independent or Platform Dependent?

Platform independence means compile once run anywhere or Program compiled in Windows Platform can run in Unix,Solaris without making any changes to the program.

Java has both compiler and interpreter implemented by javac and java respectively.

javac compiles the java program and generate the .class file which is in byte code.
Windows:-
Test.java -> javac ->  Test.class file(byte code)

java interprets the byte code and execute it, byte code can be generated in any of the platform.
Unix:-
Test.class-> java -> Hello World

JVMs are different for different platforms but they contain the same algorithm to interpret the byte code and provide the same result across all the platforms. 



No comments:

Post a Comment