Why is the java language cross-platform

Reference https://blog.csdn.net/woailuo453786790/article/details/51660015

Because the compiled code of the Java program is not the code that can be directly run by the hardware system, but a kind of " intermediate code " - bytecode. Then different Java Virtual Machines (JVMs) are installed on different hardware platforms, and the JVMs "translate" the bytecodes into codes (machine codes) that can be executed by the corresponding hardware platforms.

Therefore, for Java programmers, there is no need to consider what the hardware platform is. So Java can be cross platform. Because it has a virtual machine (JVM), the JAVA program is not directly run on the computer, but on the virtual machine. Each system platform has its own virtual machine (JVM), so the JAVA language can be cross-platform.
The compiler first compiles the java file into a class file of binary bytecode, and the jvm interprets and executes the class file.   
 It is because java runs on jvm, so its code can be run on jvm of different platforms without modification (Unix jvm on UNIX, linux jvm on linux, windows on windows If you use windows to port to UNIX, you only need to compile the java file into a class file on the UNIX jvm   
 , and then run it with jvm.  



Why Java can cross-platform
Java can cross-platform because of the java virtual machine Can be cross platform.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325348526&siteId=291194637