What are bytecodes and how does the JVM handle them

前端 未结 6 1571
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 04:33

I heard many times that Java implemments JIT(just-in-time) compilation, and its bytecodes which are portable across platforms get \"interpreted\" by JVM. However, I don\'t r

6条回答
  •  甜味超标
    2020-11-29 05:25

    Bytecode is a step between your source code and actual machine code. The JVM is what takes the bytecode and translates it into machine code.

    JIT refers to the fact that the JVM does this translation on the fly when the program is executed, rather than in a single step (like in a traditionally compiled/linked language like C or C++)

    The point of bytecode is that you get better performance than a strictly interpreted language (like PHP for example) because the bytecode is already partially compiled and optimized. Also, since the bytecode doesn't need to be directly interpreted by the CPU, it doesn't need to be tied to any specific CPU architecture which makes it more portable.

    The disadvantage of course is that it will generally be a bit slower than a natively compiled application since the JVM still has to do some work in translating the bytecode to machine code.

提交回复
热议问题