What to compile and when is up the the JVM designer. Most modern JVMs have some algorithm to decide when it's worth compiling a chunk of code, perhaps when it's been executed a few times or maybe looks like it will be executed a lot. The "Just In Time" part means they don't go overboard compiling everything before they need it, though I suppose they could if they wanted to.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
java is a compiler as well as an interpreter. When you finish creating your .java file and invoke javac <classname>.java Your .java code is compiled and converted to bytecode and when you invoke java <classname> The java interpreter is called to convert your bytecode to machine code
Joined: Jan 29, 2003
The java interpreter is called to convert your bytecode to machine code
The interpreter / JVM may or may not do this entirely at its own pleasure. You can disable the JIT compiler at the command line, but I don't think you can tell it anything else.
I find what a real interpreter does hard to put into words. The interpreter part of the JVM carries out the bytecode instructions much the way a cook follows a recipe. It doesn't convert bytecode to anything. It looks at one bytecode instruction at a time, says "I know what that means!" and does it.
The compiler part of the JVM can generate machine code from bytecode if it wants to. I guess it builds a robot that can follow part of exactly one recipe very, very quickly.
When you save your file with .java extension and when you compile it using javac classname.java you will get classname.class file which contains byte understandable by JVM Interpreter is a module in JVM which converts bytecode into machine executable code.
Originally posted by Shrikanth kumar: Interpreter is a module in JVM which converts bytecode into machine executable code.
As Stan said, this is not quite correct. An interpreter doesn't so much produce executable code (that's a compiler's job), but perform the steps needed to execute the bytecode. The native code that is the equivalent of the bytecode is not generated in the process.