In our earlier tutorial we have seen the difference between JDK, JRE, JVM. In this tutorial we will see one more important concepts which every Java Developer should know. We know JDK, JRE, JVM are platform dependent but how Java is platform independent.
The configuration for each OS is different so JDK, JRE, JVM are all platform dependent. But the Java code developed in Windows can be executed in Apple/Linux or vice versa, which is called WORA means Write Once Run Anywhere.
To understand this we must should understand the execution of Java Program.
- When we write Java Code, we will save it with an extension of .java.
- Using Java Compiler, the java source code will be converted to bytecode, means .java file will be converted into .class file.
- This .class file will be converted into native machine code by JVM and get executed.
But the magic happened in the bytecode (.class file). The converted byte code is platform independent can be executed by any JVM irrespective of Operating System.
Eg: When we develop the code in Linux machine and compiled it, we will get byte code. This byte code can be executed in Windows/Apple OS machine which makes the Java is Platform Independent.