<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Chris Ford &#187; Open University</title>
	<atom:link href="http://www.chrisfordblog.com/tag/open-university/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrisfordblog.com</link>
	<description>Just another blog</description>
	<lastBuildDate>Thu, 17 Dec 2009 21:30:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>OU M257 Revision notes</title>
		<link>http://www.chrisfordblog.com/2009/06/ou-m257-revision-notes/</link>
		<comments>http://www.chrisfordblog.com/2009/06/ou-m257-revision-notes/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 08:37:30 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Things I've Learnt]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[M257]]></category>
		<category><![CDATA[Open University]]></category>
		<category><![CDATA[OU]]></category>

		<guid isPermaLink="false">http://www.chrisfordblog.com/?p=394</guid>
		<description><![CDATA[Next week I&#8217;m sitting an Open University exam on the Java course M257.  I&#8217;ve made some notes on most of the units which you can see below: Unit 3 Implement classes in which you have specified the access level of methods and instance variables; private access level: never inherited, so can never be accessed by [...]]]></description>
			<content:encoded><![CDATA[<p>Next week I&#8217;m sitting an Open University exam on the Java course M257.  I&#8217;ve made some notes on most of the units which you can see below:</p>
<p><span style="font-size: 12pt; font-family: &quot;Times New Roman&quot;; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: RU; mso-fareast-language: RU; mso-bidi-language: AR-SA;" lang="RU"><strong>Unit 3</strong></span></p>
<ul type="disc">
<li><strong>Implement classes in which you have specified the access level of methods and</strong> <strong>instance variables;</strong></li>
</ul>
<ul type="disc">
<li>private access level: never inherited, so can never be accessed by subclasses as if they were part of the subclass.</li>
<li>Public access level: If you precede an instance variable or a method of a public class with the keyword public, then any class can access that member using a reference and a dot notation. Any public members are inherited by all subclasses, so they can be accessed within those classes without a dot notation.</li>
<li>Protected access level: available only to classes in the same package. Any subclass inherits any protected and public members of its superclass.</li>
</ul>
<ul type="disc">
<li><strong>Understand the difference between instance variables and class variables, and be</strong> <strong>able to decide when to use each;</strong></li>
</ul>
<p>Instance variables are defined in the class above the constructor. Values relates to that object. Class variable are defined as static, only one copy of the &#8216;variable&#8217; is created for all instances of the class. Reasons to use class variables:</p>
<ul type="disc">
<li>Constants: A common use is to define some constant associated with the class. For example, the Java package associated with mathematical processing implements the mathematical constant PI in this way.</li>
<li>One value for all objects: A second use of class variables and methods is to implement data that has only one value for every object of that class. One common example of this is to keep count of the number of objects of a class type that have been created. It might lead to errors if each object kept its own version of this count, as each object would have to update the count every time a new object came into existence and it would be easy to forget to update some object&#8217;s copy of this variable.</li>
</ul>
<p>private int numOfSpots; //instance variable</p>
<p>private static int numOfLegs; //class variable</p>
<p>Often but not always static variables are constants. To declare a variable as a constant the keyword final is used and for readability the name is in CAPS</p>
<p>static final int MAX_VALUE = 12;</p>
<p>Methods can also be declared as static. If you try to access a nonstatic variable from a static method then you will get a syntax error.</p>
<p><strong> </strong></p>
<ul type="disc">
<li><strong>Write constructors for classes;</strong></li>
</ul>
<p>Constructor is a method with the same name as the class. Multiple constructors can exist for the same class if they have different arguments. A constructor sets the default variable values. The constructor of the superclass can be called in a constructor using super(); if it has zero arguments. Otherwise arguments can be pass to the superclass constructor like this.</p>
<p>public FourInt (int a, int b, int c, int d)</p>
<p>{</p>
<p>super(a, b, c);</p>
<p>s = d;</p>
<p>}</p>
<ul type="disc">
<li><strong>Use inheritance to develop new classes;</strong></li>
</ul>
<p>To inherit from a class the class header needs to include the keyword extends followed by the class name.</p>
<p>public class PrivilegedUser extends User</p>
<ul type="disc">
<li><strong>Discuss the nature of the Java class hierarchy and the purpose of the Object class</strong> <strong>as the root of this hierarchy;</strong></li>
</ul>
<p>All Java classes inherit from the object class as it is at the top of the hierarchy. The object class therefore has no superclass.</p>
<ul type="disc">
<li><strong>Write an equals method for a class;</strong></li>
</ul>
<p>By default the equals method compares object references not object contents.</p>
<p>Writing another equals method means we can compare contents as well.</p>
<p>public boolean equals (User u) // this method overloads the equals method.</p>
<p>{</p>
<p>return userID.equals(u.userID); // compares if userID&#8217;s are the same.</p>
<p>}</p>
<p>public boolean equals (User u) // this method overloads the equals method.</p>
<p>{</p>
<p>return userID.equals(u.userID) &amp;&amp; emailAddress.equals(u.emailAddress) &amp;&amp;               numOfAccesses == u.numOfAccesses; // compares userID&#8217;s, emails and number of accesses.</p>
<p>}</p>
<p>public boolean equals (Object o) // this method overrides the equals method</p>
<p>{</p>
<p>// cast the Object argument to a User type</p>
<p>User u = (User) o;</p>
<p>return userID.equals(u.userID);</p>
<p>}</p>
<p>Use like this: emma.equals(maria);</p>
<ul type="disc">
<li><strong>Write a toString method for a class.</strong></li>
</ul>
<p>toString class by default returns class name followed by @ followed by a by a numeric hexadecimal value. To make a more useful toString class override method returning more useful info from constructor for example.</p>
<p>public String toString ()</p>
<p>{</p>
<p>return &#8220;User &#8221; + userID + &#8220;, Email &#8221; + emailAddress;</p>
<p>}</p>
<p>To use a toString method. Call println on an object.</p>
<p>User a = new User(&#8220;Tembo&#8221;, &#8220;<a href="mailto:zamby@lusaka.zm">zamby@lusaka.zm</a>&#8220;);</p>
<p>System.out.println(a);</p>
<p>produces the output: User Tembo, Email <a href="mailto:zamby@lusaka.zm">zamby@lusaka.zm</a></p>
<p><strong>Unit 4</strong></p>
<h2><em>Explain the concept of a stream; </em></h2>
<p>A stream for providing its input/output facilities. A stream, sometimes referred to as a byte stream, is essentially a sequence of bytes, representing a flow of data from a source to a destination. This includes the keyboard, screen and various sorts of data files, as well as between networked computers. They also allow manipulation of the data on the way: for example, by converting the data to different formats or by storing it temporarily (buffering).</p>
<h2><em>Use the basic Java facilities for input and output; </em></h2>
<p>//Read from Keyboard</p>
<p>public void hello()</p>
<p>{</p>
<p>Scanner sc = new Scanner(System.in);</p>
<p>//Ask what is your name</p>
<p>String name = sc.nextLine();</p>
<p>//Ask what is your age</p>
<p>int age = sc.nextInt();</p>
<p>//Display name and age here</p>
<p>sc.close();//take care</p>
<p>}</p>
<p>//Read from a file</p>
<p>public void hello()</p>
<p>{</p>
<p>Scanner sc = Scanner sc = new Scanner (new File (&#8220;source/use.txt&#8221;));</p>
<p>//Ask what is your name</p>
<p>String name = sc.nextLine();</p>
<p>//Ask what is your age</p>
<p>int age = sc.nextInt();</p>
<p>//Display name and age here</p>
<p>sc.close();//take care</p>
<p>}</p>
<p>//Read from a datafile.</p>
<p>FileInputStream fis = new FileInputStream(&#8220;payroll.dat&#8221;);</p>
<p>DataInputStream dataIn = new DataInputStream(fis);</p>
<p>//Output to text file</p>
<p>Public void hello()</p>
<p>{</p>
<p>PrintWriter pw = new PrintWriter(&#8220;Hello.txt&#8221;); //creates new file</p>
<p>pw.println(&#8220;The first line&#8221;);</p>
<p>pw.println(&#8220;The second line&#8221;);</p>
<p>pw.close();</p>
<p>}</p>
<p>//output to datafile</p>
<p>FileOutputStream fos = new FileOutputStream(&#8220;payroll.dat&#8221;);</p>
<p>DataOutputStream dataOut = new DataOutputStream(fos);</p>
<h2><em>Distinguish text input/output from binary input/output; </em></h2>
<ul type="disc">
<li>Text input/output: human readable using a simple text editor or word processor.</li>
<li>Binary Input/Output: machine readable, more efficient.</li>
</ul>
<h2><em>Identify when it is appropriate to use exceptions; </em></h2>
<p>If the code within a method may throw a checked exception, then you must do one of two things:</p>
<ul type="disc">
<li>Declare in the method header that an exception may be thrown. in this case you do not handle the exception within the method, but simply pass it on;</li>
<li>Catch the exception and deal with it within the method, using a try-catch statement.</li>
</ul>
<h2><em>Distinguish between checked and unchecked exceptions; </em></h2>
<p>Examples of checked exceptions.</p>
<ul type="disc">
<li>EOFException occurs when a program attempts to read past the end of a file.</li>
<li>FileNotFoundException can occur when a program attempts to open or write to an existing file. If the file cannot be found, then this exception is thrown.</li>
<li>MalformedURLException indicates that an invalid form of URL (such as a website address) has occurred.</li>
</ul>
<p>Examples of unchecked exceptions, as they are subclasses of RunTimeException.</p>
<ul type="disc">
<li>ArrayIndexOutOfBoundsException occurs when a program tries to access an array with an index outside the valid limits.</li>
<li>ArithmeticException arises when an illegal arithmetic condition occurs, such as an attempt to divide an integer by zero.</li>
<li>NumberFormatException can be caused by an application expecting to read a number of some sort, when the data does not have the appropriate format.</li>
<li>NullPointerException happens when an application attempts to use null in a case where an object is required: for example, invoking a method on a null reference.</li>
</ul>
<h2><em> </em></h2>
<h2><em>Define and use new types of exception; </em></h2>
<p>DEFINE</p>
<p>class FileFormatException extends IOException</p>
<p>{</p>
<p>private int errorPosition;</p>
<p>public FileFormatException () {}</p>
<p>public FileFormatException (String message, int bytesRead)</p>
<p>{</p>
<p>super(message);</p>
<p>errorPosition = bytesRead;</p>
<p>}</p>
<p>public int getErrorPosition ()</p>
<p>{</p>
<p>return errorPosition;</p>
<p>}</p>
<p>}</p>
<p>USE</p>
<p>try</p>
<p>{</p>
<p>// code to be checked</p>
<p>if (checkFormat(theNewFile))</p>
<p>{</p>
<p>&#8230;</p>
<p>}</p>
<p>}</p>
<p>Catch (FileFormatException exception)</p>
<p>{</p>
<p>String reason = exception.getMessage();</p>
<p>int errLoc = exception.getErrorPosition();</p>
<p>System.out.println(reason+&#8221; at &#8220;+errLoc);</p>
<p>}</p>
<h2><em>Deal with error conditions in a Java program, by means of exceptions or otherwise; </em></h2>
<p>public void loadFiles ()</p>
<p>{</p>
<p>&#8230;</p>
<p>Try</p>
<p>{</p>
<p>If (checkFormat(&#8220;File1.dat&#8221;))</p>
<p>{</p>
<p>// code to process file data</p>
<p>}</p>
<p>}</p>
<p>catch (EOFException eofEx)</p>
<p>{</p>
<p>// code to handle this exception</p>
<p>// eofEx refers to EOFException object</p>
<p>}</p>
<p>}</p>
<h2><em>Use the StringTokenizer class to split string data into substrings. </em></h2>
<p>String = new String(<a href="mailto:T.F.Jones@coolmail.com">T.F.Jones@coolmail.com</a> Tom Jones);</p>
<p>StringTokenizer em = new StringTokenizer( eMailAddress, &#8220;@.&#8221;);</p>
<p>while (em.hasMoreTokens())</p>
<p>{</p>
<p>System.out.println(em.nextToken());</p>
<p>}</p>
<p>OUTPUTS:</p>
<p>T</p>
<p>F</p>
<p>Jones</p>
<p>Coolmail</p>
<p>com Tom Jones</p>
<h2><em>Defensive programming. </em></h2>
<p>The defensive programming style of coding is appropriate for certain kinds of common error conditions. However, it has some drawbacks:</p>
<ul type="disc">
<li>If there is a lot of error checking and handling code, this can obscure the main purpose of the method;</li>
<li>It is somewhat ad-hoc &#8211; different programmers or Java library code may take different approaches to signaling or handling errors;</li>
<li>Some serious errors cannot easily be handled within the method where they occur &#8211; they may need to be passed to higher level code;</li>
<li>It may not be possible for a method to return a value indicating that an error has occurred &#8211; for example, if the method already returns a result.</li>
</ul>
<p><strong>Unit 5</strong></p>
<h2><em>Use library classes from the standard Java packages; </em></h2>
<p>First import them.</p>
<p>Import java.util.*; // The * means that the whole contents of java.util is available to use.</p>
<p>java.util and java.sql both contain a class called date. To use the date class from java.sql we can include an import at the top of our classes like below. Otherwise well get a name clash that will not compile.</p>
<p>Import java.util.*;</p>
<p>Import java.sql.*;</p>
<p>Import java.sql.Date;</p>
<p>You never need to import java.lang</p>
<h2><em>Broadly understand the contents of the java.util package; </em></h2>
<p>1.       Contain Java Collection Framework: LinkedList, ArrayList, HashSet, TreeSet, HashMap and TreeMap</p>
<p>2.       &#8216;Legacy&#8217; collection classes</p>
<p>3.       Random class</p>
<p>4.       StringTokenizer class</p>
<h2><em>Use some of the important collection classes provided within the java.util package; </em></h2>
<p>HashSet</p>
<p>Set&lt;Integer&gt; s= new HashSet&lt;Integer&gt;(); Using the Set interface.</p>
<p>if (s.isEmpty())</p>
<p>{</p>
<p>System.out.println(&#8220;Set initiallyempty&#8221;);</p>
<p>}</p>
<p>s.add(23);</p>
<p>s.add(25);</p>
<p>s.add(11);</p>
<p>// three integers added</p>
<p>System.out.println(&#8220;The set has &#8221; + s.size() + &#8220;elements&#8221;);</p>
<p>s.remove(23);</p>
<p>// there are nowonly two integers in the set</p>
<p>System.out.println(&#8220;The set now has &#8220;+ s.size() + &#8220;elements&#8221;);</p>
<p>LinkedList</p>
<p>LinkedList&lt;Integer&gt;numList =new LinkedList&lt;Integer&gt;();</p>
<p>numList.add(99);</p>
<p>numList.add(103);</p>
<p>numList.add(88);</p>
<p>// there are now three items in the list</p>
<p>System.out.println(&#8220;First item is &#8220;+numList.getFirst());</p>
<p>System.out.println(&#8220;Lastitem is &#8220;+numList.getLast());</p>
<p>ArrayList</p>
<p>ArrayList &lt;Integer&gt; holder = new ArrayList &lt;Integer&gt;();</p>
<p>holder.add(3);</p>
<p>System.out.println(holder.remove(0)+2); //returns 3 then adds on 2</p>
<p>HashMap</p>
<p>HashMap &lt;String,String&gt; hm =new HashMap&lt;String, String&gt;();</p>
<p>System.out.println(&#8220;Hello there&#8221;);</p>
<p>hm.put(&#8220;Dave&#8221;,&#8221; London &#8220;);</p>
<p>hm.put(&#8220;Robert&#8221;, &#8221; Sheffield &#8220;);</p>
<p>hm.put(&#8220;Darrel&#8221;, &#8221; Milton Keynes &#8220;);</p>
<p>System.out.println(&#8220;Darrelisassociated with &#8220;+hm.get(&#8220;Darrel&#8221;));</p>
<p>for(String name: hm.keySet()) // The code hm.keySet returns the collection of keys associated with hm.</p>
<p>{</p>
<p>System.out.println (name+&#8221; is associated with the city &#8220;+hm.get(name));</p>
<p>}</p>
<h2><em>Define your own packages for structuring large programs; </em></h2>
<p>To define a collection of classes as a package, you need to precede the source code of each of the classes with the keyword package followed by the name of the package, as follows:</p>
<p>package testPackage;</p>
<ul type="disc">
<li> * explain the role of the Object class in heterogeneous collections;</li>
<li> * explain the concept of an interface and its role in relation to multiple inheritance;</li>
</ul>
<p>An Interface is like a class that has method headers but very little method bodies. An interface declares what has to be done but not how to do it. Interfaces do not contain variables but can contain constants. Interfaces are not classes.</p>
<p>publicinterface Comparable&lt;T&gt; //T is the type being compared.</p>
<p>{</p>
<p>int compareTo(T o); // method header only in this example there are no constants defined. Methods in interfaces are know as abstract methods.</p>
<p>}</p>
<p>A class that implements the above class start like this and must contain a method called compareTo.</p>
<p>class Employee implements Comparable &lt;Employee&gt;</p>
<h2><em>Understand the concept of an abstract class; </em></h2>
<p>Abstract classes are useful in defining groups of classes related by inheritance. Abstract classes normally have at least one abstract method. An abstract method has header, but has no implementing code associated with the header. The implementation code must be supplied by subclasses of the abstract class. The keyword also used to identify these methods. Note the difference from interfaces, which have abstract methods but do not require the word abstract in the declaration.</p>
<ul>
<li>cannot be instantiated;</li>
<li>may have instance variables, finals, static variables and concrete methods.</li>
</ul>
<p>An abstract class may be useful because:</p>
<ul>
<li>it can be used to factor out common features of a number of classes, which then</li>
</ul>
<p>inherit from the abstract class and implement or override methods as required;</p>
<p>Abstract methods</p>
<p>1.       Boolean hasNext() &#8211; returns true if the iteration has more elements</p>
<p>2.       E next() &#8211; returns the next element in the iteration</p>
<p>3.       Void remove() &#8211; removes from the underlying collection the last element returned by the iterator (optional operation)</p>
<h2><em>use polymorphism in connection with abstract classes; </em></h2>
<p>If Employee is an abstract class of WeeklyEmployee and MonthlyEmployee and both contain a different method called payment. When staff is an instance of Employee we can call either of the payment methods like this.</p>
<p>staff.payment();</p>
<p>If the staff object is a WeeklyEmployee it will use its class, if the object is MonthlyEmployee it will use the payment method of the MonthlyEmplyee class. This is polymorphism.</p>
<h2><em>Contrast interfaces and abstract classes; </em></h2>
<p><span style="text-decoration: underline;">Interface:</span></p>
<p>1.      An interface is not a class.</p>
<p>2.      All its methods are abstract and, apart from its abstract methods, it may contain only constants. The methods are implicitly treated as abstract and the constants are treated as if declared as public static final.</p>
<p>3.      An interface can be implemented by any number of unrelated classes, which declare this using the implements keyword. A class may implement any number of interfaces.</p>
<p><span style="text-decoration: underline;">Abstract class:</span></p>
<p>1.      An abstract class uses the keyword abstract in the class header.</p>
<p>2.      It normally has at least one abstract method, either defined within the class or inherited from a superclass, and its abstract methods must be explicitly declared abstract. It can also have concrete methods (that is, it may be fully implemented) and instance variables, unlike an interface.</p>
<p>3.      It can only constrain its own concrete subclasses, by requiring them to implement its abstract methods &#8211; it cannot constrain any other classes.</p>
<p><span style="text-decoration: underline;">The similarities between an interface and an abstract class in Java:</span></p>
<p>1.      They can both place requirements on objects of other classes.</p>
<p>2.      Both can have abstract methods (although neither need have abstract methods).</p>
<p>3.      You cannot create objects of an abstract class type or an interface type. You can,</p>
<p>4.      however, create reference variables of either type. These are normally used to refer to an object of a subclass of the abstract type or to an object of a class that implements the interface, respectively.</p>
<p>5.      Both can inherit: the abstract class from another class; the interface only from another interface.</p>
<h2><em>Use the Iterator interface defined for Java collection classes. </em></h2>
<p>Example</p>
<p>ArrayList&lt;String&gt; userList =new ArrayList&lt;String&gt;();</p>
<p>&#8230;</p>
<p>Iterator &lt;String&gt;listIt =userList.iterator();</p>
<p>System.out.print(&#8220;The list is [");</p>
<p>while (listIt.hasNext())</p>
<p>{</p>
<p>System.out.print(listIt.next() +" ");</p>
<p>}</p>
<p>System.out.println(" ]&#8220;);</p>
<p><strong> </strong></p>
<p><strong>Unit 6</strong></p>
<p>GUI element need a JFrame, class extends JFrame.</p>
<p>Buttons:</p>
<p>JButton offButton = new JButton( ); // unlabeled</p>
<p>JButton onButton = new JButton(&#8220;Cancel&#8221;); // labeled</p>
<p>offButton.setText(&#8220;Press Me&#8221;);  // set label</p>
<p>String offButtonLabel = offButton.getText( ); // name a variable the label of an exciting button</p>
<p>Labels:</p>
<p>JLabel testLb = new JLabel(&#8220;Verbose Interface Cluster&#8221;);</p>
<p>testLb.setText(&#8220;Good Bye&#8221;);</p>
<p>Check Box:</p>
<p>JCheckBox noviceUserType = new JCheckBox(&#8220;Novice&#8221;); // labeled Novice state is true or false</p>
<p>boolean b = noviceUserType.isSelected( ); // will set b to true or false</p>
<p>Radio Buttons:</p>
<p>// first create the button group</p>
<p>ButtonGroup language = new ButtonGroup( );</p>
<p>// then create the buttons</p>
<p>JRadioButton frenchButton = new JRadioButton(&#8220;French&#8221;, true);</p>
<p>JRadioButton englishButton = new JRadioButton(&#8220;English&#8221;, false);</p>
<p>// then add the buttons to the button group</p>
<p>language.add(frenchButton);</p>
<p>language.add(englishButton);</p>
<p>Combo Box:</p>
<p>JComboBox computerChoice = new JComboBox( );</p>
<p>computerChoice.addItem(&#8220;PC&#8221;);</p>
<p>computerChoice.addItem(&#8220;Mac&#8221;);</p>
<p>computerChoice.setSelectedItem(&#8220;Mac&#8221;); // default Variable</p>
<p>Text Fields:</p>
<p>JTextField txtA = new JTextField( ); // default</p>
<p>JTextField txtB = new JTextField( 24); // 25em width</p>
<p>JTextField txtC = new JTextField(&#8220;Text Field Type here&#8221;); // default contents</p>
<p>JTextField txtD = new JTextField(&#8220;This is for typing&#8221;, 20); // default contents and width</p>
<p>Text Areas:</p>
<p>JTextArea ta = new JTextArea (&#8220;This is some text to start off with. \n&#8221; +</p>
<p>&#8220;Do you like it ? yes or no ?&#8221;, 4, 20);</p>
<p>// same as text field but has has extra argument for box length.</p>
<p>Scroll bars:</p>
<p>JScrollBar scbV = new JScrollBar(JScrollBar.VERTICAL);</p>
<p>JScrollBar scbH = new JScrollBar(JScrollBar.HORIZONTAL);</p>
<p>Menu bars:</p>
<p>JMenuBar mb = new JMenuBar( ); // new menu bar</p>
<p>JMenu m = new JMenu(&#8220;File&#8221;); // new menu section</p>
<p>m.add(new JMenuItem(&#8220;close&#8221;)); // new menu item in section</p>
<p>m.add(new JMenuItem(&#8220;save&#8221;)); // new menu item in section</p>
<p>mb.add(m); // add menu section to bar</p>
<p>setJMenuBar(mb); // set bar</p>
<p>Layout FlowLayout: Default</p>
<p>/ * Place some buttons. */</p>
<p>Container cp = getContentPane( );</p>
<p>cp.setLayout(new FlowLayout( ));</p>
<p>Layouts: GridLayout:</p>
<p>/ * Place some buttons. */</p>
<p>Container cp = getContentPane( );</p>
<p>// set size of grid &#8211; rows then columns</p>
<p>cp.setLayout(new GridLayout(3, 2)); // 3 tall by 2 wide grid.</p>
<p>Layout BorderLayout:</p>
<p>/ * Place some buttons. */</p>
<p>Container cp = getContentPane( );</p>
<p>cp.add( buttons [0 ], BorderLayout.NORTH);</p>
<p>cp.add( buttons [1 ], BorderLayout.SOUTH);</p>
<p>cp.add( buttons [2 ], BorderLayout.EAST);</p>
<p>cp.add( buttons [3 ], BorderLayout.WEST);</p>
<p>cp.add( buttons [4 ], BorderLayout.CENTER);</p>
<p>Class to display your code</p>
<p>public class FrameDemoTest</p>
<p>{</p>
<p>public static void main (String [] args)</p>
<p>{</p>
<p>FrameDemo fd = new FrameDemo(&#8220;We Love Java&#8221;);</p>
<p>fd.setVisible(true);</p>
<p>}</p>
<p>}</p>
<p><strong>Unit 7 </strong></p>
<h2><em>Work within an event-driven programming environment; </em></h2>
<p>Non linear. Event-driven programs are programs that respond to events initiated by the user, such as mouse clicks and key presses. Events can also be initiated through software coding, using for example the Timer class,</p>
<h2><em>Attach code to visual components to capture user input in the form of events such as mouse presses and text input; </em></h2>
<p><span style="text-decoration: underline;">FOR A BUTTON</span></p>
<p>buttonUp = new JButton(&#8220;Press Me Up&#8221;); // define a new button buttonUp.addActionListener(new ButtonWatcher()); // attaches ActionListener to button</p>
<p>/* Define the listener inner class implementing the interface ActionListener. */</p>
<p>private class ButtonWatcher implements ActionListener</p>
<p>{</p>
<p>/* Here is the code which is executed when the button is clicked. Note the class implements */</p>
<p>public void actionPerformed (ActionEvent a)</p>
<p>{</p>
<p>Object buttonPressed =a.getSource();</p>
<p>if (buttonPressed.equals(buttonUp))</p>
<p>{</p>
<p>buttonClicks++;</p>
<p>}</p>
<p>if (buttonPressed.equals(something else))</p>
<p>{</p>
<p>buttonClicks&#8211;;</p>
<p>}</p>
<p>label.setText(buttonClicks + &#8220;&#8221;);</p>
<p>}</p>
<p>}</p>
<p><span style="text-decoration: underline;">FOR A MOUSE CLICK etc&#8230;</span></p>
<p>c = new JPanel();</p>
<p>c.addMouseListener(new MouseEventer()); // attaches MouseListener to previously define panel called c.</p>
<p>/* Define the listener inner class implementing the adapter class</p>
<p>. */</p>
<p>private class MouseEventer extends MouseAdapter</p>
<p>{</p>
<p>/* Here is the code which is executed when the mouse is clicked. Note the class extends */</p>
<p>public void mouseClicked (MouseEvent a)</p>
<p>{</p>
<p>int xCoordinate = e.getX();</p>
<p>int yCoordinate = e.getY();</p>
<p>yCoordLabel.setText(yCoordinate + &#8220;&#8221; );</p>
<p>xCoordLabel.setText(xCoordinate + &#8220;&#8221; );</p>
<p>}</p>
<p>}</p>
<h2><em>Use inner classes; </em></h2>
<p>Inner classes are nested inside of normal classes. advantages of using inner classes is that the inner class has access to all of the methods and data fields of the surrounding class.</p>
<h2><em> </em></h2>
<h2><em>Create simple animations; </em></h2>
<p>One class sets up panels/window/frame that animation happens in. paint method is overridden.</p>
<p>public void paint (Graphics g)</p>
<p>{</p>
<p>super.paint(g);</p>
<p>myBall.paint(g);</p>
<p>}</p>
<p>// class contains move method that trigger another move methods in another class.</p>
<p>public void move ()</p>
<p>{</p>
<p>while (true)</p>
<p>{</p>
<p>myBall.move(); // not yet defined</p>
<p>repaint();</p>
<p>try</p>
<p>{</p>
<p>Thread.sleep(50);</p>
<p>} catch (InterruptedException e)</p>
<p>{</p>
<p>System.exit(0);</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p>class that  builds object above calls move method of above.</p>
<p>public class MovingBallTest</p>
<p>{</p>
<p>public static void main (String[]args)</p>
<p>{</p>
<p>MovingBall world = new MovingBall(&#8220;Moving Ball&#8221;);</p>
<p>world.setVisible(true);</p>
<p>world.move();</p>
<p>}</p>
<p>}</p>
<p>another class in this case called ball must include it own paint method and move method. Move method should contain code to change size, direction, shape, speed, coordinates etc&#8230;</p>
<h2><em>Use the graphical facilities within Java. </em></h2>
<p>Here we override the method paint to create what we want to appear on screen. */</p>
<p>public void paint (Graphics g)</p>
<p>{</p>
<p>super.paint(g);</p>
<p>g.drawRect(50, 50, 100, 75);</p>
<p>}</p>
<p>With shapes the first 2 variables are the distance in pixels from the top left corner of the window/panel.</p>
<p>topleft at (x, y)</p>
<p>Rectangle testRectangle = new Rectangle(x, y, width, height);</p>
<p>Fonts example</p>
<p>public void paintComponent(Graphics g)</p>
<p>{</p>
<p>Font someFont = new Font(&#8220;Serif&#8221;, Font.BOLD, 12);</p>
<p>g.setFont(someFont);</p>
<p>g.drawString(&#8220;Some Text!&#8221;, 50, 50); // draws, some Text! 50&#215;50 from top left in bold serif font</p>
<p>FontMetrics someFontMetric = g.getFontMetrics(someFont);</p>
<p>int wordLength = someFontmetric.stringWidth(&#8220;Hello&#8221;); // gives length in pixels of the graphic word Hello</p>
<p>}</p>
<p>assigned an image to a variable</p>
<p>private Image picture = null;</p>
<p>picture =getToolKit().getImage(&#8220;mypicture.gif&#8221;);</p>
<p>g.drawImage(picture, 0, 0, this);</p>
<p><strong> </strong></p>
<p><strong>Unit 8 </strong></p>
<h2><em>Understand how threads can help to make more effective use of a computer&#8217;s resources; </em></h2>
<p>Threads are not the actual static code itself but rather they are the dynamic process of executing that code. The threads share the CPU, the operating system will allocate small blocks of time to each thread.</p>
<h2><em>Define, create and use threads; </em></h2>
<p>Define</p>
<p>Create</p>
<p>public class WhereAmIRun extends Thread</p>
<p>{</p>
<p>int thisThread;</p>
<p>// constructor</p>
<p>public WhereAmIRun (int number)</p>
<p>{</p>
<p>thisThread = number;</p>
<p>}</p>
<p>// implement the run method</p>
<p>public void run ()</p>
<p>{</p>
<p>for (int i =0;i&lt; 100; i++)</p>
<p>{</p>
<p>System.out.println(&#8220;I&#8217;m in thread &#8221; + thisThread);</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p>You can also use the Runnable Interface which allows classes to inherit from more than just the threads class. The runnable inferface has one method called run. The creation of a threadable class is the same as defined above but has a slightly different first line.</p>
<p>public class WhereAmIRun implements Runnable</p>
<p><span style="text-decoration: underline;">USE</span></p>
<p>public class ThreadTester // for classes that extend the Thread class</p>
<p>{</p>
<p>public static void main (String [] args)</p>
<p>{</p>
<p>// create the threads</p>
<p>WhereAmI place1 = new WhereAmI(1);</p>
<p>WhereAmI place2 = new WhereAmI(2);</p>
<p>WhereAmI place3 = new WhereAmI(3);</p>
<p>// start the threads</p>
<p>place1.start();</p>
<p>place2.start();</p>
<p>place3.start();</p>
<p>}</p>
<p>}</p>
<p>public class ThreadTesterRun // for classes that use the runnable interface we need to create thread objects</p>
<p>{</p>
<p>public static void main (String [] args)</p>
<p>// create a runnable object</p>
<p>WhereAmIRun place1 = new WhereAmIRun(1);</p>
<p>// now create a thread to run it</p>
<p>Thread thread1 = new Thread(place1);</p>
<p>// repeat for two further objects</p>
<p>WhereAmIRun place2 = new WhereAmIRun(2);</p>
<p>Thread thread2 = new Thread(place2);</p>
<p>WhereAmIRun place3 = new WhereAmIRun(3);</p>
<p>Thread thread3 = new Thread(place3);</p>
<p>// start the threads</p>
<p>thread1.start();</p>
<p>thread2.start();</p>
<p>thread3.start();</p>
<p>}</p>
<p>}</p>
<h2><em> </em></h2>
<h2><em>Describe the various states that threads can be in; </em></h2>
<p>A thread is in one of five states at any moment in time. These are:</p>
<p>1. initial state;</p>
<p>2. runnable state;</p>
<ul type="disc">
<li>
<ul type="circle">
<li>
<ul type="square">
<li>
<ul type="disc">
<li>ready to be used by the JVM</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>3. running state;</p>
<p>4. blocked state;</p>
<ul type="disc">
<li>
<ul type="circle">
<li>
<ul type="square">
<li>
<ul type="disc">
<li>it is waiting for an I/O process to complete;</li>
<li>some other part of the program has not completed its processing;</li>
<li>it is not being given access to some shared data.</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>5. finished state.</p>
<h2><em>Appreciate some of the problems that can occur when threads access shared resources; </em></h2>
<p>Multiple threads accessing shared resources can cause problems as they can block each other, or change variables that other threads are relying on.</p>
<h2><em>Understand how locks affect the execution of code. </em></h2>
<p>Threads can lock a shared resources to avoid problems. To do this any thread methods that access shared data need to be defined with the static variable, synchronized (with a &#8216;Z&#8217;). This stops any other threads using this method and put them in the blocked state until the resource is unlocked. To prevent the locking of shared resources creating new potential problems follow points.</p>
<ul type="disc">
<li>If two or more threads modify a common object, then declare the methods that do the modifying as being synchronized.</li>
<li>If a thread needs to wait for an object to change, make sure that it waits inside the thread. It does this by entering a synchronized method and calling wait.</li>
</ul>
<p>When a method has changed an object, it should call the notify method or the notifyAll method before terminating. This gives other methods a chance to access the object. notifyAll(); or notify();</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisfordblog.com/2009/06/ou-m257-revision-notes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Accidental Open University M255 Revision</title>
		<link>http://www.chrisfordblog.com/2009/05/open-university-m255-revision/</link>
		<comments>http://www.chrisfordblog.com/2009/05/open-university-m255-revision/#comments</comments>
		<pubDate>Thu, 28 May 2009 09:33:34 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Everything Else]]></category>
		<category><![CDATA[M255]]></category>
		<category><![CDATA[M257]]></category>
		<category><![CDATA[Open University]]></category>
		<category><![CDATA[OU]]></category>
		<category><![CDATA[Revision]]></category>

		<guid isPermaLink="false">http://www.chrisfordblog.com/?p=379</guid>
		<description><![CDATA[I&#8217;m currently trying to do some revision for my upcoming Open University exam M257 &#8220;Putting Java to Work.&#8221; To avoid doing this in a doing it sort of way I started making an AtoZ glossary from the various PDF&#8217;s to aid my revision attempts. Problem is that half way through completing this I discovered I was [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently trying to do some revision for my upcoming Open University exam M257 &#8220;Putting Java to Work.&#8221; To avoid doing this in a doing it sort of way I started making an AtoZ glossary from the various PDF&#8217;s to aid my revision attempts. Problem is that half way through completing this I discovered I was using PDF&#8217;s for the wrong course, M255 instead of M257. Very annoying! I&#8217;ve posted the accidentally half completed M255 course glossary below, as it may help somebody else.</p>
<table style="width: 596pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0" width="795">
<colgroup span="1">
<col style="width: 596pt; mso-width-source: userset; mso-width-alt: 29074;" span="1" width="795"></col>
</colgroup>
<tbody>
<tr style="height: 51pt;" height="68">
<td class="xl27" style="width: 596pt; height: 51pt; background-color: transparent; border: #ece9d8;" width="795" height="68"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>accessor message</strong><span class="font0">An accessor message is either a getter or a setter message. For example, the messages getPosition( ) and setPosition( ) are accessor messages for the instance variable position held by instances of the Frog class. The getter message getPosition( ) returns the value of the instance variable position, while the setter message setPosition( ) changes the value of position.</span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl24" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>accessor message</strong><span class="font5"> </span><span class="font6">The general term for either a </span><span class="font5">setter </span><span class="font6">or a </span><span class="font5">getter message</span><span class="font6">.<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl27" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>accessor method</strong><span class="font0">A method that implements an accessor message.See getter method and setter method.</span></span></span></td>
</tr>
<tr style="height: 63.75pt;" height="85">
<td class="xl24" style="width: 596pt; height: 63.75pt; background-color: transparent; border: #ece9d8;" width="795" height="85"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>argument</strong><span class="font5"> </span><span class="font6">Extra information supplied with a </span><span class="font5">message</span><span class="font6">. For example, when requesting a Frog object to change its colour to that of another Frog object, it is necessary to provide that other Frog object as an argument. This is seen in the message-send frog1.sameColourAs(frog2). A message can have zero, one or more arguments. There is no argument in the message getColour( ). The message setColour( OUColour.PURPLE) has one argument (namely OUColour.PURPLE) supplying information on which colour is to be chosen. Two arguments (yourAccount and 50) supply information in the message transfer(yourAccount, 50).<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl27" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>assignment statement </strong><span class="font0">A statement that tells Java to make a variable reference a particular object or to hold a particular primitive value.</span></span></span></td>
</tr>
<tr style="height: 51pt;" height="68">
<td class="xl27" style="width: 596pt; height: 51pt; background-color: transparent; border: #ece9d8;" width="795" height="68"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>assignment </strong><span class="font0">When using objects, assignment is the process which results in the variable on the left-hand side of the assignment operator referencing the object returned by the expression on the right-hand side (this is called assignment using reference semantics). When using values of primitive data types, assignment is the process that results in the variable on the left-hand side containing a copy of the value returned by the right-hand side (this is referred to as assignment using value semantics).</span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl25" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>attribute</strong><span class="font5"> </span><span class="font6">Some property or characteristic of an </span><span class="font5">object</span><span class="font6">,suchas </span><span class="font7">position </span><span class="font6">for </span><span class="font7">Frog </span><span class="font6">objects, or </span><span class="font7">balance </span><span class="font6">for </span><span class="font7">Account </span><span class="font6">objects.</span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl25" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>attribute value</strong><span class="font5"> </span><span class="font6">The current value of an </span><span class="font5">attribute</span><span class="font6">. For example, a </span><span class="font7">Frog </span><span class="font6">object has the attributes </span><span class="font7">colour </span><span class="font6">and </span><span class="font7">position</span><span class="font6">. The attribute </span><span class="font7">colour </span><span class="font6">of a particular object might have the value </span><span class="font7">OUColour.BLUE </span><span class="font6">and the attribute </span><span class="font7">position </span><span class="font6">might have the value </span><span class="font7">1</span><span class="font6">.<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl25" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>behaviour </strong><span class="font6">This term is used to describe the way an </span><span class="font5">object </span><span class="font6">responds to the </span><span class="font5">messages </span><span class="font6">in its </span><span class="font5">protocol</span><span class="font6">.<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 51pt;" height="68">
<td class="xl27" style="width: 596pt; height: 51pt; background-color: transparent; border: #ece9d8;" width="795" height="68"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>bytecode</strong><span class="font0">Bytecode is the intermediate code produced by the Java compiler.In BlueJ, compilation is done when the Compile button is pressed. This will create a bytecode file, for example Frog.class, from the source code file Frog.java.The bytecode file is portable, because each computer that can run Java programs has a Java Virtual Machine – a program itself – that understands bytecode and converts it into the machine code required for that particular computer.</span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl24" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>class</strong><span class="font5"> </span><span class="font6">A class is a template that serves to describe all instances (objects) of that class. It defines what </span><span class="font5">attributes </span><span class="font6">the objects should have and their </span><span class="font5">protocol </span><span class="font8">– </span><span class="font6">what messages they can respond to.<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 51pt;" height="68">
<td class="xl27" style="width: 596pt; height: 51pt; background-color: transparent; border: #ece9d8;" width="795" height="68"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>comment</strong><span class="font0"> A comment is a piece of text in program code that is ignored when executing the code. In Java multi-line comments are delimited by /* and */. Single line comments are simply preceded by //. A comment can generally be placed anywhere in the code of a class, with the exception of method comments – method comments are placed between /** and */ and must appear immediately before the method header.</span></span></span></p>
<p><span id="more-379"></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl27" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>compiler</strong><span class="font0">A piece of software which first checks that text written in a high-level language is correctly formed. If the check is successful, then the source code is compiled into bytecode.</span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl27" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>compound expression</strong><span class="font0"> An expression built up using other sub-expressions; for example, the following is a compound expression: (3 + 2) * (6 -3)</span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl27" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>concatenation</strong><span class="font0"> The joining of two strings. In Java the string concatenation operator is </span><span class="font9">+ (the plus sign). For example, &#8220;Milton &#8221; + &#8220;Keynes&#8221; evaluates to &#8220;Milton Keynes&#8221;.</span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl27" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>constructor</strong><span class="font0"> A special type of message used to initialise a newly created object.</span></span></span></td>
</tr>
<tr style="height: 38.25pt;" height="51">
<td class="xl27" style="width: 596pt; height: 38.25pt; background-color: transparent; border: #ece9d8;" width="795" height="51"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>data hiding </strong><span class="font0">This is where an object is treated as a black box, with access to the encapsulated data (the instance variables) being possible only through a limited set of methods, i.e. only an object’s own methods are allowed to access the value of an instance variable (either to change it or return it).</span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl27" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>debugging</strong><span class="font0"> The identification and removal of implementation errors (bugs) from a program.</span></span></span></td>
</tr>
<tr style="height: 51pt;" height="68">
<td class="xl27" style="width: 596pt; height: 51pt; background-color: transparent; border: #ece9d8;" width="795" height="68"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>encapsulation</strong><span class="font0"> Objects allow you to encapsulate data by incorporating into a single entity (the object) both the data (instance variables) and the behaviour (methods) defined for that data. The concept of encapsulation is very powerful because it allows an efficient division of labour in large software projects. Each team member can work in isolation on one or more classes. The only things that team members need to know about other classes are the names and specifications of the methods.</span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl27" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>expression</strong><span class="font0"> Code that evaluates to a single value. Expressions are formed from variables, operators and messages.</span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl27" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>formal argument</strong><span class="font0"> An identifier used in a method to stand for a value that is passed into the method by a message.</span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl27" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>garbage collection</strong><span class="font0"> The process of destroying objects, which have become unreachable because they are no longer referenced by variables, in order to reclaim their space in memory. In certain programming languages, including Java, this process is automatic.</span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl25" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>getter message</strong><span class="font5"> </span><span class="font6">A message that returns as its message answer the value of one of a receiver’s attributes. See </span><span class="font5">setter message </span><span class="font6">and </span><span class="font5">accessor message</span><span class="font6">.<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl27" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>getter method</strong><span class="font9">An accessor method whose purpose is to return the value of an instance variable as its message answer.</span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl27" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>identifier</strong><span class="font0"> The name of a variable.</span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl24" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>initialisation</strong><span class="font5"> </span><span class="font6">The </span><span class="font5">state </span><span class="font6">of an </span><span class="font5">object </span><span class="font6">when it is first created depends on its initialisation.<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl25" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>inspector</strong><span class="font5"> </span><span class="font6">An inspector is a tool used in M255 to look at the internal state of </span><span class="font5">objects </span><span class="font6">in a system. It lists the </span><span class="font5">attributes </span><span class="font6">of an object and displays their current values.<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl25" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>instance</strong><span class="font5"> </span><span class="font6">An </span><span class="font5">object </span><span class="font6">that belongs to a given </span><span class="font5">class </span><span class="font6">is described as an instance of that class.<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 51pt;" height="68">
<td class="xl27" style="width: 596pt; height: 51pt; background-color: transparent; border: #ece9d8;" width="795" height="68"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>instance variable</strong><span class="font0"> A variable that is common to all the instances of a class but whose value is specific to each instance. Each instance variable either contains a reference to an object or contains a value of some primitive type. For example, Frog objects have the instance variables colour and position. The values of the instance variables of a particular object represent the state of that object.</span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl26" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;">Instances of the same class have the same attributes, which are initialised in the same way. They have the same <span class="font5">instance </span><span class="font6">protocol and respond in the same way to each message.<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 38.25pt;" height="51">
<td class="xl27" style="width: 596pt; height: 38.25pt; background-color: transparent; border: #ece9d8;" width="795" height="51"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>integrated development environment (IDE)</strong><span class="font0">A software tool that supports the construction, compilation and execution of a program. BlueJ is an example of an IDE that supports the development of programs in Java and includes libraries of classes and facilities for debugging and program design.</span></span></span></td>
</tr>
<tr style="height: 51pt;" height="68">
<td class="xl27" style="width: 596pt; height: 51pt; background-color: transparent; border: #ece9d8;" width="795" height="68"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>Javadoc</strong><span class="font0">A program that comes with Java. The Javadoc program picks up information from specially formatted comments and other parts of the class code such as the constructor and the method headers. These are all used to create an HTML file, which describes the class in a standard way. This description is aimed not at the Java compiler, but at human readers (and possibly the writer of the code at a later date, when he or she might well have forgotten what the methods do).</span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl27" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>literal </strong><span class="font0">A comprehensible textual representation of a primitive value or object. For example, &#8216;X&#8217; is a char literal, 4.237 is a double literal and &#8220;hello there!&#8221; is a String literal.</span></span></span></td>
</tr>
<tr style="height: 38.25pt;" height="51">
<td class="xl25" style="width: 596pt; height: 38.25pt; background-color: transparent; border: #ece9d8;" width="795" height="51"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>message</strong><span class="font5"> </span><span class="font6">A message is a request for an </span><span class="font5">object </span><span class="font6">to do something. The only way to make an object do something is to send it a message. For example, the position of a Frog object changes when it is sent the message left( ) or right( ); to obtain information on the value of a Frog object’s colour attribute, you send it the message getColour( ).</span></span></span></td>
</tr>
<tr style="height: 51pt;" height="68">
<td class="xl24" style="width: 596pt; height: 51pt; background-color: transparent; border: #ece9d8;" width="795" height="68"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>message answer</strong><span class="font5"> </span><span class="font6">When a </span><span class="font5">message </span><span class="font6">is senttoan </span><span class="font5">object </span><span class="font6">then, depending on what the message is, a message answer may be returned. A message answer is a value or an object; it is not a message. Sometimes a message answer is used, sometimes it is ignored. A message answer may be used subsequently as the receiver or argument of another message. Enquiry messages (getter messages) often return the value of an attribute, as with the message getColour( ), which returns a value such as OUColour.GREEN.<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl27" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>message expression</strong><span class="font0"> A message-send which evaluates to a value, i.e. the message returns an answer.</span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl24" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>message name</strong><span class="font5"> </span><span class="font6">The name of a </span><span class="font5">message </span><span class="font6">does not include any arguments. For example, the name of the message </span><span class="font7">left( ) </span><span class="font6">is </span><span class="font7">left( )</span><span class="font6">, and the name of the message </span><span class="font7">upBy(6) </span><span class="font6">is </span><span class="font7">upBy( )</span><span class="font6">.<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl24" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>message-send</strong><span class="font5"> </span><span class="font6">The code that sends a message to an object </span><span class="font8">– </span><span class="font6">for example, </span><span class="font7">frog1.right( )</span><span class="font6">, which consists of the </span><span class="font5">receiver </span><span class="font6">followed by a full stop and then the </span><span class="font5">message</span><span class="font6">.<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl27" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>method body</strong><span class="font0"> That part of a method enclosed by braces that follows the method header.</span></span></span></td>
</tr>
<tr style="height: 38.25pt;" height="51">
<td class="xl27" style="width: 596pt; height: 38.25pt; background-color: transparent; border: #ece9d8;" width="795" height="51"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>method header</strong><span class="font0">A method header consists of an access modifier (e.g. public), a return value (e.g. int or void) and a name (e.g. setPosition) followed by the formal argument names enclosed in parentheses (e.g. (int aNumber)). For example, the method header for a method whose name is setPosition( ) is public void setPosition(int aNumber).</span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl27" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>method invocation</strong><span class="font0"> At run-time, selecting and executing a method when an object receives a message.</span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl27" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>method signature</strong><span class="font0">The name of the method together with the parentheses and the types of any arguments. For example, the signature for the setPosition( ) method in the Frog class is setPosition(int).</span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl27" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>method</strong><span class="font0"> The code that is invoked by the Java Virtual Machine at run-time when an object receives a message.</span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl27" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>new</strong><span class="font0"> An operator used to create an object – used in conjunction with a constructor.</span></span></span></td>
</tr>
<tr style="height: 38.25pt;" height="51">
<td class="xl24" style="width: 596pt; height: 38.25pt; background-color: transparent; border: #ece9d8;" width="795" height="51"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>object</strong><span class="font5"> </span><span class="font6">An object is a software component that has a unique identity and responds to </span><span class="font5">messages</span><span class="font6">. Each object has </span><span class="font5">state </span><span class="font6">and responds to a particular set of messages (its </span><span class="font5">protocol</span><span class="font6">). Thus a </span><span class="font7">Frog </span><span class="font6">object (which has little resemblance to a real-world frog) holds information on its position and colour as values of its </span><span class="font5">attributes </span><span class="font7">position </span><span class="font6">and </span><span class="font7">colour</span><span class="font6">.<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl25" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>object-state diagram</strong><span class="font5"> </span><span class="font6">An object-state diagram represents an </span><span class="font5">object</span><span class="font6">. It shows the </span><span class="font5">class </span><span class="font6">of the object, its </span><span class="font5">state </span><span class="font6">in terms of attribute values, and its </span><span class="font5">protocol</span><span class="font6">.<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl28" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>parameter</strong><span class="font5"> </span><span class="font6">A synonym for </span><span class="font5">argument</span><span class="font6">.<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 38.25pt;" height="51">
<td class="xl24" style="width: 596pt; height: 38.25pt; background-color: transparent; border: #ece9d8;" width="795" height="51"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>polymorphism</strong><span class="font5"> </span><span class="font6">Any </span><span class="font5">message </span><span class="font6">to which </span><span class="font5">objects </span><span class="font6">of more than one </span><span class="font5">class </span><span class="font6">can respond is said to be polymorphic or to show polymorphism. For example, both Toad and Frog objects respond to the message left( ), but with different behaviours. They also respond to the message green( ), with identical behaviours.<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 38.25pt;" height="51">
<td class="xl27" style="width: 596pt; height: 38.25pt; background-color: transparent; border: #ece9d8;" width="795" height="51"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>primitive data type</strong><span class="font0">A set of values together with operations that can be performed on them. The primitive data types in Java provide a set of basic building blocks from which all the more complex types of data can be built. There are three categories of primitive data type: numbers, characters and Booleans.</span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl27" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>private</strong><span class="font0"> An access modifier. It tells the Java compiler that the only objects that have access are the object to which it belongs and other objects of the same class.</span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl28" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>protocol</strong><span class="font5"> </span><span class="font6">The set of </span><span class="font5">messages </span><span class="font6">an </span><span class="font5">object </span><span class="font6">can respond to (understands).<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl27" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>pseudo-variable</strong><span class="font0"> A special undeclared variable, visible within a method or constructor, that cannot be changed by assignment. Java has two such variables – this and super.</span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl27" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>public</strong><span class="font0"> An access modifier. It tells the Java compiler that all objects have access.</span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl28" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>receiver</strong><span class="font5"> </span><span class="font6">The </span><span class="font5">object </span><span class="font6">to which a </span><span class="font5">message </span><span class="font6">is sent.<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl27" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>reference semantics </strong><span class="font0">The situation whereby a variable holds the address of an object, rather than a value.A reference type variable on the left-hand side of an assignment statement always ends up referring to the object on the right-hand side (cf. value semantics).</span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl27" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>reference type variable</strong><span class="font0"> A variable declared to reference an object of the declared or compatible type.</span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl25" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>sequence diagram</strong><span class="font5"> </span><span class="font6">A diagram that depicts the interactions between objects, in the form of </span><span class="font5">messages </span><span class="font6">and </span><span class="font5">message answers</span><span class="font6">.<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl25" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>setter message</strong><span class="font5"> </span><span class="font6">A message that sets the value of one of a receiver’s attributes. See </span><span class="font5">getter message </span><span class="font6">and </span><span class="font5">accessor message</span><span class="font6">.<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl27" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>setter method</strong><span class="font0">An accessor method whose purpose is to assign a new value to an instance variable. The new value is determined by the single argument of the method.</span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl27" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>signature</strong><span class="font0"> See method signature.</span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl25" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>state</strong><span class="font5"> </span><span class="font6">The values of the </span><span class="font5">attributes </span><span class="font6">of an </span><span class="font5">object </span><span class="font6">constitute its state. The state of an object can vary over time as the values of its attributes change.<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl27" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>statement</strong><span class="font0">A statement represents a single instruction for the compiler or interpreter to translate into bytecode. In Java a statement must always end with a semicolon.</span></span></span></td>
</tr>
<tr style="height: 76.5pt;" height="102">
<td class="xl24" style="width: 596pt; height: 76.5pt; background-color: transparent; border: #ece9d8;" width="795" height="102"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>subclass</strong><span class="font5"> </span><span class="font6">A subclass is a new </span><span class="font5">class </span><span class="font6">defined in terms of an existing class (its </span><span class="font5">superclass</span><span class="font6">). Instances of a subclass have all the attributes that instances of the superclass have, but may have additional attributes. The protocol of the subclass includes (has at least all the messages of) the protocol of the superclass, but may define additional messages. For example, HoverFrog is a subclass of Frog. The protocol of HoverFrog objects includes that of Frog objects and has, in addition, the messages upBy( ) and downBy( ) to which Frog objects cannot respond. HoverFrog objects have all the attributes of Frog objects (colour and position) and an additional attribute – height.<span style="mso-spacerun: yes"> </span></span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl24" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>superclass</strong><span class="font5"> </span><span class="font6">If Bisa </span><span class="font5">subclass </span><span class="font6">of A, then A is the superclass of B.</span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl27" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>syntax</strong><span class="font0"> The structure of statements in a given language.</span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl27" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>this</strong><span class="font0"> A pseudo-variable used within a method to reference the receiver of the message that activated the method.</span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl27" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>value semantics </strong><span class="font0">The situation in which a variable holds a value, of some primitive data type.A value type variable on the left-hand side of an assignment statement always ends up holding a copy of the value on the right-hand side (cf. reference semantics).</span></span></span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl27" style="width: 596pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="795" height="17"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>value type variable </strong><span class="font0">A variable declared to hold a value of the declared or compatible primitive type.</span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl27" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>variable</strong><span class="font0"> A named ‘chunk’ or block of the computer’s memory which can hold either a value of some primitive type or the address (reference) of an object.</span></span></span></td>
</tr>
<tr style="height: 25.5pt;" height="34">
<td class="xl27" style="width: 596pt; height: 25.5pt; background-color: transparent; border: #ece9d8;" width="795" height="34"><span style="font-size: x-small;"><span style="font-family: Arial;"><strong>variable reference diagram</strong><span class="font0"> A diagram showing a reference type variable pointing to a representation of an object with the current values of its attributes.</span></span></span></td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisfordblog.com/2009/05/open-university-m255-revision/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
