1

Possible Duplicate:
In which language is the Java compiler, JVM and Java written?

I am just curious. Does Java run on C or can it be installed directly onto the hardware? Does it directly convert the java bytecode to machine code or does it use C somewhere?

Community
  • 1
  • 1
imgr8
  • 501
  • 4
  • 11
  • 25
  • Java is based on C .. i think java runs on its own virtual machine and it convert to bytecode .. – Sudantha May 01 '11 at 05:42
  • 1
    I don't think, that the question is a duplicate of the linked one. The other question asks about the language Java is implemented in, this (if I get it right), if Java-programs run directly on the hardware or need an interpreter/JIT (written most likely in C) to execute. To this question the answer is: most Java-implementations need an interpreter/JIT (part of the JVM), but as said by Zan Lyx, some hardware can execute Java directly. – Mnementh May 01 '11 at 05:58
  • You could try downloading the source from OpenJDK to see how this reference implementation works. – Peter Lawrey May 01 '11 at 07:32

2 Answers2

1

The JVM (Java Virtual Machine) may be an interpreter or a JIT (Just In Time) compiler or both. If it is a compiler then it is writing machine code directly. It does not write C code first.

The JVM might be written in C or C++ or in Java. It could be written in almost any language and it would still be a JVM.

There have been some kinds of hardware made that do run Java directly, like smartcards.

Zan Lynx
  • 53,022
  • 10
  • 79
  • 131
-2

Java runs on Java.

The JVM is written in Java and it converts bytecode to machine language. The class loaders, garbage collectors, etc are also written in Java and you can override them with your own Java versions as well. There may be a few bits of C to bootstrap the whole thing on a particular OS (like load the executable), but no, C does not play an important part.

Adam
  • 16,808
  • 7
  • 52
  • 98
  • The JVM **interprets** bytecode. The JIT compiler (when invoked) actually converts bytecode into machine language. – David Titarenco May 01 '11 at 05:45
  • Sun JAVA is most likely written in C or C++ – Phil Oct 23 '11 at 11:59
  • @Phil, "most likely" is a very iffy phrase. Sun's HotSpot JVM is mostly C/C++, but the OP asked about "Java" not "Sun Java". There are quite a few JVMs written in Java, for example Jikes JVM. – Adam Oct 24 '11 at 06:31