Java 是编译型还是解释型编程语言? [英] Is Java a Compiled or an Interpreted programming language ?

查看:35
本文介绍了Java 是编译型还是解释型编程语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去我使用 C++ 作为编程语言.我知道用 C++ 编写的代码要经过一个编译过程,直到它成为目标代码机器代码".

In the past I have used C++ as a programming language. I know that the code written in C++ goes through a compilation process until it becomes object code "machine code".

我想知道 Java 在这方面是如何工作的.用户编写的Java代码是如何在电脑上运行的?

I would like to know how Java works in that respect. How is the user written Java code run by the computer?

推荐答案

Java 实现通常使用两步编译过程.Java 源代码由 Java 编译器编译成字节码.字节码由 Java 虚拟机 (JVM) 执行.现代 JVM 使用一种称为即时 (JIT) 编译 的技术进行编译硬件 CPU 在运行时动态理解的本机指令的字节码.

Java implementations typically use a two-step compilation process. Java source code is compiled down to bytecode by the Java compiler. The bytecode is executed by a Java Virtual Machine (JVM). Modern JVMs use a technique called Just-in-Time (JIT) compilation to compile the bytecode to native instructions understood by hardware CPU on the fly at runtime.

JVM 的某些实现可能会选择解释字节码,而不是 JIT 将其编译为机器代码并直接运行.虽然这仍然被认为是一个解释器",但它与读取和执行高级源代码的解释器完全不同(即在这种情况下,Java 源代码不是直接解释的,Java 编译器的输出是字节码.)

Some implementations of JVM may choose to interpret the bytecode instead of JIT compiling it to machine code, and running it directly. While this is still considered an "interpreter," It's quite different from interpreters that read and execute the high level source code (i.e. in this case, Java source code is not interpreted directly, the bytecode, output of Java compiler, is.)

技术上可以提前将 Java 编译为本机代码并运行生成的二进制文件.也可以直接解释 Java 代码.

It is technically possible to compile Java down to native code ahead-of-time and run the resulting binary. It is also possible to interpret the Java code directly.

总结一下,根据执行环境,字节码可以是:

To summarize, depending on the execution environment, bytecode can be:

  • 提前编译并作为本机代码执行(类似于大多数 C++ 编译器)
  • 及时编译并执行
  • 解释
  • 由支持的处理器直接执行(字节码是某些 CPU 的本机指令集)

这篇关于Java 是编译型还是解释型编程语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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