Java is an object-oriented and class-based programming language. It is a computing platform for developing an application that can execute many statements at once.
It is an advanced form of C++ which can be downloaded and accessed freely.
Because Java allows you to run the compiled code on any Java supporting platform, it is called a platform-independent programming language.
It works on the principle of Write once, anywhere.Java platform consists of a compiler, execution engine, and set of libraries.
Hence Java programs can run on any processor.
What makes Java a platform-independent language?
Unlike an ordinary compiler that creates only natively executable code, the Java compiler produces intermediate and unique code called bytecode.
Then, the java compiler sends byte code to Java virtual machine, which recognizes the platform and then converts the bytecodes into native machine code. This is what makes Java a platform-independent programming language.
Hence, Java is a platform-independent language because the Java compiled code that is byte code can run on all operating systems.
How is the Java program executed?
Byte code is a non-executable code that requires an interpreter meaning Java Virtual Machine, which then enables the code to execute on a machine. Thus, the program runs to give the desired result.
Main points to remember
- Java does not depend on any operating system, but JVM depends on the operating system.
- JVM enables Java to become “platform-independent.
- It is byte code that makes Java platform-independent.
- .Class or bytecode adds portability features in the JAVA language.
- When you install JDK software in your system, JVM is installed automatically, enabling you to read a .class file or byte code.
- JVM is platform-dependent, but Java is platform-independent.
Here is how the system gives the final result.
Here is another example of how bytecode can run on any JVM, and its outputs on any JVM are the same.
In short, since Java does not depend on any of the platforms, it is termed platform-independent. And it is the magic of byte code or .class file which enables Java to run independently on any platform.