C++ is not platform-independent because it needs to be compiled into native code and a different compiler needs to be implemented for different CPU architectures.
A C++ compiler only translates the code into machine language or native code. This native code is executed by the processor.
From what I read on the net, a Java program is initially compiled into Bytecode by the java compiler 'javac'. This bytecode is then interpreted (and executed) on a line by line basis by the Java virtual machine.
I have few queries.
1) If C++ is not platform independent because different compilers need to be designed for different CPU architectures, then doesn't JVM differ from one hardware to another as well?
2) If I wrote a C++ code and compiled and executed it on Machine 1 and Machine 2, the output produced will be the same. Similarly, if I write a Java program and execute it on two different machines, the output will still be the same. Why the extra step of bytecode generation?
3) I read somewhere that interpreters, unlike compilers, actually execute a program by emulating a virtual machine. Does it mean that JVM actually executes the bytecode and not just interprets it into native code?