Chris Pollett >
Old Classes >
CS151

   ( Print View )

Your Grade: Course Info: Homework Assignments: Practice Exams:
                            












CS151 Practice Final

Return to classpage.

1. Define the following terms and give an example
   (a) Inversion of control (w.r.t. application frameworks)
   (b) Bags
   (c) Composite pattern
   (d) Comparable interface
   (e) Map
 
2. Suppose you have five JButtons on a JFrame and you want to lay them out like

    1   2
      3
    4   5

   Explain how you could do this in Java.

3. Write a short Java application with one JButton and one JLabel on it. 
   The labels text is initial `0' but whenever the button is clicked this value
   is increased by 1.


4. (a) Write a Java program which writes the object i = new Integer(10);
   to a file Foo. Then reads it back in and prints out the int stored in i.
   (b) Give the UML for the Decorator pattern.

5. Write a short Java program that runs as either an applet or as
   an application which at first draws nothing but when the mouse is dragged
   over a JPanel used by the program it then draws an oval in this JPanel.

6. (a) What is the difference between the Factory pattern and the Factory
   method pattern? Give an example use of each.
   (b) What is the iterative development process?

7. Suppose in a Java program we have the line: 
      bob.notify();
   What does this line do? Explain the differences (if any) between how
   the following two code fragments would execute.

   FRAGMENT A:

   public synchronized void tonyTheTiger()
   {
      roar();
   }

   FRAGMENT B:

   public void tonyTheTiger()
   {  
      synchronized(this)
      {
         roar();
      }
   }


8. Write a short Java program that creates a server (using sockets) that
   listens for connections on port 1234. When a connection is accepted
   It gets an output stream for that socket and writes the message:
   "Thank goodness your here. I can take a break now." Then it closes
   the connection and terminates.

9. Write a Client that could connect to the server in (8) above, receive
   the server's message and print it to the screen.

10. (a) What is the difference between a Client pull and a Server push?
    (b) What is the proxy pattern? How is it implemented in RMI?