Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between a Java interpreter and JVM

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 a Java interpreter and JVM?

like image 680
Happy Mittal Avatar asked Aug 09 '10 17:08

Happy Mittal


People also ask

Is interpreter and JVM same?

JVM have both compiler and interpreter. Because the compiler compiles the code and generates bytecode. After that the interpreter converts bytecode to machine understandable code. Example: Write and compile a program and it runs on Windows.

Why Java interpreter is known as JVM?

What is Java Virtual Machine (JVM)? Java Virtual Machine, or JVM, loads, verifies and executes Java bytecode. It is known as the interpreter or the core of Java programming language because it executes Java programming.

What is difference between Java compiler and interpreter?

The interpreter scans the program line by line and translates it into machine code whereas the compiler scans the entire program first and then translates it into machine code. The interpreter shows one error at a time whereas the compiler shows all errors and warnings at the same time.

What are the differences between JVM and DVM?

JVM will work based on byte code and the DVM will work based on optimized bytecode, it is optimised for mobile platforms because mobile devices have less memory, low process and low power that's why it is using the linux kernal.


2 Answers

Yes, there is a 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 a JVM.

Check:

  • Java Virtual Machine

  • Java SE HotSpot at a Glance

like image 135
YoK Avatar answered Sep 21 '22 07:09

YoK


Simply put, a JVM interprets bytecode and a Java interpreter interprets Java. They are different because bytecode and Java are different languages.

Bytecode is 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.

Java is 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 is usually "interpreted" by translating the Java program into a bytecode program first. Then the Java Virtual Machine (JVM) runs the bytecode.

But you could interpret any language this way. The JVM could interpret other languages if you translated them into the right bytecode.

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.

like image 34
L Fields Avatar answered Sep 20 '22 07:09

L Fields