The final exam for CPSC 225 is scheduled for 7:00 PM on Tuesday, December 13.
The exam is cumulative, with some emphasis on material covered since the second test. The new material includes threads (Chapter 12, Sections 1 through 4) and some advanced GUI programming (Chapter 13, Sections 1 through 4). This includes the general idea of "design patterns" and the details of the Model/View/Controller pattern in particular. There was also some new material on networking in Labs 11 and 12.
The final exam is worth 21% of the grade for the course. It will be 6 or 7 pages long, with a format similar to other tests. You should expect one or two long, general essay questions on the last page or two of the test.
The other remaining part of the course is the final project, which is worth 10% of the course grade. You should be prepared to give a presentation about your project in the final lab, on Thursday, December 8. In the presentation, you should demonstrate the program, discuss the structure of the program, and present some of the code that you wrote. Concentrate on the aspects of the code that you think will be interesting to other people in the course. The project is due on Friday, December 9, and it should be in your homework folder by noon on Saturday, December 10. If it is not absolutely clear where I should look for your project, send me an email to let me know. It is possible to get an extension on the due date for the final project until the day of the final exam, but only if you come to my office, discuss the code with me, and present your plan for finishing the project.
Here are some terms and ideas covered since the second test:
the HTTP protocol basic format of HTTP request headers and HTTP response headers mime types and the Content-Type header basic operation of a web server and how it can be implemented the URLConnection class and how it is used to download resources from the web threads how threads are similar to subroutines and how they differ class Thread; creating threads using subclasses of Thread the run() method in a thread 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 thread pools Thread API: static method Thread.sleep() instance methods: thread.start() thread.join() thread.setPriority(priority) InterruptedException (in Thread.sleep() or Thread.join()) object.wait() and object.notify() deadlock uses for threads: animation (as an alternative to Timers) background computation (for a responsive GUI during a long computation) parallel processing (for speeding up computation) dealing with blocking I/O (using a thread to receive network messages) how threads can be used in a Web server; and the advantage of using them blocking queues ArrayBlockingQueue<T> and LinkedBlockingQueue<T> 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 elements of GUI programming: components, layout, events, listeners Image and BufferedImage the constructor new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB) drawing on a buffered image; the image.createGraphics() method the method g.drawImage(image, x, y, null) for drawing a BufferedImage Graphics2D: the idea of antialiasing using g.setStroke(new BasicStroke(strokeWidth)) to draw wide lines the idea of TexturePaint and GradientPaint the idea of geometric transforms design patterns the MVC (Model/View/Controller) pattern relationships among the model, the view, and the controller using multiple views of the same model JList ListModel and how it is used with JList how events are used in implementing the MVC pattern PropertyChangeEvents "loose coupling" between components of a complex system
Here are some of the most important topics from earlier in the term:
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, etc. 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 ADT (Abstract Data Type): what they are and why they are important 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 hash tables and hash codes streams input versus output streams binary versus character streams Scanner and PrintWriter files and the File class designing file formats computer networks and network protocols IP: unreliable delivery of packets to a computer on the Internet TCP: reliable, two-way communication between programs host names, IP addresses, and port numbers the client/server model for TCP connections
You can also see the review sheets for the two in-class tests,
which
are available on-line.
1. A class named WorkerThread is a subclass of Thread. Write a code segment that creates and starts ten threads of type WorkerThread.
2. 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.
3. 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); thread.start(); }
4. 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.
5. What is meant by a blocking queue? How might one be used?
6. Explain the following class. What does it do? How does it do it? How would it be used? Import statements are omitted. Recall that new Color(r,g,b,a) creates a color with red, green, blue, and alpha components given as integers in the range 0 to 255.
public class OptimisticView extends JPanel { private BufferedImage image; public OptimisticView(String resourceName) throws Exception { URL imageLoc = getClassLoader.getResource( resourceName ); image = ImageIO.read(imageLoc); } public void paintComponent(Graphics g) { g.drawImage(image,0,0,getWidth(),getHeight(),null); g.setColor( new Color(255, 0, 0, 100) ); g.fillRect(0,0,getWidth(),getHeight()); } }
7. Write a code segment to create a BufferedImage containing a picture of a "crosshair" like the one shown at the right. The size of the image should be 32-by-32 and its type should be BufferedImage.TYPE_INT_ARGB. The crosshair should be drawn in black on a white background.
8. What is drawn by this paintComponent method?
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D)g; for (int i = 1; i < 10; i++) { g2.setStroke(new BasicStroke(i)); g2.drawLine(10,10*i,110,10*i); } }
9. What is antialiasing?
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?"