You are on page 1of 6

APPROVED

EXAMINATION PAPER: ACADEMIC SESSION 2008/2009

School Computing and Mathematical Sciences

Department Computer Science

Level Three

TITLE OF PAPER Object Oriented Software Development

COURSE CODE COMP1307

Date Wednesday 3rd June 2009

Duration 2 Hours

BAHRAIN 15:00 BOTSWANA 15:00


GREECE 15:00 HONG KONG 18:30
KENYA 16:00 LONDON 13:00
MALAYSIA 18:30 MALTA 15:00
MALIWI 14:00 MAURITIUS 18:00
MYANMAR 15:30 RWANDA 14:00
SAUDI ARABIA 16:00 SINGAPORE 17:30
SRI LANKA 18:30 SOUTH AFRICA 15:00
SYRIA 14:00 TANZANIA 16:00
TRINIDAD 09:30 UAE 17:00
ZAMBIA 15:00

You MUST answer question 1 from Section A which is worth 40 marks


AND TWO questions from section B which are worth 30 marks each.

If you answer more than two questions from section B, marks will ONLY be awarded
for your TWO best answers.

CALCULATORS AND ELECTRONIC DEVICES ARE NOT PERMITTED


APPROVED

Section A (Compulsory)

1. a) The canonical form of classes specifies functionality that Java classes


should provide beyond any of their normal business logic. Two key
requirements of the canonical form are the concepts of object equality
and cloning. Explain these concepts in the context of the canonical
form.
[7 marks]

b) Study the class below and comment on how far it meets the canonical
form of classes.

class TutorialAttendance implements java.io.Serializable {


String name;
int attendance;

public void TutorialAttendance(String name, Boolean attendance) {


setName(name);
setAttendance(attendance);
}
public void setName(String name) {
this.name = name;
}
public void setAttendance(Boolean attendance) {
if (attendance) {
this.attendance++;
}
}
public String toString() {
return name;
}
public boolean equals(Object o) {
return this==o;
}
}

public class TutorialAttendances {


public static void main(String[] args) {
TutorialAttendance TutorialAttendance1 = new TutorialAttendance(),
TutorialAttendance2 = new TutorialAttendance();
TutorialAttendance1.setName("Fred");
TutorialAttendance2.setName("Bob");
TutorialAttendance1.setAttendance(true);
TutorialAttendance2.setAttendance(false);
System.out.println(TutorialAttendance1.name + " has " +
TutorialAttendance1.attendance + " attendances");
System.out.println(TutorialAttendance2.name + " has " +
TutorialAttendance2.attendance + " attendances");
}
}
[10 marks]

Question 1 is continued on the following page.


_________________________________________________________________
Object Oriented Software Development
COMP1307
Page 2 of 6
APPROVED

Question 1 continued.

(c) Design patterns are now well recognized and used in software
development. Why is this? Explain the rationale and the benefits
behind their use.
[6 marks]

(d) (i) The presentation tier of a large application has to handle many
user requests and ensure they are all processed. One solution to
managing these is to use the Front Controller Pattern. Give an
outline of how this patterns works and the problem it is trying to
solve.
[5 marks]

(ii) The Front Controller Pattern is typically used with two other
J2EE patterns: the Application Controller Pattern and the
Intercepting Filter Pattern. Critically discuss ONE of these
patterns in detail.

[7 marks]

(iii) The Front Controller Pattern is also an implementation of the


MVC framework. Give a brief overview of MVC and its benefits.
[5 marks]

_________________________________________________________________
Object Oriented Software Development
COMP1307
Page 3 of 6
APPROVED
Section B (Answer any TWO questions)

2. (a) The Java Collections Framework contains the following:

• Interfaces
• Implementations
• Algorithms

Explain these three terms.


[6 marks]

(b) Critically discuss the benefits of the Java Collections Framework.

[10 marks]

(c) Discuss the concept Thread-Safe in terms of race conditions in


multithreading.
[4 marks]

(d) Synchronising methods can make shared objects thread-safe but this is
not enough to coordinate the threads. Explain with an example when
threads need coordinating and the key Java methods that allow such
coordination to take place.
[10 marks]

3. (a) You have been commissioned to develop a simple web application for
an online bookshop using the Struts framework. The type of
functionality you will need to support will be adding books for sale,
allowing users to create book reviews, updating prices etc.

(i) Discuss how Struts processes a user request. Your answer


should include a description of the Struts components involved.
[9 marks]

(ii) Provide an overview of how you would approach the


development of a Struts application, for example in terms of the
order of the stages that you would work through.
(Note: you are not required to write any code)
[6 marks]

Question 3 continued on the following page.

_________________________________________________________________
Object Oriented Software Development
COMP1307
Page 4 of 6
APPROVED

Question 3 continued.

(b) Consider the following Java application. The line numbers are for
reference only.

01 public class Creatures {


02 public static void main(String[] args) {
03 String talk;
04 Animal animal = new Animal();
05 Cat tiddles = new Cat();
06 Snake sid = new Snake();
07
08 talk = animal.says();
09 System.out.println(talk);
10 animal = tiddles;
11 talk = animal.says();
12 System.out.println(talk);
13 animal = sid;
14 talk = animal.says();
15 System.out.println(talk);
16 }
17 }
18
19 class Animal {
20 protected int legs;
21 public Animal() { legs = 4; }
22 public String says() { return "Animals can't talk! " + sayLegs(); }
23 protected String sayLegs() { return "I have " + legs + " legs"; }
24 }
25
26 class Cat extends Animal {
27 public String says() { return "Miaow! " + sayLegs(); }
28 }
29
30 class Snake extends Animal {
31 public Snake() { legs = 0; }
32 public String says() { return "Hiss! " + sayLegs(); }
33 }

(i) What is the output produced by running this application?


[3 marks]
(ii) What output would be produced if line 20 were to be replaced
by the following code:
20 protected static int legs;
Give reasons for your answer.
[4 marks]
Question 4 continued on the following page.

_________________________________________________________________
Object Oriented Software Development
COMP1307
Page 5 of 6
APPROVED
Question 4 continued.
(iii) If line 10 were to be replaced by the following code:
10 tiddles = animal;
Explain why this would result in a compiler error.
[3 marks]
(iv) With reference to this application, briefly discuss the concept of
polymorphism in Java.
[5 marks]

4. (a) Explain briefly


(i) the similarities, and
(ii) the differences
between Servlets and JSPs.
[10 marks]

(b) What do you understand by the term scope in the context of a JSP?
[8 marks]

(c) Give a brief account of the unit testing framework JUnit, stressing its
importance for the philosophy of test driven development.
[12 marks]

_________________________________________________________________
Object Oriented Software Development
COMP1307
Page 6 of 6

You might also like