Alex Rivera | Logout

How exactly does java compilation take place?

Asked 2010-08-04T15:12:22.530
67

Confused by java compilation process

OK i know this: We write java source code, the compiler which is platform independent translates it into bytecode, then the jvm which is platform dependent translates it into machine code.

So from start, we write java source code. The compiler javac.exe is a .exe file. What exactly is this .exe file? Isn't the java compiler written in java, then how come there is .exe file which executes it? If the compiler code is written is java, then how come compiler code is executed at the compilation stage, since its the job of the jvm to execute java code. How can a language itself compile its own language code? It all seems like chicken and egg problem to me.

Now what exactly does the .class file contain? Is it a abstract syntax tree in text form, is it tabular information, what is it?

can anybody tell me clear and detailed way about how my java source code gets converted in machine code.

Edit
Report

2 Answers

3

The .class file contains bytecode which is sort of like very high-level Assembly. The compiler could very well be written in Java, but the JVM would have to be compiled to native code to avoid the chicken/egg problem. I believe it is written in C, as are the lower levels of the standard libraries. When the JVM runs, it performs just-in-time compilation to turn that bytecode into native instructions.

answered 2010-08-04T15:16:02.460
1

Windows doesn't know how to invoke Java programs before installing a Java runtime, and Sun chose to have native commands which collect arguments and then invoke the JVM instead of binding the jar-suffix to the Java engine.

answered 2010-08-04T15:39:32.507

Your Answer