Bytecode is an intermediate code between source code (what you write) and machine code (what the CPU runs). It’s designed to be run by a virtual machine, not directly by hardware.
So you install the virtual machine which is carefully made for your operating system and thus the same code runs everywhere.
Examples of Bytecode Usage:
| Language | Bytecode Format | Virtual Machine |
|---|---|---|
| Java | .class files (JVM bytecode) | JVM (Java Virtual Machine) |
| Kotlin | JVM bytecode | JVM |
| Scala | JVM bytecode | JVM |
| C# | CIL (Common Intermediate Language) | CLR (.NET Common Language Runtime) |
| Python | .pyc files (Python bytecode) | Python Virtual Machine |
| Lua | Lua bytecode | Lua Virtual Machine |
Why Use Bytecode?
- Portability: Write once, run anywhere (as long as the VM exists).
- Security: VMs can sandbox execution.
- Optimisation: JIT (Just-In-Time) compilation can optimise hot code paths at runtime.
- Language Interoperability: Different languages targeting the same VM can work together.
Summary:
**Bytecode is a general approach used by many modern languages to run code efficiently and portably via virtual machines.