In which language are the Java compiler and JVM written?

JavaJvmJavac

Java Problem Overview


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

Java Solutions


Solution 1 - Java

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 Smalltalk

  • The Java libraries (java.lang, java.util etc, often referred to as the Java API) are themselves written in Java, although methods marked as native will have been written in C or C++.

  • I believe that the Java compiler provided by Sun is also written in Java. (Although again, there are multiple compilers out there)

Solution 2 - Java

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.

Solution 3 - Java

From Java Docs

> The compiler is written in Java and the runtime is written in ANSI C

Solution 4 - Java

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/

Solution 5 - Java

In principle almost anything, usually C

Solution 6 - Java

This link should answer your question

It seems the compiler is now written in Java, but the runtime is written in ANSI C

Solution 7 - Java

  • 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/)

Solution 8 - Java

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."

Solution 9 - Java

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRahul GargView Question on Stackoverflow
Solution 1 - Javaoxbow_lakesView Answer on Stackoverflow
Solution 2 - JavashrinathView Answer on Stackoverflow
Solution 3 - JavaSevView Answer on Stackoverflow
Solution 4 - JavaUrbenLegendView Answer on Stackoverflow
Solution 5 - JavadjnaView Answer on Stackoverflow
Solution 6 - JavamicmooView Answer on Stackoverflow
Solution 7 - JavaTrishant SaxenaView Answer on Stackoverflow
Solution 8 - JavaSam HarwellView Answer on Stackoverflow
Solution 9 - JavaMichael FoukarakisView Answer on Stackoverflow