views:

235

answers:

4

I have heard people saying "a JVM is necessarily a java interpreter but a java interpreter is not necessarily a JVM". Is that true?
I mean is there a difference between java interpreter and JVM?

A: 

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.

Justin Ethier
I think that's incorrect. As far as I know, a Java interpreter is no more bound to Java than the JVM is. The actual Java-language code is traditionally compiled, after that it's byte code, which is interpreted and/or otherwise executed in/by the JVM.
Carl Smotricz
A: 

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.

Kent Murra
That's not strictly true. The JVM will run the code in interpreted mode for a while before deciding which bits to compile. So, yes, the JVM is a Java Bytecode (class file) interpreter.
dty
@Danny: There is no "the" JVM. There are multiple JVM implementations from different vendors on different platforms that don't necessarily all work the same.
Michael Borgwardt
Hey, I wasn't the first person to mention "the JVM"! Depends what you mean by "work the same". They all execute bytecode, and provide a mapping to underlying OS functions like threads, files, etc. Some of them don't have JIT (which would add to my argument that saying "the JVM is a JIT compiler" is inaccurate), some of them have different thread models (vis JRockit's old m:n model), some have different GC algorithms, but they all essentially do the same thing. But it is NOT accurate to say "the JVM is a JIT compiler".
dty
+3  A: 

Yes there is difference.

Java virtual machine:

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 interpreter:

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

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

check:

http://en.wikipedia.org/wiki/Java_Virtual_Machine

http://www.oracle.com/technetwork/java/javase/tech/index-jsp-136373.html

YoK
A: 

As I understand it...

A Java interpreter executes lines of byte code as commands to be executed. The byte code is executed.

The JVM takes the byte code and generates machine code. The byte code is compiled to machine code, and the machine code is executed.

baultista
**A** JVM need not necessarily include a JIT compiler. Some of those that do include a JIT compiler have an option to disable it. `-Xint` on mine.
JeremyP