Computer Laboratory

Supervisions 2009/2010

Supervision questions: Object Oriented Programming

This is the set of questions for my supervisions in Object Oriented Programming. I will typically email you a list of question numbers before each supervision, but if not, attempt the next two or three. (More questions will appear here as I set them, so come back if you want to make an early start on some of the future work.)

Administrativa & handing in work

I expect you to make a good attempt at producing solutions to the relevant questions before each supervision. I prefer submissions by email (PDF or text format). Please submit your work 24 hours before the supervision. If you want to submit a hard copy of the work to student administration, please hand it in before 17:00 two days before the supervision (i.e. before Wednesday, 17:00 for a Friday afternoon supervision) as I will have to scan it. Remember that Student Administration is closed on weekends.

When emailing me regarding supervisions, please only use my lab address, or your email will be misfiled and may slip by unnoticed:

The mark allocation (whilst very approximate) should give you a rough idea of how you should divide your time between the questions, as well as how much credit I expect a similar question to be worth in the exam. It will also serve as a guide for me when marking the questions.

If there is a particular part of the course you would like explaining, or questions you have about the lectures (independent of whether they are covered by the questions or not), please let me know in an email before the supervision so that I can prepare appropriately.

Supervision 1: Fundamentals

  1. In the context of functional and imperative programming, what is the difference between a function and a procedure? Which is used with which programming methodology? [4 marks]
  2. Explain in a short (max. a couple of paragraphs) high-level description of how a computer can execute a program written in some imperative programming language. Your answer should mention the following terms:
    • memory address,
    • compilation (or compile, compiler etc.),
    • main (system) memory,
    • registers,
    • transistors / logic gates.
    • fetch-execute cycle,
    [8 marks]
  3. Q1 from the course notes (page 12) [3 marks]
  4. Q2 and Q3 from the course notes (page 17) [5+4 marks]
  5. Explain briefly the concept of Java bytecode and how the process described in 2. changes if we are considering a Java program. [Hint: There is one additional step that has to be performed]. [3 marks]
  6. What might a pointer type of int **p in the C language mean? Explain how you would get at the int value stored. [2 marks]
  7. Q4 from the course notes (page 27) [4 marks]
  8. Q5 from the course notes (page 29) [5 marks]
  9. Explain the difference between passing something "by reference" and "by value". Assuming a class Int with a member field value, write a small piece of code that contrasts the behaviour of this with the primitive int type. [Hint: Consider passing them to a procedure that will change the value, and what value they will hold after the procedure has returned]. [5 marks]
  10. 1999 Paper 3 Question 3, first part only [15 marks]

Supervision 2: OOP Principles, Java

  1. 2009 Paper 1 Question 8, part (a) only [6 marks]
  2. Explain the terms coupling and cohesion, and indicate what we are generally optimising for with each of them ("low"/"high"). [4 marks]
  3. Q6 from the course notes (page 54) [6 marks]
  4. Q7 from the course notes (page 54) [10 marks]
  5. Q8 from the course notes (page 59) [7 marks]
  6. Explain what polymorphism is in the context of object-oriented programming languages and how its realisation differs between Java and C++. [Hint: Use a worked example and consider virtual functions in the case of C++]. [5 marks]
  7. Give an example of variable shadowing as a result of inheritance. [3 marks]
  8. Q9 from the course notes (page 65) [12 marks]
  9. Q10 from the course notes (page 65) [2 marks]
  10. What is the difference between shallow and deep copying when cloning an object (using the clone() keyword or otherwise). [6 marks]
  11. Q12 from the course notes (page 65) [5 marks]
  12. Bonus question:Q13 from the course notes (page 65) [8 marks]

Supervision 3: Class Library, Design Patterns

  1. What is the Java class library? In the context of the class library, explain what a collection and a comparator are and why they are useful. What are examples of each? [4 marks]
  2. What are generics in Java? Why were they introduced? [Hint: Think about early versions of the collections framework] [4 marks]
  3. Optional bonus question: Amend your linked list implementation from the second Java supervision to provide a generic linked list of objects, rather than a linked list of strings. [5 marks]
  4. Is there a difference between the == operator and calling the .equals() method on an object, and if so, when? [2 marks]
  5. Q19 from the course notes (page 88), except part (d) [Hint: Note that you can make your life a lot easier by using the equals() method for implementing your ForenameComparator] [8 marks]
  6. What is a design pattern? [1 mark]
  7. Q21 from the course notes (page 105) [5 marks]
  8. What is the difference between the state and strategy patterns? [3 marks]
  9. Q22 from the course notes (page 113) [12 marks]
  10. Q23 from the course notes (page 118) [4 marks]
  11. Draw the diagram for and explain the abstract factory pattern. Then sketch a solution to Q25 (p. 131) in the course notes by re-labeling the components of your diagram with their correspondences in this example (e.g. using a different colour). [8 marks]
  12. Without referring to the solution notes, do the second question of the sample exam questions. You may skip the differences between abstract classes and interfaces in part (a) [18 marks]
  13. 2009 Paper 1 Question 8, part (b) [14 marks]