4

In the answer Platform independence in Java ByteCode, it is said that Java Compiler is same across all the platforms. I do understand that.

My question is that why Java compiler is distributed as an .exe file (for windows) then? Why not as JVM bytecode to be executed by JRE. This way there wont be different version of the compiler for different platforms. I don't know if it is even possible?

Community
  • 1
  • 1
user_3068807
  • 397
  • 3
  • 13

1 Answers1

8

javac.exe (on my installation, JDK 1.8 on Windows x64) is about 15K in size. This isn't the full compiler. The compiler itself really is written in Java, and javac.exe is just a launcher, effectively. This is true of many of the tools that come with Java - it would be a pain to have to run something like:

java -cp path/to/javac.jar java.tools.Javac -cp path/to/your/libraries Foo.java

for example.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • So this means that this launcher (javac.exe) "invokes" the Java compiler (that is bytecode just like all other java programs that are distributed) and "makes" JVM to run it. And the source files are given as input to this process. am i right? – user_3068807 Apr 02 '14 at 10:36