views:

1981

answers:

8

Hi can you please let me know in which language the Java compiler, virtual machine (JVM) and java is written.

A: 

In principle almost anything, usually C

djna
+6  A: 

From Java Docs

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

Sev
Very 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
This 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
Well, since when has documentation been really up-to-date, especially after large changes? :)
Esko
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
+3  A: 

This link should answer your question

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

micmoo
+1  A: 

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

280Z28
+8  A: 

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)

oxbow_lakes
I think he means "java" the program that you use to start a JVM.
Stephen C
Actually, *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
+1  A: 

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.

Michael Foukarakis
+4  A: 

Should you wish to, you can download the sources for the OpenJDK from jdk.dev.java.net.

McDowell
A: 

Most OSes, JVMs are written in ISO C++. I doubt ANSI C is used, an entirely different language that is quite antiquated nowadays.

Mickey