<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE251%3ALecture_Debriefing</id>
	<title>SE251:Lecture Debriefing - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE251%3ALecture_Debriefing"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE251:Lecture_Debriefing&amp;action=history"/>
	<updated>2026-04-20T00:04:10Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.kram.nz/index.php?title=SE251:Lecture_Debriefing&amp;diff=9327&amp;oldid=prev</id>
		<title>Mark: 8 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE251:Lecture_Debriefing&amp;diff=9327&amp;oldid=prev"/>
		<updated>2008-11-03T05:20:54Z</updated>

		<summary type="html">&lt;p&gt;8 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Lecture Debriefing ==&lt;br /&gt;
&lt;br /&gt;
Here is your opportunity to catch up on anything you didn&amp;#039;t quite get during a particular lecture/Friday session, or you didn&amp;#039;t get a chance to ask at the time. It&amp;#039;s also the lecturers&amp;#039; opportunity to clarify any points they&amp;#039;ve made in the lectures/Friday sessions.&lt;br /&gt;
&lt;br /&gt;
Now, to make this page purposeful, &amp;#039;&amp;#039;&amp;#039;please&amp;#039;&amp;#039;&amp;#039; only ask questions specifically pertaining to what the lecturers said &amp;#039;&amp;#039;&amp;#039;during the lectures&amp;#039;&amp;#039;&amp;#039;. Thus, it&amp;#039;s suggested that you take notes during the lecture regarding any unclear points so you can post them here.&lt;br /&gt;
&lt;br /&gt;
I didn&amp;#039;t realise this when I created this, but there&amp;#039;s a similar excellent page made by David for [[SE251:StudentLectureClarifications|Richard&amp;#039;s lectures]].&lt;br /&gt;
&lt;br /&gt;
=== (31 March &amp;amp; 1st April) OOP Revision ===&lt;br /&gt;
&lt;br /&gt;
Any questions? Comments?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== (4 April) Assignment 1 Post-mortem ===&lt;br /&gt;
&lt;br /&gt;
A few new handy Java constructs were mentioned during the session: enums and the for-each mechanism.&lt;br /&gt;
&lt;br /&gt;
==== Enums ====&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Enum&amp;#039;&amp;#039;&amp;#039;s were introduced in Java 1.5 to provide a type-safe alternative to keeping integer constants. For example, in the BankAccount assignment, the class Transaction has an integer field (instance variable) called &amp;#039;&amp;#039;transactionType&amp;#039;&amp;#039;, which can have three possible values: the integer constants DEPOSIT, WITHDRAWAL and INTEREST. Now you may realise this is inherently dangerous, as it would be easy to assign a bogus value to &amp;#039;&amp;#039;transactionType&amp;#039;&amp;#039;. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
transactions.add(new Transaction(4214788,amount,this)); //assuming transactions is a Vector&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Also we could accidentally change the values of one of the constants to be equal to some other, for example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public static final int DEPOSIT = 10;&lt;br /&gt;
public static final int WITHDRAWAL = 10; //woops!&lt;br /&gt;
public static final int INTEREST = 12;&lt;br /&gt;
private int transactionType;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can imagine how this would affect &amp;#039;&amp;#039;withdraw()&amp;#039;&amp;#039; for savings account, right?&lt;br /&gt;
&lt;br /&gt;
So instead what we could do is introduce a new Enum type called, say, TransactionType, which can have the values of either DEPOSIT, WITHDRAWAL or INTEREST. Like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public static enum TransactionType {DEPOSIT, WITHDRAWAL, INTEREST};&lt;br /&gt;
private TransactionType transactionType;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now our field &amp;#039;&amp;#039;transactionType&amp;#039;&amp;#039; is no longer of type int but instead the new TransactionType. The &amp;#039;&amp;#039;&amp;#039;only&amp;#039;&amp;#039;&amp;#039; possible values it could have are TransactionType.DEPOSIT, TransactionType.WITHDRAWAL and TransactionType.INTEREST. Thus it would be impossible to provide a bogus type as the compiler would simply not allow anything as long as it&amp;#039;s not one of these three. So now we can modify Transaction class&amp;#039;s constructor and &amp;#039;&amp;#039;type()&amp;#039;&amp;#039; method to take in and return, respectively, a TransactionType instead of int. Like this;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Transaction( TransactionType type, Money amount, BankAccount account ) {&lt;br /&gt;
   this.transactionType = type;&lt;br /&gt;
   ... //etc&lt;br /&gt;
}&lt;br /&gt;
public TransactionType type() {&lt;br /&gt;
   return transactionType;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Correspondingly, we modify any callers of Transaction class&amp;#039;s constructor and &amp;#039;&amp;#039;type()&amp;#039;&amp;#039; method to pass in and retrieve, respectively, a TransactionType value. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
transactions.add(new Transaction(TransactionType.WITHDRAWAL,amount,this));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There&amp;#039;s actually so much more you can do with Enums. Try looking further [http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html here].&lt;br /&gt;
&lt;br /&gt;
==== The for-each construct ====&lt;br /&gt;
The for-each construct is the mechanism that allows you to do this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
String[] words = {&amp;quot;hi&amp;quot;,&amp;quot;my&amp;quot;,&amp;quot;name&amp;quot;,&amp;quot;is&amp;quot;,&amp;quot;not&amp;quot;,&amp;quot;to&amp;quot;,&amp;quot;be&amp;quot;,&amp;quot;spoken&amp;quot;};&lt;br /&gt;
for (String word : words) {&lt;br /&gt;
   System.out.println(word);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It&amp;#039;s essentially a cute version of our classic for loop:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for (int i = 0; i &amp;lt; words.length; i ++) {&lt;br /&gt;
   String word = words[i];&lt;br /&gt;
   System.out.println(word);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This not only applies to arrays but also to any types that implement the [http://www.cs.auckland.ac.nz/JavaCache/java1.5/api/java/lang/Iterable.html &amp;#039;&amp;#039;Iterable&amp;#039;&amp;#039;] interface. And it happens that all &amp;#039;&amp;#039;Collection&amp;#039;&amp;#039; classes, which include Vector, implement this &amp;#039;&amp;#039;Iterable&amp;#039;&amp;#039; interface. I cover all this stuff in April 8th&amp;#039;s lecture.&lt;br /&gt;
&lt;br /&gt;
=== (7 April) Interfaces, Lists and Generics essentials ===&lt;br /&gt;
&lt;br /&gt;
[Insert your questions/comments here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== (8 April) Exploring the Java Collections Framework ===&lt;br /&gt;
&lt;br /&gt;
A very minor follow-up to slide 12: I mentioned a shorthand alternative to the original Money&amp;#039;s compareTo():&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return this.cents - other.cents;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Although concise, this actually is not 100% safe if for instance this.cents is a large positive integer and other.cents is a large negative integer. As you may be aware from COMPSYS 201, subtracting between such two integers could result in an integer overflow thereby producing an unexpected result. This won&amp;#039;t be a problem if we enforce a constraint that cents can&amp;#039;t be negative, but it&amp;#039;s always good to be on the safe side.&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>