Bytecode
Байт-код
A set of instructions produced by compiling a program for a runtime, rather than directly for a CPU. The runtime can interpret those instructions or translate them into native machine code.
What bytecode is
When you build a Java program, javac normally produces .class files, not instructions for an Intel or ARM processor. The methods in those files are encoded using the instruction set of the Java Virtual Machine (JVM). That encoded instruction stream is bytecode. It sits between the source code you write and the native machine code a CPU can execute directly.
What runs it?
In an interpreter, a loop reads bytecode instructions and carries out their operations. The CPU is running the interpreter's own machine code, not the bytecode itself. With just-in-time (JIT) compilation, the runtime translates bytecode into native instructions while the program is running. These approaches can coexist: HotSpot, a JVM implementation, can interpret a method at first and compile it once it has run often enough. The compiled method can then run without interpreting each bytecode instruction on every call.
Reading a real example
Put static int add(int a, int b) { return a + b; } in a Java class named Example, compile it, and run javap -c Example. The listing for add contains:
0: iload_0
1: iload_1
2: iadd
3: ireturn
The first two instructions put the arguments on the method's operand stack. iadd takes both values off the stack and puts their sum back. ireturn returns that sum to the caller. The numbers on the left are byte offsets within the method. The names on the right are mnemonics that javap prints for people; the class file stores binary instructions, not those strings.
Where it shows up
Java and Kotlin/JVM target the same bytecode format, so their compiled classes can run on the same JVM. CPython also compiles source to bytecode. When it imports a module, it may cache that bytecode in a .pyc file so a later import can reuse it. This is why calling Python “interpreted” does not mean there is no compilation step. Unlike JVM bytecode, CPython bytecode is an implementation detail that can change between releases.
What to clarify in an interview
If asked why bytecode helps with portability, explain that the runtime is built for the host platform, while the bytecode targets the runtime's instruction set. The same .class file can run on x86-64 and ARM without recompilation, provided each machine has a JVM that supports the class-file version and the application can find its dependencies. Also avoid reading too much into the name: a bytecode instruction need not be exactly one byte long. It can include operands, such as an index identifying a local variable.