SE251:Test Tut

From Marks Wiki
Jump to navigation Jump to search

Test Revision

Overview

Things you should focus on studying

(that is, madly make notes of. Remember you can bring notes as long as they're handwritten on a lab book):

  • The basics of the Java language: goes without saying.
    • Know what kind of a language Java is: is it a procedural or an object-oriented language? Is it compiled into machine code or an intermediate object code to be interpreted by a virtual machine?
    • Know what a class declaration and a method declaration looks like. Know what packages are and why we need import statements.
    • Know what the difference between a class and an object is, and thus what differentiates a static (class) member from an instance member.
    • Know how to instantiate objects of a certain class and call instance methods on them.
  • Object-orientation: Inheritance, polymorphism and dynamic binding - this is obviously the key theme of the test, so make sure you are comfortable with
    • How to extend from a superclass, how super constructor calls are handled, how method overriding is done, and how to call methods from a superclass
    • Scope and visibility: what is the difference between private, protected and public members? When would you use instance variables and when would you use local variables?
    • Typing rules: what can a reference variable of type T point to, and what methods can you invoke on it? Also, what kind of polymorphic assignments can cause ClassCastExceptions to be thrown?
    • Dynamic binding: when you invoke a method on a reference variable of type T, which (possibly overridden) method is called?
    • How abstract classes and interfaces are defined and how to extend from/implement them
    • Value vs. referential equality: i.e. what's the difference between == and equals()?
  • The basic JUnit assertions and what they test: assertEquals(), assertSame(), assertTrue() and assertFalse()
  • Exception handling
    • How try, catch and finally clauses work
    • The difference between checked and unchecked exceptions
    • Knowledge about the common runtime (unchecked) exceptions, including NullPointerException, ClassCastException and ArrayIndexOutOfBoundsException. When do they occur?
  • Generics: there's not so much in the way of generics. Just make sure you are comfortable understanding code that uses type parameters and generic types. Focus on revising the typing rules, for instance:
    • What types of arguments can you pass in to a method that declares public<T> void foo(List<T>, T obj)?
    • What types of elements can you add to a list of type List<Number>?
  • Collections: again, there's not so much in the way of collections.
    • Familiarise yourself with the general Collection class/interface hierarchy - What are the interfaces, what are the implementations, how are they related, etc.
    • Know how the interfaces Comparable and Comparator are utilised to define ordering and create sorted collections
    • Know how the implementations of List, Set and Map work. Know how to iterate over collections.
  • Assignments 1 and 2. Revise the object-oriented techniques you applied for BankAccount and think of how you would extend BankAccount to create new account types.

Things you should not focus on

  • Memorising the details of every single class from the Java API and its methods, apart from say the very basic methods of String, Object and System. We will provide sufficient details of any special classes you may need to use for a particular question.
  • Likewise, the exact details of the individual methods of ArrayList, LinkedList, HashSet, TreeSet, HashMap and TreeMap. Just know how the very basic methods work, and the key difference between the implementations.
  • Squeezing just one more DotA (or whatever the fad is right now) melee before finishing your notes

Last years' tests

There are some questions from the 2006 and 2007 tests that refer to material not covered during the first 6 weeks of this year's SOFTENG 251. Below is the list of questions you are not be required to be able to solve:

2007 Test:

  • 5. Details of UML modeling and design will be covered later in Ian's part.
  • 14. The question makes references to the assignment Bounce, which will be handed out later in the course.

2006 Test:

  • 7. The question mentions JPanel and ActionListener, which are part of the Java AWT and Swing frameworks.
  • 8. You should be able to answer this now you had the information hiding lecture, but this won't be covered in this year's test.
  • 14. Again the question deals with Swing, which you are not required to know yet.
  • 15. The question concerns enum types, which were not covered during the first 6 weeks.
  • 16. You may be able to do this question without knowing about the Decorator design pattern, but don't panic if you aren't.
  • 17. Again the question makes references to the assignment Bounce.

Your Questions

Post your questions here.

Q: How can we tell in Generics, where to paramaterize and where not to. That is, how do we know where to add the <> brackets.

A: In terms of when to put angled brackets: only when you are either parameterising a generic type (class) or method, or declaring a type variable inside a generic class or method declaration.

    • In terms of where to put them: when you parameterise a type (class), you always put them immediately to the right of the type (class) name, e.g. List<Movie>, new Comparator<String>(), etc. On the other hand when you parameterise a method, you always put the angled brackets immediately to the left of the method name, e.g. Collections.<String>sort(stringList). Also realise angled brackets are used when declaring a type variable, e.g.
      • public class Pair<E1,E2> - here we have made the class Pair a generic type by giving it two type parameter E1 and E2. The angled brackets enclosing the type parameters come immediately to the right of the class name.
      • public<T> void append(List<T> list, T[] newItems) - here we have made the method append() a generic method by giving it one type parameter T. Note for generic methods, the angled brackets enclosing the type parameter (T) come immediately to the left of the return type (void). Now here, do not confuse the <T> that appears to the left of void with the <T> that appears to the right of List - they stand for different things. The former, as mentioned earlier, is a declaration of the type parameter T, whereas the latter is parameterising the List with the type parameter T.


Q: I'm not too sure on question 8 from last years paper. What's the difference between ==, equals and same for comparing objects?

A: For two values a and b, == means "referential equality". That is, it evaluates to true if and only if a and b both point to the same object. On the other hand, equals() is what can be called "value equality". Now the meaning of a.equals(b) depends on whether the class of the object that a points to overrides the equals() method.

  • If the class does not override equals(), then a.equals(b) returns exactly the same as a == b.
  • If the class does override equals(), then a.equals(b) returns whatever the overridden method returns.

For example, the class String overrides the equals() method, returning true if the two strings contain the same sequence of characters. Thus if we have:

String a = "XYZ";
String x = "XY";
String b = x + "Z";

then while a == b returns false, a.equals(b) returns true, because a and b both comprise the character sequence "XYZ"

Q: What is the difference between abstract classes and interfaces? Dont both define behaviour??