Java 解释器和 JVM 之间的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3442387/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between a Java interpreter and JVM
提问by Happy Mittal
I have heard people saying "a JVM is necessarily a Java interpreter but a Java interpreter is not necessarily a JVM". Is that true?
我听人说“JVM 一定是 Java 解释器,但 Java 解释器不一定是 JVM”。真的吗?
I mean is there a difference between a Java interpreter and JVM?
我的意思是 Java 解释器和 JVM 之间有区别吗?
采纳答案by YoK
Yes, there is a difference.
是,有一点不同。
Java virtual machine:
Java虚拟机:
A software "execution engine" that safely and compatibly executes the byte codes in Java class files on a microprocessor (whether in a computer or in another electronic device).
一种软件“执行引擎”,可以在微处理器(无论是在计算机中还是在其他电子设备中)安全且兼容地执行 Java 类文件中的字节码。
Java interpreter:
Java解释器:
A module that alternately decodes and executes every statement in some body of code. The Java interpreter decodes and executes bytecode for the Java virtual machine.
交替解码和执行某些代码体中的每个语句的模块。Java 解释器为 Java 虚拟机解码并执行字节码。
The Java interpreter is actually a part of JVM. Virtual machine is not just executing the bytecodes, it has lot of tasks to do. That full-fledged environment is referred to as a JVM.
Java 解释器实际上是 JVM 的一部分。虚拟机不只是执行字节码,它还有很多任务要做。这种成熟的环境被称为 JVM。
Check:
查看:
回答by Justin Ethier
For one, code from (theoretically) any language can be compiled down to JVM bytecodes to allow execution within that environment. A Java interpreter is only able to run Java code.
一方面,来自(理论上)任何语言的代码都可以编译成 JVM 字节码,以允许在该环境中执行。Java 解释器只能运行 Java 代码。
回答by Kent Murra
Calling a JVM a Java interpreter is incorrect. The JVM is a JIT compiler that compiles and runs byte-code. Other languages can be compiled into byte-code targeted for the JVM. Wikipedia article detailing such languages.
将 JVM 称为 Java 解释器是不正确的。JVM 是一个 JIT 编译器,用于编译和运行字节码。其他语言可以编译为针对 JVM 的字节码。 详细介绍此类语言的维基百科文章。
回答by ravibhagw
As I understand it...
据我了解...
A Java interpreter executes lines of byte code as commands to be executed. The byte code is executed.
Java 解释器将字节码行作为要执行的命令执行。字节码被执行。
The JVM takes the byte code and generates machine code. The byte code is compiled to machine code, and the machine code is executed.
JVM 获取字节码并生成机器码。字节码被编译成机器码,机器码被执行。
回答by SARUPPYA SATPATHI
java virtual machine is a virtual processor and a java interpreter is javatool.thanks
java虚拟机是虚拟处理器,java解释器是java工具。谢谢
回答by L Fields
Simply put, a JVM interprets bytecode and a Java interpreter interprets Java. They are different because bytecode and Java are different languages.
简单地说,JVM 解释字节码,Java 解释器解释 Java。它们是不同的,因为字节码和 Java 是不同的语言。
Bytecodeis a low-level language, like machine code. The bytecode is meant to be run by a program called a bytecode interpreter, also called a virtual machine. The purpose of bytecode is to be easy to interpret.
字节码是一种低级语言,就像机器码一样。字节码旨在由称为字节码解释器(也称为虚拟机)的程序运行。字节码的目的是易于解释。
Javais a higher-level language, like C or Python. These languages can be interpreted too: you just write a program that can run their code. It doesn't have to involve bytecode. It's just that higher-level languages are harder to interpret directly.
Java是一种高级语言,类似于 C 或 Python。这些语言也可以解释:您只需编写一个可以运行其代码的程序。它不必涉及字节码。只是高级语言更难直接解释。
Java is usually "interpreted" by translating the Java program into a bytecode program first. Then the Java Virtual Machine(JVM) runs the bytecode.
Java 通常通过首先将 Java 程序翻译成字节码程序来“解释”。然后Java 虚拟机(JVM) 运行字节码。
But you could interpret any language this way. The JVM could interpret other languages if you translated them into the right bytecode.
但是你可以用这种方式解释任何语言。如果您将其他语言翻译成正确的字节码,JVM 可以解释它们。
You can also interpret a programming language directly, without any bytecode. Some BASIC interpreters just look for BASIC instructions in the sourcecode and execute them. They don't make make a new program in a different language first. If you did the same thing for Java, it would be a Java interpreter but not a JVM.
您还可以直接解释编程语言,而无需任何字节码。一些 BASIC 解释器只是在源代码中寻找 BASIC 指令并执行它们。他们不会先用不同的语言制作一个新程序。如果你对 Java 做同样的事情,它会是一个 Java 解释器,而不是一个 JVM。