Beruflich Dokumente
Kultur Dokumente
Level Three
_________________________________________________________________
Object Oriented Software Development
COMP1307
Page 1 of 14
Approved
1. (a) Study the Java class below. Does the Hello class follow the canonical
form of classes? Fully justify your answer, commenting on all the
requirements for classes to meet the canonical form. If the method
signatures are wrong then provide corrected code. If the content of a
method is wrong then state why and what it should do. You are not
required to provide the code for the content of any method.
public Hello() {
message=null;
}
[12 marks]
[13 marks]
___________________________________________________________________
Object Oriented Software Development
COMP1307
Page 2 of 14
Approved
//Listing 1
public interface Stack<E> {
public int size();
public boolean isEmpty();
public boolean push (E element); //returns false if stack is full
public E pop(); //returns null if stack is empty
} //end code fragment Stack
//Listing 2
public class ArrayStack<E> implements Stack<E> {
protected int capacity;
public static final int CAPACITY = 1000;
protected E s[];
protected int top = -1;
public ArrayStack() {
this(CAPACITY);
}
public E pop() {
if (isEmpty()) return null;
else return s[top--];
}
Page 3 of 14
Approved
(i) Explain what this code does (both Listing 1 and Listing 2). In
particular, comment about the use of E, capacity and
CAPACITY.
[8 marks]
[5 marks]
(b) (i) Give an account of the different testing phases that are
commonly used in the development of software systems.
[6 marks]
(ii) Identify the testing phase of a Java software system where the
framework JUnit may be used, and describe briefly the way this
framework operates.
[6 marks]
3. (a) Discuss the “bounded queue” problem and briefly describe how thread
synchronization is used to solve the problem.
[12 marks]
[13 marks]
___________________________________________________________________
Object Oriented Software Development
COMP1307
Page 4 of 14
Approved
4. (a) Examine the following code for a simple HTML document, which
contains a form with action set to run a servlet ListData on the server:
<HTML>
<HEAD>
</HEAD>
<BODY>
<H1><FORM NAME=form1 METHOD=GET
ACTION=http://stutomcat.cms.gre.ac.uk/cd05/servlet/ListData>
What's your name? <INPUT TYPE=TEXT NAME=username
SIZE=20><BR>
What's your user id? <INPUT TYPE=TEXT NAME=userid
SIZE=5><BR>
<P><INPUT TYPE=SUBMIT VALUE="Send fields to server">
</FORM></H1>
</BODY></HTML>
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ListData extends HttpServlet {
public void doGet (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
ServletOutputStream out = res.getOutputStream();
String name = req.getParameter("username");
String id = req.getParameter("userid");
out.println("<H3>");
out.println("You entered<BR>");
out.println("Name: " + name + "<BR>");
out.println("User Id: " + id + "<BR>");
out.println("</H3>");
out.close();
}
}
[2 marks]
(ii) Describe what happens if the user inputs Sam Smith to the
name field and ss01 to the user id field and presses the submit
button.
[5 marks]
Page 5 of 14
Approved
[6 marks]
(b) Compare and contrast the use of servlets and java server pages. In your
answer, stress the relative advantages and disadvantages of these two
technologies.
[12 marks]
5. Study the following Java application. (The line numbers are for reference
purposes only)
01 import java.awt.*;
02 import javax.swing.*;
03
04 public class AandB extends JFrame {
05
06 JTextField aTxt = new JTextField(2);
07 JTextField bTxt = new JTextField(2);
08 JLabel message = new JLabel();
09 JButton aBtn = new JButton("a");
10 JButton bBtn = new JButton("b");
11 JButton resetBtn = new JButton("Reset");
12 int a = 0, b = 0;
13
14 public static void main(String[] args) { new AandB(); }
15
16 public AandB() {
17 JPanel top = new JPanel();
18 JPanel middle = new JPanel();
19 JPanel bottom = new JPanel();
20 ABHandler abh = new ABHandler();
21 setLayout(new BorderLayout());
22 setSize(200, 120);
23 setTitle("a and b");
24 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
25 top.setLayout(new FlowLayout());
26 top.add(aBtn);
27 top.add(resetBtn);
28 top.add(bBtn);
29 add("North", top);
30 middle.setLayout(new FlowLayout());
31 middle.add(aTxt);
32 middle.add(bTxt);
33 add("Center", middle);
___________________________________________________________________
Object Oriented Software Development
COMP1307
Page 6 of 14
Approved
34 bottom.setLayout(new FlowLayout());
35 bottom.add(message);
36 add("South", bottom);
37 setResizable(false);
38 setVisible(true);
39 abh.update();
40 }
41
42 class ABHandler {
43
44 // update the display
45 public void update() {
46 aTxt.setText("" + a);
47 bTxt.setText("" + b);
48 if (a < b) message.setText("b is bigger");
49 else if (a > b) message.setText("a is bigger");
50 else message.setText("They are the same");
51 }
52 }
53 }
(b) The programmer doesn‟t understand how event handling works in Java.
He has included a nested class ABHandler as shown (lines 42 – 52) with
a method update. He has called this method at line 39 to set the display
to its initial state. In addition he wants:
1 to be added to a whenever the aBtn is clicked
1 to be added to b whenever the bBtn is clicked
a and b to be reset to 0 whenever the resetBtn is clicked
and then the update method to be called in each case.
What additional code is required to achieve this? (In your answer you
may refer to the line numbers in the given code.)
[8 marks]
[10 marks]
___________________________________________________________________
Object Oriented Software Development
COMP1307
Page 7 of 14
Approved
6. (a) The Java Collections framework defines a set of interfaces and classes,
designed to support the storage and retrieval of objects, using a variety
of data structures, algorithms and time-space complexities. Discuss
these three terms in the context of the collections framework.
[6 marks]
(b) An online music store (doing similar business as Apple iTunes Store)
requires the company, where you work as a senior software consultant,
to provide a solution that would record all the downloads of music such
as albums and tracks in real time 24 hours a day and seven days a
week. The recorded information must include title and count of
downloads of all the music they sell on-line. Compare and contrast two
data structures from the Java collection framework before choosing one
for solution. Justify your decision.
[7 marks]
(c) Critically evaluate two design patterns that you have learned about.
Your answer should include an example of where you might choose to
use each one.
[12 marks]
___________________________________________________________________
Object Oriented Software Development
COMP1307
Page 8 of 14
Approved
Level Three
___________________________________________________________________
Object Oriented Software Development
COMP1307
Page 9 of 14
Approved
1. (a) Study the Java class below. Does the Hello class follow the canonical
form of classes? Fully justify your answer, commenting on all the
requirements for classes to meet the canonical form. If the method
signatures are wrong then provide corrected code. If the content of a
method is wrong then state why and what it should do. You are not
required to provide the code for the content of any method.
public Hello() {
message=null;
}
[13 marks]
(b) Discuss the DAO pattern and explain its use of the Transfer Object
Pattern in J2EE applications.
[14 marks]
___________________________________________________________________
Object Oriented Software Development
COMP1307
Page 10 of 14
Approved
(c) Below is example code for a singleton design pattern. Explain the
purpose of the pattern and when you would use it. Your answer should
include an explanation of how the code works.
[13 marks]
2. (a) Discuss the “bounded queue” problem and briefly describe how thread
synchronization is used to solve the problem.
[12 marks]
[6 marks]
(c) Compare and contrast the use of servlets and java server pages. In your
answer, stress the relative advantages and disadvantages of these two
technologies.
[12 marks]
___________________________________________________________________
Object Oriented Software Development
COMP1307
Page 11 of 14
Approved
3. (a) You are the senior developer in a website development team who are
currently developing a large J2EE application. The system you have
developed is running slowly. You have checked potential problems
such as replication issues and these would appear to be ok so you are
now looking at the code that your colleagues have written and you are
horrified! Their code is really inefficient and your line manager has
now asked you to prepare notes for a seminar to your colleagues on
how to write efficient code so they can make amendments. Prepare
notes for this seminar. Your answer should include a discussion of how
to make use of caching.
[14 marks]
(b) Critically evaluate two design patterns that you have learned about
EXCLUDING those mentioned in question 1 (DAO, TO and
Singleton). Your answer should include an example of where you
might choose to use each one.
[16 marks]
4. (a) Identify the testing phase of a Java software system where the
framework JUnit may be used, and describe briefly the way this
framework operates.
[5 marks]
[12 marks]
___________________________________________________________________
Object Oriented Software Development
COMP1307
Page 12 of 14
Approved
//Listing 1
public interface Stack<E> {
public int size();
public boolean isEmpty();
public boolean push (E element); //returns false if stack is full
public E pop(); //returns null if stack is empty
} //end code fragment Stack
//Listing 2
public class ArrayStack<E> implements Stack<E> {
protected int capacity;
public static final int CAPACITY = 1000;
protected E s[];
protected int top = -1;
public ArrayStack() {
this(CAPACITY);
}
public E pop() {
if (isEmpty()) return null;
else return s[top--];
}
Page 13 of 14
Approved
(i) Explain what this code does (both Listing 1 and Listing 2). In
particular, comment about the use of E, capacity and
CAPACITY.
[8 marks]
[5 marks]
___________________________________________________________________
Object Oriented Software Development
COMP1307
Page 14 of 14