• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java is interpreter

 
ramchander yshetti
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai,

please clear for me interpreted or JIT which one is first
when my program is first executed.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ajay Divakaran
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shrikanth Nekkanti
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mandar Khire
Ranch Hand
Posts: 569
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this links
JVM
Again JVM
 
Campbell Ritchie
Sheriff
Pie
Posts: 50189
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't resurrect a 1-year old thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic