What a program is
After this: Say what a program is, pick a language, and run a one-line program.
On this page · 8 sections · 3 checks
Imagine you leave a note for a friend who is going to the shop for you:
- Go to the bakery.
- Buy one loaf of bread.
- Come home.
Your friend reads the first line and does it. Then the second. Then the third. The note works because the lines are in order, and each line says one thing to do.
A computer works the same way, with one difference. It does exactly what the lines say, and nothing more. It never guesses what you meant.
A program is instructions in order
A is a series of instructions written one under another. The computer reads the top line and does what it says. Then it moves to the next line. It carries on until it reaches the last line, and then it stops.
That is the whole idea. The rest of this learning path is about the kinds of instruction you can write.
Pick a language
Instructions must be written in a language the computer understands. This site teaches two of them, Python and Java, and shows you one at a time.
Look at the top bar of this page, or open the menu on a phone. There is a switch with two choices, Python and Java. The same switch sits in the top corner of every block of code. Choose one now.
Either choice is a fine first language, and you can change your mind at any time: press the switch and every lesson follows. Java asks for a little more at the start, because every Java program needs a few extra lines around it. Python needs none. If you have no reason to prefer one, start with Python.
The first program
Here is the smallest program that does something you can see.
print("Hello")Hello
public class Main { public static void main(String[] args) { System.out.println("Hello"); }}Hello
print is an instruction that shows something on the screen. The thing to show goes between the round brackets. The quotes around Hello mark it as text to be shown as it is. The quotes themselves are not shown.
Watch the computer follow two lines
The picture below is a . It shows the program with a marker on the line the computer is on, and an output panel that fills up as lines print. Press Run it, then step forward one step at a time.
- Run the programPress Run it, then step forward. Watch the marker move from the first print line to the second, and watch the output panel gain one line each time.
print("Hello")print("Nice to meet you")run the program to see its boxes
nothing printed yetPress Run it, then step through the program one line at a time.
- lines
- 0
- prints
- 0
- calls
- 0
The marker starts on the first print line. That line prints Hello. The marker moves to the second print line, which prints the next text. Then the program ends. Top to bottom, one line at a time.
The computer works things out
An instruction can contain a sum. The computer works out the sum first and then shows the answer.
print(7 * 6)print(7 + 6)run the program to see its boxes
nothing printed yetPress Run it, then step through the program one line at a time.
- lines
- 0
- prints
- 0
- calls
- 0
7 * 6 means seven times six. The star is the multiplication sign on a keyboard. The computer works out 42 and shows 42. It never shows the text 7 * 6, because there are no quotes around it. Without quotes, the computer works it out.
Run it yourself
Python runs in your browser on this site. Java does not run here: if you chose Java, you step through every example with the trace instead, and you can paste the Java code into a Java tool on your own computer. Press Run below.
Change the numbers, or change the * to a +, and run it again: the answer follows your change.
Check yourself
A program has five lines. In what order does the computer do them?
What does this print?
print("Hello")print("Bye")public class Main { public static void main(String[] args) { System.out.println("Hello"); System.out.println("Bye"); }}What does this print?
print(9 * 8)public class Main { public static void main(String[] args) { System.out.println(9 * 8); }}What comes next
The next lesson looks at the kinds of thing a program can show: numbers, text, and yes or no.
- Say what a program is: instructions written one under another, which the computer follows from top to bottom.
- Read the first program: print is an instruction that shows something on the screen.
- Choose Python or Java with the switch in the top bar, or in the menu on a phone, and change it whenever you like.
- Run a one-line program in the browser and change it.