1/98
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Software development is all about learning a programming language.
False
Object Oriented Programming
A program consisting of classes and objects organized to manage the complexity of large-scale systems
Procedural Programming
A program consisting of methods/functions calling each other
Method
Implements behaviours relevant to the purpose of the system
Field or Attribute
Stores data relevant to the purpose of the system
Entity Object
Model of a real-world thing in an application
Control object
organize computation or flow of the program
Interface Object
Facilitates communication between the system and the outside world
Container Object
Data structure to store entities
A UML Class Diagram is a type of behavioural diagram
False
What does a toString() method do in Java?
It allows a programmer to define a String representation of their class
The tree class does not have a ‘chopDown’ method. What describes it’s behaviour?
a) Set height to 0
b) Mark isDead = true
c) Free memory
d) Set tree to null
The tree variable is set to null
Why doesn’t the Tree class have a height setter?
a) height is public
b) height never changes
c) grow() is the setter
d) getHeight() sets it
it has one, the method grow() acts as a mutator
which class acts as the main/client program?
a) inventory
b) forest
c) tree
d) TreePlanter
TreePlanter
which step was ommited from the lecture development process?
a) documentation
b) unit testing
c) uml
d) stub methods
unit testing
what was the final step in the development process followed in the lecture?
a) uml
b) unit testing
c) documentation
d) coding methods
a) implementing/coding methods
which of the following types could be stored in a container of WaterMonster?
a) Squiiirtle
b) Starfishy
c) Peekatu
d) Monster
e) ElectricMonster
f) WaterMonster
squirtle, starfishy, watermonster
effective use of polymorphism is good because it increases coupling in a software system
false
which keyword is used to indicate inheritance in java?
extends
polymorphism can be used with both inherited super types and implemented interface types
true or false
true
which of the following methods are inherited from the Object class?
a) getClass()
b) equals()
c) scanner.readInt(),
d) System.out.println()
e) attack()
f) toString()
getClass, equals(), toString()
the downside to polymorphism is that you cannot convert an object back to its original type
false
which of the following are a benefit of polymorphism?
a) Reduces coupling
b) Reduces code
c) Simplifies code
d) Increases flexibility
all of the above
which keyword defines a class uses an interface in Java?
a) inherits
b) implements
c) instanceof
d) extends
implements
which of the following data structures in Java can store primitive types?
a) TreeMap
b) ArrayList
c) Array
d) HashSet
Array
An ArrayList uses an Array to store its data, and therefore an ArrayList has a fixed size that must be specified upon creation
false
An Array can only store primitive data types.
false
Both TreeMap and HashMap implement the same Map interface, and can therefore be used interchangeably
true or false
true
Imagine you are creating a role-playing game and need to store all of your inventory items in a collection. You want to be able to look up an item by name, and frequently get a list of all of the item names sorted alphabetically. Which of the following collections would you use?
a) TreeSet
b) TreeMap
c) Hashmap
d) LinkedList
TreeMap
Imagine you are in need of a collection that stores items in a linear structure and will be frequently inserting and deleting from the middle of the collection. Which collection would be the best option?
a) HashMap
b) TreeSet
c) ArrayList
d) LinkedList
d) LinkedList
The collections classes, such as LinkedList and TreeMap, are defined using Generic typing.
true or false
true
Generic typing is reserved for classes provided by Java, such as ArrayList. We cannot implement generic typing in custom classes.
False
It is possible to restrict a generic type to a particular supertype, such as a class or an interface type.
true or false
true
The Comparable interface allows different instances of the same class to be comparable using the '<' and '>' operators.
false
By implementing the Comparable interface, Java will automatically generate the rules by which to compare that object.
false
After an exception is caught, the program continues execution where the exception was originally thrown.
false
Which of the following scenarios describe a situation when an exception should be thrown?
a) a user enters bad/incorrect data
b) a test regression fails
c) a bug detected in the program
d) a parameter violates a stated precondition
a user enters bad data, a parameter violates a stated precondition
Where is the best place to catch and handle an exception?
a) the main program
b) the method that has enough information to most effectively handle the exception
c) immediately, the place where the method that threw the exception is originally called
the method that has enough information to most effectively handle the exception
A try-catch statement can catch multiple different types of exceptions from the same try block.
true or false
true
When using the Scanner class' nextInt() method, which of the following exceptions are most likely to be thrown if the user enters something that isn't a number?
a) ArithmeticException
b) InputMismatchException
c) NullPointerException
d) InputMismatchException
InputMismatchException
Which of the following statements about exceptions is true?
a) A checked exception is named because it indicates a bug that should have been checked over by the programmer
b) Unchecked exceptions are things like IOException and FileNotFoundException
c) Your code will not compile if you don't try to catch a potential checked exception
d) Your code will not compile if you don't try to catch a potential unchecked exception
Your code will not compile if you don't try to catch a potential unchecked exception
Which of the following will create a pop-up dialogue box, prompting the user to enter some text into the program?
a) JOptionPane.showMessageDialogue()
b) JOptionPane.showOptionDialogue()
c) JOptionPane.showConfirmDialogue()
d) JOptionPane.showInputDialogue()
JOptionPane.showInputDialogue()
Which of the following classes in Java Swing represents the application's window?
a) JWindow
b) JFrame
c) JPanel
d) JLabel
b) JFrame
Which of the following is not a JComponent?
JFrame
JPanel
JButton
JLabel
JFrame
Which of the following is a container widget/component?
JButton
JPanel
JLabel
JTextField
JPanel
When creating a graphical user interface, the interface is automatically made visible when the JFrame object is created.
false
JFrame is a Java class, which means we can create a custom window/frame by creating our own custom class which inherits from JFrame.
true or false
true
In the event delegation model, which of the following is a JButton?
Event Source
Event Handler
Event
Listener
Event Source
Assume you want to respond to a button click. Which of the following describes the process?
You create a class that inherits from ActionListener
You create a class that implements the ActionListener interface
You directly bind a method to the button using the 'addMethodBinding()' method
You write a method called 'actionPerformed()' which is automatically bound to the button
You create a class that implements the ActionListener interface
Consider the following code:
public class MyFrame extends JFrame {
JButton myButton;
public MyFrame(){
JPanel panel = new JPanel();
myButton = new JButton("Click me");
myButton.addActionListener(new MyClickListener());
panel.add(myButton);
this.setContentPane(panel);
}
class MyClickListener implements ActionListener {
public void actionPerformed(ActionEvent e){
System.out.println("clicked");
}
}
}
Which of the following describes what 'MyClickListener' is?
A method
An Anonymous class
A Local Inner class
A Nested Inner class
A Nested Inner class
An anonymous inner class is defined without needing to assign the class a name.
true or false
true
In software design, a goal is to maximize cohesion.
true or false
true
In software design, a goal is to maximize coupling.
false
A design pattern and an algorithm are the same thing.
false
Which type of design pattern is the Singleton Pattern?
Adaptable
Structural
Behavioural
Creational
Creational
Which features does the Singleton Pattern provide?
Encapsulates an action or behaviour into a separate class
An abstracted approach for broadcasting updates to other objects in the system
Provides global access to the object instancer
Guarantees at most one instance of the class can exist in the system
Provides global access to the object instancer
Guarantees at most one instance of the class can exist in the system
A static method can access both static variables and instance variables.
false
Which of the following is not part of the Singleton Pattern?
A public, static method that returns the instance
A public constructor
Creating an instance if one doesn't already exist
A private, static instance to an object of its own type
A public constructor
What type of design pattern is the Factory Pattern?
Behavioural
Adaptable
Creational
Structural
Creational
What is the main goal of the Factory Pattern?
To create lots of objects very quickly
To encapsulate an action or method as a separate object
To guarantee at most one instance of a class can exist in the system
To abstract the creation of a class or a hierarchy of classes
To abstract the creation of a class or a hierarchy of classes
In lecture, our initial implementation of the Factory Pattern used Strings as the parameter type to the factory method. What was the issue with this design choice?
It is easy to make spelling errors
It made the coupling between the main program and the factory too high
The Factory was inefficient
The factory wasn't returning the correct type of object
It is easy to make spelling errors
What type was String replaced with in the second iteration of the Factory?
A Set
A character Array
An integer
A Java enum
A Java enum
In the third iteration of the factory, we refactored the Monster inheritance hierarchy. Which classes in the system had to be rewritten to accommodate this large refactor (besides the Monster classes themselves)?
Only the MonsterFactory class
The main program and the MonsterFactory class
The main program
Everything
Only the MonsterFactory class
Which type of design pattern is the Strategy Pattern?
Creational
Structural
Adaptable
Behavioural
Behavioural
What is the main goal of the Strategy Pattern?
Define and encapsulate a family of algorithms to make them interchangeable in the program
To encapsulate a method for the purpose of storing actions in data structures
To gain global access to a specific object instance
To more efficiently create object instances
Define and encapsulate a family of algorithms to make them interchangeable in the program
What is meant by the principle to "program to the supertype, not an implementation"?
More levels of inheritance are always better to increase cohesion
You should store objects in the most specific type possible
When using Java Collections, you should pick the correct type to best model your program
You should store objects in the most general type possible
You should store objects in the most general type possible
What is meant by the principle of "favour composition over inheritance"?
You should prioritize 'is-a' relationships over 'has-a' relationships
Inheritance is always the best approach to designing and organizing your program
Inheritance always over complicates your program and it should be avoided
In some cases, encapsulating behaviours as objects makes the program more flexible than using inheritance
In some cases, encapsulating behaviours as objects makes the program more flexible than using inheritance
Which of the following would be reasonable candidates for using the Strategy Pattern?
Implementing an 'undo/redo' system
Abstracting the creation of many different types of ducks
Creating a bunch of different types of shapes in a drawing program
Managing a Queue of web requests
Choosing different routing algorithms in a map program
Storing a central data structure of Student objects
Equipping different attacks/abilities to a pokemon
Choosing different routing algorithms in a map program, Equipping different attacks/abilities to a pokemon
What are the three layers in the 'Three-Layer Architecture'?
Presentation, Domain, System
Which of the following is NOT true about the Three-Layer Architecture?
The Command pattern can be used to coordinate between the Presentation and Domain layer
The Observer Pattern is used to update the databases whenever classes in the Domain layer change
It promotes increased cohesion by forcing classes to be focused on smaller tasks
Each layer can only call methods in the layer below
The Observer Pattern is used to update the databases whenever classes in the Domain layer change
Which type of design pattern is the Command Pattern?
Adaptable
Creational
Behavioural
Structural
Behavioural
What is the main goal of the Command Pattern?
Define and encapsulate a family of algorithms to make them interchangeable in the program
To more efficiently create object instances
To encapsulate a method for the purpose of storing actions in data structures
To gain global access to a specific object instance
To encapsulate a method for the purpose of storing actions in data structures
The Command Pattern uses Inheritance instead of Composition
False
How are individual commands abstracted?
Commands don't share a common supertype, but they can be stored in the same data structure
An intermediate class handles the creation and management of Command objects
Commands all inherit from a common super class
Commands all implement the same 'Command' interface
Commands all implement the same 'Command' interface
Which of the following would be reasonable candidates for using the Command Pattern?
Storing a centra data structure of Student objects
Equipping different attacks/abilities to a Pokemon
Creating a bunch of different types of shapes in a drawing program
Choosing different routing algorithms in a map program
Implementing an 'undo/redo' system
Managing a Queue of web requests
Abstracting the creation of many different types of ducks
Implementing an 'undo/redo' system
Managing a Queue of web requests
Client/Driver
Creates the objects and sets up the pattern
Subject/Observable
The thing being observed
Observer
The classes that receive notifications/updates
indicate the corresponding component of an analogy using Podcast distribution: Observer
The user that subscribes and listens to the podcast
The publisher/creator of the podcast
The act of subscribing to a podcast
The user that subscribes and listens to the podcast
indicate the corresponding component of an analogy using Podcast distribution: Subject/Observable
The user that subscribes and listens to the podcast
The publisher/creator of the podcast
The act of subscribing to a podcast
The publisher/creator of the podcast
indicate the corresponding component of an analogy using Podcast distribution: Client/Driver
The user that subscribes and listens to the podcast
The publisher/creator of the podcast
The act of subscribing to a podcast
The act of subscribing to a podcast
In order to minimize coupling, the Subject should minimize it's knowledge about the Observer's details, but the Observer should always have full access to the Subject.
false
Which of the following describes the use of UML 'ball-and-socket' notation?
Creating an interface to abstract/loosen coupling between two objects
An alternative version of 'Composition' and 'Aggregation' that indicates a stronger contains relationship
A special kind of inheritance used in the Observer Design pattern
Indicates a part of the program with excessive coupling that needs to be fixed
Creating an interface to abstract/loosen coupling between two objects
Which of the following previous topics uses the Observer pattern?
ArrayLists
ActionListeners
Polymorphism
Encapsulation
ActionListeners
Which design pattern is commonly used in the Model-View-Controller architecture?
Strategy
Observer
Factory
Command
Observer
Which of the following would be the responsibility of the Model?
Interprets user input through ActionListeners
Visually presents data to the user
Generate ActionEvents in response to user interaction
Perform the program's business logic
Call methods on the Model in response to user commands
Update the View when the program's data changes
Perform the program's business logic
Update the View when the program's data changes
Which of the following would be the responsibility of the Controller?
Generate ActionEvents in response to user interaction
Perform the program's business logic
Interprets user input through ActionListeners
Update the View when the program's data changes
Call methods on the Model in response to user commands
Visually presents data to the user
Interprets user input through ActionListeners
Call methods on the Model in response to user commands
Which of the following would be the responsibility of the View?
Generate ActionEvents in response to user interaction
Interprets user input through ActionListeners
Visually presents data to the user
Perform the program's business logic
Call methods on the Model in response to user commands
Update the View when the program's data changes
Generate ActionEvents in response to user interaction
Visually presents data to the user
Which part of the architecture is the Observer?
Model
Main Program
Controller
View
View
When does the Model send an update to the View?
Every time the data changes
Every second
It doesn't
60 times per second
Every time the data changes
To create a custom GUI element/widget, which class do we need to inherit from?
JFrame
Observable
JWidget
JComponent
JComponent
Which method needs to be overridden to make a custom GUI element/widget appear?
drawWidget
fillRect
repaint
paintComponent
paintComponent
Which method needs to be called in order to update a custom GUI element/widget's appearance at runtime?
fillRect
drawWidget
repaint
paintComponent
repaint
What type of object is passed into the paintComponent method as a parameter?
Graphics
Canvas
GraphicsContext
Context
Graphics
When you are writing code to draw a GUI element/widget, you need to set the colour for each shape you draw
true or false
false
By default, a javax.swing Timer object will send an ActionEvent repeatedly with a specified delay
true or false
true
A javax.swing Timer automatically starts when the Timer object is created
true or false
false
n the Flashing Rectangle example from class, which part of the MVC architecture managed the Timer to initiate animation changes?
Controller
Model
Main Program
View
controller
In the Flashing Rectangle example from class, which part of the MVC architecture stored the animation data (i.e., the sequence of colours)?
Model
View
Main Program
Controller
Model