Java is platform independent, because in it code firstly compiled and then JVM convert into the code which is understand by OS. So I have doubt, do I need to install JVM on each OS or not?
3 Answers
The OS does not understand the code without any translation layer. The JVM understands the code. You need to install the java run time (JRE) which runs the JVM on any machine you wish to run java code. This is due to that java is not "native" code like C or C++ instead something is needed to convert the instructions to machine code which the JVM does.

- 2,896
- 9
- 36
- 64
When java compiles, it not compiled directly into machine code. It's compiled to bytecode - this bytecode cannot be read by a computer by itself, it needs some other program to come in and interpret the code for it. This is where the JVM comes in, it takes the bytecode and then turns it into machine code that the computer can execute.
So you need a JVM to run the bytecode produced by a java compiler, although you don't have to specifically have one installed. It is possible to bundle a JVM with your java program, so when a user downloads you program - they have java installed along with it.
This has the major benefit of having a java application able to run on any operating system that can run a JVM. This is why java is write once, run anywhere.

- 1,470
- 14
- 22