How Java is platform independent?
Platform independence refers to the fact that java compiled code (byte code) can execute on any operating system.
A programme is written in a language that can be understood by humans. It could contain words, phrases, or other information that the machine doesn’t understand. The source code must be written in a machine-readable language, usually a machine-level language, in order for the machine to understand it. As a result, a compiler is required. The compiler transforms the high-level language (human language) into a machine-readable format. As a result, a compiler is a programme that converts source code from one computer language to executable code for another programme. Join Java Training in Chennai to learn why java is platform independent.
This executable code could be a set of machine instructions that can be directly executed by the CPU, or it could be an intermediate representation that a virtual machine interprets. The Java Byte Code is the intermediate representation in Java.
Step-by-step instructions Java Program Execution:
- When a programme is created in JAVA, the javac compiler compiles it.
- The JAVA compiler produces a.class file or bytecode rather than machine native code (unlike C compiler).
- The resulting bytecode is non-executable and requires the use of an interpreter to run on a computer. The JVM is this interpreter, and it is the JVM that executes the Bytecode.
- Finally, the programme executes to get the desired result.
The compiler outputs an.exe file that is OS dependant in the case of C/ C++ (languages that are not platform neutral). When we try to run this.exe file on a different OS, it fails since it is OS dependant and thus incompatible with the other OS. Java Online Training will enhance your programming skills in Java.
Although Java is platform independent, the JVM is platform dependent.
The essential element to remember about Java is that the JVM is dependent on the operating system – thus if you’re using Mac OS X, your JVM will be different than if you’re using Windows or another operating system. This fact may be verified by attempting to download the JVM for your specific machine – you will be presented with a list of JVMs corresponding to various operating systems, and you will obviously select the JVM that is aimed for the operating system that you are using. As a result, we may deduce that JVM is platform-dependent, which is why Java is able to be “Platform Independent.”
Points to Remember:
- In the case of Java, it’s Bytecode’s magic that makes it platform agnostic.
- This contributes to a key aspect of the JAVA language known as portability. Every system has its own JVM, which is installed when the Java Development Kit (JDK) is installed. There is a different JVM for each operating system that can read the.class file or byte code.
- It’s worth noting that, while JAVA is a platform-agnostic language, the JVM is platform-specific. Different JVMs are built for different operating systems, and byte code can execute on different operating systems.
Here, in this blog we have discussed about the why java is called platform independent and how is java platform independent and to learn more about Java Platform, join Java Training in Coimbatore at FITA Academy.