SyntaxPilot
Courses/Java/Lesson 50
Video coming soonThis lesson’s video is being made

Start with the notes below; the video appears here as soon as it is on YouTube.

Java · Lesson 50 of 51

Capstone: library management system

queued

These are the notes for Java episode 50, the capstone of the course. A capstone is the final project that puts everything together. The colony library runs on a paper register: finding who has a book means flipping pages, fines are counted by hand, and one busy Sunday the same copy goes to two members. We replace the register with a Java program, one problem at a time: arrays crash, a record plus a Map fixes that, Map.put silently loses a loan, a checked custom exception fixes that, LocalDate counts the fines, and java.nio.file.Files makes the data survive a power cut. Every example was run with javac 21.

The problem: the colony library

Real-life problem. 500 books, 200 members, one thick paper register run by the librarian, Mr Joshi.

On paper What goes wrong
"Who has Godaan?" flip through every page
"Who is late, and what is the fine?" days counted by hand, month ends get missed
a busy Sunday the same copy is given to two members

Requirements first

Requirements are the list of things the software must do, written before any code.

  1. Add books, and find a book by its ID fast.
  2. Borrow and return books.
  3. Never give one copy to two members.
  4. A loan lasts 14 days; the fine is Rs 2 per late day.
  5. Keep the data after the program stops.

Each requirement maps to something from the course: collections (episodes 30-32), exceptions (26-27), the Date/Time API (42), file I/O (35), Scanner (4).

First attempt: parallel arrays (and the crash)

Two arrays, titles and authors, both of size 3, and a count of filled slots. These are parallel arrays: slot i of each array belongs to the same book.

public class Main {
    static String[] titles = new String[3];       // the register has 3 rows
    static String[] authors = new String[3];
    static int count = 0;

    static void addBook(String title, String author) {
        titles[count] = title;
        authors[count] = author;
        count++;
        System.out.println("Added: " + title);
    }
    public static void main(String[] args) {
        addBook("Wings of Fire", "A. P. J. Abdul Kalam");
        addBook("Malgudi Days", "R. K. Narayan");
        addBook("Godaan", "Premchand");
        addBook("The Guide", "R. K. Narayan");      // book number 4
    }
}

Output:

Added: Wings of Fire
Added: Malgudi Days
Added: Godaan
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3
    at Main.addBook(Main.java:7)
    at Main.main(Main.java:16)

Why it failed. An array's size is fixed when it is created, so book number 4 has no slot: ArrayIndexOutOfBoundsException. And one book is split across two arrays that must be kept in step by hand; every new field (member, due date) adds another array.

The fix: a record per book and a map by ID

Real-life example: catalogue cards in a drawer.

In a library In Java
one catalogue card per book (ID, title, author together) record Book (episode 24): fields kept together, read-only
a drawer ordered by card ID, pull out B103 at once Map<String, Book>: ID → book, O(1) lookup with a hash map (episode 32)
only the librarian touches the drawer class Library with a private map and public methods: encapsulation (episode 17)

An ISBN (International Standard Book Number) is the unique number every published book gets; the examples use short IDs like B101. LinkedHashMap is a hash map that also remembers the order keys were added.

import java.util.*;

record Book(String isbn, String title, String author) {}

class Library {
    private final Map<String, Book> books = new LinkedHashMap<>();   // isbn -> book

    void addBook(Book b) { books.put(b.isbn(), b); }
    Book find(String isbn) { return books.get(isbn); }   // O(1) lookup
    List<Book> byAuthor(String author) {
        return books.values().stream()
                    .filter(b -> b.author().equals(author)).toList();
    }
    int size() { return books.size(); }
}

public class Main {
    public static void main(String[] args) {
        Library lib = new Library();
        lib.addBook(new Book("B101", "Wings of Fire", "A. P. J. Abdul Kalam"));
        lib.addBook(new Book("B102", "Malgudi Days", "R. K. Narayan"));
        lib.addBook(new Book("B103", "Godaan", "Premchand"));
        lib.addBook(new Book("B104", "The Guide", "R. K. Narayan"));
        System.out.println("Books: " + lib.size());
        System.out.println(lib.find("B103"));
        System.out.println("By Narayan: " + lib.byAuthor("R. K. Narayan").size());
    }
}

Output:

Books: 4
Book[isbn=B103, title=Godaan, author=Premchand]
By Narayan: 2

A record gets toString, equals and hashCode for free, so find("B103") prints all its fields. There is no size limit, and no arrays to keep in step.

Borrowing: one copy, two members (the silent bug)

A second map, issuedTo, records which member has each book.

import java.util.*;

class Library {
    private final Map<String, String> issuedTo = new HashMap<>();   // isbn -> member

    void borrow(String isbn, String member) {
        issuedTo.put(isbn, member);
        System.out.println(member + " borrowed " + isbn);
    }
    String holder(String isbn) { return issuedTo.get(isbn); }
}

public class Main {
    public static void main(String[] args) {
        Library lib = new Library();
        lib.borrow("B101", "Asha");
        lib.borrow("B101", "Ravi");                 // the same copy!
        System.out.println("B101 is with: " + lib.holder("B101"));
    }
}

Output:

Asha borrowed B101
Ravi borrowed B101
B101 is with: Ravi

Why it failed. Map.put on a key that already exists replaces the old value, silently, and returns the old value (which we ignored). Asha's loan vanished with no error. A silent wrong answer is worse than a crash.

The fix: a checked custom exception

A custom exception is your own exception class. Extending Exception (not RuntimeException) makes it a checked exception: the compiler forces every caller to catch it or declare it with throws (episodes 26-27). throw raises it where the rule is broken; throws in the method signature warns callers.

import java.util.*;

class BookNotAvailableException extends Exception {
    BookNotAvailableException(String message) { super(message); }
}

class Library {
    private final Map<String, String> issuedTo = new HashMap<>();

    void borrow(String isbn, String member) throws BookNotAvailableException {
        String holder = issuedTo.get(isbn);
        if (holder != null)                          // already issued?
            throw new BookNotAvailableException(isbn + " is with " + holder);
        issuedTo.put(isbn, member);
        System.out.println(member + " borrowed " + isbn);
    }
}

public class Main {
    public static void main(String[] args) {
        Library lib = new Library();
        lib.borrow("B101", "Asha");
        lib.borrow("B101", "Ravi");
    }
}

Compiler output:

Main.java:22: error: unreported exception BookNotAvailableException; must be caught or declared to be thrown
        lib.borrow("B101", "Asha");
                  ^
Main.java:23: error: unreported exception BookNotAvailableException; must be caught or declared to be thrown
        lib.borrow("B101", "Ravi");
                  ^
2 errors

javac refuses to compile main, because it ignores a checked exception. So main must decide what to do when a book is out:

import java.util.*;

class BookNotAvailableException extends Exception {
    BookNotAvailableException(String message) { super(message); }
}

class Library {
    private final Map<String, String> issuedTo = new HashMap<>();

    void borrow(String isbn, String member) throws BookNotAvailableException {
        String holder = issuedTo.get(isbn);
        if (holder != null)                          // already issued?
            throw new BookNotAvailableException(isbn + " is with " + holder);
        issuedTo.put(isbn, member);
        System.out.println(member + " borrowed " + isbn);
    }
}

public class Main {
    public static void main(String[] args) {
        Library lib = new Library();
        for (String member : List.of("Asha", "Ravi")) {
            try {
                lib.borrow("B101", member);
            } catch (BookNotAvailableException e) {
                System.out.println("Sorry " + member + ": " + e.getMessage());
            }
        }
    }
}

Output:

Asha borrowed B101
Sorry Ravi: B101 is with Asha

Rule of thumb: throw where the rule is, catch where you can answer (here, where a polite message can be shown).

Due dates and fines

Real-life problem: counting late days by hand. Issued 1 November, due 15 November (14 days), returned 20 November: 5 days late, Rs 10.

  • LocalDate (episode 42) is a date with no time of day. plusDays(14) gives the due date and handles month ends and leap years.
  • ChronoUnit.DAYS.between(a, b) counts the days from a to b (negative if b is before a).
  • Collectors.groupingBy(key, mapFactory, downstream) groups items by a key; summingLong adds a number per group. Passing TreeMap::new keeps the members sorted.

today is fixed as 20 November 2026 so the output is the same on every run; a real system uses LocalDate.now().

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;

record Loan(String isbn, String member, LocalDate issued) {
    LocalDate due() { return issued.plusDays(14); }   // 14-day loan
    long fine(LocalDate today) {
        long late = ChronoUnit.DAYS.between(due(), today);
        return late > 0 ? late * 2 : 0;   // Rs 2 per late day
    }
}

public class Main {
    public static void main(String[] args) {
        LocalDate today = LocalDate.of(2026, 11, 20);
        List<Loan> loans = List.of(
            new Loan("B101", "Asha", LocalDate.of(2026, 11, 1)),
            new Loan("B102", "Ravi", LocalDate.of(2026, 10, 25)),
            new Loan("B103", "Asha", LocalDate.of(2026, 10, 30)),
            new Loan("B104", "Neha", LocalDate.of(2026, 11, 15)));
        for (Loan l : loans) {
            long f = l.fine(today);
            if (f > 0) System.out.println(l.isbn() + " due " + l.due() + ": Rs " + f);
        }
        Map<String, Long> perMember = loans.stream()
             .collect(Collectors.groupingBy(Loan::member, TreeMap::new,
                      Collectors.summingLong(l -> l.fine(today))));
        System.out.println("Fines per member: " + perMember);
    }
}

Output:

B101 due 2026-11-15: Rs 10
B102 due 2026-11-08: Rs 24
B103 due 2026-11-13: Rs 14
Fines per member: {Asha=24, Neha=0, Ravi=24}

B102 was issued on 25 October and due on 8 November, across a month end: 12 days late, Rs 24, counted correctly.

Saving to a file (persistence)

Real-life problem: the power cut. Our maps live in RAM, the computer's working memory, which is wiped when the program stops. Persistence means keeping data after the program stops, here by writing it to a file on the disk.

CSV (comma-separated values) stores one record per line with fields separated by commas. Files.write(path, lines) writes a list of lines; Files.readAllLines(path) reads them back. Both can throw IOException, a checked exception, so main declares throws IOException (episode 35).

import java.io.IOException;
import java.nio.file.*;
import java.util.*;

record Book(String isbn, String title, String author) {
    String toLine() { return isbn + "," + title + "," + author; }
    static Book fromLine(String line) {
        String[] p = line.split(",");
        return new Book(p[0], p[1], p[2]);
    }
}

public class Main {
    public static void main(String[] args) throws IOException {
        Path file = Path.of("books.csv");
        List<Book> books = List.of(new Book("B101", "Wings of Fire", "Kalam"),
                                   new Book("B102", "Malgudi Days", "Narayan"),
                                   new Book("B103", "Godaan", "Premchand"));
        Files.write(file, books.stream().map(Book::toLine).toList());   // save
        System.out.println("Saved " + books.size() + " books");

        List<Book> loaded = Files.readAllLines(file).stream()   // load
                                 .map(Book::fromLine).toList();
        loaded.forEach(System.out::println);
    }
}

Output:

Saved 3 books
Book[isbn=B101, title=Wings of Fire, author=Kalam]
Book[isbn=B102, title=Malgudi Days, author=Narayan]
Book[isbn=B103, title=Godaan, author=Premchand]

A real system saves after every change and loads at start-up. Caution: a plain split(",") breaks if a title itself contains a comma; real code uses a CSV library or a different separator.

The whole system

Two records (Book, Loan), the exception, and the Library service with two private maps. main reads commands with a Scanner (episode 4): borrow <isbn> <member> <date> or return <isbn> <date>. Any refusal is caught, so one bad command doesn't stop the program.

Program input (the input box):

borrow B101 Asha 2026-11-01
borrow B101 Ravi 2026-11-03
borrow B109 Ravi 2026-11-03
borrow B102 Ravi 2026-11-03
return B101 2026-11-20
return B102 2026-11-10
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.*;

record Book(String isbn, String title) {}
record Loan(String member, LocalDate issued) {}
class BookNotAvailableException extends Exception {
    BookNotAvailableException(String msg) { super(msg); }
}

class Library {
    private final Map<String, Book> books = new LinkedHashMap<>();
    private final Map<String, Loan> loans = new HashMap<>();   // isbn -> loan

    void add(Book b) { books.put(b.isbn(), b); }
    void borrow(String isbn, String member, LocalDate day)
            throws BookNotAvailableException {
        if (!books.containsKey(isbn))
            throw new BookNotAvailableException("no book " + isbn);
        if (loans.containsKey(isbn))
            throw new BookNotAvailableException(isbn + " is out");
        loans.put(isbn, new Loan(member, day));
        System.out.println(member + " took " + books.get(isbn).title());
    }
    void giveBack(String isbn, LocalDate day) {
        Loan l = loans.remove(isbn);
        long late = ChronoUnit.DAYS.between(l.issued().plusDays(14), day);
        long fine = Math.max(0, late * 2);   // Rs 2 a day
        System.out.println(l.member() + " returned " + isbn + ", fine Rs " + fine);
    }
}

public class Main {
    public static void main(String[] args) {
        Library lib = new Library();
        lib.add(new Book("B101", "Wings of Fire"));
        lib.add(new Book("B102", "Malgudi Days"));
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            String cmd = in.next(), isbn = in.next();
            try {
                if (cmd.equals("borrow"))
                    lib.borrow(isbn, in.next(), LocalDate.parse(in.next()));
                else
                    lib.giveBack(isbn, LocalDate.parse(in.next()));
            } catch (BookNotAvailableException e) {
                System.out.println("Sorry: " + e.getMessage());
            }
        }
    }
}

Output:

Asha took Wings of Fire
Sorry: B101 is out
Sorry: no book B109
Ravi took Malgudi Days
Asha returned B101, fine Rs 10
Ravi returned B102, fine Rs 0

How it's organised: layers

Layer In this project Job
Interface the Scanner command loop talks to the user
Service class Library the rules: no double loan, fines
Model record Book, record Loan plain data
Errors BookNotAvailableException says why something was refused
Storage books.csv keeps data after the program stops (a database later)

Splitting a program into layers lets you change one (say, files → a database) without touching the others. Spring Boot applications are built exactly this way (controller, service, model, repository).

Common mistakes (and what you see)

Mistake What you see Why Fix
new String[3], then a 4th book java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3 arrays have a fixed size a Map or List
issuedTo.put(isbn, member) with no check no error: the old loan is silently replaced put overwrites an existing key check first, throw an exception
calling lib.borrow(...) without try/catch error: unreported exception BookNotAvailableException; must be caught or declared to be thrown it's a checked exception try/catch, or throws
issuedTo.remove(k) inside for (String k : issuedTo.keySet()) java.util.ConcurrentModificationException the map changed under the loop removeIf
Files.readAllLines on the first run java.nio.file.NoSuchFileException: books.csv the file isn't there yet check Files.exists first
split(",") on a title with a comma no error: fields shifted, wrong data the comma is also the separator a CSV library or another separator

The safe way to remove while looping:

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Map<String, String> issuedTo = new HashMap<>(Map.of("B101", "Asha", "B102", "Ravi", "B103", "Asha"));
        issuedTo.values().removeIf(member -> member.equals("Asha"));   // safe removal
        System.out.println(issuedTo);
    }
}

Output:

{B102=Ravi}

Mini project: a waiting list

When a book is out, members join a waiting list; when it comes back, the first one waiting gets it. That's a FIFO queue (episode 33), one per book.

import java.util.*;

class Library {
    private final Map<String, String> issuedTo = new HashMap<>();
    private final Map<String, Deque<String>> waiting = new HashMap<>();   // isbn -> queue of members

    void borrow(String isbn, String member) {
        if (issuedTo.containsKey(isbn)) {
            waiting.computeIfAbsent(isbn, k -> new ArrayDeque<>()).offer(member);
            System.out.println(member + " joins the waiting list for " + isbn);
        } else {
            issuedTo.put(isbn, member);
            System.out.println(member + " took " + isbn);
        }
    }
    void giveBack(String isbn) {
        String old = issuedTo.remove(isbn);
        System.out.println(old + " returned " + isbn);
        Deque<String> q = waiting.get(isbn);
        if (q != null && !q.isEmpty()) borrow(isbn, q.poll());   // first come, first served
    }
}

public class Main {
    public static void main(String[] args) {
        Library lib = new Library();
        lib.borrow("B101", "Asha");
        lib.borrow("B101", "Ravi");
        lib.borrow("B101", "Neha");
        lib.giveBack("B101");
        lib.giveBack("B101");
    }
}

Output:

Asha took B101
Ravi joins the waiting list for B101
Neha joins the waiting list for B101
Asha returned B101
Ravi took B101
Ravi returned B101
Neha took B101

Practice

  1. Add a Member record and a limit of 3 books per member.
  2. Search books by a word in the title (ignore upper/lower case), sorted by title.
  3. Save the loans too, and load them at start-up (the first run has no file yet).
  4. A report: the top 3 most borrowed books.
Solution 1
import java.util.*;

record Member(String id, String name) {}
class LimitReachedException extends Exception {
    LimitReachedException(String msg) { super(msg); }
}

class Library {
    static final int LIMIT = 3;
    private final Map<String, Member> members = new HashMap<>();
    private final Map<String, String> issuedTo = new HashMap<>();   // isbn -> member id

    void addMember(Member m) { members.put(m.id(), m); }
    long countFor(String memberId) {
        return issuedTo.values().stream().filter(memberId::equals).count();
    }
    void borrow(String isbn, String memberId) throws LimitReachedException {
        if (countFor(memberId) >= LIMIT)
            throw new LimitReachedException(members.get(memberId).name() + " already has " + LIMIT + " books");
        issuedTo.put(isbn, memberId);
        System.out.println(members.get(memberId).name() + " took " + isbn);
    }
}

public class Main {
    public static void main(String[] args) {
        Library lib = new Library();
        lib.addMember(new Member("M1", "Asha"));
        for (String isbn : List.of("B101", "B102", "B103", "B104")) {
            try {
                lib.borrow(isbn, "M1");
            } catch (LimitReachedException e) {
                System.out.println("Sorry: " + e.getMessage());
            }
        }
    }
}

Output:

Asha took B101
Asha took B102
Asha took B103
Sorry: Asha already has 3 books
Solution 2
import java.util.*;

record Book(String isbn, String title, String author) {}

public class Main {
    static List<Book> search(Collection<Book> books, String word) {
        String w = word.toLowerCase();
        return books.stream()
                    .filter(b -> b.title().toLowerCase().contains(w))
                    .sorted(Comparator.comparing(Book::title))
                    .toList();
    }
    public static void main(String[] args) {
        List<Book> books = List.of(new Book("B101", "Wings of Fire", "Kalam"),
                                   new Book("B102", "Malgudi Days", "Narayan"),
                                   new Book("B105", "The Fire Next Time", "Baldwin"),
                                   new Book("B103", "Godaan", "Premchand"));
        search(books, "fire").forEach(System.out::println);
        System.out.println("days: " + search(books, "DAYS").size() + " book(s)");
    }
}

Output:

Book[isbn=B105, title=The Fire Next Time, author=Baldwin]
Book[isbn=B101, title=Wings of Fire, author=Kalam]
days: 1 book(s)
Solution 3
import java.io.IOException;
import java.nio.file.*;
import java.time.LocalDate;
import java.util.*;

record Loan(String isbn, String member, LocalDate issued) {
    String toLine() { return isbn + "," + member + "," + issued; }
    static Loan fromLine(String line) {
        String[] p = line.split(",");
        return new Loan(p[0], p[1], LocalDate.parse(p[2]));
    }
}

public class Main {
    static final Path FILE = Path.of("loans.csv");

    static Map<String, Loan> load() throws IOException {
        Map<String, Loan> loans = new HashMap<>();
        if (!Files.exists(FILE)) return loans;                 // first run: nothing saved yet
        for (String line : Files.readAllLines(FILE)) {
            Loan l = Loan.fromLine(line);
            loans.put(l.isbn(), l);
        }
        return loans;
    }
    static void save(Map<String, Loan> loans) throws IOException {
        Files.write(FILE, loans.values().stream().map(Loan::toLine).toList());
    }
    public static void main(String[] args) throws IOException {
        Map<String, Loan> loans = load();
        System.out.println("Start-up: " + loans.size() + " loans");
        loans.put("B101", new Loan("B101", "Asha", LocalDate.of(2026, 11, 1)));
        loans.put("B102", new Loan("B102", "Ravi", LocalDate.of(2026, 11, 3)));
        save(loans);
        System.out.println("After restart: " + load().values());
    }
}

Output:

Start-up: 0 loans
After restart: [Loan[isbn=B101, member=Asha, issued=2026-11-01], Loan[isbn=B102, member=Ravi, issued=2026-11-03]]
Solution 4
import java.util.*;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        List<String> history = List.of("B101", "B102", "B101", "B103", "B104",
                                        "B101", "B103", "B102", "B103", "B105");
        Map<String, Long> times = history.stream()
            .collect(Collectors.groupingBy(isbn -> isbn, Collectors.counting()));
        times.entrySet().stream()
             .sorted(Map.Entry.<String, Long>comparingByValue().reversed()
                     .thenComparing(Map.Entry.comparingByKey()))
             .limit(3)
             .forEach(e -> System.out.println(e.getKey() + ": " + e.getValue() + " times"));
    }
}

Output:

B101: 3 times
B103: 3 times
B102: 2 times

Ties (B101 and B103, 3 times each) are broken by ISBN with thenComparing.

Quick quiz

Map<String, String> m = new HashMap<>();
m.put("B101", "Asha");
m.put("B101", "Ravi");
System.out.println(m);

A) {B101=Asha} B) {B101=Ravi} C) {B101=Asha, B101=Ravi} D) a compile error

Answer

B. A map holds one value per key; the second put replaces Asha with Ravi silently (and returns "Asha"). That is exactly why borrow must check first.

Interview questions

How would you design a library management system?

Start from requirements, then pick the objects: Book, Member, Loan (model), a Library service holding the rules, exceptions for refusals, and a storage layer behind an interface so files can be swapped for a database. Mention maps by ID for O(1) lookup, and how fines are computed from dates.

Checked or unchecked: which would you use for "book not available", and why?

It is an expected business situation the caller can handle (show a message, offer the waiting list), so a checked exception is reasonable: the compiler forces callers to deal with it. Many modern codebases prefer unchecked exceptions for less boilerplate; either is defensible if you explain the trade-off.

Why use a record for Book?

It is plain, immutable data: a record gives the constructor, accessors, equals, hashCode and toString in one line, and immutability means a book can't be changed by accident while it sits in a map.

What does Map.put return?

The previous value for that key, or null if there was none. Checking it (or using putIfAbsent) would also have caught the double loan.

How do you avoid ConcurrentModificationException?

Don't change a collection while a for-each loop walks it. Use removeIf, an explicit Iterator and its remove(), or collect the keys first and remove after the loop.

Glossary

Term Meaning Example
Capstone project a final project that combines everything learned this library system
Requirements the list of things the software must do, written before code "never give one copy to two members"
Parallel arrays several arrays where slot i of each belongs to the same item titles[i], authors[i]
ArrayIndexOutOfBoundsException thrown when an array index is below 0 or ≥ its length index 3 of a length-3 array
Record a compact class for immutable data with accessors, equals, hashCode, toString generated record Book(String isbn, String title, String author)
ISBN International Standard Book Number, a book's unique ID B101 in our examples
Map / HashMap stores key → value pairs; a hash map finds a key in O(1) on average books.get("B103")
LinkedHashMap a hash map that remembers insertion order books listed in the order added
Encapsulation keeping data private and changing it only through methods private final Map inside Library
Custom exception your own exception class BookNotAvailableException
Checked exception an exception the compiler forces you to catch or declare extends Exception, IOException
throw / throws throw raises an exception; throws in a signature declares it throws BookNotAvailableException
try / catch run code, and handle an exception if one is thrown the polite "Sorry" message
LocalDate a date without a time of day LocalDate.of(2026, 11, 1)
ChronoUnit.DAYS.between number of days between two dates due 15 Nov, today 20 Nov → 5
Collectors.groupingBy groups stream items by a key into a map fines per member
RAM the computer's working memory, wiped when a program stops objects in our maps
Persistence keeping data after the program stops saving to books.csv
CSV comma-separated values: one record per line B101,Wings of Fire,Kalam
Files.write / Files.readAllLines write a list of lines to a file / read all lines back save and load
Scanner reads input token by token in.next()
Layers splitting a program into interface, service, model, storage change files to a database alone
ConcurrentModificationException thrown when a collection changes while being iterated remove inside for-each
Waiting list (queue) first in, first out list of members waiting for a book ArrayDeque.offer / poll

Summary

  • Write the requirements first; then choose the objects.
  • Arrays have a fixed size and parallel arrays drift apart: use a record per thing and a map by ID.
  • Map.put silently replaces an existing key: check first.
  • A checked custom exception makes callers handle the refusal (throw, throws, try/catch).
  • LocalDate, plusDays and ChronoUnit.DAYS.between count due dates and fines; groupingBy totals per member.
  • Files.write / Files.readAllLines give persistence; check Files.exists on the first run.
  • Organise code in layers (interface, service, model, storage): the shape of every Spring Boot app.
  • Next episode: Java interview questions and the road to Spring Boot.