Exam 2 Flashcards

1
Q

PTUI

A

Plain text user interfaces - command line interfaces

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

GUI

A

Graphical user interface - comprised of graphical controls

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

GUI toolkit used in class

A

JavaFX

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

Java’s original GUI toolkit

A

Abstract Window Toolkit - OS specific. Used heavyweight windows

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

Java Swing

A

GUI added in v. 1.2. lightweight and platform-independent.

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

GUI using JavaFX begins by __ the __ __.

A

Extending, Application class. Application is abstract.

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

The ___ is a window in which the JavaFX application runs

A

Stage

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

T/F: A stage is used to display a scene

A

True

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

T/F: Only one stage can exist at a time.

A

False. Additional stages show as separate windows. Primary is auto-created with start method

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

Scenes contain __, which can be __ or __

A

Single control. Widgets (button, label, text). Pane (container for other controls).

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

The graphical element that is the building block of a GUI

A

Control aka node

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

Control used to display a string of text

A

Label

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

JavaFX controls are highly __

A

Customizable

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

Some basic modifications to a label

A

setText(String)
setFont(Font)
setPadding(Insets)

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

Common stage sets

A

stage.setTitle(String)
stage.setScene(scene)
stage.show()

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

Controls can be customized __ and through the use of __

A

Programmatically. Cascading style sheets (CSS)

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

Layout

A

Container in which nodes can be added. Determines where the nodes are, including position and size. Layout is also a node.

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

Layout that arranges children from left to right

A

HBox

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

Layout that arranges children from top to bottom

A

VBox

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

To add children to an HBox or VBox

A

box.getChildren.add(Node)

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

T/F: HBox and VBox layouts automatically fill in extra space by default

A

False. Only use space each child needs. Use setMaxHeight(Double.POSITIVE_INFINITY) or width to adjust widgets

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

A __ method contains code to build some product

A

Factory. Anything that stays the same between outputs is placed in method. Changing factors in parameters.

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

Insets

A

Used to define extra space on the top, bottom, left, and right of something. Can be used within padding setting to achieve.

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

CornerRadii

A

Used to round corners on otherwise rectangular shapes

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

Border

A

Drawn around outside edges of a component

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

BorderPane

A

Divided into five regions: top, bottom, left, right, center. One node each max (last kept if multiple)

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

T/F: An empty region in a BorderPane will be invisible

A

True

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

GridPane

A

Organizes children into columns and rows (col first). Exact num doesn’t need specifying on instantiation.

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

T/F: In a GridPane, children can only exist in one location (col, row)

A

False. Nodes can expand using additional arguments on add method
gp.add(label, 3, 4, 1, 2)

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

TextField

A

Control in which user can type single line of text. Can include prompt text.

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

Button

A

Control that users can interact with using the mouse or keyboard. Created with text or image. Responds to mouse events (enter, exit, hover, click)

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

Trying to set a background for a button will…

A

Remove its default highlights and shading

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

Observer Design Pattern

A

When there is a subject of interest, it maintains a list of observers that will be notified when something happens.

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

EventHandler<T></T>

A

An observer interface that must be implemented by classes that want to be notified when an event occurs on a JavaFX control.

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

When using event handler, the real type that replaces the T must …

A

Extend the Event class. handle (T) called when event of interest occurs

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

ActionEvent

A

Used for button interaction. Button is subject. Observers must implement EventHandler<ActionEvent>. Can use button.setOnAction(EventHandler) to register to be notified</ActionEvent>

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

Image

A

Used to load and display images

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

Ways to load an image

A
  1. String URL, starting with “file:…”
  2. An InputStream
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

ImageView

A

Control just for displaying images. Cannot be added directly to a scene. Must have a parent.

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

StackPane

A

Stacks children one on top of the other in order added. Can be used to create a composite image.

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

Media

A

Class that represents an audio or video file. Source may be internet address or file in local system

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

Used to play media

A

MediaPlayer. Does not have a visual component

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

T/F: Labels can also be used to display graphics

A

True. Can set where image sits in relation to text

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

Grow Priority

A

Used for HBox and VBox to determine if child nodes will grow horizontally or vertically (respectively) to fill in extra space

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

Architecture

A

High level design that determines how the classes in a system are organized

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

MVC

A

Model View Controller is a pattern used when creating applications with user interfaces.

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

In MVC, the model

A

Basic building blocks of the app. Core elements and any logic needed to maintain or update the state of the application

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

In MVC, the view:

A

Part of the app the user can see. Represents current state of the model. Updated as model changes.

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

In MVC, the controller:

A

Core application logic. When input provided, it determines how to translate this action to the model. May also update the interface.

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

In GUIs some or all of the controller logic is often ___

A

Embedded in the GUI

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

A background can be set to an image using

A

BackgroundImage. If smaller than the control, image can be repeated

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

Practice of writing code that is executed in response to events is referred to as __

A

Event-Driven Programming

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

Abstract Data Type

A

Describes the behavior of data structure from user perspective without implementation details

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

Data Structure

A

Grouping of related data (elements)

55
Q

Queue

A

First in, first out (FIFO). No random access.

56
Q

A data structure that has at least one field of its own type is __

A

Recursive. Used to build linked sequences.

57
Q

Components of a Node

A

Value of some type (content)
Reference to the next node in the sequence (could be null)

58
Q

In a node sequence, the first node is the __ and the last is the __

A

Head. Tail. Tail’s next is null.

59
Q

A queue should be implemented as a __ and has the following operations:

A

Interfaces.
Enqueue
Dequeue
Size
(Front, back, is empty) Optional

60
Q

In a node-based queue composed of a single node, that node will be ___

A

The front and back

61
Q

In a node-based queue, the __ node is the front and the __ is the back

A

Oldest. Newest.

62
Q

T/F: In a node-based queue, if a dequeue is performed, the new front is changed to the old front’s next node.

A

True

63
Q

An array-based queue can use a __

A

Circular array. If indexes of front or back reach the end, they wrap around to the beginning

64
Q

In an array-based queue, when an element is enqueued, it is added at the __ index, which is then incremented

A

Back

65
Q

When does a circular array need to be resized?

A

When the size is equal to the length of the array before an enqueue

66
Q

In an array-based queue, when dequeuing, the __ index is returned and the index is incremented

A

Front

67
Q

In an array-based queue, the value at the index being dequeued should be __ before the index is incremented

A

Set to null

68
Q

How to handle dequeue on an empty queue

A

Return null
OR
Throw an exception

69
Q

T/F: In an array-based queue, after a resize, the indexes stay the same for the head and tail

A

False. Head will be set to 0 and tail will be set to size.

70
Q

Time complexity for queue operations

A

O(C). Worst is for array when it needs to be resized, which is rare (O(N))

71
Q

Space complexity: node vs array queues

A

Creating node object for every element uses more memory than array, but arrays queues usually over-allocate memory.

72
Q

Generic Type

A

Declares one or more type parameters between angle brackets. When variable declared, a real type is specified in place of each type parameter.

73
Q

Generic Class

A

Class that uses a generic type

74
Q

Trying to use a different type after a variable is declared with a real type on a genetic type will cause …

A

A compiler error

75
Q

T/F: A generic type can’t use its own type parameter when declaring variables of a generic type.

A

False. Generics can be combined.

76
Q

T/F: A type parameter cannot be used within the body of a class unless it is declared as part of the class.

A

True.

77
Q

Two options when extending/implementing a generic type

A
  1. Make the new class generic as well
    public class A<T> extends B<T></T></T>
  2. Make the new class only work with a specific real type
    public class A extends B<String>
    Will lose flexibility with second</String>
78
Q

T/F: Generics only work with reference types

A

True. Cannot use primitive types without autoboxing

79
Q

Autoboxing

A

Translating from a primitive type to a wrapper class (int to Integer)

80
Q

Unboxing

A

Translating from a wrapper class to a primitive type (Integer to int)

81
Q

List operations

A

Append
Get
Set
Size
(Insert and Remove optional. Would cause shifting)

82
Q

T/F: Lists maintain elements in order added

A

True

83
Q

Lists closely resemble a __ array

A

Dynamically sized

84
Q

An array list is created with an array of ___ that are then ___

A

Objects. Cast to other types
Object[] things = new Object[10];
things[0] = anyValue;
Object obj = things [5];
T thing = (T)obj;

85
Q

Array lists keep track of

A

Capacity and size
Resize when size equals capacity

86
Q

Method to copy an array

A

Arrays.copyOf(orig, size)

87
Q

Linked list keeps track of

A

First node - head
Last node - tail
Size
Similar to linked nodes, but uses indexes to search, get and set.

88
Q

Array List time complexity

A

O(C)
O(N) for append when need to resize array.
O(N) for any shift operations in middle of list

89
Q

Linked list time complexity

A

Append, get, set, insert, remove at head or tail, O(C).
Anything in middle of list, O(N)

90
Q

Java for-each loop

A

for(int element : an_array)

91
Q

Iterator

A

Returns each element in a data structure in some sequential order. Defines basic methods used by for-each loop

92
Q

T/F: An iterator is guaranteed to return each element in the sequence exactly once.

A

True

93
Q

A data structure must implement the __ interface and return a working __ to work with for-each

A

Iterable. Iterator.

94
Q

T/F: An interface can extend a class

A

False. An interface can only extend another interface

95
Q

An interface may provide a ___ of one or more of its methods

A

Default implementation

96
Q

If a class implements an interface but doesn’t provide an implementation of a default method …

A

The default implementation is used by default

97
Q

Default method typical use

A

For adding methods to an existing interface to avoid compilation errors in existing classes

98
Q

JCF

A

Java Collections Framework. Java’s unified architecture for representing and manipulating collections.

99
Q

Collection frameworks contain three things:

A

Interfaces defining abstract Data structure
Implementations of interfaces
Methods provide useful algorithms

100
Q

JFC Queue method names for enqueue and dequeue

A

Offer and poll

101
Q

JFC’s Stack iterates __

A

Backwards (bottom to top)

102
Q

Non-empty binary tree comprises at least one __

A

Node

103
Q

Leaf

A

A node whose left and right subtrees are both empty

104
Q

Internal node

A

A node that is not a leaf

105
Q

Root node

A

Has no parent node

106
Q

Visiting each node in a tree is referred to as…

A

Traversing the tree

107
Q

Infix Traversal

A

Nodes are visited left, middle, right. Would get values in increasing order. Also called in order traversal

108
Q

Binary trees are __ data structures

A

Recursive

109
Q

General search process for binary trees

A

If target is the root, return true. Else go down the left or right subtrees (if not null) and search for target. If not found at all, return false.

110
Q

Search complexity of a binary tree

A

O(N). On average, half of the nodes need searching.

111
Q

Binary Search Tree

A

Left subtree is only values less than parent. Right is only values more than parent.

112
Q

Binary Search Tree searching algorithm

A

Same as binary tree, but uses value of target to determine which subtree to go down

113
Q

A binary tree should be __ and its subtrees __

A

Balanced. Bushy. Approximately same number of nodes in both halves at every level

114
Q

Unbalanced trees are more __

A

Branchy than bushy

115
Q

An extremely unbalanced tree becomes __

A

A list

116
Q

Complexity of searching a BST

A

Depends on how balanced the tree is. A balanced tree O(log2N). An unbalanced tree approaches O(N)

117
Q

A type is made naturally comparable by …

A

Implementing the Comparable interface.

118
Q

Comparable

A

Generic interface that defines type parameter T. Class usually subs its own type. Uses compareTo(T other) method.

119
Q

Comparator

A

Helper class that can be used to sort objects that don’t have a natural order or need to be sorted another way.

120
Q

A comparator class will …

A

Implement Comparator. Uses the compare(T a, T b) method

121
Q

Heap

A

Binary tree in which each node is of equal or lower priority than that of its parent. Root has highest priority.

122
Q

T/F: In heaps, the horizontal order of nodes matters

A

False. Only the relationship between child and parent matters in terms of priority.

123
Q

Min-heap/Max-heap

A

Organizes values from smallest to largest/largest to smallest

124
Q

T/F: Priority is determined by the programmer

A

True. Based on the problem statement

125
Q

Heaps can be created using an __ on an array

A

Overlay. Root is index 0
k is the index of a node where 0<=k<N
left child: 2k+1
right child: 2k+2

126
Q

If a value added to a heap is higher priority than its parent…

A

Values are swapped. Swap continues until value in correct position. Called sifting up.

127
Q

The __ is always removed from the heap

A

Root. The rightmost node on the bottom level becomes new root. Values sift until priority is correct.

128
Q

Worst case time complexity for adding to heap

A

Standard is O(C), but O(log2N) if value needs to sift all the way up

129
Q

Worst case time complexity for removing from heap

A

Standard O(C). If value needs to sift all the way down O(log2N) length of the tree

130
Q

TreeSet and TreeMap are unique in that they…

A

Keep elements/keys in sorted order. Require comparable elements or a comparator. Perform slightly slower as a result.

131
Q

Red-Black Tree

A

Self-Balancing BST. Elements moved around to maintain balance. Guaranteed O(log2N) for search, insert or remove

132
Q

HashSet and HashMap provide __ performance for all basic operations

A

O(C)

133
Q

TreeSet/Map should only be used over HashSet/Map when…

A

The elements must be maintained in sorted order