我有时想知道为什么 Java 被称为平台无关语言?
我找不到以下几点的正确解释:
如果以上问题的答案是否定的,那么平台独立性是如何实现的。
请帮助我学习这个基本概念。
最佳答案
Is the JVM same for Windows/Linux/Mac OS?
完全没有。编译器在所有平台上都是相同的。但是,因为它是一个 executable file ,文件本身会有所不同,即在 Windows 上,它将是 .exe,在 Linux 上,它将是 Linux 可执行文件等。
Are the bytecode generated same for a same Class in the above environments?
是的。这就是为什么 Java 是 COMPILE ONCE 的原因。随处运行。
开始之前please read this doc by oracle
https://stackoverflow.com/questions/17691261/