In which languages are the Java compiler (javac
), the virtual machine (JVM) and the java
starter written?

- 2,352
- 1
- 22
- 33

- 8,410
- 8
- 33
- 28
10 Answers
The precise phrasing of the question is slightly misleading: it is not "the JVM" or "the compiler" as there are multiple JVM vendors (jrockit is one, IBM another) and multiple compilers out there.
The Sun JVM is written in
C
, although this need not be the case - the JVM as it runs on your machine is a platform-dependent executable and hence could have been originally written in any language. For example, the original IBM JVM was written in SmalltalkThe Java libraries (
java.lang
,java.util
etc, often referred to as the Java API) are themselves written in Java, although methods marked asnative
will have been written inC
orC++
.I believe that the Java compiler provided by Sun is also written in Java. (Although again, there are multiple compilers out there)

- 133,303
- 56
- 317
- 449
-
I think he means "java" the program that you use to start a JVM. – Stephen C Aug 03 '09 at 07:44
-
1Actually, *one* library in Sun's JRE is written in NetRexx. (It's one of the arbitrary precision math libraries, either BigInteger, BigNum or BigDecimal. I forgot which one.) In theory, you could use any language to implement the JRE, as long as it can compile to a representation that a Java program can understand. – Jörg W Mittag Jan 26 '10 at 11:05
-
21Please provide a reference to the Sun JVM being written in C. – Mohamed Bana Apr 02 '11 at 19:03
-
@JörgWMittag: I think this is not the case anymore since quite some editions of the JDK (I think 1.4 or even already 1.3). Now BigInteger is written in Java (and BigDecimal simply uses BigInteger internally). – Paŭlo Ebermann Mar 03 '12 at 17:34
-
10The HotSpot JVM is written in C++ - http://www2.research.att.com/~bs/applications.html – devdimi Mar 19 '12 at 11:05
-
5@devdimi the link is broken and now resides at: http://www.stroustrup.com/applications.html – flup Jul 13 '13 at 11:25
-
Also, Java is Turing complete. So you can write a JVM in Java. But this is a purely academic exercise as it provides no benefit and only introduces complications. – cyotee doge Mar 01 '17 at 19:33
-
3Good luck with that, cyotee. What would your JVM run on? – oxbow_lakes Mar 03 '17 at 09:59
-
1@cyoteedoge GraalVM is more than a “purely academic exercise”. The advantages of using Java as implementation language are the same as for any other software (especially for *complex* software). – Holger Sep 08 '22 at 17:13
The very first Java compiler was developed by Sun Microsystems and was written in C using some libraries from C++. Today, the Java compiler is written in Java, while the JRE is written in C.
We can imagine how the Java compiler was written in Java like this:
The Java compiler is written as a Java program and then compiled with the Java compiler written in C(the first Java compiler). Thus we can use the newly compiled Java compiler(written in Java) to compile Java programs.
-
74
-
4fyi this process of "upgrading" to new compilers by compiling their code in more basic compilers is called "bootstrapping", as in "pulling yourself up by your bootstraps", which is where "booting" a machine comes from. Computerphile on YouTube has a good video about this and "T diagrams" – iono Oct 09 '19 at 06:42
-
4
-
-
2In theory, you dont' even need the bootstraping compiler. You can refer to the Java Language Specification and manually translate the Java Compiler code into bytecode(class file), hence bootstrapping. Though I only tried manually do that with a HelloWorld. – AwesomeHunter Dec 18 '20 at 14:37
-
2Just clarifying, the JVM cannot be written in Java because Java needs JVM to run so if JVM-version2 was written in Java, it would have to run on JVM-version1, thus it would be a VM running on a VM. – Aritro Shome Oct 08 '21 at 09:21
-
@AritroShome Nothing is stopping you from running a VM on a VM. Of course, practically it would be incredibly slow, but you can still do it if you want. (You can't run a VM on *itself*, at least not on the latest version of itself. You would eventually have to reach a point when the VM runs on a compiled language.) – R Z Oct 10 '21 at 12:47
-
I see when it came to the JVM, they couldn't stomach the slowness of Java. I'm surprised they transitioned to Java for the compiler. Large systems might have benefited from a C-coded compiler. – user904963 Dec 26 '21 at 03:16
-
The JVM cannot be sensibly written in java because it requires intimate knowledge of the underlying architecture to be effective. – alife Jul 29 '22 at 15:55
-
1@alife there is no contradiction between having “intimate knowledge of the underlying architecture” and being able to write Java code. Look at the GraalVM for an example of a JVM written in Java. – Holger Sep 08 '22 at 17:05
From Java Docs
The compiler is written in Java and the runtime is written in ANSI C
-
2Very first Java compiler developed by Sun Microsystems was written in C using some libraries from C++ http://en.wikipedia.org/wiki/Java_compiler – Rahul Garg Aug 03 '09 at 07:00
-
4This is really rather an old document (>10 years by the look of things). For example, it says *"Java bytecodes are translated on the fly to native machine instructions (interpreted) and not stored anywhere"* which has not been true for about 5 years! – oxbow_lakes Aug 03 '09 at 07:02
-
3Well, since when has documentation been really up-to-date, especially after large changes? :) – Esko Aug 03 '09 at 09:41
-
Well - the answer isn't really correct; the Sun JVM is written in C, and the Sun java compiler is written in Java. The first IBM JVM was written in Smalltalk. – oxbow_lakes Aug 03 '09 at 10:36
-
10
-
3@user4903 Not necessarily. You can translate Java code into bytecodes by hand if you would like to. – AwesomeHunter Dec 18 '20 at 14:38
-
2@AwesomeHunter In fact, the first programming languages must have been coded in 1s and 0s by hand. Hard to imagine with how far we've come. – user904963 Dec 26 '21 at 03:23
Actually the Oracle JVM is written in C++, not C.
Take a look at the HotSpot JVM code here: http://openjdk.java.net/groups/hotspot/

- 341
- 4
- 6
- When Java was introduced by Sun Microsystem, the java compiler was written in C using some libraries from C++.
- As there is a concept in Compiler Design called Bootstrapping, Mostly it is used in Compiler Development, Bootstrapping is the process of writing a compiler(Or Assembler) In the source programming language which it is intended to compile. It is used to produce a self-hosting compiler. The development of compilers for new Programming languages first developed in an existing language and then rewritten in the new language and compiled by itself. That's why today, Java compiler is written in Java itself.
- Java Virtual Machine: Java virtual machine is an abstract machine. Like a real computing machine, It has an instruction set and manipulates various memory areas of runtime. Usually, JVM interprets the byte code into Machine code.
(For More Information You can check this link: https://docs.oracle.com/javase/specs/jvms/se7/html/)

- 388
- 3
- 14
-
-
-
1The JVM might be a virtual machine that executes Java bytecode, but somewhere, it itself has to be coded in something. – user904963 Dec 26 '21 at 03:14
-
Yes that's why I mentioned the concept of Bootstratpping here, you can refer the article to understand the concept https://www.geeksforgeeks.org/bootstrapping-in-compiler-design/ – Trishant Saxena Jul 27 '23 at 20:46
Jikes RVM, a self-hosting JVM used extensively for research purposes is written in Java. It's not the one people run on their desktops, but it's way up there on my list of "now let's show off the general power of the language."

- 97,721
- 20
- 209
- 280
-
1It's turtles *all the way down*? Does it have some kind of microkernel? If so, what language is that written in? – Raedwald Jul 21 '13 at 23:19
Supposing you're talking about the Hotspot JVM, which is iirc provided by Sun, it is written in C++. For more info on the various virtual machines for Java, you can check this link. javac, like most Java compilers, is written in Java.

- 39,737
- 6
- 87
- 123
As always popular languages written in - C, C++.

- 39
- 1
- 6
-
Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 10 '22 at 12:51
-
This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/33126091) – Trooper Z Nov 13 '22 at 03:39