Wednesday, May 14, 2008

Write Once Run Anywhere – what does it actually mean?

In Java, all programs are compiled into bytecodes in form of .class files. These bytecodes can run on any platform.

Bytecodes are special kind of representation for the instructions, which are interpreted by the native JVM. It contains the instructions in a standard format and doesn’t include any platform specific stuff. The native JVM is responsible for converting those instructions into native instructions, which the underlying OS can understand and execute.

This extra layering enables that the Java programs written once can run anywhere. Java Compiler is not a platform dependent entity, so irrespective of the platform you used for writing you Java program, you can use the standard Java Compiler ‘javac’ on any platform of your choice to compile the code. Or, you can simply ship the compiled ‘.class’ file to the system you want to run the code on.


No comments: