CPSC 225, Spring 2019
Information About the Final Exam

The final exam for CPSC 225 is scheduled for 1:30 PM on Sunday, May 12.

The exam is cumulative, with some emphasis on material covered since the second test. The new material includes basic networking (Section 11.4); threads (parts of Sections 12.1–12.4, but not inlcuding 12.1.4, 12.1.5, 12.3.4, 12.3.5, 12.4.2, or 12.4.5); and from Chapter 13, just observable properties and the MVC pattern. JavaFX will not be on the text, except for the few topics from Chapter 13. See below for the full list of topics from the last part of the course that might be on the final exam.

You might want to also review the study guides for the two in-class tests, which you can find on the course web page or at http://math.hws.edu/eck/cs225/s19/test2info.html and http://math.hws.edu/eck/cs225/s19/test1info.html

The final exam is worth 20% of the grade for the course. It will be 6 pages long, with a format similar to other tests. You should expect one or two long, general essay questions at the end of the test.

The other remaining part of the course is the final project, which is worth 10% of the course grade. It is due on the last day of class, but will not actually be collected and printed until the afternoon of Tuesday, May 7. (However, we can discuss possible extensions to to this due date in class.) Your project should be submitted into a folder named final in your homework folder. You should be sure that the comment on your main class makes it completely clear how to use the program and what it is supposed to do.

Here are some terms and ideas covered since the second test:

computer networks
IP: unreliable delivery of packets to a computer on the Internet
TCP: reliable, two-way communication between programs
host names and IP addresses
port numbers for TCP
the client/server model for networking with TCP
class Socket: one end of an open TCP connection
     constructor:  socket = new Socket(host,port)
using a PrintWriter to send outgoing text over a network
using a Scanner to read incoming text over a network
class ServerSocket:  listening for connection requests
    constructor:  listener = new ServerSocket(port)
    using listener.accept() in an infinite loop to handle multiple connections
network operations can block
writing simple clients and servers using Socket and ServerSocket
how threads are similar to subroutines and how they differ
creating threads using subclasses of class Thread
creating a thread using the constructor new Thread(runnable)
starting a thread
using Thread.sleep(milliseconds) to pause the execution of a thread
using thread.join() to wait for the thread to terminate
InterruptedException (in Thread.sleep() or Thread.join())
race conditions
mutual exclusion
synchronized methods
the synchronized statement
the synchronization lock in every Object, and how it is used in synchronization
multiprocessing: dividing up a job among available processors

uses for threads:
   animation (as an alternative to AnimationTimer)
   background computation (for a responsive GUI during a long computation)
   parallel processing (for speeding up computation)
   dealing with blocking I/O (using a thread for network operations)
how threads can be used in a network server; and the advantage of using them

blocking queues
ArrayBlockingQueue<T> and LinkedBlockingQueue<T>
limited capacity blocking queues versus unlimited capacity blocking queues
the blocking operations queue.put(x) and queue.take() on a blocking queue
the producer/consumer pattern and how it is implemented using a blocking queue
thread pool
using a blocking queue to deliver tasks to threads in a thread pool

observable properties in JavaFX such as:
     sldr.valueProperty() for a Slider
     txt.textProperty()  for a Label or TextField
     btn.disableProperty()  for a button
adding a listener to an observable property
binding a property to another property

design patterns
the Observer pattern and how it applies to observable properties
the MVC (Model-View-Controller) pattern
relationships among the model, the view, and the controller

Here are some of the most important topics from earlier in the term:

subclasses and extending classes; class hierarchies
abstract classes and interfaces

analysis of algorithms
Big-Oh and Big-Theta notation
worst case and average case run times
run-time analysis of operations on stacks, lists, trees

exceptions and exception classes
throwing an exception
checked exceptions and mandatory exception handling
the full try..catch statement, including the finally clause

recursion and recursive methods
base case of a recursion
infinite recursion
examples of recursion such as maze-solving, blob-counting...

linked data structures
linked lists; traversing a linked list with a "runner"
adding and deleting nodes in a linked list

the "queue" and "stack" abstract data types
operations on stacks and queues (push/pop and enqueue/dequeue)
implementation of stacks and queues as linked lists
implementation of stacks as arrays

binary trees
pre-order, in-order, post-order traversal of binary trees
recursive processing of binary trees
expression trees

generic programming and generic classes in Java
the JCF (Java Collection Framework)
Collection, List, ArrayList, LinkedList, Set, TreeSet, HashSet
for-each loops for traversing a collection
Map, TreeMap, HashMap

lambda expressions

I/O streams
input I/O stream versus output I/O stream
binary I/O stream versus character I/O stream
Scanner and PrintWriter
files and the File class
designing file formats

A few sample questions on new material:

1. Write a Java code segment that will create a client Socket to connect to a server on math.hws.edu, port 20000. It should read one line of text from the server and output that line to System.out, then close the connection.

2.   A class named WorkerThread is a subclass of Thread. Write a code segment that creates and starts ten threads of type WorkerThread. (Why might you want to create ten threads?)

3.   Write a subclass of Thread to represent a thread that does nothing but output the numbers from 1 to 4, one number to a line. Then write commands to create and start two such threads. Describe the possible outputs that this could produce.

4.   Explain the intent of the following code, explain why it can give an incorrect answer, and explain how it can be fixed so that the answer is guaranteed to be correct.

double sum = 0;  // global variable!

static class Adder extends Thread {
    int s;
    Adder(int first) {
        s = first;
    public void run() {
        double x = 0;
        for (int i = s; i < s+100000; i++)
            x = x + Math.sin(i);
        sum = sum + x;

for (int i = 1; i < 1000000; i += 100000) {
    Thread thread = new Adder(i);

5.   You have this problem: Your GUI program uses a method double compute() to do a long computation. You don't want to call the method and wait for it to complete, since that would make your program hang for a long time. You decide that the method should be run in a separate thread. Write a subclass of Thread to execute the compute() method. Your class should have some way to get the return value from compute() back to the program after the computation has completed. Also, write a few sentences to explain what you have done.

6.   Threads and parallel processing are becoming increasingly important in modern computer programming. Explain why, and describe at least two different reasons for using threads in Java.

7.   What is meant by a blocking queue? How might one be used?

8.   Suppose that bttn is a Button and box is a CheckBox. Explain what is accomplished by the following statement:

bttn.disableProperty().bind( box.selectedProperty() );

9.   Show how to accomplish the same thing as the previous problem, using a listener instead of binding.

10.   The Model-View-Controller architecture is one of the most important design patterns in computer science. Explain what it is, how it is used in Java, and what advantages it offers. What is meant by the "model," the "view," and the "controller?"