Question
How is java platform independent?
Answer
-
The source code (the .java file) is compiled by the java compiler (javac) into a bytecode ( .class file), this bytecode can be run on any machine having any OS installed, but a JRE must be installed on the machine pertaining to the particular OS.
-
With Java, you can compile the source code on any OS and the compiled code (bytecode) can be executed (interpreted) on any platform running a JRE.
-
So the JRE for Windows is different, for Linux-based OS it is different etc. but the bytecode generated on a windows machine can be run on a mac (for eg.) with JRE, for mac installed.
-
Therefore, though JRE is platform dependent, the bytecode is platform independent. Thus, java is platform independent.