Past Exam Questions
Data Structures
Graphs
JavaFX / MVC
Threads /Networking
100

How many superclasses may a class directly extend? And how many interfaces may a class implement?

A class can only extend one superclass. A class can implement an unlimited number of interfaces.

100

Which Java interface guarantees constant-time access by index: List or Set

List

100

What’s the difference between a directed and undirected graph?

An undirected graph can be represented by a directed graph where all edges go both ways.

In a directed graph, you may be able to go from node A to node B, but not back from node B to node A.

100

(True / False) A JavaFX application is usually started by calling its start method within main.

False

100

What is the difference between the start() method, and the run() method in the Thread class?

Calling the run() method directly runs the threads in the main thread (not parallel). The correct way to have threads run concurrently is to call the start() method.

200

What is the difference between types like int and types like Integer? When can we use one and not the other?

The lowercase int is the primitive version, and the uppercase Integer is the class version. We can not use the primitive int when declaring the generic type of things like ArrayLists.

200

What is the difference between an array and an ArrayList?

Arrays are built in, and cannot be resized. No add or remove methods. Index with [].

ArrayLists are part of the Java Collections Framework, and can be resized. Has add and remove methods. Index with .get().

200

In an adjacency list, how is the graph represented?

The graph is represented by a key-value pair. Key: a node on the graph, Value: A list of the adjacent nodes

200

Draw a BorderPane where the top is a Label("Top"), the center is a Button("Center"), and the right is a Button("Right").

"Top" spans the entire top, "Center" should be in the bottom left, and "Right" should be in the bottom right.

200

When a thread calls this method, it blocks until the other thread finishes.

join( )

300

What does a try-with-resources block do? What types of objects can be put in the beginning of such a block?

try-with-resources ensures that whatever IO class you open with it will be closed when you leave the try-with-resources.

You can put IO classes in the beginning of such a block.

300

How does a HashSet determine whether two objects are the same?

They have the same hashcode, and the equals method returns true on them.

300

Write the adjacency list for this graph:

Show Image Slide 1

{ A: [B, C],    B: [D],    C: [D],    D: [A, C, E],    E: [F],    F: [G],    G: [H],    H: [D] }

300

What is the Model, the View, and the Controller?

Model: The state of the world represented by code, it has no GUI elements directly

View: The part of the GUI that the user can see, and interact with.

Controller: Handles user input events, such as button presses or mouse movement. Accepts input and converts it to commands for the model or view.

300

One endpoint of a two-way communication link between two programs running on the network.

Socket

400

The big-O time complexity of adding an item to a TreeSet currently containing N items

O(log n)
400

What is the value property of heaps? And what is the shape property of heaps?

Value property of heaps: Each node's value is less than all its children
Shape property of heaps: The shape is “complete” (a heap with 6 elements always looks the same)

400

Dijkstra's Shortest Path Algorithm is a modification of what previous algorithm we learned? What is the modification?

Dijkstra's is a modification of BFS. Instead of using a regular queue, it uses a priority queue to always explore the next closest node based on the current shortest distance. Dijkstra also tracks the cumulative weight of the edges, not just the number of steps.

400

Assume we would like to add an event handler so that when Button b1 is clicked, the text in Label l2 changes to "Pushed!". Write the code

b1.setActionEvent(event -> l2.setText("Pushed!"))

400

In the 7 Layer OSI model, the name of the end-user layer; the layer the user interacts with. (The only layer that we wrote code for in class)

Application Layer

500

What are the differences between a Checked Exception, and an Unchecked Exception? Give an example of each.

Checked must be caught at compile time by the programmer, they represent potentially unavoidable problems. Example: FileNotFound Exception 

Unchecked exceptions represent mistakes in your code that can be avoided in other ways. Example: Arithmetic Exception

500

Draw the min heap after each step.

1. Add 23,    2. Add 13,    3. Add 25,    4. Add 17,    5. Add 41,    6. Add 63,    7. Remove 13

Image on Slide 3
500

Perform Dijkstra's Algorithm from A to F on this graph. (Image Slide 2)

1. Write the order that Nodes were visited when searching the graph.

2. Write the shortest path + the total weight of the path.

1. A, C, D, B, E, F

2. A, C, D, E, F.    Total: 11

500

Describe what the general job of GUI components like GridPane, VBox and BorderPane is. Then, state specifically what each of those three classes do (do not worry about how they do it, just the result of their work).

They are containers for other GUI components and on their own they don't have any content. Gridpane lays out its children in an N x M grid. VBox lays out its children top to bottom. BorderPane has a center, left, right, top, and bottom child.

500

What are TCP and UDP, what do they stand for, and when are either one used?

Transmission Control Protocol: Connection-oriented and reliable. It is used when you don't want to lose data, and the order of the data matters.

User Datagram Protocol: Connectionless and unreliable. It is used when you want very fast transmission and it's okay to lose some packets.