How do programming languages turn human-written instructions into actions performed by a computer?
Programming languages allow humans to write instructions in a readable format, but computers can only directly execute machine language—a numerical form consisting of binary bit patterns. To bridge this gap, human-written code must be processed into machine-executable instructions through one of two primary methods:12
- Compilation: A compiler translates the entire source code into machine code before execution, saving it for later use. This process is generally more efficient for frequently run programs.13
- Interpretation: An interpreter examines and executes the program one instruction at a time, calling on the necessary machine operations as it goes.1
Some languages use an intermediate approach, such as Java, which compiles code into an intermediate language (bytecode) that is then executed by a virtual machine. Once the instructions are in machine language, the computer's central processing unit (CPU) carries them out using a "fetch-decode-execute" cycle, where it retrieves instructions from memory, decodes their meaning, and performs the required arithmetic or logic operations via its arithmetic-logic unit.12