Final exam study guide
The final exam is cumulative. It covers everything on the Test 1, Test 2, Test 3, Test 4 and Test 5 study guides, plus lectures 23–28 and their associated readings, discussion activites and assignment A5.
The exam will ask you to write correct and stylish Java code. Your code should not be redundant, needlessly inefficient or complicated, or indicate a lack of understanding of Java features. Your code should follow our coding guidelines, with one exception: unless comments are specifically requested, you may omit them on the exam. Your code should contain at most minor syntactic errors: syntax errors that can be corrected by (i) a local insertion or deletion of punctuation and/or whitespace, (ii) corrected spelling of identifiers, or (iii) transposition of adjacent tokens. In other words, a malformed program that an experienced programmer can nonetheless understand unambiguously with a second or two of thought.
The exam will not allow access to reference materials. You will not have access to notes, a “cheat sheet”, or IntelliJ, or the Java API documentation. Except: if there is a Java API method you must use to solve a problem not listed among the topics below, we will provide a brief specification for it.
List of topics (not listed on prior study guides)
GUIs and lambda expressions
- GUI widgets
- Swing components
- Inversion of control
- Events, event sources, and event handlers
- Anonymous functions and functional interfaces
- Control flow of painting
- The event dispatch thread (EDT)
Concurrency
- Threads
- Race conditions
- Deadlock
- Mutex locks (
synchronized
) - Condition variables (
wait()
/notifyAll()
) - Ring buffers
- Barriers
Design patterns
- Iteration (
Iterator
andIterable
), enhanced for-loops - Alternatives to
null
(optional akaMaybe
)
Skills
To do well on the exam, you should be able to do the following:
- Given an interface, state whether a lambda expression could be used to provide that interface. Example:
ActionListener
, which declares one abstract method namedactionPerformed()
. - Write a JUnit assertion to check that a given expression results in an exception being thrown.
- Write a lambda expression to be passed as an argument to a method expecting a functional interface. Examples: write an expression for an
ActionListener
to print a message when a button is pressed; write an expression for aComparator
to order students by age when sorting them. - Match a picture of a standard GUI widget to its name. Widgets could include labels, buttons, text fields, sliders, radio buttons, progress bars, and scroll bars.
- Given a picture of a window containing bordered panels and standard widgets, sketch a hierarchy of how the components could be contained within one another (the frame will be at the root).
- Given a sketch of a GUI with labels indicating variable names that reference each widget, write the code to cause a component to react in a specified way. For example, make a button change the text of a label when clicked. A sufficient subset of the Swing API will be provided for reference.
- Given a snippet of Swing code that registers an event listener, identify the the event source, the event object, and the listener.
- Given a desired outcome (example: notify Swing that a component’s appearance needs to change), circle which painting-related method (e.g.
repaint()
,paintComponent()
) should be called or overridden. - Not in scope: Model-View-Controller.
- Given two sequences of instructions (in pseudocode or Java) that are executed concurrently and require exclusive access to one or more shared resources, state whether deadlock is possible. If so, propose an alteration to one of the sequences that eliminates this possibility while preserving the desired behavior of the original instructions.
- Given two or more sequences of Java statements that are executed concurrently and that access shared objects, state whether a race condition may be encountered, and what class invariants might be invalidated because of the race condition. Or, add synchronization to the code to prevent race conditions.
- Given two sequences of Java statements that are executed concurrently and that increment a shared
int
variable with or without synchronization, state which numbers are possible final values for the variable after both sequences have completed execution. - Given the implementation of a method that employs synchronization, state which object is serving as the mutex.
- Given the implementation of a method that employs synchronization, circle which statements could cause a thread to block, and for each such statement, describe what another thread could do to cause the first thread to become unblocked.
- Given an abbreviated reference for the API of Java’s
Thread
class, write code to execute a function on a new thread. - Given a sequence of addition and removal operations made to a circular buffer with a specified capacity, draw the contents of its backing array after those operations have completed.
- Given a specification for the desired behavior of a class, and a partial implementation of the class, add code that uses condition variables (i.e.,
wait
andnotifyAll
) to complete the implementation. The code you add causes threads to correctly synchronize by making some threads block and wait for others. Example:Barrier
from DIS. - Not in scope: Swing Event Dispatch Thread
- Write a
while
-loop to perform an operation on every element contained in anIterable
collection. - Given the implementation of a collection, write the methods of an
Iterator
class to yield the collection’s elements in a specified order. Out of scope: coroutines. - Describe a situation in which returning a
Maybe
is preferable to possibly returningnull
. Or, given an API forMaybe
, rewrite code that potentially throws aNullPointerException
to instead useMaybe
and thereby avoid the possibility of that exception.
Study tips
To prepare for the exam, we recommend the following study habits:
- Practice writing and testing Java classes and methods. Draw accompanying pictures (type hierarchies, object diagrams) to bridge between models/abstractions and code.
- Review our lecture materials and your notes from lecture. Review the required textbook readings.
- Make flash cards for key terms, based on lecture slides and the textbook glossary (online). Consider comparing definitions with JavaHyperText to check your interpretation.
- Review past quizzes.
- Attempt the sample exam questions. Do this first without notes, in a distraction-free environment. Later, review your responses with your notes open and identify weak areas; review these further.
Sample exams
Here are some examples of exams from past courses covering similar material. Please note: these examples cover topics that are not in scope for our exam this semester, and they do not cover all topics that are in scope for our exam. The organization and style of questions on these exams is not necessarily indicative of what you will see this semester. Some notational conventions differ between other courses and ours.
Merely reading solutions is ineffective for knowledge retention. Pro-tip: do not look at the solutions until you have already solved the problems and checked your answers using your notes, IntelliJ, and/or a study partner.
- Sample exam 1 (solutions)
- Note: Tree balancing will not be on our final exam. This exam is not well aligned with the above study skills.
- Sample exam 2 (solutions)
- Sample exam 3 (solutions)