I have downloaded the javac
source code from here and I found that the it itself is written in java language. However, I was expecting that it was written in c/c++.
Anyway, how does this java compiler source code written in java compiled when there was no java compiler?
From here :
The very first Java compiler developed by Sun Microsystems was written in C using some libraries from C++
Besides the compiled bytecode is interpreted by JVM which is written in c++. From here:
The Oracle JVM, named HotSpot, is written in the C++ language
A compiler that is written in the language it compiles is called a bootstrapping compiler.
The way they are made is kind of a head trip, but just think: when the original language was written, there was no java, and so they had to create the compiler in another language, which, actually, was written in C/C++. Check it out, here: In which language are the Java compiler and JVM written?
Also, the way that Java works, I don't know if you know, is that the compiler (javac
) actually doesn't generate machine code files, it creates bytecode files that are then interpreted by the JVM.
You usually need an existing Java compiler (and runtime) to bootstrap. However, there are other Java compilers available, like Jikes, that are written in C++. Whether you can use Jikes to bootstrap OpenJDK is a different story, but in theory, it should be possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With