为什么Java语言需要字节码?为什么用这种方式设计java? [英] Why the Java language need bytecode? Why java design in this way?

查看:220
本文介绍了为什么Java语言需要字节码?为什么用这种方式设计java?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认识java开发人员,需要让他们的.java文件成为.class,而.class需要JVM转换为本机代码才能执行。为什么用这种方式设计Java?为什么不只是使用解释器作为脚本语言来解释.java文件?或者为什么不将它转换为像C这样的可执行文件?为什么需要转换为字节码? java语言背后的设计理念是什么?

As I know a java developer, need to let their .java file to become .class, and the .class requires the JVM to convert to native code to execute. Why the Java design in this way? Why don't just as a scripting language, using a interpreter, to interpreter .java file? or why don't just convert it to executable like C? Why need to convert to bytecode? What is the design philosophy behind the java language?

推荐答案


这是为了速度和便携性同时。

It is for sake of speed and portability at the same time.

我要说的所有内容都是根据具体情况进行调整和审核,但大致如下:

All of what I am going to say is to be adapted and moderated depending on the case, but roughly:


  • 如果您只是用解释器解释java文件,那么
    将具有可移植性但不具有速度

如果您必须编译给定处理器
架构的代码,您将拥有速度但不具备可移植性

使用字节码,您可以编译一个共同的
机器的代码(进入字节码),它将执行它(JVM)它是
速度与便携性之间的折衷

With the bytecode, you compile the code (into bytecode) for a common machine that will execute it (the JVM) it is a compromise between speed and portability.

这篇关于为什么Java语言需要字节码?为什么用这种方式设计java?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆