CISC124 - Final Review

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/98

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

99 Terms

1
New cards

What is the purpose of the Set abstract data type?

To represent a collection of unique elements where no two elements are equal.

2
New cards

"Which Java Set implementation is most similar to a Python set and offers very fast O(1) expected complexity for add

remove

3
New cards

Which Java Set implementation maintains its elements in a sorted order?

java.util.TreeSet.

4
New cards

"In Java

can you create a set of primitive types like HashSet<int>?"

5
New cards

Which Java Set implementation guarantees that the iteration order will be identical to the order in which elements were added?

java.util.LinkedHashSet.

6
New cards

"What is the expected time complexity for add

remove

7
New cards

"What is the time complexity for add

remove

8
New cards

The method s1.addAll(s2) transforms s1 into the _ of s1 and s2.

union

9
New cards

"Which method is used to compute the intersection of two sets

s1 and s2

10
New cards

The method s1.removeAll(s2) transforms s1 into the set _ of s1 and s2.

difference

11
New cards

"What are 'map'

'dictionary'

12
New cards

"In a Java Map

the keys must be unique and form a _____."

13
New cards

"In a Java Map

the values are not necessarily unique and form a _____."

14
New cards

Which Java Map implementation is most similar to a Python dictionary and makes no guarantees about iteration order?

java.util.HashMap.

15
New cards

Which Java Map implementation maintains its keys in a sorted order?

java.util.TreeMap.

16
New cards

Which Java Map implementation maintains its keys in insertion order?

java.util.LinkedHashMap.

17
New cards

What method is used to add a key-value pair to a map?

"The `put(key

18
New cards

What does the keySet() method of a Map return?

A Set containing all the keys from the map.

19
New cards

"In Java

what is a type?"

20
New cards

What is the term for an instance of a class?

An object.

21
New cards

"In object-oriented programming

what is encapsulation?"

22
New cards

"In Java

the variables that represent the state of an object are called _."

23
New cards

What is the primary purpose of a constructor in Java?

To initialize the state of a newly created object.

24
New cards

"If a class defines no constructors

what does the Java compiler do?"

25
New cards

What is the term for a method that changes the state of an object?

A mutator method.

26
New cards

What is the term for a method that returns information about the state of an object without changing it?

An accessor method.

27
New cards

What two components make up a method's signature in Java?

The method name and the types in the parameter list.

28
New cards

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).

29
New cards

What is a static field in Java?

"A per-class member

30
New cards

What is the purpose of a utility class?

To group related static fields and methods where creating an object is not necessary.

31
New cards

How can you prevent a utility class from being instantiated by client code?

By declaring a single private no-argument constructor.

32
New cards

What is a static factory method?

"A static method that returns an instance of the class

33
New cards

"By default

what does the Object.equals() method check?"

34
New cards

What is the reflexivity property of the equals contract?

"For any non-null reference value x

35
New cards

What is the symmetry property of the equals contract?

"For any non-null reference values x and y

36
New cards

What rule must be followed regarding hashCode() if you override equals()?

"If two objects are equal according to the equals(Object) method

37
New cards

What does it mean for a class to implement the Comparable interface?

"It must provide an implementation for the compareTo method

38
New cards

What is the return value contract for x.compareTo(y)?

"It returns a negative integer

39
New cards

What is an enumerated type (enum) in Java?

A special type whose values consist of a fixed set of constants.

40
New cards

"What method

automatically generated for enums

41
New cards

"In a UML class diagram

what does a '-' symbol before a field or method name signify?"

42
New cards

"What relationship between classes is modeled by a solid line with a filled diamond

implying ownership?"

43
New cards

"What is the term for the relationship where a class has-a field of another class

but does not own it

44
New cards

What is a 'privacy leak' in the context of composition?

"When a class exposes a reference to its internal

45
New cards

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.

46
New cards

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

47
New cards

A class that implements the _____ interface can be the target of a for-each loop.

Iterable

48
New cards

What is the defining characteristic of a Stack data structure?

It is a Last-In-First-Out (LIFO) collection.

49
New cards

What are the two primary operations of a stack?

push (add to top) and pop (remove from top).

50
New cards

"In a recursive function

what is the 'base case'?"

51
New cards

What is a default method in a Java interface?

"A method in an interface that has an implementation

52
New cards

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.

53
New cards

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.

54
New cards

How does a subclass constructor invoke a constructor from its direct superclass?

"By using the super() keyword

55
New cards

What is polymorphism in the context of Java objects?

"The ability of an object to take on many forms

56
New cards

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

57
New cards

What is an abstract class in Java?

A class that cannot be instantiated directly and is intended to be used as a superclass.

58
New cards

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.

59
New cards

What problem do generics solve in Java?

"They provide compile-time type safety for collections and classes

60
New cards

What is the syntax for declaring a generic class named Box with one type parameter?

public class Box<E> { ... }

61
New cards

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.

62
New cards

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.

63
New cards

"Arrays are _

meaning if Sub is a subtype of Super

64
New cards

"Generic types are _

meaning for distinct types T1 and T2

65
New cards

What is the defining characteristic of a Queue data structure?

It is a First-In-First-Out (FIFO) collection.

66
New cards

What are the two primary operations of a queue?

enqueue (add to back) and dequeue (remove from front).

67
New cards

"In an array-based list

what is the worst-case time complexity of removing an element from the front of the list?"

68
New cards

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.

69
New cards

"In a linked-node based queue

what is the time complexity of the enqueue and dequeue operations?"

70
New cards

What is a generic method?

"A method that is parameterized over types

71
New cards

"In a singly-linked list

what is the worst-case time complexity of the get(int index) operation?"

72
New cards

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

73
New cards

"What does the iterator() method

required by the Iterable interface

74
New cards

What is the purpose of the hasNext() method in the Iterator interface?

To check if there are more elements in the iteration.

75
New cards

What does the next() method in the Iterator interface do?

It returns the next element in the iteration and advances the iterator's position.

76
New cards

The remove() method of an Iterator deletes the element that was most recently returned by the _____ method.

next()

77
New cards

Write the method signature for the indexOf method in the String class as shown on the final exam review.

"`indexOf(String

78
New cards

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.

79
New cards

What is the difference between a class and an interface in Java?

"A class is an implementation of a reference type

80
New cards

"What is the term for a class that is defined inside of another class

typically to serve the enclosing class?"

81
New cards

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

82
New cards

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.

83
New cards

The term for a key-value pair in a Java Map is an _____.

entry

84
New cards

What is the final exam date and time for CISC 124 in Fall 2025?

"December 9

85
New cards

What are the four main elements of the object model discussed in the course?

"Abstraction

86
New cards

"In Java

every class is a descendant of which class?"

87
New cards

The keyword this inside a constructor refers to what?

A reference to the object that is currently being initialized.

88
New cards

"When a parameter name is the same as a field name

the parameter is said to _ the field."

89
New cards

What is the term for a constructor invoking another constructor in the same class?

Constructor chaining.

90
New cards

How can a method check a precondition and signal that it has not been met?

"By throwing an exception

91
New cards

"What does a final field of a mutable type

like List

92
New cards

"What is the relationship between List

Set

93
New cards

What is the declared type of t in the statement: List<String> t = new ArrayList<>();?

List.

94
New cards

What is the runtime type of t in the statement: List<String> t = new ArrayList<>();?

ArrayList.

95
New cards

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.

96
New cards

"In a linked list

the node at the front is called the _____ node."

97
New cards

"In a singly-linked list

what indicates the end of the sequence?"

98
New cards

True or False: A Set is a Collection that cannot contain duplicate elements.

True.

99
New cards

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.