Exam Kit Question Bank — All 41

Question Bank — All 41

These are the 41 questions from your Question Bank 3 Merged.pdf, answered in everyday language.

Each answer is short enough to remember, and every one ends with "If you remember one thing" — so if the exam nerves hit, that line is what saves you.

Chapter 1 = Unit 1, Chapter 2 = Unit 2, and so on. They line up exactly.

Java version: all code targets Java 25 LTS (2025) and also compiles on Java 21 and Java 17.


How to use this page


Chapter 1 · Unit 1 — OOP and Java

1.1 · Define Object-Oriented Programming and its principles

In plain words: OOP is a way of writing programs where you build small "objects" that hold their own data and their own actions, instead of one long list of instructions.

Think of a school. Instead of one giant register of everything, you have separate records — one per student — each holding that student's name, marks and attendance. Each record knows how to do its own jobs.

The four principles:

Principle In plain words
Encapsulation Keep the data private, hand out keys only through methods
Inheritance A child class borrows everything from its parent, then adds its own
Polymorphism One name, many behaviours — draw() means different things for a circle and a square
Abstraction Show the button, hide the wiring

If you remember one thing: the four pillars are encapsulation, inheritance, polymorphism, abstraction. Say all four even if you can only explain two.


1.2 · Explain encapsulation with an example

In plain words: Encapsulation means hiding your data inside a class and letting people touch it only through methods you control.

Think of an ATM. You press buttons — you never reach inside and move the cash yourself. The machine decides what is allowed.

class Account {
    private double balance;              // hidden from outside

    public void deposit(double amount) {
        if (amount > 0) {                // you decide the rules
            balance += amount;
        }
    }
    public double getBalance() {
        return balance;
    }
}

public class Main {
    public static void main(String[] args) {
        Account a = new Account();
        a.deposit(5000);
        // a.balance = -999;             // ❌ not allowed - it's private
        System.out.println(a.getBalance());   // 5000.0
    }
}

Why bother? Because deposit() can reject a negative number. If balance were public, anyone could set it to −999 and break your program.

If you remember one thing: private data + public getters and setters.


1.3 · Difference between a class and an object

In plain words: A class is the plan. An object is the thing built from the plan.

Class Object
The blueprint The real item
Takes no memory Takes memory in the heap
Written once Can be many
class Dog { } Dog d = new Dog();

One cookie cutter, many cookies. The cutter has no taste — only the cookies do.

If you remember one thing: "A class is a blueprint and takes no memory; an object is an instance and lives in memory."


1.4 · Why is Java important as an OOP language?

In plain words: Java does the four OOP things well, and it also runs everywhere without changes.

Used in real life: Android apps, bank back-ends, retail billing systems, big-data tools like Hadoop.

If you remember one thing: "write once, run anywhere" — that's the sentence that earns the mark.


1.5 · What is bytecode? How is it different from machine code?

In plain words: Bytecode is a halfway language. Not English, not machine code — something only the JVM understands.

Think of a document written in Esperanto. Not anyone's native language, but there's a translator (the JVM) on every computer.

Bytecode Machine code
Runs on any JVM Runs on one kind of CPU
File ends .class File ends .exe
Platform independent Platform dependent

The flow:

Hello.java --javac--> Hello.class --JVM--> your output

If you remember one thing: "JVM is platform-dependent, but Java is not." The JVM is built separately for each OS; the bytecode it runs is the same everywhere.


1.6 · What do JVM, JDK and JRE do?

In plain words: Three layers, one inside the other.

Name Its job Think of it as
JVM Runs the .class file The player
JRE JVM + built-in libraries The player + the films
JDK JRE + the tools to write code The player + films + the camera

JDK ⊃ JRE ⊃ JVM

You write with the JDK. You run with the JRE. The JVM does the actual work.

If you remember one thing: JDK contains JRE contains JVM. Write it as a nest, not as three separate things.


Chapter 2 · Unit 2 — Language Basics

2.1 · Primitive data types and their default values

In plain words: Java has 8 basic types for simple values. Everything else is an object.

Type Size Holds Default
byte 1 byte tiny whole numbers 0
short 2 bytes small whole numbers 0
int 4 bytes normal whole numbers 0
long 8 bytes huge whole numbers 0L
float 4 bytes decimals (less exact) 0.0f
double 8 bytes decimals (more exact) 0.0
char 2 bytes one letter '\u0000'
boolean 1 bit true / false false

Objects like String and arrays default to null.

If you remember one thing: numbers default to 0, boolean to false, char to '\u0000', and objects to null.


2.2 · Type conversion and casting

In plain words: Moving a value from one type to another. Small → big happens automatically. Big → small needs a cast and can lose data.

int a = 10;
double b = a;          // widening - automatic, safe
System.out.println(b); // 10.0

double x = 9.78;
int y = (int) x;       // narrowing - you must cast
System.out.println(y); // 9   <- the .78 is chopped off

Careful: it truncates, it does not round. (int) 9.99 gives 9, not 10. Use Math.round() if you want rounding.

If you remember one thing: widening is automatic and safe; narrowing needs a cast and may lose data.


2.3 · Types of operators; explain arithmetic and logical

In plain words: An operator is a symbol that does something to values.

Family Symbols
Arithmetic + - * / %
Relational == != > < >= <=
Logical && \|\| !
Bitwise & \| ^ ~ << >>
Assignment = += -= *= /=
Unary ++ --
Ternary ? :

Arithmetic does maths. Watch out: dividing two whole numbers throws away the decimals.

System.out.println(10 / 3);     // 3      <- not 3.33
System.out.println(10 / 3.0);   // 3.3333 <- one decimal changes everything
System.out.println(10 % 3);     // 1      <- remainder

Logical combines true/false values, and stops early when the answer is already known.

int age = 20;
boolean id = true;
System.out.println(age >= 18 && id);   // true
System.out.println(age >= 18 || id);   // true

int b = 0;
System.out.println(b != 0 && 10 / b > 1);   // false, and no crash

If you remember one thing: 10 / 3 is 3, not 3.33. That single fact appears on nearly every paper.


2.4 · Scope and lifetime of variables

In plain words: Scope = where you can see the variable. Lifetime = how long it exists.

Think of a whiteboard in one classroom. Everyone in that room can read it (scope). When the class ends, it gets wiped (lifetime).

Kind Where declared Where usable Lives until
Local inside a method that block only the block ends
Instance in a class, outside methods the whole object the object is garbage collected
Static with static in a class the whole program the program ends
class Demo {
    int instanceVar = 10;          // one per object
    static int classVar = 20;      // one shared copy

    void show() {
        int localVar = 5;          // exists only here
        System.out.println(localVar);
    }
    // System.out.println(localVar);   ❌ can't see it out here
}

If you remember one thing: local exists only inside its braces. Instance belongs to the object. Static belongs to the class.


2.5 · Define dynamic initialization

In plain words: Setting a variable's value while the program runs, using an expression, instead of typing a fixed number when you write the code.

public class Main {
    public static void main(String[] args) {
        int a = 10, b = 5;

        int sum  = a + b;             // calculated while running
        double avg = sum / 2.0;
        double root = Math.sqrt(144);
        int max = (a > b) ? a : b;

        System.out.println(sum);      // 15
        System.out.println(avg);      // 7.5
        System.out.println(root);     // 12.0
        System.out.println(max);      // 10
    }
}

Why it matters: the value might come from user input, a file, or another variable — things you can't know when you write the code.

If you remember one thing: the value is worked out at run time, not typed in at compile time.


Chapter 3 · Unit 2 — Control Statements

3.1 · Syntax and usage of if-else and switch

In plain words: if asks a yes/no question. switch picks from a list of options.

Think of a fork in a road (if) versus a lift with numbered buttons (switch).

// if-else
int marks = 78;
if (marks >= 90)      System.out.println("A");
else if (marks >= 75) System.out.println("B");
else                  System.out.println("C");

// switch
int day = 3;
switch (day) {
    case 1: System.out.println("Monday");    break;
    case 3: System.out.println("Wednesday"); break;
    default: System.out.println("Other");
}
if-else switch
Checks any true/false test one value against fixed options
Types anything int, char, String, enum
Range checks yes no

Watch out: forget break and Java falls through into the next case. That's the classic trap.

If you remember one thing: switch needs break; if doesn't.


3.2 · How does while differ from for?

In plain words: Use while when you don't know how many times to repeat. Use for when you do know.

Think of while as "keep stirring until it thickens" and for as "stir 10 times".

int i = 1;
while (i <= 5) {          // continue while something is true
    System.out.println(i);
    i++;                  // you must remember to change it
}

for (int j = 1; j <= 5; j++) {   // everything in one line
    System.out.println(j);
}

do-while always runs at least once, because it checks the condition at the end.

If you remember one thing: while = condition-driven. for = count-driven.


3.3 · What are jump statements?

In plain words: Instructions that jump you somewhere else.

Statement What it does
break Leave the loop or switch immediately
continue Skip the rest of this round, go to the next
return Leave the whole method

If you remember one thing: break quits, continue skips, return exits the method.


3.4 · Program using conditional and looping statements

In plain words: One program that shows an if, a switch and a loop together.

public class Main {
    public static void main(String[] args) {

        int marks = 78;
        if (marks >= 90)      System.out.println("A");
        else if (marks >= 75) System.out.println("B");
        else                  System.out.println("C");

        int day = 3;
        switch (day) {
            case 1: System.out.println("Mon"); break;
            case 3: System.out.println("Wed"); break;
            default: System.out.println("Other");
        }

        for (int i = 1; i <= 5; i++) System.out.print(i + " ");
        System.out.println();

        int i = 1, sum = 0;
        while (i <= 5) { sum += i; i++; }
        System.out.println("sum = " + sum);
    }
}
B
Wed
1 2 3 4 5
sum = 15

3.5 · Difference between break and continue

In plain words: break quits the loop. continue skips one round.

Think of a queue. break = you leave the queue. continue = you step aside for one person, then rejoin.

for (int i = 1; i <= 5; i++) {
    if (i == 3) break;
    System.out.print(i + " ");       // 1 2
}

for (int i = 1; i <= 5; i++) {
    if (i == 3) continue;
    System.out.print(i + " ");       // 1 2 4 5
}

If you remember one thing: after break the loop is gone; after continue it carries on.


Chapter 4 · Unit 3 — Arrays

4.1 · What are arrays? Explain the types

In plain words: An array is a row of boxes that all hold the same kind of thing, and the row is a fixed length.

Think of an egg carton: exactly 12 slots, all for eggs, numbered 0 to 11.

Type Example
One-dimensional int[] a = new int[5];
Two-dimensional int[][] m = new int[3][4];
Jagged rows of different lengths

Four rules: fixed size · stored in order · same type · one name.

If you remember one thing: counting starts at 0, not 1. A 5-slot array runs 0 to 4.


4.2 · Multidimensional arrays

In plain words: In Java, a 2D array is really an array of arrays. Each row is its own separate array — which means rows can have different lengths.

int[][] m = {
    {7, 3, -5, 10},
    {11, 13, -15, 2}
};

System.out.println(m.length);       // 2  <- number of ROWS
System.out.println(m[0].length);    // 4  <- length of row 0

If you remember one thing: m.length gives rows, m[0].length gives columns.


4.3 · Program to find the largest element in an array

In plain words: Assume the first number wins. Look at each remaining number. If it's bigger, it becomes the new winner.

public class Main {
    public static void main(String[] args) {
        int[] a = {12, 45, 7, 89, 23, 56};

        int max = a[0];
        for (int i = 1; i < a.length; i++) {
            if (a[i] > max) max = a[i];
        }
        System.out.println("Largest = " + max);
    }
}
Largest = 89

4.4 · How are arrays stored in memory?

In plain words: An array is a single object sitting in the heap, with all its boxes next to each other. Your variable only holds the address, not the data.

Stack                 Heap
┌─────┐          ┌────┬────┬────┬────┐
│  a  │────────► │ 10 │ 20 │ 30 │ 40 │
└─────┘          └────┴────┴────┴────┘
                  [0]  [1]  [2]  [3]

Because the boxes are next to each other, Java can jump straight to any index — that's why a[2] is instant.

If you remember one thing: arrays live in the heap, and the variable only holds a reference to them.


4.5 · How do you pass arrays to a function?

In plain words: Java always passes by value. But for an array, the "value" is the address. So the method can change the contents, but cannot make your variable point somewhere else.

public class Main {
    static void doubleAll(int[] arr) {      // changes the contents
        for (int i = 0; i < arr.length; i++) arr[i] *= 2;
    }
    static void replace(int[] arr) {        // only changes its own copy
        arr = new int[]{99, 99};
    }

    public static void main(String[] args) {
        int[] a = {1, 2, 3};
        doubleAll(a);
        System.out.println(java.util.Arrays.toString(a));   // [2, 4, 6]
        replace(a);
        System.out.println(java.util.Arrays.toString(a));   // [2, 4, 6] - unchanged
    }
}

If you remember one thing: you can change what's inside the array, but not which array it points to.


Chapter 5 · Unit 4 — Classes and Constructors

5.1 · What are classes and objects? How do you declare and initialise them?

In plain words: A class declares the shape. An object is one real copy of it.

class Student {
    int rollNo;
    String name;

    void show() {
        System.out.println(rollNo + " " + name);
    }
}

public class Main {
    public static void main(String[] args) {
        Student s = new Student();      // create
        s.rollNo = 101;                 // fill in
        s.name = "Aarav";
        s.show();                       // 101 Aarav
    }
}

Watch out: Student s2 = s; does not copy the object. Both names now point at the same one.


5.2 · Constructors with an example

In plain words: A constructor is the setup code that runs the moment you create an object. It fills in the starting values.

Three rules: the name is exactly the class name · it has no return type · it runs once per object.

class Cube {
    double w, h, d;

    Cube(double w, double h, double d) {   // parameterized
        this.w = w; this.h = h; this.d = d;
    }
    double volume() { return w * h * d; }
}

public class Main {
    public static void main(String[] args) {
        Cube c = new Cube(10, 10, 10);
        System.out.println(c.volume());     // 1000.0
    }
}

If you remember one thing: if you write no constructor, Java gives you an empty one. Once you write your own, that free one disappears.


5.3 · Method overloading vs method overriding

In plain words:

Think of one person called "Alex" who can carry 1 bag, 2 bags, or 3 bags (overloading). Then think of a son who says "in our house, dinner is at 9, not 8" (overriding).

Overloading Overriding
Same class Parent + child
Inputs differ Inputs identical
Decided before running Decided while running
Compile-time polymorphism Runtime polymorphism
class Calc {
    int add(int a, int b)        { return a + b; }   // 2 numbers
    int add(int a, int b, int c) { return a + b + c; } // 3 numbers
}
class Animal { void sound() { System.out.println("animal"); } }
class Dog extends Animal {
    @Override
    void sound() { System.out.println("dog"); }
}
public class Main {
    public static void main(String[] args) {
        Calc c = new Calc();
        System.out.println(c.add(2, 3));        // 5
        System.out.println(c.add(2, 3, 4));     // 9
        Animal a = new Dog();
        a.sound();                              // dog
    }
}

If you remember one thing: overloading changes the inputs; overriding changes the body.


5.4 · How does garbage collection work?

In plain words: Garbage collection is Java's automatic cleaner. When an object can no longer be reached by any name, Java quietly frees its memory.

Think of a hotel room. When the guest checks out and takes all their luggage and keys, housekeeping clears the room — you don't do it.

Point Detail
Who runs it The JVM, automatically
What it cleans objects nothing points to anymore
Where the heap
Can you force it? System.gc() is only a request, not a command
Destructors? None in Java
Student s = new Student();
s = null;                    // now nothing points at that object
                             // it becomes eligible for collection

If you remember one thing: Java has no destructors — the JVM does it for you, whenever it decides to. (C++ has destructors; Java does not.)


5.5 · static vs final

In plain words: static means "belongs to the class, shared by everyone." final means "locked, cannot change."

Think of static as the school notice board — one board, everyone reads it. final is a printed certificate — once printed, no edits.

static final
One shared copy Cannot be reassigned
Callable without an object Method cannot be overridden
Nested classes only Class cannot be extended
class Counter {
    static int total = 0;     // shared
    int own = 0;              // per object
    Counter() { total++; own++; }
}
public class Main {
    public static void main(String[] args) {
        new Counter();
        new Counter();
        System.out.println(Counter.total);   // 2
    }
}

If you remember one thing: static = shared. final = frozen.


Chapter 6 · Unit 4 — Inheritance

6.1 · What is inheritance? Explain with an example

In plain words: A child class gets everything from its parent, then adds its own extras. You write the shared code once.

Think of a family business. The child inherits the shop and the name, then opens a new counter of their own.

class Vehicle {
    void start() { System.out.println("started"); }
}
class Bike extends Vehicle {
    void ride() { System.out.println("riding"); }
}
public class Main {
    public static void main(String[] args) {
        Bike b = new Bike();
        b.start();     // inherited
        b.ride();      // its own
    }
}

Five types: single · multilevel · hierarchical · multiple (interfaces only) · hybrid (interfaces only).

If you remember one thing: extends means "is a kind of". A Bike is a Vehicle.


6.2 · How does super work?

In plain words: super means "my parent". You use it to call the parent's constructor, method or field.

class Person {
    String name;
    Person(String name) {
        this.name = name;
        System.out.println("Person: " + name);
    }
}
class Employee extends Person {
    int id;
    Employee(String name, int id) {
        super(name);              // must be the FIRST line
        this.id = id;
        System.out.println("Employee: " + id);
    }
}
public class Main {
    public static void main(String[] args) {
        new Employee("Riya", 501);
    }
}
Person: Riya
Employee: 501

Notice: the parent always finishes first.

If you remember one thing: super() must be the first line of the child's constructor.


6.3 · Method overriding with an example

In plain words: The child writes its own version of a method the parent already has — same name, same inputs — and Java uses the child's version.

class Animal {
    void sound() { System.out.println("some sound"); }
}
class Dog extends Animal {
    @Override
    void sound() { System.out.println("dog barks"); }
}
public class Main {
    public static void main(String[] args) {
        Animal a;
        a = new Dog();
        a.sound();          // dog barks  <- uses the real object, not the label
    }
}

Rules: same name · same inputs · same return type · cannot reduce the access level · final, static and private methods cannot be overridden.

If you remember one thing: Java looks at the real object, not the type of the variable.


6.4 · What are abstract classes and when would you use them?

In plain words: An abstract class is half-built. Some methods work already, some are just empty promises you must fill in later. You cannot create one directly.

Think of a recipe a chef started. Some steps are done; the last ones are left blank for you.

abstract class Shape {
    abstract void draw();                 // you must fill this in
    void describe() {
        System.out.println("a shape");    // this already works
    }
}

class Square extends Shape {
    void draw() { System.out.println("square"); }
}

public class Main {
    public static void main(String[] args) {
        // Shape s = new Shape();   ❌ cannot create an abstract class
        Shape s = new Square();     // ✅ but a variable can hold one
        s.draw();
        s.describe();
    }
}
square
a shape

Use one when: several classes share the same code and differ only in a few steps.

If you remember one thing: abstract class = shared code + empty promises.


6.5 · Dynamic method dispatch

In plain words: The decision about which version of a method to run is made while the program runs, based on the real object — not on the type of the variable.

Think of a manager telling staff "call the driver". Whoever is actually driving answers — not the job title.

class Shape { void draw() { System.out.println("shape"); } }
class Circle extends Shape { void draw() { System.out.println("circle"); } }
class Box extends Shape { void draw() { System.out.println("box"); } }

public class Main {
    public static void main(String[] args) {
        Shape[] all = { new Circle(), new Box() };
        for (Shape s : all) {
            s.draw();      // picks the right one automatically
        }
    }
}
circle
box

Why it matters: you can add a new shape later without changing this loop.

If you remember one thing: it's how Java decides at run time which overridden method to run.


Chapter 7 · Unit 7 — Strings, Packages, Interfaces

7.1 · String manipulation with examples

In plain words: String comes with ready-made tools for cutting, searching and changing text. And a String never changes — every edit hands you a brand-new one.

public class Main {
    public static void main(String[] args) {
        String s = "  Hello Java  ";

        System.out.println("[" + s.trim() + "]");          // [Hello Java]
        System.out.println(s.trim().toUpperCase());        // HELLO JAVA
        System.out.println(s.trim().charAt(0));            // H
        System.out.println(s.trim().substring(0, 5));      // Hello
        System.out.println(s.trim().indexOf("Java"));      // 6
        System.out.println(s.trim().replace("Java","C++"));// Hello C++

        String[] parts = "a,b,c".split(",");
        System.out.println(parts.length);                  // 3

        System.out.println("Java" == "Java");              // true
        System.out.println("Java" == new String("Java"));  // false
        System.out.println("Java".equals(new String("Java"))); // true
    }
}

If you remember one thing: use .equals() to compare text, not ==. == asks "are these the same object", not "do they say the same thing".


7.2 · Difference between a class and an interface

In plain words: A class is a real thing you can build. An interface is just a list of promises — no building allowed.

Class Interface
Can be created with new Cannot be created
Can have constructors No constructors
Has working methods Only promises by default
Can extend one class Can implement many interfaces

If you remember one thing: an interface can never be new-ed. That one sentence is worth a mark.


7.3 · Program that implements an interface

interface Drawable {
    void draw();
}
class Circle implements Drawable {
    public void draw() { System.out.println("circle"); }
}
class Box implements Drawable {
    public void draw() { System.out.println("box"); }
}
public class Main {
    public static void main(String[] args) {
        Drawable d;
        d = new Circle(); d.draw();    // circle
        d = new Box();    d.draw();    // box
    }
}

7.4 · Purpose of packages; how to create one

In plain words: A package is a folder for classes. It stops name clashes and keeps related things together.

Think of a filing cabinet. Two people can both be called "Rahul Sharma" — in different folders, no confusion.

Benefits: avoids name clashes · groups related classes · controls access · reusable · easier to maintain.

Steps: 1. Put package mypack; as the very first line 2. Compile with javac -d . MyClass.java — the -d creates the folder 3. Write import mypack.MyClass; where you need it 4. Run with java -cp . Main

If you remember one thing: the -d flag in javac -d . is what builds the folder structure. Most students forget it.


7.5 · Enumerations in Java

In plain words: An enum is a short way to list a fixed set of allowed values. Nothing outside the list can be used.

Think of a traffic light — only red, yellow, green exist. Any other colour is not a valid state.

enum Day { MON, TUE, WED, THU, FRI }

public class Main {
    public static void main(String[] args) {
        Day d = Day.WED;
        System.out.println(d);              // WED
        System.out.println(d.ordinal());    // 2  (counts from 0)

        for (Day x : Day.values()) System.out.print(x + " ");
        System.out.println();
    }
}
WED
2
MON TUE WED THU FRI

Why better than plain numbers: if you write Day.MONDAY and it isn't in the list, the compiler stops you. A wrong int would slip through and fail later.


Chapter 8 · Unit 5 — Exceptions

8.1 · What are exceptions and their types?

In plain words: An exception is an error object. Something went wrong, Java creates a note describing it, and your code can catch that note and recover.

The family tree:

Throwable
├── Exception
│   ├── RuntimeException   ← unchecked (found while running)
│   └── IOException, SQLException …  ← checked (compiler makes you handle)
└── Error                  ← serious, do not catch
Kind Compiler forces handling? Examples
Checked Yes IOException, SQLException
Unchecked No ArithmeticException, NullPointerException
Error Should not catch OutOfMemoryError, StackOverflowError

If you remember one thing: Error is bad news you cannot recover from; Exception is usually something you can handle.


8.2 · Handling exceptions with try-catch

In plain words: Wrap risky code in try. If it breaks, catch takes over. If nothing breaks, catch never runs.

Think of a safety net under a trapeze artist. You hope it's never used — but you never perform without it.

public class Main {
    public static void main(String[] args) {
        try {
            int a = 10, b = 0;
            System.out.println(a / b);          // 💥 breaks here
        } catch (ArithmeticException e) {
            System.out.println("cannot divide by zero");
            System.out.println(e.getMessage()); // / by zero
        }
        System.out.println("still running");
    }
}
cannot divide by zero
/ by zero
still running

Notice: the program does not crash. That's the whole point.


8.3 · Program handling multiple exceptions with multi-catch

In plain words: One catch can handle several kinds of error at once, separated by |.

public class Main {
    public static void main(String[] args) {
        try {
            int[] a = new int[3];
            int x = 10 / 0;          // ArithmeticException
            a[5] = 9;                // would be ArrayIndexOutOfBounds
        }
        catch (ArithmeticException | NullPointerException e) {
            System.out.println("caught: " + e.getClass().getSimpleName());
        }
        catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("index problem");
        }
        finally {
            System.out.println("done");
        }
    }
}
caught: ArithmeticException
done

Careful: once an exception is caught, the rest of the try block is skipped. That's why only the first error is reported.

If you remember one thing: the pipe | lets one block catch several types.


8.4 · Checked vs unchecked exceptions

In plain words:

Think of airport security (checked — you cannot board without it) versus tripping on a step (unchecked — nobody warns you).

Checked Unchecked
Must catch or declare throws Optional
Found at compile time Found at run time
IOException, SQLException ArithmeticException, NullPointerException
Usually a file or network issue Usually a coding mistake

If you remember one thing: a checked exception is checked by the compiler.


8.5 · Why is finally important?

In plain words: finally always runs — whether the try succeeded, failed, got caught, or even returned early.

Think of going home after work. Whatever happened during the day, you still lock the door.

public class Main {
    public static void main(String[] args) {
        try {
            System.out.println("try");
            return;                       // early exit
        } finally {
            System.out.println("finally");   // STILL runs
        }
    }
}
try
finally

What it's for: closing files, network connections, scanners — the cleanup that must happen no matter what.

If you remember one thing: finally runs even after a return. Only System.exit() can stop it.


The 41, at a glance

Chapter Unit Questions What it's really about
1 1 6 What OOP is, and how Java runs
2 2 5 Types, casting, operators, scope
3 2 5 Decisions and loops
4 3 5 Arrays
5 4 5 Classes, constructors, memory
6 4 5 Inheritance and polymorphism
7 7 5 Strings, interfaces, packages
8 5 5 Exceptions
41