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.