Is Java compiled or interpreted? - Both

Depending on the execution environment, bytecode can be:
  • compiled (to the native instructions understood by the CPU) ahead of time and executed as native code (similar to C++)
  • compiled just-in-time and executed
  • interpreted
  • directly executed by a supported processor (bytecode is the native instruction set of some CPUs)
Some HotSpot JVMs start out by interpreting bytecodes, and only compiles them to native code after they have figured out what is worth compiling, and gathered some stats on how the code is being run.

No comments:

Post a Comment