How exactly does the Java interpreter or any interpreter work?

I have been figuring out the exact working of an interpreter, have googled around and have come up with some conclusion, just wanted it to be rectified by someone who can give me a better understanding of the working of interpreter.

So what i have understood is:

  1. An interpreter is a software program that converts code from high level language to machine format.
  2. speaking specifically about java interpreter, it gets code in binary format (which is earlier translated by java compiler from source code to bytecode).
  3. now platform for a java interpreter is the JVM, in which it runs, so basically it is going to produce code which can be run by JVM.
  4. so it takes the bytecode produces intermediate code and the target machine code and gives it to JVM.
  5. JVM in turns executes that code on the OS platform in which JVM is implemented or being run.

Now i am still not clear with the sub process that happens in between i.e.

  1. interpreter produces intermediate code.
  2. interpreted code is then optimized.
  3. then target code is generated
  4. and finally executed.

Some more questions:

  • so is the interpreter alone responsible for generating target code ? and executing it ?
  • and does executing means it gets executed in JVM or in the underlying OS ?

Leave a Comment

tech