Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Java compiler as distributed as executable and not as JVM bytecode?

Tags:

java

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?

like image 565
user_3068807 Avatar asked Feb 14 '23 08:02

user_3068807


1 Answers

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.

like image 133
Jon Skeet Avatar answered Apr 30 '23 06:04

Jon Skeet