[ answers online ]
Name: _______________________________
Student ID: _______________________________

Total points: 110
  1. What do you think of the Java programming language overall? Compare it to another language you know. [4]
  2. What is object-oriented programming? How does it differ from procedural programming? [4]

    Procedural programming is action-oriented: the code is a sequence of procedures, and the data structures are passed as parameters to the procedures. The focus is on the 'verbs'. In contrast, object-oriented programming is data-oriented: code is organized into classes, centred around objects, and the procedures are treated as methods within each class. The focus is on the 'nouns'.
  3. Describe and contrast the four options we have in Java for access modifiers on attributes/methods. [4]
    private
    only methods in this class can access
    (no modifier)
    methods in this class and this package can access
    protected
    also subclasses can access
    public
    anyone can access
  4. What is the effect of the final keyword on
  5. What is an interface in Java? What is an abstract class? What's the difference? Describe an example of each (you may come up with your own). [6]
    An abstract class is not meant to be instantiated directly. An abstract superclass can be used as a way of organizing its subclasses under one category. For example, Dog, Cat, and Cow all are within the Mammal category. It makes sense to have specific instances of Dog, Cat, and Cow, but not of Mammal. Mammal is the abstract superclass.
    An interface is a named set of methods, for instance the ActionListener interface specifies the actionPerformed() method and advertises that a class knows how to respond to action events. Interfaces specify functionality, i.e., what a class knows how to do. Abstract superclasses specify identity, i.e., what a class is. Multiple classes that inherit from different superclasses may implement the same interface, but in Java multiple inheritance is not permitted.
  6. Name and briefly describe the features of at least 4 Swing widgets (i.e., subclasses of JComponent). If you can't remember the exact name of the class, describe the widget in as much detail as you can. [8]
    Many to choose from: JPanel, JFrame, JButton, JCheckBox, JComboBox, JRadioButton, JLabel, JTextField, JPasswordField, JTextArea, JMenu, JMenuItem, JSlider, JProgressBar, ...
  7. What is object serialization in Java? Describe a situation where serialization might be useful. [4]
    Serialization converts Java objects into byte streams that can be sent across any I/O channel. Objects can be serialized if their classes implement the Serializable interface and if all its non-transient instance variables are serializable. Primitive types (int, char, etc.) and arrays of primitive types are serializable. Any kind of inter-process communication may benefit from object serialization: e.g., a client-server restaurant ordering system may wish to send objects that represent customer orders over a network I/O channel.
  8. What is a component framework? Why are they cool? Describe one such framework in detail (it need not even be computer-related). Describe a couple example components and what you could do with them. [5]
  9. What is an Android Activity? Is it a complete application? Describe an example. [4]
    An Activity is the UI for one focused user endeavour, e.g., one screen or dialogue window. Android applications may be composed of multiple Activities, background Services, BroadcastReceivers, and ContentProvider databases.
  10. Why do Android applications not have a main() method? [3]
    Modular component architecture: applications are not monolithic but may have several entry points. This is so other apps can directly call individual Activities within the application, rather than having to go through main().
  11. What are Android string resources? Why are they cool? [4]
    Name-value pairs, stored in res/values/strings.xml. In the code or UI layout, refer to strings via their resource IDs, rather than hard-coding them in. This facilitates localization/translation into other languages.
  12. Design a class hierarchy of your own choosing, with an abstract superclass and at least two concrete subclasses.
    1. Design attributes and methods appropriate for each class and draw a UML class diagram. [5]
    2. Design a method that takes advantage of the polymorphism in this class hierarchy, and explain how it does so. The polymorphic method need not live inside any of the classes. [4]
  13. For each of the three categories of design patterns in the "Gang of Four" book, name at least three example patterns (for a total of nine patterns). For each pattern you choose, describe it in words and give an example or analogy illustrating it.
    1. Creational: [5]
      factory method, abstract factory, prototype, singleton
    2. Structural: [5]
      facade, adapter, bridge, proxy, decorator, flyweight
    3. Behavioural: [5]
      observer, mediator, chain of responsibility, iterator, memento, command
  14. Write a complete Java program that reads in a file "input.txt", removes all digits, and outputs the result in the file "output.txt". Include full doc-comments with pre-/post-conditions. [8]
    (See StripDigits.java.)
  15. A BankTransaction consists of an account number, date, dollar amount, and a flag that indicates whether it was a withdrawal or deposit.
    1. Write a complete Java class defining a BankTransaction, including attributes and two constructors (one with a full set of parameters, and one with no parameters at all). Be sure to do error-checking of all input parameters. To keep things simple, no set/get functions are required.
      The java.util.Date class stores a date/time object; the default constructor returns the current date/time. [6]
      (See BankTransaction.java.)
    2. Add a copy constructor to the implementation. Check for null references and other errors. [4]
  16. Design a console-based networked chatroom in Java. Users may be able to join and leave the chatroom, and any line of text entered by any user is broadcast to all other users. What classes will you need? What methods might those classes have? Describe how you would handle having multiple users connected at the same time. Describe in detail what should happen when a new user tries to connect to the chatroom. [8]
  17. We wish to design a system that tracks the location of public buses in real-time and updates displays at bus stops informing riders of how long they'll need to wait for the next bus. Draw a UML use-case diagram for this system. [8]