Key ideas, in lecture order
One idea per block, in the order the lecture covers them. Java code has a comment on every line. If you want to see how the same thing looks in Python, open the “Show me the Python version” boxes. They start closed.
Ideas: 1 · 2 · 3 · 4 · 5 · 6 · 7 · 8 · 9 · 10 · 11 · 12
1What programming is
A program is a set of instructions that tells a computer what to do. People also call it software or an application. Programming means writing those instructions.
We write programs in a programming language. That is a language with strict rules that a computer can follow. Java and Python are both high-level languages. “High-level” means they use English-like words, so humans can read them.
Java is object-oriented (you will learn what that means later in the module) and general-purpose (used for desktop, server and phone apps). Its motto is “write once, run anywhere”: the same Java program runs on Windows, Mac and Linux.
Where in the recording: 2026 recording 4:28 (What Is Programming) and 7:37 (Getting to Know Java).
2Using BlueJ: open, compile, run
.java file) into bytecode (a .class file). Bytecode is a form the Java Virtual Machine (JVM) can run. Python skips this visible step: you just run the file. In Java you must compile first, and the compiler tells you about mistakes before the program runs.- Download the week’s original lab zip (this week:
enhanceForChoices.zip). It is also on MyStudies. - In BlueJ: Project → Open ZIP/JAR… and pick the zip. BlueJ unzips it into a folder with the same name. Your work lives in that folder, not in the zip.
- Each yellow box is a class. Double-click a box to open its code.
- Click Compile (in the editor, or on the left of the main window). A striped box is not compiled yet. Red cross-hatches mean there are errors to fix.
- Right-click the class box and choose void main(String[] args), then click OK. The program runs.
- The output appears in the Terminal Window.
To experiment without breaking the original, right-click a class and choose Duplicate…. Give the copy a new name that starts with a capital letter.
The workflow, from the BlueJ guide slides: open project → open class → compile → run → edit → compile again.
Where in the recording: 2026 recording 7:38 (BlueJ). The BlueJ demo with HelloWorld runs through the long section that starts at 14:14.
3How the module runs
- 12 teaching weeks. Each week: a 2-hour lecture and a 2-hour lab.
- Lab instructions are always at the end of the lecture slides. Each week has a project zip with examples, exercises (
Ex_) and solutions (Sol_). - Labs are practice. They are not marked, but they prepare you for the coursework.
- The module is assessed by one coursework project. You need 40 out of 100 overall to pass. The lecturer will introduce it around Week 8, so you do not need to read the brief yet.
Where in the recording: 2026 recording 1:21 (Module, Assessment & Resources), 9:47 (Timetable and Resources) and 10:34 (Lab Sessions).
4The three basic control structures
Every program, however big, is built from just three building blocks:
| Structure | What it means | Java this week |
|---|---|---|
| Sequence | Do the instructions in order, one after another. | Lines in a method run from top to bottom. |
| Selection (decision) | Ask a question and choose what to do. | if / else, switch |
| Iteration (loop, repetition) | Repeat instructions. | the enhanced for loop |
if/elif/else, and for/while.Where in the recording: 2026 recording 13:04 (Three Basic Control Structures).
5Our first program: HelloWorld
Here is HelloWorld from the lab project, with a comment on every line. Focus on the line with System.out.println. The rest is the “wrapper” every Java program needs.
// What this class does: it prints one message, Hello World.
// The class name must match the file name: HelloWorld.java
public class HelloWorld { // start of the class; everything in it sits inside these { }
// run() is a method: a named block of instructions
public void run() { // start of the run method
// Show Hello World in the Terminal Window, then move to a new line
System.out.println("Hello World"); // the ; ends this instruction
} // end of the run method
// main is where Java starts the program.
// BlueJ calls it when you pick void main(String[] args)
public static void main(String[] args) {
new HelloWorld().run(); // make a HelloWorld object, then call its run() method
} // end of main
} // end of the classrun() or main(). It is like a Python function (def).The lab file explains the structure as a house: the class is the house, a method is a room, and each instruction is an item in a room.
; character. In Java it ends each instruction, like a full stop ends a sentence. Python uses the end of the line instead.{ } group lines into a block: the body of a class, a method, a loop or an if. Python uses indentation (spaces) instead."Hello World".System.out.println("Hello World"); means: use Java’s built-in System, take its screen output out, and print a line. The dot . means “the thing inside”. println moves to a new line afterwards; print stays on the same line.
Show me the Python version
# Python: one line is a whole program
print("Hello World")Python lets you write the instruction on its own. Java needs it inside a method, and the method inside a class. Python’s print() always adds a new line, like Java’s println.
Where in the recording: 2026 recording 14:14 (Our First Program: HelloWorld).
6Java is strict: spelling, capitals and punctuation
- Capital letters matter. Java is case-sensitive:
Systemis notsystem, andHelloWorldis nothelloworld. - Punctuation matters. Semicolons, commas and full stops are vital. Brackets
( ) { } [ ]and quotes" "must come in matching pairs. - Layout and colour do not matter to Java (mostly). They help humans read. This is the big difference from Python, where indentation is part of the rules.
- Comments: after
//, Java ignores the rest of the line. Use comments to explain your code./* ... */makes a comment over several lines.
Show me the Python version
# Python comments start with # name = "Brighton" # this part is ignored
Java’s // does the same job as Python’s #.
7Variables and types: boxes for data
// A box called age for whole numbers (int), with 20 put in it int age = 20; // Put 25 in the same box. The old value 20 is gone for good age = 25; // A box for decimal numbers (double) double price = 9.99; // A box for text (String). Text goes in double quotes String city = "Brighton"; // + joins text and values together. This prints: Brighton 25 9.99 System.out.println(city + " " + age + " " + price);
int age = 20; reads as type name = value;. Writing the type and name is called declaring the variable. Putting the first value in is called initialising it. Once a variable is declared, you write just its name (no type) to change it: age = 25;.
| Type | Holds | Example |
|---|---|---|
int | whole numbers | int count = 10; |
double | decimal numbers | double price = 9.99; |
String | text | String city = "Brighton"; |
Show me the Python version
age = 20 # Python works out the type for you age = 25 # the old value is replaced, same as Java price = 9.99 city = "Brighton" print(city, age, price)
In Python you never write the type. In Java you must, and the box then only accepts that type: you cannot put text into an int box.
From the “Variables and Types: The Basics” slides. A full introduction to types comes later in the module.
8Arrays: many boxes joined together
String[] means “an array of Strings”.// An array of four Strings, stored in a variable called placeList.
// Curly brackets hold the items, commas go between them, and a ; ends the line
String[] placeList = {"World", "Europe", "UK", "Brighton"};
// An array of three whole numbers. Every item must be the same type (int)
int[] scores = {80, 75, 90};
// Print the first place, just to show the array is there.
// (Square brackets with a number pick one item. You will meet this properly later.)
System.out.println(placeList[0]);Show me the Python version
place_list = ["World", "Europe", "UK", "Brighton"] # a Python list scores = [80, 75, 90] print(place_list[0])
A Java array is like a Python list, but it uses { } instead of [ ] when you create it, and all items must be the same type.
Where in the recording: 2026 recording 39:24 (World/Hello World examples).
9The enhanced for loop (for-each)
HelloBrighton prints four lines with four almost identical println instructions. That is repetition. “Good programmers are lazy”: whenever you repeat yourself, look for a way not to. A loop is the main way.
The pattern is for (type variable : array) { body }. Read the colon : as “in”.
// What this class does: says Hello to every place in a list,
// using one println inside a loop instead of four separate printlns.
public class HelloPlaces {
public void run() {
// The list (array) of places to say hello to
String[] placeList = {"World", "Europe", "UK", "Brighton"};
// Loop: for each String in placeList, copy it into the box called place
// and run the body. It runs 4 times, then stops after the last item.
for (String place : placeList) {
// + joins "Hello " and the current place. Prints e.g. Hello Europe
System.out.println("Hello " + place);
} // end of the loop body
}
// Start the program (BlueJ: right-click, void main)
public static void main(String[] args) {
new HelloPlaces().run();
}
}
How it runs: place is "World", the body prints Hello World. Then place becomes "Europe" and the body runs again, then "UK", then "Brighton". After the last item the loop ends and Java carries on with the code after the closing }.
The win: add ten more places and you still only have one println. Change “Hello” to “Bonjour” in one place and every line changes.
Show me the Python version
place_list = ["World", "Europe", "UK", "Brighton"]
for place in place_list: # same idea: one item at a time
print("Hello " + place)Java’s for (String place : placeList) is Python’s for place in place_list:. Java also needs the type (String), round brackets around the header, and curly brackets around the body.
Why not just copy and paste? The slides warn: repeated code is hard to test and change, code you copy without understanding may not work, and other people’s code usually needs their permission.
Where in the recording: 2026 recording 33:09 (Loops), 34:40 (Loops in Java), 35:15 (Enhanced For Loop), 38:06 (How the Enhanced For Loop Works) and 39:24 (examples).
10Making choices: if and else
age == 18 or place.equals(home).The pattern is if (test) { ... } else { ... }. The test goes in round brackets. The code to run goes in curly brackets. The else part is optional. After the if statement, the program carries on with the next line.
// What this class does: says Hello to each place, and adds an extra
// message for our home town. Everywhere else gets "I've never been there".
public class HomeTown {
public void run() {
// The places to visit
String[] placeList = {"London", "Paris", "Brighton", "New York"};
// A new variable that stores our home town
String home = "Brighton";
// Loop: go through every place in the list, one at a time
for (String place : placeList) {
// Always say hello first
System.out.println("Hello " + place);
// Choice: only ONE of these two blocks runs each time round.
// The first runs if place is the same text as home; otherwise the else runs.
if (place.equals(home)) {
// print keeps the cursor on the same line...
System.out.print("there's no place like home, ");
// ...and println finishes that line
System.out.println("my favourite place is " + place);
} else {
// Runs for every place that is not home
System.out.println("I've never been there");
}
}
}
// Start the program
public static void main(String[] args) {
new HomeTown().run();
}
}
Comparing text: to check whether two Strings are the same, write place.equals(home). Do not use == for Strings. Use == for numbers, such as age == 18. And remember: a single = stores a value; a double == compares two values.
Show me the Python version
place_list = ["London", "Paris", "Brighton", "New York"]
home = "Brighton"
for place in place_list:
print("Hello " + place)
if place == home: # Python uses == for text too
print("there's no place like home, my favourite place is " + place)
else:
print("I've never been there")Same logic. Python uses a colon and indentation; Java uses round brackets for the test and curly brackets for each block. Python compares text with ==, but in Java you should use .equals().
Combining statements: a for loop and an if are each treated as one instruction that holds a block. So you can put an if inside a for (as here), a for inside an if, and so on. This is called nesting. BlueJ indents nested code and shades each block a different colour to help you see the structure.
Where in the recording: the if statements are after 39:24 in the 2026 recording, which has no more contents entries after that. In the 2025 recording (with sound), this comes just before the mid-lecture break.
11Several choices: else if
When there are more than two possibilities, chain tests with else if. Java checks the tests from the top. The first one that is true runs, and the rest are skipped. The final else runs only if every test was false.
// The rooms we walk through on the house tour
String[] rooms = {"hall", "kitchen", "lounge", "bedroom", "attic"};
// Loop: go through every room in the list, one at a time
for (String room : rooms) {
// print (not println) so the comment stays on the same line
System.out.print("Here we are in the " + room + ". ");
// Choice: Java checks each test from the top and runs only the FIRST block
// whose test is true. If none is true, the final else block runs.
if (room.equals("kitchen")) {
System.out.print("Can you smell the coffee?");
} else if (room.equals("bedroom")) {
System.out.print("Plenty of room for all your clothes.");
} else if (room.equals("lounge")) {
System.out.print("Notice the original fireplace.");
} else if (room.equals("hall")) {
System.out.print("Nice and big windows.");
} else {
System.out.print("What is this room used for?");
}
// Finish the line before the next room
System.out.println();
}Show me the Python version
for room in ["hall", "kitchen", "lounge", "bedroom", "attic"]:
print("Here we are in the " + room + ". ", end="") # end="" is like Java's print
if room == "kitchen":
print("Can you smell the coffee?")
elif room == "bedroom": # Java: else if
print("Plenty of room for all your clothes.")
elif room == "lounge":
print("Notice the original fireplace.")
elif room == "hall":
print("Nice and big windows.")
else:
print("What is this room used for?")Java’s else if is Python’s elif. Python’s print(..., end="") is like Java’s print (no new line).
This is the EstateAgent example from the lab project (with an extra “attic” so you can see the else run).
12switch, case, break and default
When you test one variable against many exact values, a switch is easier to read than a long else-if chain.
- In the round brackets goes a value (usually a number or a String), not a true/false test.
- Each
caseis labelled with one possible value, followed by a colon. break;means “I’m done here, jump out of the switch”.default:runs when no case matches, likeelse. It is optional.- Notice there are no curly brackets around each case’s lines.
// The room we are in right now
String room = "lounge";
// Choice: jump to the case whose label matches room ("lounge" here).
// break stops each case so only one message prints.
// If no label matches, the default block runs.
switch (room) {
case "kitchen":
System.out.println("Can you smell the coffee?");
break; // jump out of the switch
case "bedroom":
System.out.println("Plenty of room for all your clothes.");
break;
case "lounge":
System.out.println("Notice the original fireplace.");
break;
default: // no case matched
System.out.println("What is this room used for?");
}
Fall-through. Without break, Java carries on into the next case’s code. Usually that is a mistake, but you can use it on purpose so several cases share the same code:
// The month we want to know about
String month = "june";
// Choice: april, june, september and november have no code of their own,
// so they "fall through" to the same println. break stops it going further.
switch (month) {
case "april":
case "june":
case "september":
case "november":
System.out.println("30 days");
break;
case "february":
System.out.println("28 days");
break;
default: // every other month
System.out.println("31 days");
}
The StarRating example uses fall-through to print stars. Rating 3 starts at case 3 and falls through cases 2 and 1, printing three stars. (The lab uses ★ stars; here we use *.)
// The rating to show, from 1 to 5
int rating = 3;
// Choice with deliberate fall-through: start at the matching case and keep
// going down, printing one star per case, until the break after case 1.
switch (rating) {
case 5: System.out.print("*");
case 4: System.out.print("*");
case 3: System.out.print("*");
case 2: System.out.print("*");
case 1: System.out.print("*");
break; // stop here
default:
System.out.print("Invalid rating");
}
// Finish the line. For rating 3 the line shows ***
System.out.println();Show me the Python version
room = "lounge"
match room: # Python 3.10+ has match/case
case "kitchen":
print("Can you smell the coffee?")
case "bedroom":
print("Plenty of room for all your clothes.")
case "lounge":
print("Notice the original fireplace.")
case _: # like Java's default
print("What is this room used for?")Python’s match never falls through, so it needs no break. In older Python you would use if/elif. In Java, forgetting break is a classic bug.
switch rules
- switch can only check equality. It cannot do
<,>,<=or>=. Use if-else for ranges. - Allowed case types:
int(andbyte,short),char,String, and enums (ignore for now). - Not allowed:
long,float,double,boolean.
for, if, else, switch, case and break are reserved words in Java. You cannot use them as variable names.Where in the recording: switch is not in the 2026 contents list (it ends at 39:24), and it is not in the 2025 transcript we have either. Use the slides for this part.
What the lecturer stressed
These points come from the part of the 2025 recording that the transcript covers (green labels), plus points the slides themselves flag as tips or warnings (beige labels). The transcript has no timestamps, so each point gives the stage of the lecture instead. Where the topic appears in the 2026 contents list, its 2026 time is given too.
- 2025, start of the transcriptFollow the syntax exactly, even the punctuation. In everyday English, “close enough” is fine and people still understand you. In programming it is not. Topic in the 2026 recording: 35:15.
- 2025, for-loop partKnow which bracket does what. The round brackets hold the loop’s header (or an if’s condition). The curly brackets hold the body, which can be one statement or many.
- 2025, for-loop partThe loop variable walks along the array. The lecturer pictured a group of students: the loop takes the first one, runs the body, moves to the next, runs the body again, until the last one. The worked example was World, Europe, UK, Brighton. 2026 recording: 38:06 and 39:24.
- 2025, for-loop partA variable is a box with a type label, and it holds one value at a time. A String box only takes text; a whole-number box only takes whole numbers. When you put a new value in, the box completely forgets the old one.
- 2025, if-statement partPut the structure in first. Type the brackets of the if/else before you fill them in. Otherwise you end up wondering why there is an error, and it turns out to be a missing bracket.
- 2025, if-statement partUse
.equals()to compare text, not==. A single=puts a value into a box;==compares.==is fine for numbers, but it is not the safe way to compare Strings. The lecturer said to remember: useequals. - 2025, if-statement partThe else block only runs when the condition is false. The lecturer traced the loop place by place: only Brighton printed the extra message; everywhere else got the else message. When the loop finishes, the code after the loop runs.
- 2025, just after the breakOne yes/no question is not enough when there are many cases. The lecturer wanted a different message for Brighton, London (“the capital of the UK”) and New York (USA). That needs more than one test, which leads to else-if and switch.
- “Good programmers are lazy.” If you repeat yourself, look for a way not to. Concise, general code is easier to understand, test, reuse and change.
- The perils of copy-paste. Repeated code is hard to test and change. Using code you do not understand is dangerous. Other people’s code needs their permission.
- Do not forget
break. Without it, Java falls through into the next case. - Labs and the coursework. Weekly labs are practice and are not marked, but they prepare you for the coursework. Always read the lab instructions at the end of the slides before your lab. The coursework project is introduced around Week 8.
Flashcards
Read the question. Say your answer out loud or in your head. Then click the card to flip it. Be honest: click I know it or Don’t know yet. Your marks are saved in this browser, so you can come back later.
“Only the ones I don’t know” hides every card you have marked I know it. Cards you have not marked yet stay in, so nothing gets skipped.
Quiz
15 questions: multiple choice, “what will this print?” and “spot the bug”. Click an answer. You find out straight away if it is right, with a short explanation. Your answers and your score are saved in this browser.
Common mistakes
These are the slips beginners make most often with this week’s topics. The “wrong” code is shown in red; do not copy it.
Forgetting the semicolon
Every instruction ends with ;. The compiler says ';' expected. Look at the end of the line it points to, or the line just before.
System.out.println("Hello")// Print Hello; the ; ends the instruction
System.out.println("Hello");Comparing Strings with ==
Use .equals() for text. == is for numbers.
if (place == home) {
System.out.println("Home!");
}// .equals() checks whether the two texts are the same
if (place.equals(home)) {
System.out.println("Home!");
}Using = when you mean ==
One = stores a value. Two == compare. if (age = 18) will not compile.
if (age = 18) {
System.out.println("Adult");
}// == compares the number in age with 18
if (age == 18) {
System.out.println("Adult");
}Semicolon instead of colon in the for loop
The enhanced for loop uses :. Read it as "in".
for (String place ; placeList) {
System.out.println(place);
}// for each place in placeList, print it
for (String place : placeList) {
System.out.println(place);
}Missing break in a switch
Without break, Java falls through and runs the next case too. Only leave it out on purpose (like StarRating).
switch (room) {
case "kitchen":
System.out.println("Coffee");
case "bedroom":
System.out.println("Clothes");
}// Choice on room: break stops each case running into the next
switch (room) {
case "kitchen":
System.out.println("Coffee");
break; // jump out of the switch
case "bedroom":
System.out.println("Clothes");
break;
}Unbalanced brackets
Every { needs a } and every ( needs a ). Type both brackets first, then fill in the middle. Click next to a bracket in BlueJ to see its partner.
Wrong capital letters
system.out.Println will not compile. It must be System.out.println. Class names start with a capital; variable names start with a small letter.
Trying a range in a switch
case > 5: is not allowed. Use if / else if for ranges.
Python habits
No colon after if (...) or for (...). Indentation alone does not make a block in Java: you need { }. Strings use double quotes "...", not single quotes.
Running before compiling
After every change, compile again. If the box is striped, it has not been compiled. If you see red cross-hatches, fix the errors first.
The recording
Watch the 2025 Week 1 lecture recording (with sound). This is the one the lecturer recommends.
2026 Week 1 lecture recording (no sound). You can still use it to see the slides and code. Its contents list:
| Time (2026 recording) | Section |
|---|---|
| 1:21 | Module, Assessment & Resources |
| 4:28 | What Is Programming |
| 7:37 | Getting to Know Java |
| 7:38 | BlueJ |
| 9:47 | Module Timetable and Resources |
| 10:34 | Lab Sessions |
| 12:20 | Enhanced for Loop & Making Choices |
| 13:04 | Three Basic Control Structures |
| 14:14 | Our First Program: HelloWorld |
| 33:09 | Loops |
| 34:40 | Loops in Java |
| 35:15 | Enhanced For Loop |
| 38:06 | How the Enhanced For Loop Works |
| 39:24 | World/Hello World examples |
The recordings are on Panopto, so you need to be signed in to your University of Brighton account. The 2025 recording has no contents list with times that we could use, so no 2025 times are given.
Files: Week 1 Sunday Prep · Week 1 Lab Walkthrough · main lecture slides (.pptx) · original lab project enhanceForChoices.zip · commented lab code (learning only)
How this pack was made
This pack was made from:
- The Week 1 slides: Module Overview, Enhanced for Loop & Making Choices (the lab is at the end), Variables and Types - The Basics, Using BlueJ - A practical guide for Java programming, and the optional Programming and Java - Additional Background and Getting Started.
- The Week 1 lab project
enhanceForChoices.zip(HelloWorld, HelloBrighton, HelloPlaces, HomeTown, EstateAgent, StarRating and the exercises). - The auto-generated transcript of the 2025 Week 1 recording, because the 2026 recording has no sound. The transcript is rough, has no timestamps and covers only part of the lecture (the enhanced for loop, if/else, and the start of else-if). Garbled words were read against the slides, and nothing garbled is quoted as the lecturer’s words.
- The contents list of the silent 2026 Week 1 recording, used only for the “where in the recording” times.
Every Java example that is meant to be correct was compiled with the Java compiler (javac). The “what will this print?” answers were checked by running the code.