![]() |
VOOZH | about |
The meaning of Java platform-independent is that the Java compiled code(byte code) can run on all operating systems. A program is written in a language that is human-readable. It may contain words, phrases, etc. which the machine does not understand. For the source code to be understood by the machine, it needs to be in a language understood by machines, typically a machine-level language. So, here comes the role of a compiler. The compiler converts the high-level language (human language) into a format understood by the machines.
Therefore, a compiler is a program that translates the source code for another program from a programming language into executable code. This executable code may be a sequence of machine instructions that can be executed by the CPU directly, or it may be an intermediate representation that is interpreted by a virtual machine. This intermediate representation in Java is the Java Byte Code.
In the case of C or C++ (languages that are not platform independent), the compiler generates an executable file (such as a .exe file) which is both OS-dependent and CPU-dependent. When we try to run this executable file on another OS or CPU architecture, it does not run, since it is specifically compiled for the target operating system and hardware architecture, making it incompatible with others.
In Java, the main point here is that the JVM depends on the operating system – so if you are running Mac OS X you will have a different JVM than if you are running Windows or some other operating system. This fact can be verified by trying to download the JVM for your particular machine – when trying to download it, you will be given a list of JVM corresponding to different operating systems, and you will obviously pick whichever JVM is targeted for the operating system that you are running. So we can conclude that JVM is platform-dependent and it is the reason why Java is able to become "Platform Independent".
Important Points:
Note: Java is platform-independent because of bytecode, but JVM is platform-dependent as it is OS-specific. Thus, Java achieves portability through JVMs on different systems.