Final exam study guide

The final exam is cumulative. It covers everything on the Prelim 1 and Prelim 2 study guides, plus lectures 23–28 and their associated readings, discussion sections 12–13, quizzes 10–12, and assignment A6.

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: we may overlook missing semicolons or unambiguous spelling/capitalization mistakes, but ambiguous or structurally invalid code will be penalized.

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

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

  • Design patterns (purpose, specification)
  • Iteration (Iterator and Iterable), enhanced for-loops
  • Iterators for tree and graph traversals

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 named actionPerformed().
  • 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 a Comparator 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.

  • 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 and notifyAll) 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.

  • Write a recommendation for whether it would be appropriate to deploy a particular design pattern to address a programming challenge. The pattern might be one of “Iterator” or “Factory method”, or a description of a new pattern may be provided.
  • Write a while-loop to perform an operation on every element contained in an Iterable collection.
  • Given the implementation of a collection, write the methods of an Iterator class to yield the collection’s elements in a specified order. Examples: preorder or level-order traversal of a tree.

Study tips

To prepare for the exam, we recommend the following study habits:

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.