Wednesday, December 14, 2011

Java Applications Run Anywhere?



Unlike applications written in most languages, Java applications can work across most Operating System platforms (Windows, Linux, Solaris, iOS, etc.). This is a major reason why Java is becoming more and more popular. But how does Java behave with such portability?

Not all operating Systems allow all sorts of executables to run in them. For example, a Windows executable would not run under Linux, at least not without any tricks. These different types of executables contain binary instructions compatible with their native OS platform.

Most languages like C, C++, Pascal etc, come with compilers which compiles the code directly into binary executables compatible to the targeted Operating System platform. So, an executable compiled targeted to one platform may not run on another platform.

What java compilers do is to compile the code into an intermediate code known as the bytecode. Bytecode however is not executable to any plain OS platform! For any OS to execute this bytecode, an environment called JVM (Java Virtual Machine) must run within itself. JVM knows how to execute the bytecode. Plus, for each OS platform, there is a compatible JVM. Sometime, JVMs come built into the OS itself so you need not install the JVM. So, as long as an OS is Java enabled, it can run any Java written application despite its platform.

A downside of Bytecode is decreased efficiency. Prior to execution, bytecode should be converted to a compatible form with the OS platform. While JVM is involved in doing this, efficiency of execution may be decreased. In contrast, any other executable with compatible binary data can execute instructions without any unnecessary steps.

No comments:

Post a Comment