Final Superdeck Flashcards

1
Q

Q1: Software development is all about learning a programming language.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Q1: Object Oriented Programming is

A

A program consisting of classes and objects organized to manage the complexity of large-scale systems.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Q1: Procedural programming is

A

A program consisting of methods/functions calling each other.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Q1: A method ___

A

Implements behaviors relevant to the purpose of the system

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Q1: A field or attribute ___

A

Stores data relevant to the purpose of the system

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Q1: A container object

A

Data structure to store entities

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Q1: A control object

A

Organize computation or flow of the program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Q1: An interface object

A

Facilitates communication between the system and the outside world

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Q1: An entity object

A

Model of a real-world thing in an application

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Q2: T/F A UML Use Case diagram is a type of behavioral diagram.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Q2: In a UML Use Case diagram, what relationship is used in a situation where the execution of a use case ALWAYS involves the execution of an associated use case?

A

Include.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Q2: T/F A UML Class diagram is a type of behavioral diagram.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Q2: Given three classes, plant, tree, and flower, which of the following best describes their relationship to each other?

A

Inheritance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Q2: Given two classes, House and Wall, where the House is a container of Wall objects, what describes their relationship?

A

Composition.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Q2: Given two classes, Book and Bookshelf, what best describes their relationship?

A

Aggregation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Q2: Given two classes, Hammer and Nail, what best describes their relationship?

A

Association.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Q3: What principle should be used to have a method have different behaviors depending on the class it’s invoked on?

A

Polymorphism.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Q3: What phrase/term is used to describe inheritance?

A

a ____ is a _____
i.e.
a cat is an animal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Q3: T/F Interface and inheritance are different names for the same concept.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Q3: T/F. Polymorphism can be expressed in a UML diagram.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Q3: What is the conceptual advantage to Polymorphism?

A

refactor ugly if and switch/case statements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Q3: What is the conceptual advantage to inheritance?

A

eliminate redundant code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Q3: What is the conceptual advantage to abstraction?

A

hide details and show the essentials; isolate the impact of changes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Q3: What is the conceptual advantage to encapsulation?

A

grouping related variables and functions together to reduce complexity and increase reusability

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Q4: Is a String a primitive data type in Java?

A

No.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

Q4: T/F All data types in Java are references to data allocated on the Heap.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Q4: What Java data type is ideal for measurement data?

A

Double.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Q4: T/F. Both single and double quotes can denote a String literal in Java.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Q4: What is the basic syntax for a for loop in Java?

A

for (int i=0; i<10; i++)
{
System.out.println(“hello world”);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Q6: What does toString() do in Java?

A

Lets programmers define a String representation of their class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

Q7: What is Validation in testing?

A

Any method to increase confidence in the correctness of a software system

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Q7: What is an error?

A

The cause of an undesired behaviour or incorrect result

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

Q7: What is debugging?

A

Inferring the cause of undesired behaviour or incorrect results

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

Q7: What is a Fault?

A

An undesired behaviour or incorrect result

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

Q7: What is Automated testing?

A

The computer runs a script performing the tests

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

Q7: What is manual testing?

A

A human types some input into a program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

Q7: What causes a fault?

A

An error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

Q7: What is coverage in testing?

A

How much of the code is tested.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

Q7: What is a failure in testing?

A

The inability of the system to do what is required.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

Q7: What is unintended behavior defined as?

A

A fault.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

Q7: T/F It is possible for a code to have an error but cause no faults.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

Q7: T/F If there is no error in the code, there are no faults.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

Q7: T/F It’s possible for a fault to be observed but no error to cause it.

A

Falst.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

Q7: T/F If’s possible for one error to produce multiple faults.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

Q7: When should testing code be removed from a class?

A

Never.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

Q7: Is it okay to set private attributes to set up test cases?

A

Yes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q

Q7: When should a regression test print the status?

A

Only when they fail. I.e. If all tests pass, they should print nothing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

Q8: What Java keyword indicates inheritance?

A

extends

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q

Q8: T/F Polymorphism can be used with both inherited super types and implemented interface types.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

Q8: What are a few common methods inherited from the object class?

A

getClass(), equals(), toString()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q

Q8: T/F A downside of polymorphism is that once you have a container of the supertype, it is impossible to convert and object back to its original type.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
52
Q

Q8: List of benefits of polymorphism.

A

Can reduce the amount of code that one needs to write.
It can make code simpler and more concise.
It reduces coupling.
It can make code more flexible/adaptable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
53
Q

Q8: What keyword is used to define that a class used an interface in Java?

A

Implements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
54
Q

Q9: What data structure in Java can hold primitive data types?

A

Array (although arrays can also hold objects).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
Q

Q9: T/F Array lists have fixed size.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
56
Q

Q9: T/F Arrays can only hold primitives.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
57
Q

Q9: T/F TreeMap and HashMap can be used interchangably.

A

True, since they implement the same interface (although their performance may differ).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
58
Q

Q9: Which data structure is good for things being sorted and accessing things by their name?

A

TreeMap

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
59
Q

Q9: Which data structure is good for needing to frequently inserting and removing from a a list.

A

LinkedList.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
60
Q

Q10: T/F Collections classes are defined using generic typing.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
61
Q

Q10: T/F Generic types can be restricted to supertypes such as classes or interfaces.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
62
Q

Q10: The comparable interface lets instances of the same class be compared with < and >.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
63
Q

Q10: Java will automatically generate rules for comparisons between objects when implementing the Comparable interface.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
64
Q

Q11: T/F after catching an exception, the program continues where the exception was originally thrown.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
65
Q

Q11: T/F An exception should be thrown if a user enters bad/incorrect data.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
66
Q

Q11: T/F An exception should be thrown if a regression test fails.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
67
Q

Q11: T/F An exception should be thrown if a bug is detected in the program.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
68
Q

Q11: T/F An exception should be thrown if a parameter violates a stated precondition.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
69
Q

Q11: What is the best place to catch and handle an exception?

A

The method with enough information to effectively handle the exception.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
70
Q

Q11: T/F A try-catch statement can catch multiple different types of exceptions from the same try block.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
71
Q

Q11: T/F code will NOT compile if you don’t try to catch a potential checked exception.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
72
Q

Q12: What is used to create a pop-up dialog box to prompt the user to enter text?

A

JOptionPane.showInputDialogue()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
73
Q

Q12: What is used in Java Swing to represent the application’s window?

A

JFrame

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
74
Q

Q12: T/F JFrame is a component.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
75
Q

Q12: What is used in Java Swing to contain other components?

A

JPanel.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
76
Q

Q12: T/F we can create a custom window/frame by making a class that inherits from JFrame.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
77
Q

Q13: In the event delegation model, what is a JButton?

A

An Event Source.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
78
Q

Q13: If you want to respond to a button click, what describes the process (as in the lecture).

A

Create a class that implements the ActionListener interface.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
79
Q

Q13: T/F An anonymous inner class can be defined without needing to assign the class name.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
80
Q

Q15: T/F A goal of software design is to maximize cohesion.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
81
Q

Q15: T/F A goal of software design is to maximize coupling.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
82
Q

Q15: T/F A design pattern and algorithm are the same thing.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
83
Q

Q15: What type of design pattern is the Singleton Pattern?

A

Creational.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
84
Q

Q15: What are the features of the Singleton Pattern?

A

Guarantees at most one instance of the class can exist in the system.
Provides global access to the object instance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
85
Q

Q15: T/F A static method can access both static and instance variables.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
86
Q

Q15: What is done with the constructor in the Singleton Pattern?

A

It is made private.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
87
Q

Q16: What type of design pattern is the Factory Pattern?

A

Creational.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
88
Q

Q16: What is the main goal of the Factory pattern?

A

To abstract the creation of a class or a hierarchy of classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
89
Q

Q16: What is the issue of using strings as parameters to a factory?

A

Spelling errors are possible and easy to make.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
90
Q

Q16: What can a string be replaced with in the Factory pattern?

A

A Java enum

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
91
Q

Q17: What type of design pattern is the Strategy Pattern?

A

Behavioural.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
92
Q

Q17: What is the main goal of the Strategy Pattern?

A

Define and encapsulate a family of algorithms to make them interchangeable in the program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
93
Q

Q17: What is meant by the principle to program the the supertype, not an implementation?

A

Objects should be stored in the most general type possible.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
94
Q

Q17: What is meant by favor composition over inheritance?

A

In some cases, encapsulating behaviors as objects makes the program more flexible than using inheritance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
95
Q

Q17: What are a couple in class/lecture/lab examples of candidates for the strategy pattern?

A

Choosing different routing algorithms in a map program.
Equipping different attacks/abilities to a game creature.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
96
Q

Q18: What are the three layers in the Three-Layer Architecture?

A

Presentation, Domain, System.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
97
Q

Q18: T/F The Command Pattern can be used to coordinate between the presentation and the domain layer.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
98
Q

Q18: T/F Each layer in the Three-Layer Architecture can only call methods in the layer below.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
99
Q

Q18: T/F The Observer Pattern is used to update the databases whenever classes in the Domain layer change.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
100
Q

Q18: T/F The Three-Layer Architecture promotes increased cohesion by forcing classes to be focused on smaller tasks.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
101
Q

Q19: What type of design pattern is the Command Pattern?

A

Behavioral.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
102
Q

Q19: What is the main goal of the Command Pattern?

A

To encapsulate a method for the purpose of storing actions in data structures.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
103
Q

Q19: T/F The command pattern uses inheritance instead of composition.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
104
Q

Q19: how are individual commands in the Command Pattern abstracted?

A

Commands all implement the same ‘Command’ interface.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
105
Q

Q19: What are a couple examples from class for candidates for the Command Pattern?

A

Managing a Queue of web requests.
Implementing an ‘undo/redo’ system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
106
Q

Q20: In the Observer pattern, what is the purpose of the Observer?

A

The classes that receive notifications/updates

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
107
Q

Q20: In the Observer pattern, what is the purpose of the Subject/Observable?

A

The thing being observed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
108
Q

Q20: In the Observer pattern, what is the purpose of the Client/Driver?

A

Creates the objects and sets up the pattern

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
109
Q

Q20: Recall the podcast distribution system example. What is the Observer, Subject, and Driver in this system?

A

Observer: The user that subscribes to the podcast and listens to it.
Subject: The publisher/creator. They notify the observer of new releases.
Client/Driver: The act of subscribing to the podcast.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
110
Q

Q20: What is the use of the UML ‘ball-and-socket’ notation?

A

Creating an interface to abstract/loosen coupling between two objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
111
Q

Q21: What design pattern is commonly used in the MVC architecture?

A

Observer pattern.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
112
Q

Q21: What is the responsibility of the model?

A

Perform the program’s business logic.
Update the View when the program’s data changes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
113
Q

Q21: What is the responsibility of the controller?

A

Interprets user input through ActionListeners.
Call methods on the Model in response to user commands (i.e. translates events into messages for the model).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
114
Q

Q21: What is the responsibility of the View?

A

Generate ActionEvents in response to user interaction.
Visually present data to the user.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
115
Q

Q21: What part of the MVC is the Observer?

A

The View.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
116
Q

Q21: What part of the MVC is the Subject?

A

The Model.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
117
Q

Q21: When does the Model send an update to the View?

A

Every time the data changes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
118
Q

Q22: To make a custom GUI element/widget, which class do we need to inherit from?

A

JComponent.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
119
Q

Q22: What method needs to be overridden to make a custom GUI element/widget appear?

A

paintComponent.

120
Q

Q22: What method needs to be called in order to update a custom GUI element/widget’s appearance at runtime?

A

repaint

121
Q

Q22: What type of object is passed into the paintComponent method as a parameter?

A

Graphics

122
Q

Q22: T/F When writing code to draw a GUI element/widget, the color needs to be set for each shape drawn.

A

False.

123
Q

Q23: T/F A Java Character Stream should be used to read in the data from a .png file.

A

False.

124
Q

Q23: T/F A Java Byte Stream represents the data as a literal sequence of characters.

A

False.

125
Q

Q23: Would a Text File or a Binary file likely be more compact?

A

Binary file.

126
Q

Q23: Which Java class is used to read data from an input stream?

A

Scanner.

127
Q

Q24: T/F A javax.swing Timer object will send an ActionEvent repeatedly with a specified delay.

A

True.

128
Q

Q24: T/F A javax.swing timer automatically starts when created.

A

False.

129
Q

Q24: As explained in class, what part of the MVC architecture was used to control the timer?

A

Controller.

130
Q

Q24: As explained in class, what part of the MVC architecture was used to store the animation data?

A

Model.

131
Q

Q25: Multithreading allows us to…

A

program multiple parallel threads of execution in a single program/process.

132
Q

Q25: T/F if using two threads to manage a large amount of data, it will take exactly half the time of a single thread.

A

False.

133
Q

Q25: What are a few reasons to use multithreading?

A

Improved design.
Improved user experience.
Improved performance.

134
Q

Q25: What are the two given ways to use threads in Java?

A

Create a class that implements the Runnable interface.
Create a class that extends Thread.

135
Q

Q25: What is a given example of a race condition?

A

Multiple threads trying to write to the same file.

136
Q

Q25: What is the solution to race conditions.

A

Lock objects.

137
Q

Q25: What is Deadlock?

A

When multiple threads cannot proceed because they are waiting for locks from each other.

138
Q

Q25: What is the solution to fixing/preventing deadlock?

A

Condition objects.

139
Q

How does OOP handle complexity?

A

Decomposition.

140
Q

Simple explanation for classes and objects?

A

Class: A blueprint.
Object: An instance of a class.

141
Q

Entity

A

Models real things

142
Q

Container

A

A data structure to store entities

143
Q

Interface

A

Communicates with the outside world

144
Q

Control

A

Organizes computations

145
Q

What is a concrete object?

A

I.e. People, buildings, equipment. Representative of physical objects.

146
Q

What is a conceptual object?

A

I.e. organizations, agreements, abstractions.
Represent concepts that aren’t physical objects.

147
Q

What is a state-change object?

A

I.e. Purchase, sale, birth.
Represent events.

148
Q

What is an interface object?

A

Handles communication between software and external entities. I.e. people and other hardware.

149
Q

Types of methods.

A

Accessors/Getters.
Mutators/Setters.
Hybrid (discouraged in modern software).

150
Q

Steps to software development process.

A
  1. Requirements.
  2. Design.
  3. Implementation.
  4. System Testing and Verification.
  5. Maintenance.
151
Q

What does UML stand for?

A

Unified Modelling Language.

152
Q

What are the two kinds of UML diagrams?

A

Structural and Behavioral.

153
Q

Types of behavioral diagrams?

A

Use Case, State, Sequence, Interaction.

154
Q

Types of structural diagrams?

A

Component, object, class, deployment.

155
Q

What is a Use Case Diagram?

A

Specifies the expected behavior, but not the exact method of making it happen (the what, but not the how).

156
Q

What is a Primary Actor?

A

Triggers a use case to happen.

157
Q

What is a Supporting Actor?

A

Someone/something that is indirectly involved with a use case.
i.e. When a user (primary actor) tries to get money from an ATM, the Bank (supporting actor) has to verify they have enough money.

158
Q

What is a Use Case?

A

Represents a system function.
Verb+noun. do something
Each actor must be linked to a use case, not every use case needs an actor.

159
Q

Use case relationship for may conditionally execute the associated use case.

A

Solid arrow, dashed line, extend in double angle brackets.

160
Q

Use case for will always execute the associated use case.

A

Solid arrow, dashed line, include in double angle brackets.

161
Q

What is generalization?

A

Child inherits behavior and meaning of parent use case. Hollow arrow, solid line.

162
Q

Inherit UML arrow.

A

Solid line, hollow arrow.

163
Q

Implements UML arrow.

A

(Generalization).
Dashed line, hollow arrow.

164
Q

Association UML arrow.

A

Solid line. They call each other.

165
Q

One way association arrow.

A

Solid line, line arrow (like an angle bracket on the end).

166
Q

What is reflexive association?

A

A class may have multiple functions or responsibilities.
Another box underneath to the lower right in UML.

167
Q

Aggregation UML arrow.

A

Solid line, hollow diamond.

168
Q

Composition UML arrow.

A

Solid line, solid diamond.

169
Q

How do multiplicities work in UML?

A

Can specify a number:
i.e. 1
A range of numbers:
i.e. 1..*

I.e.
Teacher: 1
Student: 1..*
1 teacher may relate to many students/many students relate to 1 teacher.

170
Q

Encapsulation principle.

A

Group related variables and functions to reduce complexity and increase reusability.

171
Q

Abstraction principle.

A

Hide details, show essentials, isolate the impact of changes.

172
Q

Inheritance principle.

A

Eliminate redundant code.

173
Q

Polymorphism principle.

A

Refactor ugly if and switch/case statements.

174
Q

4 principles of OOP.

A

Encapsulation
Abstractions
Inheritance
Polymorphism

175
Q

What is the substitution principle?

A

You can always use a subclass where a superclass is expected.

I.e. Want an animal? A cat works.

176
Q

What is dynamic method lookup?

A

Methods called are determined by the object, not the variable. I.e.

177
Q

What is an abstract class?

A

Cannot be instantiated.
I.e. Could make Animal abstract. Can have Animal variables, but they must really be concrete subclasses.
I.e.
Animal some_animal = new Cat();

178
Q

What do Java executables run on?

A

A virtual machine.

179
Q

What is the difference between Static and Dynamic typing?

A

Static Typing: Expressions checked at compile time. Must be fixed before running.

Dynamic typing: Expressions checked at run time. Can run the program, but it may crash.

180
Q

Benefits to Java running on virtual machines?

A

Safety: Can attack the virtual machine, but not the physical machine.
Portability: “Write once, run everywhere.” Can run on any machine with the JVM installed.
More secure.

181
Q

Does Java treat everything as objects?

A

No. Some values are stored on the heap as objects. Other are stored as bit sequences. I.e. all numbers.

182
Q

What numeric operator is restricted to integers?

A

Modulo (%)

183
Q

And, or, not in Java.

A

&&
||
!
Inherited from C.

184
Q

How many times can you declare a variable?

A

Only once.

185
Q

How many times can you initialized a variable?

A

Only once.

186
Q

How to make a constant in java?

A

Use the keyword “final”
This tells the compiler that no future changes are allowed.

187
Q

How to you put a float in an int in Java?

A

You must explicitly type cast.
i.e.
int some_int = (int) some_float_value;

Note that this truncates the float.

188
Q

Java, if, else statements.

A

if (condition) {
} else if (condition) {
} else {
}

189
Q

Java do while loops?

A

do
{
} while (condition);

190
Q

Steps to being able to use keyboard input in java.

A

import java.util.Scanner;

Scanner in = new Scanner(System.in);

… = in.next(); or in.nextInt(); or in.nextDouble(); or ….

in.nextLine(); is common for strings.

191
Q

How to convert a string into another type?

A

I.e.
For integers.
Integer.parseInt(String s);

Other examples:
Float.parseFloat(String s);
Double.parseDouble(String s);

192
Q

String Comparison in java.

A

.equals() is best practice as I recall. That actually compares by value.

193
Q

Types of errors.

A

Errors of Commission:
Code you made has errors.
Syntax errors.
Minor logic errors.
Errors of Omission:
You did not write code for some behavior.
No design.
No plan.

194
Q

What is defensive programming?

A

A practice of writing code to facilitate validation and debugging.

195
Q

What is debugging?

A

Deducing the error from the fault.

196
Q

What is validation?

A

Using techniques to increase our confidence in the code.
I.e. formal proofs, informal reasoning, testing.

197
Q

Can we test all possible inputs?

A

No. But we can cover every method, check the return values, check that they manage errors appropiately, etc.

198
Q

What are the levels of testing?

A

Unit Testing.
Integration Testing.
System Testing.

199
Q

What is Unit Testing?

A

Test each method individually.

200
Q

What is Integration Testing?

A

Some methods working together. Limited combinations.

201
Q

What is System Testing?

A

The entire application. Very time consuming.

202
Q

What is bottom-up and top-down testing?

A

Bottom up:
First test units that use no other units. Work up, moving on to other modules that use the already tested modules.

Top down:
Implement the top-level methods first. Write tests for them. Leave low level methods as stubs. Work down until complete.

203
Q

When to use top-down vs bottom-up testing?

A

Top-down: Nebulous modules (or open-ended free-form projects).

Bottom-up: Well understood modules (or well-structured assignments).

204
Q

What is regression testing?

A

Comprehensive test scripts created during implementation. Rerun whenever a change is made. Easy to rerun and verify things are still correct.
Never delete a test case, unless the method it tests is deleted.

205
Q

How can we check the actual type of an object?

A

getClass()
instanceof
Casting

206
Q

What is the cosmic superclass?

A

Object

207
Q

List of basic data structures provided by Java.

A

Array
LinkedList
ArrayList
TreeMap
HashMap
TreeSet
HashSet

208
Q

What is an array in Java?

A

A single block of memory with a fixed number of values accessed by integer index. All values of the same type.
Can hold primitive or reference types.
Can hold duplicates.
Not part of the Java Collection Framework.

209
Q

ArrayList

A

Memory space to contain values. Accessed by integer index. Can grow or shrink as needed. All of the same type. ONLY REFERENCE TYPES. Duplicate lists permitted.

Methods like
get
add
remove
clear
isEmpty
size

210
Q

LinkedList

A

Sequence of values accessed in order of all the same type and only reference types. Exactly as much space as needed.
Exact same interface as List.

211
Q

Maps

A

Stores key-value pairs. Called dictionaries in Python.
HashMap (array-like)
TreeMap (tree-like)

212
Q

Example map methods?

A

put
remove
get

213
Q

T/F every object has a built in hash function.

A

True. However, it is not optimal. Can be overridden to make a better implementation. This often needs the .equals method to be overridden too.

214
Q

Sets in Java

A

Unordered collection. Can store, remove, and check values in sets. Only unique values. Like a map that only stores keys.

215
Q

What can we do if we want to use a primitive where we must use a reference type?

A

Java provides wrapper classes.
I.e. Interger
Such as ArrayList<Integer>()
Java automatically box and unboxes between the primitive and reference types. I.e. can just give an int literal and java will figure out the rest.</Integer>

216
Q

Generics.

A

I.e.
public class SomeCollection<i>{
private ArrayList<i> listofstuff;
….
}</i></i>

When making SomeCollection, can specify the type i to use.
Can also use restrictions.
i.e.
public class SomeCollection<i>{
….</i>

217
Q

What is an exception?

A

Any event that disrupts the normal flow of the program’s execution.
In Java, exceptions are objects.

218
Q

What happens if an exception if caught and not handled by the program?

A

The program halts and an error report is displayed.

219
Q

What did exceptions replace?

A

Error codes. Before, codes like -1, or -2,… would be returned to signify an error occurring.

However, these could be ignored (which is problematic). Exceptions cannot be ignored.

220
Q

How do you throw an exception?

A

throw new SomeKindOfException
(“Message to accompany the exception”);

221
Q

Try catch statement

A

try
{
codethatcouldthrowexceptions
}
catch (ExceptionType exception)
{
do something
}
catch (Exception exception)
{
do something
}

222
Q

Types of exceptions.

A

Error. Internal JVM errors.
Unchecked: Runtime exceptions. Caused by bad code (programmer’s fault). Compiler doesn’t force you to handle them.
Checked: All other types. Not the programmer’s fault. Compiler makes sure you handle these. Things like IOException, FileNotFoundException, etc.

223
Q

What do you do when you write a method that could potentially throw a checked exception?

A

Use the throws clause.
i.e.
public Type someFunction(args)
throws Some1Exception, Some2Exception,…

Note: Only needed if it does not catch the exception, only if it throws one.

224
Q

What is the finally clause?

A

In a try/catch block, it causes action to be taken whether or not an exception is thrown.

I.e. Closing a file whether or not writing to it works.

225
Q

How do you test exception?

A

Set up the test in a try catch block and intentionally do something that should cause an exception.
If it isn’t caught, print the error message for the test failing.

226
Q

Tips for exceptions?

A

Throw Early. Better to handle it that use an imperfect fix.
Catch Late: Only catch it if it can really be handled. Otherwise let it propagate until it finds something competent.
Do not squelch: Don’t do ‘do-nothing’ blocks. This only hides problems that could be serious.

227
Q

JFrame

A

A single GUI window

228
Q

JComponent

A

A single UI element (sometimes called a widget).
Like JPanel, JTextComponent, JLabel, JButton, and many more.

229
Q

JPanel

A

A JComponent that contains other Components

230
Q

What is the event delegation model?

A

When the user interacts with an event source, it makes an Event object. An EventListener can be registered to the event source. Custom code can be added to the Event Listener to respond.

231
Q

How do you register a listener to an event source?

A

ActionListener listener = new MyListener();
someEventSource.addActionListener(listener);

232
Q

What are the types of inner classes in Java?

A

Nested Inner Class.
Local Inner Class.
Anonymous Inner Class.

233
Q

How does a nested Inner Class work?

A

A class defined within another class.

class OuterClass {

class InnerClass {

}
}

The Inner Class has access to all members of the outer class, including private data members and methods.

234
Q

How does a Local Inner Class work?

A

Defined inside a method. Only exists in the scope of that method.

public class SomeClass {

void someMethod() {
class LocalInnerClass() {

}
}
}

235
Q

How does an anonymous inner class work?

A

Defined exactly when needed without a name. Instead of a name, provide the class or interface the inner class should inherit or implement from.

i.e.

public interface SomeInterface {
someMethod();
}

public class OuterClass {
public static void main(String[] args) {
SomeInterface n = new SomeInterface() {
void someMethod() {
somecode
}
}
n.someMethod();
}
}

236
Q

Cohesion

A

A class should represent a single concept.
A class if cohesive if all methods and attributes are related to the concept the class represents.
High cohesion is good.

237
Q

Coupling.

A

Many classes having relationships to each other is high coupling.
Low coupling is preferred.

238
Q

What is a design pattern?

A

A way to structure some part of the application code.
A general approach to some common design problems.

Used to reduce coupling and increase cohesion.

239
Q

What do design patterns consist of?

A

Intent: Brief description of problem and solution.

Motivation: Further explains the problem and the solution the pattern makes possible.

Structure: of classes showing each part of the pattern and how they are related.

Code example: used to make it easier to grasp the idea behind the pattern.

240
Q

Types of design patterns.

A

Creational.
Structural.
Behavioral.

241
Q

What does the Singleton pattern do?

A

Guarantees that only one instance of a class can exist in a system.
Provides global access to that instance form anywhere in the system.

242
Q

How do you use the Singleton pattern?

A

Make the constructor private.
Make the constructor not create more than 1 instance.
All interactions with the single instance uses static methods.

Make the constructor private.
Use a private static attribute to store the object.
Write a static method that returns this object.

243
Q

What is a static attribute?

A

A single value shared by all instances.

244
Q

What is a static method?

A

Used by providing the class name, not an instance/object. Can only use static attributes and local variables. Can not use instance attributes.

245
Q

What is the factory pattern useful for?

A

Abstracting the object creation process to reduce coupling between specific classes and other parts of the system.

I.e. We tell the factory we want a Cat, it gives us an Animal.

246
Q

Factory UML.

A

Some module (like main/the driver) makes calls to the Factory. The Factory makes calls to the Class hierarchy (which is enclosed in a larger box).

247
Q

How do you define an enum in Java?

A

public enum NameOfEnumType {
ENUM1,
ENUM2,
ENUM3
}

248
Q

Principles of the strategy design pattern.

A

Identify what varies and separate it from what is constant.
Program to a super-type, not an implementation.
Favour composition over inheritance.

249
Q

What is the main idea of the strategy design pattern?

A

Turn behaviors into classes.
A class contains (composition) SomeBehavior interfaces, the implementations of which contain methods.
Can then call said methods like
SomeBehavior.doThing(args);

250
Q

What is the favour composition over inheritance principle?

A

Favour “has-a” over “is-a”.
I.e.
Duck subclass is-a bird, and has-a flybehavior, instead of Duck is-a flying bird.

251
Q

Difference between architecture and pattern?

A

Patterns are good for pieces. Architectures are for the whole system’s organization. Less concerned with details, and more on the overall structure.

252
Q

Presentation layer of Three-Layer-Architecture.

A

User interface.
Calls methods in the Domain layer.

253
Q

Domain layer of Three-Layer-Architecture.

A

Also called business layer. Gets the work done. Contains methods called by presentation layer.

254
Q

System layer of Three-Layer-Architecture.

A

Also called Data layer. Collections (databases) needed by the Domain. Sometimes in another language or technology.

255
Q

Advantages to the Three-Layer-Architecture.

A

Reduces coupling.
Increases cohesion.
Organization. Very useful for larger programs.

256
Q

How can the Presentation and Domain layer be separated?

A

The Command Pattern.

257
Q

When is the Command Pattern less useful?

A

Heavily interactable programs, such as games. They are better with MVC.

258
Q

What is the basic thing the Command Pattern does?

A

Encapsulates requests as Command Objects.
Hides the action behind a common interface. They independently perform their action. They can be tested automatically.

259
Q

What is the Command Interface?

A

Make a new class for every unique request and implement the command interface. Write the code for the request in the method defined in the interface.

Can then create a new object for each request as needed, store commands in data structures, etc.

Essentially taking a verb (action) and treating it as a noun (thing).

260
Q

Strategy vs. Command pattern.

A

Strategy is for how something should be done.

Command is for what needs to be done.

261
Q

What does the Observer pattern do?

A

Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.

Has a:
subject/observable
observer
client/driver program

262
Q

UML of Observer pattern.

A

Client makes calls to both subject and observer. Subject aggregates observers, and makes call to them (for push).

263
Q

What does the Subject need in a UML?

A

Attributes:
observers: ArrayList<Observers></Observers>

Methods:
addObserver
removeObserver
notifyObservers

264
Q

What does the observer need in a UML?

A

Methods:
update

265
Q

How can coupling be minimized in MVC?

A

Subject shouldn’t know everything about the observer.
Observer shoudn’t know everything about the subject.
The subject needs to notify the observer that data changes, but does not need to know the detail of who it’s notifying.

User an interface in the middle.

266
Q

UML, minimized MVC coupling.

A

Using an interface in the middle (ActionListener).
Ball and socket notation.
source has socket, listener has ball. Write text for the name of the interface. i.e. “ActionListener”

267
Q

MVC with Observer Pattern UML.

A

Controller aggregates View and Model, composed of a Listener (MyListener).

MyListener connected to View with ActionListener interface (ball and socket).

View connected to Model with Observer interface (ball and socket).

Client calls controller, model, and view.

Model implements Observable.

268
Q

View - Observer

A

Implements Observer interface
update() called by model when data changes

269
Q

Model - Observable

A

Inherits form Observable class.
addObserver() inherited

model.addObserver(view) can be used after creation (in client) to let the view be notified when the model wants.

270
Q

What do you do in the model after making a change to the data?

A

Call
setChanged()
notifyObservers()

271
Q

How does the View Update?

A

It can request data from the model (pull via accessors) or be sent data directly (push).

If pulling, the view needs to store the model as an instance variable.

If pushing, use notifyObservers(Object arg)
Which sends an object of our choice to all observers.

272
Q

How to make a custom JComponent.

A

Make a class that inherits from JComponent. Override the paintComponent method.
Write custom drawing code to customize how your component works.

273
Q

What are some basic drawing commands?

A

g.setColor(Color)
g.drawRect(int x, int y, int width, int height)
g.fillRect(int x, int y, int width, int height)

And many many more

274
Q

What are the categories of steam objects in java?

A

Java Byte Streams: used to perform input and output for 8-bit bytes

Java Character Streams: perform input and output for 16-bit Unicode characters.

275
Q

What are the two ways to store data in a file?

A

Text format (character streams)
Binary format (byte stream)

276
Q

What makes Java binary files special?

A

They are platform independent.

277
Q

Difference between InputStream/OutputStream and Reader/Writer?

A

Stream uses byte streams.
Reader/Writer used Character streams.

278
Q

How to read text from a file?

A

Scanner stream = new Scanner( new FileInputStream(filename));

Scanner behaves the same as if from System.in.

Or:
File inputFile = new File(“filename”);
Scanner in = new Scanner(inputFile);

279
Q

How to output to a file?

A

PrintWriter out = new PrintWriter(“filename”);
If filename exists, it will be overwritten, if not, it will be created.
out.println(“line to print”);

280
Q

How to close a file in Java?

A

fileobj.close();

281
Q

What package are timers part of?

A

javax.swing

282
Q

How do the timers in Java work?

A

They fire an ActionEvent with a specified delay.

283
Q

Creating a timer example.

A

MyActionListener L = new MyActionListener();
Timer t = new Timer(1000, L);
t.start();

1000 is ms

284
Q

Processes vs Threads

A

Modern OS can run multiple processes at the same time. Each process can have multiple threads.

285
Q

How can multithreading speed things up?

A

Divide a large job into many independent threads. Run all threads at the same time.

Can also do things like separating the UI from the work.

286
Q

Thread object methods.

A

run()
start() (jvm calls run)
wait()
sleep(long ms)

287
Q

How can you create a thread in java?

A

Extend the thread class and override run, or use the runnable interface and implement run() method.

288
Q

What is a race condition?

A

The effect of multiple threads on a shared resource depends on the order in which they are scheduled.

289
Q

What is an atomic action?

A

An action that cannot be interrupted until it is complete. At the machine code level, not the Java source level.

290
Q

How can race conditions be handled?

A

Only allow one thread to access the resource at a time. This is called synchronizing. Access controlled with locks. When one thread has the lock for a resource, no other thread can access it until it releases the lock.

291
Q

How do you use a built in Lock?

A

Put the synchronized modifier on a method (this only allows one thread to use the method at time).
public synchronized void myMethod() {}

292
Q

Lock object methods.

A

lock()
try to obtain the lock, if successful, other threads cannot obtain it. If unsuccessful, the thread is paused.

unlock()
release the lock. other threads can try to obtain it now.

293
Q

What happens if an exception is thrown between a lock and unlock?

A

lock it

in a try statement, manipulate it

in the final statement, unlock it

294
Q

What is a deadlock?

A

occurs when no thread can proceed because they are all waiting for another to do some work first.

295
Q

What is a condition object?

A

Allow a thread to temporarily release a lock and regain it again at a later time.

296
Q
A