Platform Independency is more specifically concerned with the compiled code of a java program should be executed in any operating system, irrespective of the operating system in which that code had been implemented.
Reasons That Control Platform Independence
Java's architecture facilitates the creation of platform-independent software, but also allows you to create software that is platform-specific. When you write a Java program, platform independence is an option.
The degree of platform independence of any Java program depends on several factors. As a developer, some of these factors are beyond your control, but most are within your control. Primarily, the degree of platform independence of any Java program you write depends on how you write it.
Besides the Java Platform version and edition your program depends on, the other major factor determining the extent of platform independence of your Java program is whether or not you call native methods. The most important rule to follow when you are writing a platform independent Java program is: don't directly or indirectly invoke any native methods that aren't part of the Java API.
Java solves the problem of platform independence by using bytecode. The Java compiler does not produce native executable code for a particular machine like a C compiler would. Instead, it produces a special format called bytecode.
This looks a lot like machine language, but unlike machine language, Java bytecode is exactly the same on every platform. This bytecode fragment means the same thing on a Solaris workstation as it does on a Macintosh PowerBook. Java programs that have been compiled into byte code still need an interpreter to execute them on any given platform.
The interpreter reads the bytecode and translates it into the native language of the host machine on the fly. The most common such interpreter is Sun's program java (with a little j). Since the bytecode is completely platform independent, only the interpreter and a few native libraries need to be ported to get Java to run on a new computer or operating system. The rest of the runtime environment including the compiler and most of the class libraries are written in Java.
All these pieces, the javac compiler, the java interpreter, the Java programming language, and more are collectively referred to as Java.