3

I was reading some posts about JVM and found some confusing information.

for example here: http://www.cs.cmu.edu/~jcarroll/15-100-s05/supps/basics/history.html

it says "In fact, the Java compiler is often called the JVM compiler (for Java Virtual Machine)".

Further more, I could not find the exact answer if the java compiler is part of the JVM or not. I know that the the JVM is an interpreter, but i read that it does some compiling too. Also, as far as i know, JVM is part of JRE; javac part of JDK and JRE part of JDK.

So is javac part of JVM? I think it's not, but not sure though.

Alex Salajan
  • 85
  • 1
  • 8

4 Answers4

7

That is mainly about terminology, wording.

There is the java binary executable (and some subtle variations of it, such as javaw). That is the java virtual machine! You invoke that binary, and a JVM gets launched (see here for all the glory details).

In essence:

  • a JRE contains a JVM (the aforementioned java binary)
  • a JDK contains a JVM, and the tools and libraries to develop for Java (so: java and javac)

Finally: using the term "JVM compiler" for javac is wrong and misleading. javac turns java source code into java bytecode, which then can be executed by the JVM. But just to be really complete here: most JVM implementations also contain a "just in time" compiler component to transform byte code into native machine code to improve performance.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • 1
    To be more precise, `java` executable is not a Java virtual machine. And JRE includes [a lot more things](https://stackoverflow.com/a/26025656/3448419) besides JVM. But the main point is true - `javac` is not a part of JVM. – apangin Dec 03 '18 at 10:43
  • @apangin Good points. I reworked my answer, and send the due votes their way ;-) – GhostCat Dec 03 '18 at 11:39
  • 1
    @apangin the JIT compiler is part of the JVM however. ;) – Peter Lawrey Dec 03 '18 at 14:52
  • @PeterLawrey Well. I have neither 10 questions with 600+ votes, nor 600+ questions with 10. So, that comment wasn't exactly *comforting* me. On the other hand, I am glad that I didn't search for your questions with 9 votes then ;-) – GhostCat Dec 03 '18 at 19:18
  • @GhostCat I take comfort in the fact I *am not* on the top 50 page overall ;) – Peter Lawrey Dec 03 '18 at 19:46
  • 1
    @PeterLawrey I didn't try to comfort you, if that helps. And at least, you are not one of the few double-legendary holders on SE, so theoretically, if I pick another community, and start working really hard, I could do that first ;-) ( https://meta.stackexchange.com/questions/299754/which-user-is-the-most-legendary-across-the-whole-network-of-sites ) – GhostCat Dec 03 '18 at 19:52
5

Meanwhile, I found this image which illustrates exactly where the java compiler is situated and that it is part of JDK but not part of JVM or JRE:

Diagram

valiano
  • 16,433
  • 7
  • 64
  • 79
Alex Salajan
  • 85
  • 1
  • 8
2

Some JVMs will perform JIT (Just in Time )compilations to optimize java byte code. In addition it is possible to do this in code

JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

however traditionally the compiler was part of the JDK and applications were distributed with the JRE which does not contain a javac

newbie
  • 558
  • 7
  • 12
0

Though "Java compiler is often called the JVM compiler (for Java Virtual Machine)" might be misleading, it still holds because javac essentially converts Java source code to byte code for JVM to be run which then interprets it to machine readable instruction depending on the platform

As javac is a compiler for JVM, it is not a part of it.

But as Ghostcat states referring javac as JVM compiler is misleading as JVM has got its own Just-In-Time Compilation implementation

Hope this adds to the earlier answers

Aarish Ramesh
  • 6,745
  • 15
  • 60
  • 105