← Back to Week 3 Hub

Week 3 Cheat Sheet

Quick reference — exceptions, file I/O, dates, collections, and Agile basics

1. try/catch — handling exceptions

try { String[] names = { "Ezra", "Ian" }; System.out.println(names[99]); } catch (Exception e) { System.out.println("Out of range!"); e.printStackTrace(); }
Rule of thumb: catch the specific exception (IOException, NumberFormatException) when you know what can go wrong. Catch generic Exception as a backstop.

2. Reading files — BufferedReader

try { FileReader fr = new FileReader("data.txt"); BufferedReader br = new BufferedReader(fr); String line; while ((line = br.readLine()) != null) { System.out.println(line); } br.close(); } catch (IOException e) { e.printStackTrace(); }

3. Writing files — BufferedWriter

try { FileWriter fw = new FileWriter("out.txt"); BufferedWriter bw = new BufferedWriter(fw); bw.write("Hello\n"); bw.write("World\n"); bw.close(); // flushes buffer } catch (IOException e) { e.printStackTrace(); }

4. Date types — java.time

LocalDatedate only (YYYY-MM-DD)
LocalTimetime only (HH:mm:ss)
LocalDateTimeboth together
LocalDate today = LocalDate.now(); LocalTime time = LocalTime.now(); LocalDateTime stamp = LocalDateTime.now(); today.getYear(); // 2026 today.getMonthValue(); // 1-12 today.getDayOfMonth(); today.getDayOfWeek(); // WEDNESDAY

5. DateTimeFormatter — format & parse

DateTimeFormatter fmt = DateTimeFormatter.ofPattern("MM/dd/yyyy"); // date → string String s = today.format(fmt); // string → date LocalDate d = LocalDate.parse("04/15/2026", fmt);
y / yyyyyear
M / MM / MMM / MMMMmonth
d / ddday of month
E / EEEEday of week
H / HHhour (0-23)
m / mmminute
s / sssecond
aAM/PM
Watch out: MM = month, mm = minute. Easy mix-up.

6. ArrayList

import java.util.ArrayList; ArrayList<String> kids = new ArrayList<>(); kids.add("Ezra"); // append kids.add(0, "Ian"); // insert at index kids.get(0); // "Ian" kids.set(0, "Eli"); // replace kids.remove(0); // shifts others down kids.size(); // count kids.clear(); // empty it Collections.sort(kids);

7. HashMap

import java.util.HashMap; HashMap<String, String> states = new HashMap<>(); states.put("TX", "Austin"); states.get("TX"); // "Austin" states.get("OK"); // null (not found) states.containsKey("TX"); // true states.remove("TX"); states.size();

Iterating

for (String v : states.values()) { ... } for (String k : states.keySet()) { ... } for (Map.Entry<String,String> e : states.entrySet()) { e.getKey(); e.getValue(); }
Null danger: get(key) returns null for missing keys. Always check before using the result.

8. ArrayList or HashMap?

Quick test: can I ask "given X, find Y"? If yes → HashMap. Otherwise → ArrayList.
list of studentsArrayList
employee by idHashMap
log of eventsArrayList
state → capitalHashMap

9. Agile — the basics

Scrum roles

Scrum events

10. User Stories

As a [role], I want [action], so that [benefit].
Not a user story: "As a developer, I want to set up the project structure…" That's a technical task. Keep user stories for real users.

11. GitHub Project Board

Limit work in progress. Focus on finishing cards before starting new ones. Finishing is what delivers value.

12. MVP — Minimum Viable Product

Glossary / Key Terms →