1/98
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
What is the purpose of the Set abstract data type?
To represent a collection of unique elements where no two elements are equal.
"Which Java Set implementation is most similar to a Python set and offers very fast O(1) expected complexity for add
remove
Which Java Set implementation maintains its elements in a sorted order?
java.util.TreeSet.
"In Java
can you create a set of primitive types like HashSet<int>?"
Which Java Set implementation guarantees that the iteration order will be identical to the order in which elements were added?
java.util.LinkedHashSet.
"What is the expected time complexity for add
remove
"What is the time complexity for add
remove
The method s1.addAll(s2) transforms s1 into the _ of s1 and s2.
union
"Which method is used to compute the intersection of two sets
s1 and s2
The method s1.removeAll(s2) transforms s1 into the set _ of s1 and s2.
difference
"What are 'map'
'dictionary'
"In a Java Map
the keys must be unique and form a _____."
"In a Java Map
the values are not necessarily unique and form a _____."
Which Java Map implementation is most similar to a Python dictionary and makes no guarantees about iteration order?
java.util.HashMap.
Which Java Map implementation maintains its keys in a sorted order?
java.util.TreeMap.
Which Java Map implementation maintains its keys in insertion order?
java.util.LinkedHashMap.
What method is used to add a key-value pair to a map?
"The `put(key
What does the keySet() method of a Map return?
A Set containing all the keys from the map.
"In Java
what is a type?"
What is the term for an instance of a class?
An object.
"In object-oriented programming
what is encapsulation?"
"In Java
the variables that represent the state of an object are called _."
What is the primary purpose of a constructor in Java?
To initialize the state of a newly created object.
"If a class defines no constructors
what does the Java compiler do?"
What is the term for a method that changes the state of an object?
A mutator method.
What is the term for a method that returns information about the state of an object without changing it?
An accessor method.
What two components make up a method's signature in Java?
The method name and the types in the parameter list.
What does it mean for methods to be 'overloaded'?
Two or more methods in the same class have the same name but different signatures (parameter lists).
What is a static field in Java?
"A per-class member
What is the purpose of a utility class?
To group related static fields and methods where creating an object is not necessary.
How can you prevent a utility class from being instantiated by client code?
By declaring a single private no-argument constructor.
What is a static factory method?
"A static method that returns an instance of the class
"By default
what does the Object.equals() method check?"
What is the reflexivity property of the equals contract?
"For any non-null reference value x
What is the symmetry property of the equals contract?
"For any non-null reference values x and y
What rule must be followed regarding hashCode() if you override equals()?
"If two objects are equal according to the equals(Object) method
What does it mean for a class to implement the Comparable interface?
"It must provide an implementation for the compareTo method
What is the return value contract for x.compareTo(y)?
"It returns a negative integer
What is an enumerated type (enum) in Java?
A special type whose values consist of a fixed set of constants.
"What method
automatically generated for enums
"In a UML class diagram
what does a '-' symbol before a field or method name signify?"
"What relationship between classes is modeled by a solid line with a filled diamond
implying ownership?"
"What is the term for the relationship where a class has-a field of another class
but does not own it
What is a 'privacy leak' in the context of composition?
"When a class exposes a reference to its internal
How does a class using composition protect against privacy leaks when receiving a mutable object in a constructor or mutator method?
It creates a defensive copy of the object and stores the copy.
What is the difference between a shallow copy and a deep copy of a collection?
"A shallow copy creates a new collection but shares references to the original elements
A class that implements the _____ interface can be the target of a for-each loop.
Iterable
What is the defining characteristic of a Stack data structure?
It is a Last-In-First-Out (LIFO) collection.
What are the two primary operations of a stack?
push (add to top) and pop (remove from top).
"In a recursive function
what is the 'base case'?"
What is a default method in a Java interface?
"A method in an interface that has an implementation
What is the relationship between a subclass and a superclass in Java?
A subclass is derived from a superclass using the extends keyword and inherits its non-private members.
What does the 'is-a' relationship in inheritance signify?
It means a subclass object is substitutable for an object of any of its ancestor classes.
How does a subclass constructor invoke a constructor from its direct superclass?
"By using the super() keyword
What is polymorphism in the context of Java objects?
"The ability of an object to take on many forms
The process of using the runtime type of an object to determine which version of an overridden method to call is known as _.
dynamic dispatch or late binding
What is an abstract class in Java?
A class that cannot be instantiated directly and is intended to be used as a superclass.
What is the Liskov Substitution Principle?
It states that objects of a superclass should be replaceable with objects of its subclasses without altering the correctness of the program.
What problem do generics solve in Java?
"They provide compile-time type safety for collections and classes
What is the syntax for declaring a generic class named Box with one type parameter?
public class Box<E> { ... }
Why is the statement new E[10]; illegal in Java when E is a generic type parameter?
Java does not allow the creation of arrays of a generic type.
What is the common workaround for the inability to create generic arrays in Java?
Create an array of Object (new Object[10];) and cast the elements back to the generic type when they are retrieved.
"Arrays are _
meaning if Sub is a subtype of Super
"Generic types are _
meaning for distinct types T1 and T2
What is the defining characteristic of a Queue data structure?
It is a First-In-First-Out (FIFO) collection.
What are the two primary operations of a queue?
enqueue (add to back) and dequeue (remove from front).
"In an array-based list
what is the worst-case time complexity of removing an element from the front of the list?"
What data structure can be conceptualized as a circular array to efficiently implement a queue?
An array-based queue uses indices that wrap around to avoid shifting elements on every enqueue or dequeue operation.
"In a linked-node based queue
what is the time complexity of the enqueue and dequeue operations?"
What is a generic method?
"A method that is parameterized over types
"In a singly-linked list
what is the worst-case time complexity of the get(int index) operation?"
How is inserting an element at the front of a singly-linked list different from an array-based list in terms of complexity?
"In a singly-linked list
"What does the iterator() method
required by the Iterable interface
What is the purpose of the hasNext() method in the Iterator interface?
To check if there are more elements in the iteration.
What does the next() method in the Iterator interface do?
It returns the next element in the iteration and advances the iterator's position.
The remove() method of an Iterator deletes the element that was most recently returned by the _____ method.
next()
Write the method signature for the indexOf method in the String class as shown on the final exam review.
"`indexOf(String
What is a class invariant?
A condition concerning the state of an object that must be true whenever the object is available for use by a client.
What is the difference between a class and an interface in Java?
"A class is an implementation of a reference type
"What is the term for a class that is defined inside of another class
typically to serve the enclosing class?"
What is the key difference between a static nested class and a non-static inner class?
"A non-static inner class object has an implicit reference to an object of its enclosing class
Why might a programmer choose a TreeMap over a HashMap?
When they require the keys of the map to be maintained in a sorted order.
The term for a key-value pair in a Java Map is an _____.
entry
What is the final exam date and time for CISC 124 in Fall 2025?
"December 9
What are the four main elements of the object model discussed in the course?
"Abstraction
"In Java
every class is a descendant of which class?"
The keyword this inside a constructor refers to what?
A reference to the object that is currently being initialized.
"When a parameter name is the same as a field name
the parameter is said to _ the field."
What is the term for a constructor invoking another constructor in the same class?
Constructor chaining.
How can a method check a precondition and signal that it has not been met?
"By throwing an exception
"What does a final field of a mutable type
like List
"What is the relationship between List
Set
What is the declared type of t in the statement: List<String> t = new ArrayList<>();?
List
What is the runtime type of t in the statement: List<String> t = new ArrayList<>();?
ArrayList
What is the purpose of the @Override annotation?
To indicate to the compiler that a method is intended to override a method in a superclass or interface.
"In a linked list
the node at the front is called the _____ node."
"In a singly-linked list
what indicates the end of the sequence?"
True or False: A Set is a Collection that cannot contain duplicate elements.
True.
What is the purpose of a copy constructor?
To initialize the state of a new object by copying the state of another object of the same type.