How Computers Run Programs
What a program actually is, why programming languages exist, and Java's clever two-step trick — no code required yet.
Before writing any Java, let's answer the most basic question: what is a program?
A program is a list of instructions that a computer follows, one after another, exactly as written. That's it. Every app on your phone, every game, every website is — underneath everything — a very long list of small instructions.
Think of a cooking recipe:
1. Preheat the oven to 180°.
2. Mix flour and sugar.
3. Bake for 25 minutes.
A recipe is instructions for a cook. A program is instructions for a computer. The big difference: a cook can improvise when a step is unclear. A computer cannot. It does exactly what the instructions say — nothing more, nothing less.
Deep down, a computer's processor (the CPU) only understands machine code — long sequences of 1s and 0s like 10110000 01100001. Nobody wants to write that by hand.
That's why programming languages exist. A programming language lets you write instructions in something close to English:
System.out.println("Hello!");Text written in a programming language is called source code (or just code). It's for humans to read and write. The computer still needs it translated before it can run — and Java's way of doing that translation is what made it famous.
What is a program?
- AA list of instructions that a computer follows exactly, in order
- BA description of what a computer should roughly try to do
- CThe physical parts inside a computer
- DA file that only contains text for humans to read
Most languages pick one of two translation strategies — but Java picked both, and that two-step trick is its superpower.
Step 1: compile. A tool called the compiler (javac) translates your source code — the whole file at once — into bytecode: a compact, universal instruction format. Not machine code for one specific CPU; a portable in-between language.
Step 2: run. A program called the Java Virtual Machine (the JVM) reads that bytecode and executes it on whatever device it's installed on — Windows, Mac, Linux, an Android phone, a bank's server.
The same compiled bytecode runs everywhere a JVM exists. That's Java's famous slogan: "Write once, run anywhere."
Three words to remember:
- Source code — the
.javafile you write. - Bytecode — the compiled
.classfile the compiler produces. - JVM — the program that runs bytecode on any device.
What does "Write once, run anywhere" mean for Java?
- ACompiled Java bytecode runs on any device that has a JVM installed
- BJava programs never need to be compiled
- CJava code only needs to be saved once
- DJava programs run without a processor
One more thing before we start: errors are a normal part of programming.
When your code has a typo or breaks a language rule, the compiler refuses to translate it and prints an error message instead. This is not failure — it's the compiler helping you, pointing at problems before the program ever runs.
Every professional programmer sees compiler errors every single day. In this course you'll learn to read them calmly, fix the code, and try again. That write → compile → fix cycle is programming.
Next up: what Java actually powers (hint: you've probably played it), and how it became the language universities teach first.
The Java compiler translates your source code into ___, which the JVM can run on any device.