Where you are: Week 0 review > Prerequisite diagnostic
This short self-check covers the four CSCD 210 ideas that Week 1 leans on most: the difference between == and .equals, how an assignment copies a reference and not the object, the sign contract of compareTo, and writing a one-line compareTo without subtraction.
It is low-stakes by design. The point is to find any gap now, before new material depends on it. If a question stumps you, the matching week-0 review lesson covers it: References, ==, and aliasing, equals and hashCode, and Comparable and compareTo. Answer each from memory first, then reveal it.
Check Yourself
Check your understanding
True or False: two String variables s1 and s2 that both hold the value “hello” are guaranteed to make s1 == s2 return true.
== compares references (addresses), not contents. s1 and s2 can refer to different String objects with the same characters. Use .equals to compare content.
Tier 1 · COMPETENCY-RECONCILIATION Area 3 CORE (== identity vs equals content); BJP (Reges and Stepp), Ch 8-9
True or False: when you write Cat b = a; (a is already a Cat), Java creates a second independent Cat object named b.
Assignment copies the reference, not the object. Both a and b point to the same Cat on the heap; mutating through one is visible through the other.
Tier 1 · COMPETENCY-RECONCILIATION Area 3 CORE (reference copy on assignment); BJP (Reges and Stepp), Ch 8
True or False: implementing compareTo by returning this.age - other.age is always safe when age is a positive int field.
Integer subtraction can overflow when the values are far apart, flipping the sign and breaking the order. The safe form is Integer.compare(this.age, other.age).
Tier 2 · COMPETENCY-RECONCILIATION Area 3 CORE (delegate to Integer.compare to avoid overflow); BJP (Reges and Stepp), Ch 10
A class implements Comparable<Product>. The compareTo method returns what sign when this product orders BEFORE other, when the two are EQUAL in ordering, and when this product orders AFTER other?
A model answerNegative when this orders before other, zero when they are equal, positive when this orders after other.
The compareTo contract: a negative integer means less-than (orders earlier), zero means equal in ordering, a positive integer means greater-than (orders later).
Tier 2 · COMPETENCY-RECONCILIATION Area 3 CORE; clos.yaml CLO-09 enabling prerequisite; BJP (Reges and Stepp), Ch 10
A class Song has one int field year and declares implements Comparable<Song>. Write the single return statement that completes compareTo(Song other), ordering by year ascending, with no subtraction.
A model answerreturn Integer.compare(this.year, other.year);
Integer.compare returns the correct sign with no overflow risk. Subtraction (this.year - other.year) is rejected because it can overflow.