Is the JVM a compiler or interpreter?

I have a very simple question about the JVM: is it a compiler or interpreter?

If this is an interpreter, then what about the JIT compiler that exists inside the JVM?
If not, what is a JVM? (I do not want the basic jVM definition of converting byte code to machine code, etc.)

+74
java jvm
Oct 06 2018-11-11T00:
source share
8 answers

First, let's have a clear idea of ​​the following members

Javac is a Java compiler. Composes Java code in Bytecode

JVM - Java Virtual Machine - Runs / interprets / translates Bytecode into native machine code

JIT is a Just In Time compiler. Compiles a given sequence of byte code instructions for machine code at run time before executing it initially. The main goal is to make a big performance optimization.

So, let's find the answers to your questions.

1) JVM: is it a compiler or an interpreter? - Ans: Interpreter

2) what about JIT compiler that exist inside the JVM? - Ans: If you read this answer in full, you probably know it now

3) what exactly is the JVM? - Ans:

  • JVM is a virtual platform that resides in your RAM.
  • Its class loader component loads the .class file into RAM
  • The Verifier bytecode component in the JVM checks for any access restriction violations in your code. (This is one of the main reasons for Java security)
  • The Execution Engine then converts the Bytecode into executable machine code.

Hope this helps you.

+140
Feb 05 '13 at 13:26
source share

This is a little, but not in the traditional sense.

Modern JVMs take bytecode and compile it into native code when necessary. "JIT" in this context means "just in time." It acts as an interpreter from the outside, but in fact, behind the scenes, it compiles into machine code.

JVM should not be confused with a Java compiler that compiles source code into bytecode. Therefore, it is impractical to consider it as a “compiler”, and to know that in the background it performs some compilation.

+30
Oct 06 2018-11-11T00:
source share

As @delnan is no longer indicated in the comments section, this is neither.

JVM is an abstract Java bytecode machine.

JVM has several implementations:

... and many others .

Most of the other answers when it comes to JVMs relate either to HotSpot or to some combination of the above approaches to JVM implementation.

+5
Aug 04 '17 at 21:07 on
source share

It is both. It starts by interpreting the bytecode and can (if it decides it's worth it), then compile this bytecode to your own machine code.

+4
Oct 06 2018-11-11T00:
source share

It is both. It can interpret bytecode and compile it into native code.

+4
06 Oct 2018-11-11T00:
source share

As others have said, this is both! If you want to convey it in good detail than you can see: This is an IBM description

+1
Feb 15 '12 at 13:29
source share

A Java virtual machine is software that runs on a computer and installs on any computer that interprets .JVM class files creates an environment on the computer. The JVM creates an interpreter environment for the bytecode. JVA Interprets the bytecode and generates a machine according to the machine code. The JVM is an abstract machine that provides a runtime environment in which the bytecode can be a JVM, plays an important role in creating java portable.it provides a level of abstraction between the compiled Java program and the hardware platform and operating system. HOW TO WORK JAVA PROGRAM. PROGRAM↔COMPILED --- BYTECODE --- JVM - INTERPRETER ---- MACHINE CODE When the JVM program is compiled. it generates a bytecode, and bytecode is the class files that it is independent of, and after creating the bytecode, the JVM interprets the bytecode and generates the machine code. teeztaree

0
Jun 16 '19 at 7:12
source share

JVMs have both a compiler and an interpreter. Because the compiler compiles the code and generates bytecode. After that, the interpreter converts the bytecode into machine-friendly code.

Example. Write and compile the program, and it works on Windows. Take the .class file to another OS (Unix), and it will be launched due to an interpreter that converts the bytecode into machine-friendly code.

-5
May 01 '12 at 7:49 AM
source share



All Articles