← Back to CI401Revision home
CI401 Introduction to Programming · University of Brighton · Week 1 · Revision

Module Introduction; Enhanced for Loop & Making Choices

Revision pack. Covers the module introduction, BlueJ, variables, arrays, the enhanced for loop, if / else and switch. Use it after the lecture: read the key ideas, then test yourself with the flashcards and the quiz.

About the recording. The 2026 Week 1 lecture recording has no sound. The lecturer says to use the 2025 recording instead, so this pack uses the 2025 recording’s auto-generated transcript, plus this year’s slides and lab project. That transcript is short (about 1,600 words), so it only covers part of the 95-minute lecture: the enhanced for loop and the first if statements. Everything else here comes from the slides. The transcript has no times, so the “where in the recording” pointers use the contents list of the silent 2026 recording (you can still watch the slides and code there).

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.

IDE stands for Integrated Development Environment. It is one app that brings the tools for writing, checking and running programs together. Our IDE is BlueJ.

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.

The lecturer’s point: this is not just a Java module. It is a programming module that uses Java. The ideas carry over to other languages, including the Python you already know.

Where in the recording: 2026 recording 4:28 (What Is Programming) and 7:37 (Getting to Know Java).

2Using BlueJ: open, compile, run

Compile means translating the Java you typed (a .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.
  1. Download the week’s original lab zip (this week: enhanceForChoices.zip). It is also on MyStudies.
  2. 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.
  3. Each yellow box is a class. Double-click a box to open its code.
  4. 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.
  5. Right-click the class box and choose void main(String[] args), then click OK. The program runs.
  6. The output appears in the Terminal Window.
Terminal here means BlueJ’s Terminal Window: a plain text window where your program prints its output and where you type input. It is like the output pane you see when you run Python.

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:

StructureWhat it meansJava this week
SequenceDo 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
A good first question for any new language: how does it do sequence, selection and iteration? You already know the Python answers: lines in order, 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.

Java
// 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 class
Class is a named container for code. For now, think of a class as one small program. Each yellow box in BlueJ is one class.
Method is a named block of instructions inside a class, like run() 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.

Semicolon is the ; character. In Java it ends each instruction, like a full stop ends a sentence. Python uses the end of the line instead.
Curly brackets { } group lines into a block: the body of a class, a method, a loop or an if. Python uses indentation (spaces) instead.
String is a piece of text, written inside double quotes, like "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
# 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: System is not system, and HelloWorld is not helloworld.
  • 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
# Python comments start with #
name = "Brighton"   # this part is ignored

Java’s // does the same job as Python’s #.

BlueJ tip from the lab file: click just before or after a bracket and BlueJ highlights its matching bracket.

7Variables and types: boxes for data

Variable is a named box that holds one value. Each box has a name, a type (what shape of value fits in it) and one value at a time.
Java
// 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;.

TypeHoldsExample
intwhole numbersint count = 10;
doubledecimal numbersdouble price = 9.99;
StringtextString city = "Brighton";
Show me the Python version
Python
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

Array is a group of boxes of the same type, stored together under one name, like train coaches joined together. String[] means “an array of Strings”.
Java
// 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
Python
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.

Loop is code that repeats a block of instructions. Java has four kinds: enhanced for, for, while and do-while. This week is the enhanced for loop, which goes through an array one item at a time.

The pattern is for (type variable : array) { body }. Read the colon : as “in”.

Java
// 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
Python
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

Condition (also called a test) is something that is either true or false, such as 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.

Java
// 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
Python
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.

Java
// 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
Python
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 case is 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, like else. It is optional.
  • Notice there are no curly brackets around each case’s lines.
Java
// 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:

Java
// 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 *.)

Java
// 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
Python
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 (and byte, short), char, String, and enums (ignore for now).
  • Not allowed: long, float, double, boolean.
Keywords such as 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.

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.

Question

“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.

Wrong
System.out.println("Hello")
Right
// Print Hello; the ; ends the instruction
System.out.println("Hello");

Comparing Strings with ==

Use .equals() for text. == is for numbers.

Wrong
if (place == home) {
    System.out.println("Home!");
}
Right
// .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.

Wrong
if (age = 18) {
    System.out.println("Adult");
}
Right
// == 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".

Wrong
for (String place ; placeList) {
    System.out.println(place);
}
Right
// 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).

Wrong
switch (room) {
    case "kitchen":
        System.out.println("Coffee");
    case "bedroom":
        System.out.println("Clothes");
}
Right
// 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:21Module, Assessment & Resources
4:28What Is Programming
7:37Getting to Know Java
7:38BlueJ
9:47Module Timetable and Resources
10:34Lab Sessions
12:20Enhanced for Loop & Making Choices
13:04Three Basic Control Structures
14:14Our First Program: HelloWorld
33:09Loops
34:40Loops in Java
35:15Enhanced For Loop
38:06How the Enhanced For Loop Works
39:24World/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:

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.