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

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

问题描述

在过去,我已经使用C ++作为一种编程语言。我知道用C ++编写的代码经过编译过程,直到它成为目标代码机器代码。



我想知道Java在这方面的工作原理。用户编写的Java代码如何由计算机运行?

解决方案

Java实现通常使用两步编译过程。 Java源代码由Java编译器向下编译为字节码。字节码由Java虚拟机(JVM)执行。现代JVM使用一种名为即时(JIT)编译的技术



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

在技术上可以将Java编译成本地代码并运行生成的二进制文件。也可以直接解释Java代码。



总之,根据执行环境,字节码可以是:




  • 提前编译并作为本机代码执行(类似于大多数C ++编译器)

  • 按时编译并执行

  • 解释

  • 由支持的处理器直接执行(字节码是某些CPU的本地指令集)


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".

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

解决方案

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.

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.)

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:

  • compiled ahead of time and executed as native code (similar to most C++ compilers)
  • compiled just-in-time and executed
  • interpreted
  • directly executed by a supported processor (bytecode is the native instruction set of some CPUs)

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

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