The Plain Picture#
The cook (the CPU) only speaks one very primitive language: "take from shelf 7, add, jump to step 12". You want to write something like "if the score is above 150, show a gold star". Somebody has to translate.
There are two ways to get a book translated:
Translate the whole book in advance — slow at first, but then anyone can read the finished translation quickly. This is compiling.
Hire an interpreter who translates sentence by sentence while you listen — you can start immediately, but every reading is slower because translation happens live. This is interpreting.
The Real Names#
Source code — the human-readable program you write (
if (score > 150) ...).Compiler — a program that translates source code into machine code ahead of time. Languages like C, C++, Go and Rust are compiled this way. The result is an executable file.
Interpreter — a program that reads your source code and carries it out step by step while running. Python is the famous example (with a twist, below).
Bytecode — a middle ground: code is compiled to a simple, portable intermediate language that isn't any real CPU's machine code. A program called a virtual machine then runs it.
Under the Hood#
How Java runs (you'll use it for DSA)#
Score.java javac (compiler) Score.class
(source code) ─────────────────────▶ (bytecode, same on every OS)
│
▼
JVM (Java Virtual Machine)
┌─────────────────────────────┐
│ starts by interpreting the │
│ bytecode; spots "hot" code │
│ that runs often and compiles│
│ it to real machine code │
│ while running (JIT compiler)│
└─────────────────────────────┘
│
▼
CPU runs machine codeThe same
.classfile runs on Windows, Mac and Linux, on Intel and ARM — the JVM for each system does the last step. This was Java's original selling point: "write once, run anywhere".The JIT (Just-In-Time) compiler makes Java fast: code that runs a lot gets turned into real machine code while the program is running. That's why Java programs are a bit slow for the first moment and then speed up ("warming up").
How Python runs (you'll use it for backend and AI)#
quiz.py ───▶ CPython compiles to bytecode (.pyc) ───▶ CPython's loop runs each (source) (automatic, you never see it) bytecode instruction one by one
The standard Python program is called CPython (because it is written in C).
It compiles your code to bytecode automatically, then interprets that bytecode. Standard CPython had no JIT for most of its history; an experimental one arrived in Python 3.13.
That's the main reason plain Python loops are often 10–100× slower than Java for the same work, and why Python programs call libraries written in C (like NumPy) for heavy maths. You'll learn this properly in Python Internals (coming soon).
How JavaScript runs (you'll use it for frontend)#
JavaScript runs inside the browser (or Node.js). Engines like Google's V8 interpret it first, then JIT-compile the hot parts — similar to Java. That's covered in JavaScript Basics (coming soon).
Comparison#
| Compiled (C, Go, Rust) | Bytecode + VM (Java) | Interpreted (CPython) | |
|---|---|---|---|
| When translated | Before running | Before (to bytecode) + during (JIT) | During running |
| Startup | Fast | Slower (VM starts, warms up) | Fast |
| Speed once running | Fastest | Close to compiled | Slowest |
| Portability | Must rebuild per CPU/OS | Same bytecode everywhere | Same source everywhere |
What "running a program" really means#
When you double-click StudyBuddy:
The operating system (next file) copies the program's instructions from disk into RAM, because the CPU can only fetch instructions from memory, not directly from disk.
It sets aside RAM for the program's data.
It points the CPU's program counter (Chapter 5) at the first instruction.
The fetch–decode–execute loop begins.
A program sitting on disk is just a file. A program loaded into RAM and running is called a process — the main character of the next file.
Gotchas
"Java is slow" and "Python is slow" are both half-truths. Java is fast once warmed up. Python is slow at raw loops, but fast when the heavy work is done by C libraries underneath.
Machine code isn't portable. A program compiled for an ARM Mac won't run on an x86 server without being rebuilt. Bytecode and interpreted languages avoid this, but the VM/interpreter itself must exist for each platform.
Check yourself
5 questionsWhat's the difference between a compiler and an interpreter?
Show answerHide answer
A compiler translates the whole program to machine code before it runs; an interpreter translates and carries it out step by step while it runs.
What is bytecode, and why does Java use it?
Show answerHide answer
A portable in-between code that a virtual machine runs. Java uses it so the same compiled file runs on any operating system or CPU that has a JVM.
What does the JIT compiler do?
Show answerHide answer
It translates frequently-run bytecode into real machine code during execution, making it faster.
Why must a program be copied into RAM before it runs?
Show answerHide answer
The CPU fetches instructions from memory (RAM), not directly from disk.
What's the difference between a program and a process?
Show answerHide answer
A program is a file on disk; a process is that program loaded into memory and running.