Styrow.dev
Question 2 of 247
Java Topic: General medium

How is java platform independent?

Question

How is java platform independent?

Answer

  1. 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.

  2. 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.

  3. 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.

  4. Therefore, though JRE is platform dependent, the bytecode is platform independent. Thus, java is platform independent.