How is the Java cross-platform implemented? This will refer to the Java Virtual machine (Java VM, or JVM).
We write the Java source code, compiled will generate a. class file, called a bytecode file.
Bytecode cannot be run directly and must be translated into machine code by the JVM to run.
The Java Virtual machine is responsible for translating bytecode files into machine code under a specific platform and then running.
The JVM is also a software that has different versions of different platforms. A bytecode file can be run as long as the corresponding JVM is installed on different platforms.
The same Java program, through the "middle tier" of the JVM, can be run on different platforms, enabling "compile once, run everywhere".
JVM is a "bridge", is a "middleware", is the key to achieve cross-platform, Java code is first compiled into bytecode files, and then by the JVM to translate bytecode files into machine language, so as to achieve the purpose of running Java programs.
Note: The result of compiling is not generating machine code, but generating bytecode, the bytecode generated under different platforms is the same, but the machine code translated by the JVM is not the same.
Java Cross-platform