JMU CS446 - Software Analysis and Design
Help Policies Solutions Study-Aids Syllabus Tools
Sample Questions for Exam 2


  1. Discuss the purpose of each of the following:
    1. Assertions
    2. Logging
    3. Reflection
    4. Serialization
  2. Suppose you have written a ShapeLabel class that extends JLabel javax.swing.JLabel and overrides its paint() method so that, instead of rendering text, it renders the shape. Create a ShapeRenderer that extends the ShapeLabel class and also implements the ListCellRenderer javax.swing.ListCellRenderer interface.
  3. Modify your answer to the last question so that a ShapeLabel object can be printed at its current position and size (i.e., it does not need to be translated or scaled) using a PrinterJob object on page 0. You may assume that it will fit on a single page.
  4. Explain how a proxy might be used to prevent an "expensive" task from being performed needlessaly (i.e., when it had already been performed during the current session).
  5. Explain why the singleton pattern is often used with the state pattern.
  6. Explain the advantages of the state pattern.
  7. From an interaction design perspective, explain the difference between "Drag and Drop" and "Cut, Copy and Paste".
  8. Build a hierarchical model of an address book that contains addresses, phone numbers (of various kinds), and email addresses. Provide three sample entries in both XML and in JSON.
  9. Consider the following XML document:
      <play>
        <title>All's Well That Ends Well</title>
        <personae>
          <persona>KING OF FRANCE</persona>
          <persona>DUKE OF FLORENCE</persona>
          <persona>BERTRAM, Count of Rousillon.</persona>
          <persona>LAFEU, an old lord.</persona>
        </personae>
      </play>
      

    Write an application (that includes a class that extends DefaultHandler and a driver) that can use a SAXParser to list all of the persona in a play (of the kind in the previous question).

  10. Create a JSON document that is equivalent to the XML document that contains the above play.
  11. Write an application that uses JSON-P to list all of the persona in a play (of the kind in the previous question).
  12. Carefully explain how references complicate serialization.
  13. In Java:
    1. How do you indicate that a class is serializable?
    2. What class is used for serialization? What class is used for deserialization?
  14. Explain why the deserialization of untrusted data is inherently dangerous.
  15. Complete the following class:
      import java.lang.reflect.*;
    
      public class ObjectFactory
      {
        /**
         * Uses reflection to create an Object of a given class
         *
         * @param  className   The name of the class (e.g., String)
         * @return             An instance of the given class
         */
        public Object createObject(String className)
        {
    
    
    
    
    
    
    
    
    
    
    
    
    
        }
      }
      
  16. Explain how annotations might be used in an automated submission system (like WebCAT, Autolab, or GradeScope) to associate points with JUnit tests. What might compile-time processing be used for in such a system? What might run-time processing be used for in such a system?

Copyright 2022