Reputation: 19
I've seen a lot of online resources saying, Java is platform-independent because of its combination of using both interpretation and compilation. Stage 1: Java compiles the source code into a byte code Stage 2: this byte code is interpreted during the run time.
But, isn't Java platform-independent because byte code is platform-independent and it can be run on any machine that has a compatible JVM? Wouldn't Java still be platform-independent even if it's interpreted in both stages or compiled in both stages?
Upvotes: 1
Views: 63
Reputation: 6994
You are right, the key to java's platform independence is bytecode and JVM is. When you compile a Java program, it is compiled into bytecode which is platform independent intermediate representation of the Java code.
JVM is responsible to execute the bytecode. Each operating system has its own implementation of JVM, which interprets the bytecode into machine code.
So, whether the language uses interpretation or compilation at any stage isn't the primary factor in its platform independence. It is the use of an intermediate, platform independent bytecode and system specific JVM that makes Java platform independent.
Upvotes: 1