为什么同时编译和解释Java [英] Why is java both compiled and interpreted

查看:107
本文介绍了为什么同时编译和解释Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
Java是编译语言还是解释性编程语言?

为什么Java既是编译语言又是解释语言?

Why is Java both compiled and interpreted language?

我们首先使用javac(compiling)编译Java程序,然后使用java(解释)运行该程序.这样做有什么好处?

We first compiles the java program using javac(compiling) and the run the program using java(interpreting). What is the advantage of that?

此外,JIT角色在哪里出现?

Also, where does JIT role come into the picture?

推荐答案

Java编译器通常将源代码编译成一种中间语言,一般表示为字节码".那本身不是您的本机硬件的机器代码,但从某种意义上说,它是Java虚拟机的机器"代码.

The Java compiler typically compiles source code into an intermediate language, expressed generically as "byte code". That itself is not machine code for your native hardware, but in a sense it is "machine" code for the Java virtual machine.

这种分离的好处是(理论上)您可以在许多不同的平台上实现VM,但是所有平台都将能够运行相同编译的Java字节码.

The benefit of this separation is that (in theory) you can implement a VM on many different platforms, but all of them will be able to run the same compiled Java byte code.

即时编译器是假设的VM的一部分,并且实际上在需要时将字节代码的位动态地转换为真实的本地机器代码.这是因为观察到,纯粹在VM中运行Java程序比等效的本机代码慢得多.与本地编译的代码相比,JIT编译使Java VM在性能方面具有竞争力.

A just-in-time compiler is part of a hypothetical VM, and actually translates bits of byte code dynamically into real, native machine code, as and when needed. This grew out of the observation that running a Java program purely in a VM was a lot slower than equivalent native code. JIT compilation has made the Java VM competitive in terms of performance when compared to natively compiled code.

这篇关于为什么同时编译和解释Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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