Wednesday, July 18, 2012

PLATFORM INDEPENDENCE


Platform Independent:

All the earlier programming language compiles a piece of code that can be then run to get the desired output.  The problem with the code that is generated after the compilation is that, it can run only on the machine that it was created.

All software (including games) comes with a specification that it needs a specific OS platform to run on. So if you had bought a FIFA 2012 for WINDOWS and then you also got a MAC, you cannot run the same FIFA 2012 on MAC. 

Same thing happens with the code generated from earlier programming language. You cannot take the code that was generated on WINDOWS and run it on MAC or LINUX.

So if you can produce some kind of platform that can run on top of all OS platform and let your platform run the code generated from your programming language. Your platform can understand these codes and no matter what OS platform is beneath, you can generate the same output everytime.

For eg.,  You understand only one language. You may not be able to understand the languages of other countries when you visit them. So you install a person to every country you visit and he knows which language you know and he translates that country’s language your language.

The platform (virtual machine) that SUN creates for every OS platform is called as JVM (Java Virtual Machine). It is virtual because you cannot feel it or see it. It installed and it just there.

JRE and JDK

Not let us understand 2 parts of any application creation. Every time you write a program you use the language compiler to compile the program. The Java compiler (javac) checks the syntax and semantics of your code and makes sure that it can be run later.

The compiler is a part of JDK (Java Development Kit) but helps you to write Java programs.

Java provides some predefined and precompiled collections of code (rt.jar, tools.jar) that you can use. The collection is a part of JRE (Java Runtime Environment). JRE also supports to run your compiled code.  In a nutshell, JRE provides the environment that may be necessary to run any Java program.

Let us now bring JDK, JRE and JVM together.
You will be writing java code in .java files. You will then compile this .java file using java compiler (javac). Java compiler to create a .class file at the end of compilation. The good thing about this .class file it that, it runs of JVM and not directly on OS platform.

This is how all the 3 superheroes come together to give you platform independence.

No comments:

Post a Comment