Teacher Guide: Java Fundamentals

Student page: Java Fundamentals IB Syllabus: B2.1 Suggested timing: 6–8 periods (90 min each)

Contents

  1. Sub-page Guides
  2. Teaching Sequence
    1. Opening: data types (B2.1.1)
    2. String methods (B2.1.2)
    3. Type casting (B2.1.1)
    4. Exception handling (B2.1.3)
    5. Debugging (B2.1.4)
  3. Common Student Mistakes
  4. IB Paper 2 Exam Tips

Sub-page Guides

Each sub-page below has its own dedicated teacher guide with period-by-period lesson plans, answer keys for all practice exercises, differentiation strategies, and integration notes.

Sub-page Syllabus Student Page Teacher Guide
Variables & Data Types B2.1.1 Student page Teacher guide
String Methods B2.1.2 Student page Teacher guide
Exception Handling B2.1.3 Student page Teacher guide
Debugging Strategies B2.1.4 Student page Teacher guide

Teaching Sequence

Opening: data types (B2.1.1)

Opening question: “What kinds of information might a program need to remember?” Do not show any slides yet — let students brainstorm. They naturally name numbers (scores, prices, ages), true/false states (logged in, game over), individual letters (grades: A/B/C), and text (names, messages). Write their answers on the board, then reveal the Java type names beside each: int, boolean, char, String.

This makes the type vocabulary feel discovered rather than delivered.

Java two-step translation: Draw the pipeline on the board — .javajavac.class → JVM → output. Ask: “Why two steps? Why not compile directly to machine code?” Students should recall from the hardware/OS units that different machines have different instruction sets. The JVM abstracts that. Reinforce: write once, run anywhere.

Constants: Introduce final by example. “What is something in a program that should never change after you set it?” Pi, tax rate, maximum score. Show final double PI = 3.14159; and attempt to reassign — show the compile error. This makes final meaningful rather than abstract.


String methods (B2.1.2)

Motivation before code: Write “Alice Johnson” on the board. Ask: “If this is stored as a single String variable, how would you get just the first name? Just the last name? How many characters long is the full name?” Students will describe what they want; tell them Java has built-in methods for each operation.

Common demonstration sequence:

  1. length() — no parens trap (arr.length vs str.length())
  2. charAt(i) — ask: “what is charAt(0) of ‘Hello’?”
  3. substring(start, end) — draw an indexed diagram: H=0, e=1, l=2, l=3, o=4. Ask: “what does substring(1, 4) give?” Let them count — “ell”. End index is exclusive — this is the most common exam mistake.
  4. indexOf() — returns -1 if not found. Ask: “how would you use this to split a full name into first and last name at the space character?”
  5. equals() vs ==explain now, even before OOP. Rule: always use .equals() for Strings. The reason (== compares memory addresses) can wait for OOP; the rule cannot.

Follow-up challenge: Parse "alice.johnson@school.edu" — extract the username, domain, and school name as separate Strings using only the methods taught.


Type casting (B2.1.1)

Integer division trap — discovery activity:

Do NOT tell students the rule. Instead, give them this code:

int a = 7;
int b = 2;
System.out.println(a / b);

Ask what they expect. Nearly everyone says 3.5. They run it and get 3. The surprise creates a lasting memory.

Then ask: “How would you fix it so you get 3.5?” Let them experiment. Some will try double a = 7.0 — that works. Guide them to discover that casting one operand to double also works: (double) a / b.

char ↔ int: The Unicode connection back to the information layer. (int) 'A' → 65. Ask: “If ‘A’ is 65, what is ‘B’? What is ‘a’?” (66, 97). Ask: “Can you write code that capitalises a lowercase letter using arithmetic?” This is a memorable bridge between layers.


Exception handling (B2.1.3)

Crash first: Before explaining try/catch, ask students to run the area-of-circle program from the previous section and type “hello” when prompted for a number. Watch it crash with InputMismatchException. Ask: “What do you wish the program had done instead?” Students describe: print an error message, ask again, don’t just crash. Then introduce try/catch as the mechanism for exactly that.

Structure — use a table on the board:

Block Question it answers
try “What code might fail?”
catch “What should happen if it does fail?”
finally “What must happen regardless?”

Emphasise finally with the analogy of booking a hotel room: whether your trip goes perfectly or your flight is cancelled, you still need to check out. finally is the checkout.


Debugging (B2.1.4)

Trace table exercise: Give students a short code fragment (5–8 lines) without running it. Ask them to complete a trace table by hand first, then run the code to verify. The point is to build the habit of reading code before executing it — essential for exam conditions.

Print debugging: Have students deliberately introduce a bug into a working program, then use print statements to find it. Seeing how strategically placed print statements narrow down the problem location is more useful than any debugger tutorial.


Common Student Mistakes

Mistake What students write Why it’s wrong
Integer division double avg = (a + b) / 2; Both operands are int; result is int before assignment
String comparison if (name == "Alice") Compares memory addresses; use .equals()
substring end index "Hello".substring(1, 4) → expects “ello” End index 4 is exclusive; result is “ell”
Casting truncates Expects (int) 3.9 → 4 Truncation, not rounding; result is 3
Wrong exception type Catches Exception always Should catch the specific expected type; overly broad catch can mask bugs
finally misuse Puts business logic in finally finally is for cleanup only

IB Paper 2 Exam Tips

  • String methods appear frequently in code-tracing questions. Students must know length(), substring(start, end), charAt(i), indexOf(), toUpperCase(), equals().
  • The end index of substring(start, end) is exclusive — this is the single most common String-related error in Paper 2.
  • (int) 3.9 = 3 — truncation, not rounding. This appears in type casting questions.
  • The finally block always runs. Examiners ask about this explicitly.
  • Integer division: 7 / 2 = 3 — both operands must be int for this to apply. 7.0 / 2 = 3.5.
  • Students must be able to complete a trace table from a code fragment — this is a Paper 2 staple.

Back to top

© EduCS.me — A resource hub for IB Computer Science

This site uses Just the Docs, a documentation theme for Jekyll.