CSC

 

Possible questions for part I of the exam

These are simple questions. Anyone who passes the course must be able to answer all questions. The actual exam questions will not be chosen entirely from these.

  1. State two differences between swing and awt.
  2. a.  If you want to make sure that only one object of a particular class can be created, how do you design that class ?
    b. What is the name of the pattern you are using?
  3. What is the purpose of design pattern Singleton? (variation of previous question)
  4. Which design patters is used by Javas listener interfaces and the grafical components that can be "listened to".
  5. What does MVC stand for in software development ?
  6. How is MVC used in Javas swing-components ?
  7. What is an interface in java ?
  8. What is an abstract class in Java?
  9. What is the difference between an abstract class and an interface in Java ?
  10. What is a Layout-manager in Java?
  11. Draw a UML class diagram representing the following combination of schematic classes and interface. Remember that open and closed arrow heads mean different thing. Solid and dashed lines also have different meanings.
    interface I {
      void metoden();
    }
    
    class A {...}
    
    class B extends A { 
      private C[] c = new C[49];
    
      B() {
        for (int i=0; i<49; i++)
          c[i] = new C(...);
      }
      ...
    }
    
    class C implements I {
       A theA;
       ...
    }
  12. What is the benefit with inner classes? Are there any drawbacks?
  13. What (at least three) Java classes are necessary to write a server program capable of handling several clients and a client program ? Which two important data about the server are essential for the client program in order to connect to the server ?
  14. If two different Java threads simultaneously try to change the value of variable, problems may occur (e.g. if the threads are cash machines and the variable is the balance of bank account). What is the actual problem and how is it solved in Java ?
  15. A class declaration starts like this
      <m1> class C {
        <m2> void m() { ... }
    
    ... marks the method body and <m1> and <m2> are modifiers: private, protected, public or ~, where the last character means that you do not write any modifier at all. In another package (than C) is another class that must inherit from C and redefine (override) the method m().

    a. Which modifier must replace <m1>?
         A) protected    B) private     C) ~    D) public

    b. What must replace <m2> ?
    A) protected or private    B) protected or ~    C) protected or public    D) public or ~

  16. What will be printed by the following program ?
    class X {
        void m () { System.out.print("Hej "); }
    }
    
    class Y extends X {
        void m () { System.out.print("Hopp "); }
    }
    
    class HejHopp {
        public static void main (String[] a) {
            X x1 = new X(); X x2 = new Y(); Y y = new Y();
            x1.m(); x2.m(); y.m();
            System.out.println();
        }
    }
    
    A) Hej Hej Hopp
    B) Hej Hopp Hopp
    C) Hej Hej Hej
    D) Hopp Hopp Hopp

  17. What is a framework in software engineering? Give some examples from the Java API.
  18. Assume variable ac refers to a collection of objects, e.g. an ArrayList or LinkedList. What is the condition that must be fulfilled in order to have the collection ac sorted by calling the method Collections.sort(ac) ?
  19. It is not possible in Java to directly use functions as parameters. A method can never be called with draw(f1) and draw(f2) where f1 and f2 are declared as methods. How can it be achieved in Java to supply a method with different functions on different occasions in the same program, i.e. without compiling and restarting the program. A solution where the program chooses function in an if- och switch- clause or similar is not accepted. Which design pattern describes the solution. (There are two correct answers).
  20. What is meant by a "Mock Object" and what is gained by using that technique?
  21. What is a factory method? Describe the general idea and not the pattern "Factory Method". Give two good reasons for using such methods.
  22. Suppose you have acces to a Java framework with 112 classes in three packages and you frequently need to use a couple of combinations of methods from 7 of these classes. Which design pattern is helpful in this situation ?
  23. If N objects without references to each other are to exchange information, which design pattern can be used ? How do the objects communicate ?
  24. Mark each of the following statements to agree with one of the models for software engineering: waterfall or extreme programming:
    a) The testing phase comes late in the project.
    b) Programming is carried out in pairs
    c) System specification is made early in the project
    d) The customer is present throughout the project
  25. What is the difference between Code-and-fix and Rapid prototyping ?

Sidoansvarig: <ann "at"nada.kth.se>
Last update: may 23rd 2010
Tekniskt stöd: <webmaster@nada.kth.se>