Introduction to Computer Science II
A second course in programming emphasizing problem solving and computational thinking in an object-oriented language. Topics include abstraction, mutable data structures, methods, inheritance, polymorphism, recursion, program efficiency, testing and debugging.
Study notes
Independent, AI-drafted study guide · Public sources linked below · Added November 5, 2026
Independent Java study guide aligned with the Fall 2026 outline. The public Lanthier chapter collection is linked as optional course reading; GUI, networking, and persistence chapters may extend a particular section’s core coverage.
Shared guide for COMP 1006 / COMP 1406.
Objects, classes, and representation invariants
A class defines a representation and the operations permitted on it. An object is a particular instance with its own state. Encapsulation is useful because a method can preserve a rule that arbitrary field writes would violate. For a bounded counter, an invariant might require 0 <= value <= capacity. Constructors establish that rule, and public methods preserve it. An abstraction exposes what an object does while hiding how its data is arranged. Good method contracts describe accepted inputs, resulting state, return values, and exceptional outcomes.
References: COMP 1006A/1406A — Fall 2026 course outline · Oracle/OpenJDK — Dev.java learning resources
References, mutation, and Java parameter passing
A reference variable identifies an object rather than containing a duplicate of that object. Assignment copies the reference. Java passes argument values into parameters; when the value is a reference, caller and callee can initially refer to the same object. A method may mutate that shared object, but assigning its local parameter to a new object does not reassign the caller’s variable. Distinguish object identity from logical equality. Arrays have fixed length; an ArrayList manages a resizable sequence, though its elements may still be shared references.
References: COMP 1006A/1406A — Fall 2026 course outline · Oracle/OpenJDK — Dev.java learning resources
Composition, inheritance, and polymorphism
Composition represents a has-a relationship: a playlist contains tracks. Inheritance models an is-a relationship and allows a subtype to participate where its parent type is expected. A subtype must honor the parent’s behavioral promises. Overriding chooses behavior according to the runtime object; overloading chooses among signatures using compile-time information. An interface states required operations without requiring clients to know the implementation. Prefer composition when reuse does not imply substitutability. A superclass reference does not guarantee that every conceivable subclass-specific operation is available.
References: COMP 1006A/1406A — Fall 2026 course outline · Oracle/OpenJDK — Dev.java learning resources
Abstract data types and data-structure choices
An ADT describes observable behavior independently of storage. A stack provides last-in-first-out push and pop; a queue provides first-in-first-out insertion and removal. Arrays and linked nodes can implement these contracts with different performance and memory tradeoffs. For a linked stack, maintain a head reference and insert or remove at that endpoint. Specify what an empty removal means before implementing it. Client code should depend on the ADT interface so that replacing a representation does not force changes throughout the program.
References: COMP 1006A/1406A — Fall 2026 course outline · Oracle/OpenJDK — Dev.java learning resources
Recursion and a worked tree example
A recursive data structure contains smaller structures of the same kind. The size of an empty binary tree is zero; otherwise it is one plus the sizes of its children. A root with a left leaf and a right child containing one leaf has four nodes: 1 + 1 + 2. Each call handles one subtree, and null is the base case. The total running time is linear in the number of nodes. The maximum simultaneous call depth follows the tree height, which can be linear for a chain.
static int size(Node node) {
if (node == null) return 0;
return 1 + size(node.left) + size(node.right);
}References: COMP 1006A/1406A — Fall 2026 course outline · Oracle/OpenJDK — Dev.java learning resources
Exceptions, tests, and program efficiency
An exception communicates an unusual outcome through the call stack. Catch it where the program can recover meaningfully; swallowing an exception can hide a corrupted assumption. Validate predictable input errors at the boundary and keep object invariants intact when operations fail. Test behavior through public interfaces: construction, ordinary updates, limits, invalid operations, and repeated calls. Analyze loops and recursion using input size rather than stopwatch results alone. A nested scan over all ordered pairs usually performs quadratic work, even when a tiny demonstration appears fast.
References: COMP 1006A/1406A — Fall 2026 course outline · Oracle/OpenJDK — Dev.java learning resources
Practice & worked answers
Original exercises for this guide.
1. Why can a method change an ArrayList argument but not replace the caller’s variable?
Show worked answer
The parameter receives a copy of the reference. Mutating through it reaches the shared list; assigning a new reference changes only the local parameter.
2. A tree has seven nodes and height six edges. How much auxiliary space can recursive size use?
Show worked answer
The recursion follows a path of up to seven active node calls, plus a constant amount per call. Space is O(h), which is O(n) for this nearly chain-shaped tree.
3. Should a read-only method return its internal mutable list directly?
Show worked answer
Doing so lets callers bypass the class invariant. Return an immutable view when appropriate or a defensive copy, and consider whether mutable elements also need protection.
Public notes & references
Course sources establish the scope above. Reference materials support the explanations; linked lecture notes and books remain with their authors.
Topics
- abstraction
- mutable data structures
- methods
- inheritance
- polymorphism
- recursion
- program efficiency
- testing and debugging
Course catalogue
2026
Readings
- Learning Material Op.ons for Purchasing (e.g., Bookstore, Used, etc.)
Prerequisites & course information
Also listed as COMP 1406 . Precludes additional credit for BIT 2400 , BUSI 2402 , ITEC 2400 , ITEC 2401 , SYSC 2004 . Prerequisite(s): COMP 1005 or COMP 1405 . Lectures three hours a week, tutorial one and a half hours a week.