Classes And Objects
Classes & Objects
Tier 2 of the Java book — the OOP leap. Four chapters move from procedural code to objects: defining classes, hiding state behind a controlled interface, the class-vs-instance distinction, and the reference model (stack/heap, == vs .equals, null) that underlies every Java surprise. Every example compiled and run.
Suggest an editClasses & Objects
This is Tier 2, where Java becomes object-oriented. Tier 1 gave you decisions, loops, arrays, and methods — procedural building blocks. Here the unit of design changes: instead of methods acting on loose data, you bundle data and behavior into classes and build objects from them. The tier ends with the chapter everything rests on — the reference model — which turns the "surprises" of earlier tiers into predictable consequences.
Four chapters, in order:
- Classes & Objects — fields and methods bundled into a blueprint,
new, constructors,this, and independent instances. - Encapsulation & Access Modifiers —
private, getters/setters that enforce invariants, the four access levels, and immutability by design. staticvs Instance — class-level shared state vs per-object state, why astaticmethod has nothis,static finalconstants, andstaticblocks.- References, Equality & the Object Model — the flagship: stack vs heap, values vs references,
==vs.equals(with the Integer cache and String pool), andnull.
Every code block with a ▶ Run button is live. At this tier the highest-value habit is to draw the references: when an example aliases two variables or compares two objects, sketch which variables point at which heap objects before you predict the output. The reference model chapter gives you that picture explicitly.
📘 How to read the Intuition boxes. Each one is built in three moves:
- The mechanism — what the compiler and the JVM are actually doing.
- A concrete bite — a specific, runnable failure (often a real compiler error), shown so the trap is visible.
- The earned rule — the decision heuristic, now justified rather than asserted, plus its cost.