Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In which language are the Java compiler and JVM written?

Tags:

java

jvm

javac

People also ask

What language is the JVM coded in?

Some of these languages are interpreted by a Java program, and some are compiled to Java bytecode and JIT-compiled during execution as regular Java programs to improve performance. The JVM was initially designed to support only the programming language Java.

Is the JVM written in Java?

GraalVM has released major version 21.0 with a new component, Java on Truffle, that provides a Java Virtual Machine (JVM) implementation written in Java. GraalVM is itself a polyglot virtual machine that provides a shared runtime to execute applications written in multiple languages like Java, Python, and JavaScript.

What is compiler and JVM in Java?

Javac is Java Compiler -- Compiles your Java code into Bytecode. JVM is Java Virtual Machine -- Runs/ Interprets/ translates Bytecode into Native Machine Code. JIT is Just In Time Compiler -- Compiles the given bytecode instruction sequence to machine code at runtime before executing it natively.

Is JVM implemented in C++?

Java code needs the JVM to execute. However C++ is compiled into machine code, so it is executed more or less by the hardware. Thus you can see that to write the JVM using java, would mean that you need a JVM to run the JVM...


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)


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.


From Java Docs

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


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/


In principle almost anything, usually C