CSCD 211
Each week below lists what you will be able to do, in the order we teach it. Open a week to see its objectives. Click an objective to read its lesson. The checks and bars track your progress; nothing is ever locked.
Week 1Comparators, lambdas, and method references
Quiz w2 milestone
Comparable / Comparator: the Dual
- I can explain why a class has at most one natural order, and identify in source code whether a given class has declared one.Not started yet
- I can identify, in source code, all the Comparators defined for a given type and explain why each is a separate class rather than additional methods on the type.Not started yet
- I can choose, for a given type and ordering requirement, whether the ordering belongs in
compareTo(Comparable), in a separate Comparator, or in both, and justify the choice in one sentence.Not started yet
The `compare` Method Contract
- I can predict the sort outcome for return values that are positive, zero, or negative, independent of magnitude, and can write a
comparebody that returns sign-only.Not started yet - I can identify a comparator that violates antisymmetry or transitivity, predict the runtime failure mode, and correct the comparator.Not started yet
- I can predict, given a comparator that disagrees with
.equals, the surprising behavior of aTreeSetorTreeMapbuilt with that comparator, and explain when intentional inconsistency is appropriate.Not started yet
Comparator as a Named Class
- I can produce, given a class
Foowith a public accessor for some field, a completeFooByFieldComparator implements Comparator<Foo>class, including package declaration, imports,finalparameters,@Override, precondition check, and a one-line body that delegates to the field's natural order.Not started yet - I can identify the standard CSCD 211 package layout, name the package each kind of class belongs in, and explain why Comparators are separated from the data types they order.Not started yet
- I can produce a single line of code that sorts an array in place using a named comparator class, and explain why the comparator is constructed inline rather than stored in a variable.Not started yet
Comparator as an Anonymous Inner Class
- I can read an anonymous-class Comparator on sight, identify the type parameter, the implemented interface, and the override, and rewrite it as a lambda when the body permits.Not started yet
- I can choose between a lambda, a method reference, an anonymous class, and a named class for a given Comparator construction context, and justify the choice in one sentence per option ruled out.Not started yet
Comparator as a Lambda
- I can read and write a
Comparator<T>lambda in expression and block forms, identify the parameters and their inferred types, and translate between an anonymous-class Comparator and a lambda.Not started yet - I can identify the target type for a given lambda use site, verify the matching functional interface has a single abstract method, and predict compile errors when the target is ambiguous.Not started yet
- I can identify whether a captured local in a lambda is effectively final, predict the compile error when it is not, and apply one of the four standard escape valves when mutable state is genuinely required.Not started yet
Method References as a Comparator
- I can replace
(a, b) -> a - bwith the appropriateType::comparestatic method reference and explain why the replacement is preferred.Not started yet - I can read
String::compareTo(and similar) as the lambda(a, b) -> a.compareTo(b), and produce the corresponding method reference for any one-argument instance method.Not started yet - I can choose, given a one-line lambda body, whether it should be a method reference, and produce the reference form when applicable.Not started yet
Multiple Comparators for One Class
- I can name and explain the asymmetry between Comparable (one per type) and Comparator (unlimited per type), citing the F19 Lab 1 Player example.Not started yet
- I can declare a
public static final Comparator<T>field on a class, justify the choice over a separate Comparator class, and use the field at a call site.Not started yet - I can identify in source code (or design from a spec) a class that uses both Comparable and Comparator together, and explain the role each plays.Not started yet
Sorting Arrays and Lists with a Comparator
- I can write a single-line
Arrays.sortcall with a Comparator argument, predict the in-place mutation, and identify the runtime exceptions that can result from null arguments or contract violations.Not started yet - I can sort a
List<T>with a Comparator using both the modernlist.sort(cmp)and legacyCollections.sort(list, cmp)forms, and explain when each is appropriate.Not started yet - I can predict the result of two consecutive sorts on the same list, name the property (stability) that makes the result correct, and translate the two-pass form into a
thenComparingchain.Not started yet
The Subtraction-Trick Overflow Pitfall
- I can predict the failure mode of
(a, b) -> a - bfor at least one operand pair, name the contract violated, and describe the runtime symptom on Java 17.Not started yet - I can replace any broken
(a, b) -> a - b(or field-subtraction equivalent) with the appropriate type-specificcomparemethod orComparator.comparingInt/comparingLong/comparingDouble.Not started yet
Comparator Composition (Modern API)
- I can produce a
Comparator<T>usingComparator.comparingwith a method-reference key extractor, and can choose between the one-argument and two-argument overloads.Not started yet - I can build a multi-key
Comparator<T>usingComparator.comparing+thenComparingchains, and translate between this form and the legacy two-pass-stable-sort idiom.Not started yet - I can produce a Comparator that orders descending and one that handles nulls without NPE, using the
reversed,nullsFirst, andnullsLastdecorators.Not started yet - I can choose the appropriate primitive-friendly variant of
Comparator.comparingfor a given key extractor's return type, and explain why the variant is preferable to the boxing form.Not started yet
Week 2Composition, enums, and collections
Composition and Enums
HAS-A vs IS-A
- I can identify, in a class declaration, every HAS-A relationship by reading the field list, and articulate the relationship in English.Not started yet
- I can identify whether a relationship is HAS-A or IS-A from the source declaration, citing the keyword that establishes each.Not started yet
- I can apply Bloch's rule to a candidate design, choose HAS-A or IS-A and justify the choice in one sentence per ruled-out option.Not started yet
Association, Aggregation, Composition
- I can identify a "uses-a" relationship in code by recognizing it as a method parameter or local variable rather than a field.Not started yet
- I can distinguish aggregation from composition by inspecting the constructor: aggregation *receives* the reference, composition *constructs* internally.Not started yet
- I can identify composition in source code by recognizing constructor-internal
new(or constructor-parameter defensive copy), and explain why the contained object's lifetime is bounded by the container's.Not started yet
A class with a class-type field
- I can declare a class-type field with appropriate access modifier and initialize it in the constructor following Steiner standards (final params + IAE precondition).Not started yet
- I can predict, given a constructor body, whether the resulting class shares a reference with the caller or owns an independent copy, and choose the appropriate form for a given design intent.Not started yet
- I can write a constructor precondition check matching Steiner standards (
finalparams, IAE with class-named source message), and predict the runtime behavior when the check is missing.Not started yet
Defensive copy
- I can identify whether a given field type is immutable, and skip defensive copy when it is.Not started yet
- I can write a constructor that defensively copies a mutable reference parameter, given the contained type's accessors, and explain why direct assignment would be incorrect.Not started yet
- I can write a constructor body that defensively copies an array of mutable elements, copying both the outer array and each element, matching Steiner standards.Not started yet
Multiple EVCs and constructor delegation
Enum basics: finite named instances
- I can declare a bare-bones enum, name the SCREAMING_SNAKE_CASE convention for constants, and access individual constants via
EnumType.CONSTANT.Lesson coming soon - I can use
Enum.values()to iterate all constants, distinguishname()(safe) fromordinal()(brittle), and avoid persisting ordinals.Lesson coming soon - I can choose between bare-bones and enum-with-state for a given specification, and justify the choice in one sentence.Lesson coming soon
Enum with fields and methods
- I can declare an enum with instance fields and a private constructor, and explain why each constant has its own field values.Lesson coming soon
- I can write standard accessor methods on an enum and call them through a constant.Lesson coming soon
- I can declare enum constants with constructor arguments matching the declared constructor's signature.Lesson coming soon
Enum `toString` and display
- I can override
toString()on an enum to control the display, and predict the difference betweentoString()'s output andname()'s output.Lesson coming soon - I can implement the field + getter +
toStringtriplet on an enum, and explain when each access form is appropriate.Lesson coming soon
Enums in `switch`
- I can write a switch statement on an enum, use bare-name case labels, and avoid fall-through bugs by using
break.Lesson coming soon - I can write a switch expression with arrow form, predict the exhaustiveness check, and translate between classic switch and arrow form.Lesson coming soon
Enum natural order via `Comparable`
- I can predict the result of
enum.compareTobased on declaration order, and explain why the natural order cannot be overridden.Lesson coming soon - I can write a multi-key compareTo that delegates to enum compareTo as a tiebreaker, and explain when this is appropriate vs. brittle.Lesson coming soon
Composition of enums and collections
- I can declare a class with an enum field, write its constructor with appropriate preconditions, and explain why no defensive copy is needed.Lesson coming soon
- I can declare a class with an array-typed field of class-type elements, write a constructor that defensively copies element-by-element, and reason about the storage shape.Lesson coming soon
- I can read a class with mixed-mutability fields, classify each field's mutability, and predict whether the constructor's assignment is correct.Lesson coming soon
ArrayList and Collections (use-side)
Why a `List<E>` exists when arrays already do
- I can predict the size and capacity of an ArrayList through a sequence of
addandremovecalls.Lesson coming soon - I can identify a runtime ArrayStoreException risk in a covariant array assignment, and demonstrate the equivalent generic-list code is rejected at compile time.Lesson coming soon
- I can declare variables and parameters using
List<E>rather than concreteArrayList<E>, and explain when the concrete type is justified.Lesson coming soon
Constructing an ArrayList
- I can choose between the no-arg and capacity-hint constructors based on whether the expected size is known, and predict initial size.Lesson coming soon
- I can defensively copy a List parameter using the copy constructor, and predict whether mutations to the original affect the copy.Lesson coming soon
- I can choose between immutable
List.of(...)and mutablenew ArrayList<>(...)based on whether subsequent mutation is needed.Lesson coming soon
Reading from an ArrayList
- I can call
get(i)correctly, predict IndexOutOfBoundsException for invalidi, and reason aboutO(1)cost.Lesson coming soon - I can use
size()for loop bounds andisEmpty()for emptiness checks, and choose between them stylistically.Lesson coming soon - I can use
containsandindexOfcorrectly, predict equality semantics, and reason about O(n) cost.Lesson coming soon
Writing to an ArrayList
- I can append with
add(E)and insert withadd(int, E), and reason about the cost difference.Lesson coming soon - I can distinguish
set(i, x)(replace) fromadd(i, x)(insert) and predict size after each.Lesson coming soon - I can predict which overload of
removeis invoked given the argument type, and force the desired overload via boxing orObject-typed argument.Lesson coming soon
for-each and `Iterable<T>`
- I can write a for-each loop on a List, predict the iteration order, and identify when a traditional for-loop is needed.Lesson coming soon
- I can identify the abstract method on
Iterable<T>and explain how the compiler desugars for-each.Lesson coming soon
Explicit `Iterator<T>` and `ConcurrentModificationException`
- I can write an explicit-iterator loop and predict NoSuchElementException for over-advance.Lesson coming soon
- I can predict CME for structural modification during iteration, and identify it as a single-threaded problem despite the name.Lesson coming soon
- I can use Iterator.remove correctly and translate to/from removeIf.Lesson coming soon
Autoboxing and unboxing pitfalls
- I can identify autoboxing in code, predict the Integer cache range, and reason about cost in hot loops.Lesson coming soon
- I can identify code paths where unboxing might NPE and add a null check.Lesson coming soon
- I can predict when
==on Integer-typed values appears to work and when it silently breaks.Lesson coming soon
ArrayList vs array; sorting
- I can choose between
T[]andList<T>for a given specification.Lesson coming soon - I can sort a
List<E>with a Comparator using the modernlist.sort(cmp)form.Lesson coming soon - I can sort a List by natural order using Collections.sort or list.sort(null), and predict compile error for non-Comparable elements.Lesson coming soon
List equality, copying, and views
- I can predict the result of
list1.equals(list2)for twoListinstances given their sizes, element types, and element ordering, and explain why ordering matters.Lesson coming soon - I can produce a shallow independent copy of a
Listusingnew ArrayList<>(other)orList.copyOf, predict whether subsequent mutations affect the original, and choose between the two based on whether the result needs to be mutable.Lesson coming soon - I can predict whether a mutation to a sublist or its parent affects the other, and can produce an independent snapshot of a range when isolation is required.Lesson coming soon
- I can predict whether a mutation through a wrapped or original reference succeeds, and can choose between
unmodifiableList,List.copyOf, and a defensive copy depending on the required guarantees.Lesson coming soon
`ArrayList<E>` ↔ array interop
- I can produce a typed array from a generic
List<E>usingtoArray(new E[0]), and predict the failure when the no-argtoArray()is cast to a typed array.Lesson coming soon - I can predict whether
set,add, and direct array writes succeed on the result ofArrays.asList(arr), and contrast it withList.of(...)andnew ArrayList<>(Arrays.asList(arr)).Lesson coming soon - I can implement, in one line, the conversion from a reference-type array to an independent mutable
ArrayList, and can implement the boxing loop required for primitive-array sources.Lesson coming soon
Week 3Custom linked lists, part one
Git is a linked structure
`Node<T>` self-referential class
- I can declare a generic Node<T> with
dataandnextfields and predict the linkage shape.Not started yet - I can write three Node constructors and use
this(...)to delegate.Not started yet - I can identify the
statickeyword on a nested class, explain its effect, and predict consequences of omitting it.Not started yet
NDH vs DH header conventions
The traversal idiom
- I can write the canonical traversal idiom and predict its behavior on lists of various sizes.Not started yet
- I can predict empty-list behavior of canonical traversal and identify why explicit checks are unneeded.Not started yet
- I can compute list length by traversal when size is not tracked.Not started yet
`addFirst` and append (`add`)
remove head and tail
add and remove at index
`removeAllOccurrences(T data)`
- I can write removeAllOccurrences with proper head-match handling and the don't-advance-on-removal rule.Not started yet
- I can identify which equality test the lab uses and explain why.Not started yet
- I can write a removeAllOccurrences that returns boolean indicating whether the list changed.Not started yet
`toArray` and `toString`
Doubly-linked variant
- I can declare a doubly-linked Node and update both directions on insert/remove.Lesson coming soon
- I can write addLast and removeLast for DH-doubly-linked variant in O(1).Lesson coming soon
- I can write a backward-walk traversal on a doubly-linked list.Lesson coming soon
Custom Iterator implementation
- I can declare a non-static inner Iterator class capturing the enclosing list's head.Lesson coming soon
- I can implement Iterator's hasNext and next.Lesson coming soon
- I can declare LinkedList as Iterable and implement iterator().Lesson coming soon
Generic bound `<T extends Comparable<? super T>>`
- I can declare a generic class with a Comparable bound and use compareTo on T values inside.Lesson coming soon
- I can explain why the Comparable bound is needed and identify the alternative.Lesson coming soon
Week 4Custom linked lists, part two, and the midtermComing soon
This week is a milestone: Quiz 4 and the midterm.
Week 5Inheritance and polymorphismComing soon
`extends` and the subclass relation
- I can declare a subclass and explain that single inheritance is the rule.Lesson coming soon
- I can predict whether a subclass can access a parent member based on visibility.Lesson coming soon
- I can identify Object as the root and predict that every class has access to its methods.Lesson coming soon
`super(...)` and constructor chaining
- super first statementLesson coming soon
- Implicit super()Lesson coming soon
- Missing super errorLesson coming soon
Method overriding
- Same signatureLesson coming soon
- @OverrideLesson coming soon
- Override contractLesson coming soon
Dynamic dispatch
- Runtime vs compile typeLesson coming soon
- Method resolutionLesson coming soon
- Fields not dispatchedLesson coming soon
`super.method()` call
- super.methodLesson coming soon
- super.toStringLesson coming soon
Object class and its overridable methods
- toString defaultLesson coming soon
- equals defaultLesson coming soon
- hashCode defaultLesson coming soon
toString override in hierarchy
- super.toString patternLesson coming soon
- @Override disciplineLesson coming soon
`equals` override mechanic
- equals patternLesson coming soon
- getClass vs instanceofLesson coming soon
- hashCode pairingLesson coming soon
Upcast and downcast
- UpcastLesson coming soon
- DowncastLesson coming soon
`instanceof` classic and pattern
- Classic instanceofLesson coming soon
- Pattern instanceofLesson coming soon
Polymorphism through base-type reference
- Base array of subtypesLesson coming soon
- Virtual dispatch through a loopLesson coming soon
- Shape.area canonical exampleLesson coming soon
Concept final classes and final methods
- final class cannot extendLesson coming soon
- final method cannot overrideLesson coming soon
Concept protected access
- protected vs private vs publicLesson coming soon
- protected leaks abstractionLesson coming soon
Week 6Abstract classes, interfaces, and object identityComing soon
Abstract Classes and Interfaces
Concept Abstract class fundamentals
- Declaring abstractLesson coming soon
- Abstract class cannot be instantiatedLesson coming soon
- Abstract classes hold state and constructorsLesson coming soon
Concept Abstract methods
- Abstract method declarationLesson coming soon
- Concrete subclass must overrideLesson coming soon
Concept Partial-implementation pattern
- Concrete + abstract mixLesson coming soon
- Template MethodLesson coming soon
- Half-built superclass intuitionLesson coming soon
Concept The interface declaration
- Interface declaration syntaxLesson coming soon
- Implicit modifiers on interface methodsLesson coming soon
- Constants on interfacesLesson coming soon
Concept `implements` and multiple-interface implementation
- Single implementsLesson coming soon
- Multiple implementsLesson coming soon
- Conflict resolution across interfacesLesson coming soon
Concept Interface inheritance
- Single interface inheritanceLesson coming soon
- Multiple interface inheritanceLesson coming soon
Concept `default` methods (Java 8+)
- Default-method motivationLesson coming soon
- Diamond conflict resolutionLesson coming soon
- When to use
defaultLesson coming soon
Concept `static` (Java 8+) and `private` (Java 9+) interface methods
- Static methods on interfacesLesson coming soon
- Private interface methodsLesson coming soon
Concept Abstract class vs interface: the design choice
- Why prefer interfacesLesson coming soon
- When abstract class still winsLesson coming soon
- Skeletal implementation patternLesson coming soon
Concept The classic 211 interfaces (pointers)
- Comparable vs Comparator pointerLesson coming soon
- Iterable / Iterator pointerLesson coming soon
- Cloneable pointerLesson coming soon
Inner Classes and Object Identity
Concept Static nested class
- Declaring static nestedLesson coming soon
- No enclosing-instance referenceLesson coming soon
- When to use static nestedLesson coming soon
Concept Inner (non-static member) class
- Inner class implicit referenceLesson coming soon
- Outer.thisLesson coming soon
- Inner-class memory leaksLesson coming soon
Concept Local class
- Local classLesson coming soon
- Effectively-final captureLesson coming soon
Concept Anonymous class
- Anonymous-class syntaxLesson coming soon
- Pre-lambda anonymous-class idiomLesson coming soon
- Lambdas replace anonymous classes (when target is functional)Lesson coming soon
Concept Choosing the right inner-class kind
- Inner-class decision treeLesson coming soon
- Lambda-first styleLesson coming soon
Concept `Object.clone()` protocol
- Object.clone signatureLesson coming soon
- super.clone idiomLesson coming soon
- Cloneable as a markerLesson coming soon
Concept Shallow vs deep copy
- Shallow copy mechanicsLesson coming soon
- Deep-copy recipeLesson coming soon
Concept `Cloneable` is broken; modern alternatives
- Why Cloneable is brokenLesson coming soon
- Copy constructorLesson coming soon
- Static factory and recordsLesson coming soon
Concept The `equals` contract
- Five equals propertiesLesson coming soon
- Symmetry violation in subclassesLesson coming soon
- Real-world equals violationsLesson coming soon
Concept `equals` under inheritance: `getClass` vs `instanceof`
- getClass vs instanceofLesson coming soon
- canEqual patternLesson coming soon
Concept `hashCode` and the equals/hashCode consistency rule
- equals/hashCode consistencyLesson coming soon
- Hash-collection misbehaviorLesson coming soon
- IDE-generated implementationsLesson coming soon
Concept `==` vs `.equals` revisited
- == vs.equals on referencesLesson coming soon
- Primitive ==Lesson coming soon
- Integer cache + autoboxingLesson coming soon
Concept `final` reference vs immutable object
- final reference vs immutable objectLesson coming soon
- Bloch's immutability checklistLesson coming soon
Week 7Exceptions and recursionComing soon
Exception Handling
Concept The Throwable hierarchy
- Throwable hierarchyLesson coming soon
- Why not to catch ErrorLesson coming soon
- Drawing the Exception/RuntimeException lineLesson coming soon
Concept Checked vs unchecked
- Handle-or-declareLesson coming soon
- The checked-exception debateLesson coming soon
- Designing your own exception classLesson coming soon
Concept `try` with multiple `catch` blocks
- Specificity-first orderingLesson coming soon
- Unreachable catchLesson coming soon
Concept `finally` block
- When finally runsLesson coming soon
- When finally does not runLesson coming soon
- Return-from-finally trapLesson coming soon
Concept Multi-catch (Java 7+)
- Multi-catch syntaxLesson coming soon
- Implicit-final in multi-catchLesson coming soon
Concept `try-with-resources` (Java 7+)
- try-with-resources basicsLesson coming soon
- Suppressed exceptionsLesson coming soon
- Close orderLesson coming soon
Concept Exception chaining
- Exception cause chainLesson coming soon
- Four-constructor conventionLesson coming soon
Concept Custom exception classes
- Choosing parent classLesson coming soon
- Four-constructor convention is requiredLesson coming soon
- Exception naming and messagesLesson coming soon
Concept `throws` propagation
- Stack-walk for exceptionsLesson coming soon
- Where to catchLesson coming soon
Concept Rethrow patterns
- Wrap and rethrowLesson coming soon
- Log-and-handle patternLesson coming soon
- Don't ignore exceptionsLesson coming soon
Concept Exception vs sentinel return
- Choosing exception over sentinelLesson coming soon
- Sentinel returnsLesson coming soon
Concept Exceptions and overriding
- Throws compatibility under overrideLesson coming soon
- Unchecked override flexibilityLesson coming soon
Recursion
Concept Anatomy of a recursive method
- Base case essentialsLesson coming soon
- Shrinking the problemLesson coming soon
- Two-part canonical shapeLesson coming soon
Concept The call stack and recursive frames
- Recursion creates a stack of framesLesson coming soon
- Frame-scoped parameters and localsLesson coming soon
- StackOverflowErrorLesson coming soon
Concept Tracing recursive calls
- Trace-table conventionLesson coming soon
- Multi-parameter traceLesson coming soon
Concept Linear recursion on integers
- Factorial recursionLesson coming soon
- Sum recursionLesson coming soon
Concept Linear recursion on arrays
- Recurse-on-index patternLesson coming soon
- Identity element as base-case returnLesson coming soon
Concept Linear recursion on strings
- Substring-based string recursionLesson coming soon
- Index-based string recursionLesson coming soon
Concept Helper method with accumulator parameter
- Public/private helper splitLesson coming soon
- Accumulator threadingLesson coming soon
Concept Helper that returns partial result up the stack
- Bottom-up returnLesson coming soon
- Bottom-up combination patternsLesson coming soon
Concept Recursion on a linked list
- Recurse on node.nextLesson coming soon
- null as linked-list base caseLesson coming soon
Concept Branching recursion (a.k.a. tree recursion)
- Fibonacci recursiveLesson coming soon
- Tower of HanoiLesson coming soon
- Naïve Fibonacci complexityLesson coming soon
Concept Converting recursion to iteration
- Recursion → loop conversionLesson coming soon
- Conversion limitsLesson coming soon
Concept Print before vs print after the recursive call
- Print before vs afterLesson coming soon
- Tracing-stem variantsLesson coming soon
Week 8Recursion, generics, and the finalComing soon
Generic class declaration
- I canLesson coming soon
- I canLesson coming soon
Multi-parameter generics
- I canLesson coming soon
- I canLesson coming soon
Generic methods
- I canLesson coming soon
- I canLesson coming soon
Bounded type parameters
- I canLesson coming soon
- I canLesson coming soon
- I canLesson coming soon
Using a generic class
- I canLesson coming soon
- I canLesson coming soon
Wildcards: `? extends T` and `? super T`
- I canLesson coming soon
- I canLesson coming soon
- I canLesson coming soon
Wildcard capture and add-restrictions
- I canLesson coming soon
- I canLesson coming soon
Type erasure
- I canLesson coming soon
- I canLesson coming soon
- I canLesson coming soon
Erasure and arrays
- I canLesson coming soon
- I canLesson coming soon