Helsingin yliopisto / Tietojenkäsittelytieteen laitos / Software Design (Java)

582309 Software Design (Java), course exam 28.2.2008/AW

Write on top of every answering paper the name and date of the course, your name and student number, and also your signature. You are allowed to have A4 size paper containing information concerning the contents of the course.

Please, answer the course questionnaire on the web pages of the departmen

  1. Exceptions:
    1. Explain the exception class hierarchy consisting of Throwable, Error, Exception, and RuntimeException. What is the purpose of these different classes? Explain the difference between checked and unchecked exceptions. How are they related to the hierarchy of exceptions?
    2. Explain under what circumstances would you throw checked or unchecked exceptions from your own methods. Explain why. Which exception classes should you extend when you define your own exception classes?
                                                                        (6 points)
    
  2. Collections and generics:
    1. The Java collection library provides two major kinds (categories) of data structures. What are they? Describe their most important similarities and differencies
    2. The collections framework includes various abstract implementations of collection interfaces. Explain the purpose of these classes.
    3. Class Pair is:
        class Pair <T> {
          public T first;
          public T second;
          public Pair (T f, T s) { first = f; second = s; }
          public Pair () { first = null; second = null; }
        }
      
      Is Pair <String> a subclass of Pair <Object>. Explain why; or, if not, explain why not. Is an array of type String [ ] also of type Object [ ]? Explain why; or, if not, explain why not. Is an array of type Pair <String> [ ] also of type Pair <Object> [ ]? Explain why; or, if not, explain why not.
                                                                        (12 points)
    
  3. Threads and GUI:
    1. What are the ways of creating a new thread in Java? Why do we need a separate Runnable interface in addition to the Thread class?
    2. The following is a typical programming idiom:
        void run () {
          try { 
            while (! interrupted () && hasMoreWork) 
              ... // may block and throw..
          }
          catch (InterruptedException e) ...
            // interrupted during sleep or wait 
            ...
          finally 
            ... // cleanup in any case
        }
      
      Explain what it is and why you have to check the interrupting by two different ways.
    3. Explain event dispatch thread and worker thread.
                                                                        (12 points)