Bytecode

Bytecode is an ‘intermediate representation’ of code.

Instead of directly translating high-level code (like Python or Java) into machine code that the CPU can execute, the high-level code is first compiled into bytecode.

This bytecode is fairly low-level (it mostly consists of simple instructions that a virtual machine can understand), but it’s not specific to any particular hardware architecture.

How bytecode compilers+interpreters work

When you run a program written in a language that uses bytecode (like Java or Python), the following steps usually happen:

  1. The high-level code is compiled into bytecode by a compiler.
  2. The bytecode is then executed by a virtual machine (VM)

So you can see that actually, bytecode languages are kind of a hybrid between compiled and interpreted languages!

Advantages of bytecode

Bytecode can be used if the code needs to run on multiple platforms, so needs to be platform-independent.

Disadvantages of bytecode

Examples of bytecode languages