Tuesday, July 05, 2005

The Story behind Java

Sun Microsystems, the creators of the Java Programming Language says that with Java, you can "write once, run anywhere". What exactly makes this possible? The answer to this question lies in the fact that when you compile a java program, it is not converted into the native machine language as the other compilers like C/C++ does. But the program you have written is converted to what is called a ‘Java Bytecode’. Your program is converted into this bytecode, whether you compile the program in UNIX or Windows. When the program is executed, this bytecode is converted to the native machine code by Java Virtual Machine (JVM). JVM is an interpreter that is used to convert bytecode to platform specific instructions. By using JVM you are decreasing the speed of execution by 10 folds. But this has an added advantage that the program can run in any platform.

Have you ever noticed an error occurring for a program written in C/C++ due to lack of some run-time files? No. But if you try to run the Java Program on a machine that has no JVM installed, it will not run. The secret behind platform independency also lies here. Whether you are running on a UNIX machine or a Windows machine, you need to install JVM targeted for the same operating system to get your program working. JVM provides the platform independency. There are separate downloads for each platform available on the Sun website.

Speed penalty of the Java programs can be overcome using JIT (Just In Time) compilers. These are compilers which compile the bytecode to native instruction set of the computer running the Java program. This will overcome the problem of speed penalty when using JVM.

1 comment:

Anonymous said...

good one ... needs 2 be a bit more elaborate