Phase VIII
Identity and Contracts
Input, immutability, equality, enums, and interface contracts.
Trace keyboard and file input through Java's I/O classes, then build immutable value types with explicit equality and hashing rules. Finish with enums and the interface features used by later collection and functional APIs.
When you finish this phase you can
- Explain the three layers in new BufferedReader(new InputStreamReader(System.in))
- Explain why buffering reduces calls to an underlying input source
- Build an immutable class, including defensive copies of mutable data
- Write equals and hashCode correctly, and state the contract between them
- Demonstrate how an incorrect equality contract breaks a hash-based lookup
- Choose an enum over int or String constants and explain the compiler checks gained
- Define a functional interface, and explain why a lambda needs one
- 8.1Java I/O: Streams, Scanner, BufferedReaderRead keyboard and file input with Scanner and BufferedReader, distinguish byte streams from character readers, and explain why buffering improves performance.Stream (I/O)Buffering
- 8.2Immutable ClassesBuild an immutable class by controlling construction, reassignment, mutation, inheritance, and references to mutable data.Immutability
- 8.3The Object Class: `equals`, `hashCode`, `toString`Override equals, hashCode, and toString correctly, and follow the equality contract required by hash-based collections.The Object classequals()hashCode()The equals and hashCode contracttoString()
- 8.4EnumsDefine a fixed set of named values, attach fields and methods to them, and use exhaustive switch expressions safely.enum
- 8.5Interface Methods and Functional InterfacesDistinguish abstract, default, static, private, marker, and functional interface features and choose each for a specific purpose.Default methodFunctional interfaceMarker interface