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.
- State two differences between swing and awt.
- 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?
- What is the purpose of design pattern Singleton?
(variation of previous question)
- Which design patters is used by Javas listener interfaces and the
grafical components that can be "listened to".
- What does MVC stand for in software development ?
- How is MVC used in Javas swing-components ?
- What is an
interface in java ?
- What is an abstract class in Java?
- What is the difference between an abstract class and an interface
in Java ?
- What is a Layout-manager in Java?
- 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;
...
}
- What is the benefit with inner classes? Are there any drawbacks?
- 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 ?
- 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 ?
-
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 ~
- 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
- What is a framework in software engineering?
Give some examples from the Java API.
- 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) ?
- 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).
- What is meant by a "Mock Object" and what is gained by using
that technique?
- What is a factory method? Describe the general idea and not
the pattern "Factory Method". Give two good reasons for using
such methods.
- 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 ?
- If N objects without references to each other are to exchange
information, which design pattern can be used ? How do the objects
communicate ?
- 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
- What is the difference between Code-and-fix and
Rapid prototyping ?
|