<?xml version="1.0"?>

<!DOCTYPE document SYSTEM "javacert.dtd"> 
<!--
"SGML
or XML using a publicly available DTD" - you might like to raise this with the FSF.
-->


<!--
      Copyright 1999, 2000, 2002 Dylan Walsh.
      Permission is granted to copy, distribute and/or modify this document
      under the terms of the GNU Free Documentation License, Version 1.1
      or any later version published by the Free Software Foundation;
      with the Invariant Sections being the disclaimer,
      no Front-Cover Texts, and no Back-Cover Texts.
      A copy of the license is included in the section entitled "GNU
      Free Documentation License".

Welcome to the 'source code', as it were, for the document. The HTML webpage is
generated from this XML file by the accompanying XSL transformation file cert2HTML.xsl.
Therefore changes should be made to this file rather than the HTML.

You do not need to know XSLT to work with this document, but you do need basic XML skills,
so that you can edit the text without corrupting the document. An XML editor may help with
this.

If you are not very au fait with these technologies, you probably won't far wrong if you 
leave the general structure of this file unchanged, and just add/edit text and sections where 
needed. 

In XML, tags must be nested and closed properly, i.e. an opening tag like <title> must
have a closing tag like </title> somewhere after it. An empty tag like <br/> is alright on its
own. In your text you must use &amp; where you want an ampersand ('&') to appear, &lt; for left
angle brackets and &gt; for right angle brackets. A comment will not appear in the output HTML.
This paragraph is itself inside a comment, they are marked with a left angle bracket, followed 
by and exclamation mark and two dashes. They are ended with two dashes and a right bracket.
You cannot nest comments which is why I'm describing rather than showing what they look like.

To generate the webpage after you have made changes, you can apply the transformation with
a command-line XSLT implementation such as Michael Kays InstantSaxon.
See their documentation for information on how to do this. You can also use one of the XSLT
editor/IDEs that are available. There are DOS batch files which will do this provided you copy
saxon.exe into the same folder. InstantSaxon is available on the web, search on Google.

The affect of the XML tags below should be discernable by comparing to the HTML document. In
addition, there are comments in the DTD (javacert.dtd) which briefly describe an element.

Please annotate your changes with an XML comment containing your initials, the date and the change.
Add an entry to the change log below to the change log.

	<change>
  <date>X-XXX-X/date>
  <author>Mr X</author>
  <comment>Summary of changes.</comment>
  <permission>
   Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License,
   Version 1.1 or any later version published by the Free Software Foundation.
  </permission>
 (Required by section 4(F) of the FDL)
  <email>x@y.com</email> (Optional)
  <website>http://www.y.com</website> (Optional)
	</change>

-->

<document>

<!-- 
In future, the XSLT can be changed to output the contents of this changelog section to faciliatate the authors of modified
versions of this document conform to the FDL.
As the author of the original version, there is no requirement for such a feature in the initial version.
-->
<changelog>
	<change>
  <date>1-Oct-2002</date>
  <author>Dylan Walsh</author>
  <comment>Initial release under the FDL.</comment>
  <permission>
   Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License,
   Version 1.1 or any later version published by the Free Software Foundation.
  </permission>
	</change>
</changelog>

<title>Sun Certified Java Programmer Pre-Exam Essentials</title>
<legal><copyright-declaration><copyright/>1999, 2000, 2002 Dylan Walsh.</copyright-declaration><br/>
      <fdl>Permission is granted to copy, distribute and/or modify this document
      under the terms of the GNU Free Documentation License, Version 1.1
      or any later version published by the Free Software Foundation;
      with the Invariant Sections being the disclaimer,
      no Front-Cover Texts, and no Back-Cover Texts.
      A copy of the license is included in the section entitled "GNU
      Free Documentation License".</fdl>
<br/>The exam objectives below are quoted from Sun Microsystems website. Also there are parts quoted from the Javadocs,
also the property of Sun Microsystems.
</legal>

<!-- This disclaimer section must not be changed -->
<disclaimer>No claims are made about the accuracy of this document and no responsibility is taken for any errors. 
<br/>If you find any errors contact the maintainer of the site where you found this document, or better still submit a newer version with
a correction.
<br/>The original author cannot control, and may not be aware of, derived versions of this document.
</disclaimer>

<section>
<section_title>Introduction</section_title>
<p>The purpose of this document is to provide a <b>basis for revising</b> for the Sun Certified Programmer examinations,
<b>not to teach</b> the Java language or the topics required for the exam. It is designed to collect all the essential information
you need to retain, in one place, and is designed for someone who has already finished their own study and is about to take the exam.</p>
<p>This version is written according to the objectives of the "Sun Certified Programmer For Java<trademark/> 2 Platform 1.4"
exam. For those taking the 1.2 exam, the objectives no longer required for 1.4 have been retained towards the end of this document.
The sections have "1.2 Exam Only" at the start of their titles. I would recommend doing the 1.4 exam instead, as it is more
current and the only major new subject is assertions.</p>
<p>Aside: There is no 1.3 exam, as such. The 1.1 exam exam was replaced by a Java2 exam, which at the time seemed like it would suffice
for all Java2 releases. However in September 2002 Sun released seperate 1.2 and 1.4 exams. The 1.2 syllabus is for 1.2 and 1.3.</p>
<p>Thank you to everyone who has emailed me with compliments and/or corrections for previous versions of this document, it is appreciated.
On the other hand, if you have questions on the exam or Java, I am afraid I do not have time to answer all of these, so please try either
the certification discussion groups on the web, or the Java newsgroups.</p>
<p>Having obtained my certification, I have neither time or reason to maintain this document in the future and keep it current with
changes in the exam.
Rather than let it stagnate, I have decided to release it as a resource to the Java certification community under the Free Documentation
License.  This will allow others to change, correct, expand and update it. The <a href="javacert.xml">accompanying XML file</a> has
more information on how to do this.</p>
<p>If you are just starting to prepare for the exam, then I recommend the following steps:</p>
<ol>
<li>Buy a good certification book, read the chapters, and do all of the example questions and exercises. This is advisable even if
you are already experienced in Java. According to Barry Boones book, Java <i>instructors</i> have failed this exam. Apparently,
many people have to take the exam more than once. For experienced programmers, there are things which are examined that you may
not encounter in everyday programming, or would lookup in the Javadocs as needed. On the other hand, there are many things 
experienced developers ought to know but often do not. This exam is regarded as being more difficult than most other certifications.</li>
<li>The books I used to study for the exam were versions of the Roberts, Heller et al book. and the book by Barry Boone.
You can find more details on the latest versions of these on the web, and there are more recent books which may be worthwhile.

<br/>You don't <i>need</i> to buy both, but I found that a good way to study was to do one chapter from each every evening.
I did chapters on different topics, which made it more interesting and meant that I revised the same topic later in the other book.</li>
<li>There are courses available, which I cannot comment on, as I studied for the exam without sitting any courses.
While these may be worthwhile, I suggest you still follow step 1, as they may be general Java courses and not cover some of
the specific issues which come up in the exam.</li>
<li>When you are finished studying, do any and all mock exams available. In addition to those which come with the books,
there many available online and you can find lists of links to them on some of the websites below. Do not sit the exam until
you are getting marks comfortably above the pass level. I suggest studying until you get atleast 10% more in practice exams
than the minimum required for the real exam. A habit you may find useful is when you are marking yourself, for every question
you get wrong, hit yourself over the head with a baseball bat... Just kidding, for every question you get wrong, find out
what the right answer is, and why, and write that down in a notebook for future revision. Make sure you do the free Sun sample
questions as they most accurately reflect the exam.</li>
<li>Read this document again the night, or morning, before you take the exam.</li>
</ol>
<subh>Useful links</subh>
<p>Suns own certification site, has FAQs, objectives and sample questions:
<a href="http://suned.sun.com/US/certification/java/java_progj2se.html">http://suned.sun.com/US/certification/java/java_progj2se.html</a>
</p><p>Marcus Greens Site has exams, FAQs, tutorials:<a href="http://www.jchq.net/">http://www.jchq.net/</a>
</p><p>A discussion forum: <a href="http://groups.yahoo.com/group/javacertstudy/">http://groups.yahoo.com/group/javacertstudy/</a>
</p><p>The JavaRanch, has a nice rules exam, and lots of cows: <a href="http://www.javaranch.com/">http://www.javaranch.com/</a>
</p><p>More links: <a href="http://directory.google.com/Top/Computers/Programming/Languages/Java/Resources/Certification/">http://directory.google.com/Top/Computers/Programming/Languages/Java/Resources/Certification/</a>
</p>

<subh>The Exam</subh>
<p>Here are just a few comments on the exam itself. Firstly, time should not be a problem, as you should have time to answer all
the questions, review them, and possibly be able to leave early. It will really be an issue of whether you know/understand what
is required. That said, as with any exam, do not get bogged down in any one question, mark it and come back to it later if it is taking
too long. 
</p><p>Generally, the questions in the real exam are a lot better than the mock exams which are going around: They less ambiguously
worded, the sample code is usually short, and the slant of the questions is towards whether you understand the principles rather
than whether you have memorized a lot of methods etc. The majority of the questions are on the core language syntax rather than its
APIs. Of course, you do need to be familiar with the APIs mentioned in the objectives to get a pass mark.</p>

<subh>About This Document</subh>
<p>This document is structured around the objectives for the exams. For each objective, I have attempted to list all the bare-bones
information you may need to remember for the exam.
</p>
<p>The "1.2 Exam Only" sections are based on a subset of the 1.1 objectives with additions where needed, as they were taken from an
older version of this document. This may seem strange but they provide good information for the 1.2 exam.
At the time, the objectives for the Java 1.1 exam were more detailed and descriptive than those for the Java 2 exam, but the exams 
were very similar. I took the 1.2 exam (it was called just "Sun Certified Programmer For Java<trademark/> 2 Platform" at the time)
in 1999, and released the first version of this document afterwards.
</p>
</section>

<section>
<section_title>Declarations and Access Control</section_title>
<obj>
<objh>Write code that declares, constructs and initializes arrays of any base type using any of the permitted forms both for declaration
and for initialization. </objh>

<subh>Declaring arrays:</subh>
<p>For example,use either </p>
<code>	int[] x;</code>
<p>or</p>
<code>	int x[];</code>
<p>Both are legal positions for the brackets. To declare a multidimensional array, use multiple sets of brackets,
e.g. <pcode>int i[][];</pcode> declares a two dimensional array. Note that, for example, <pcode>int[]i[];</pcode> is also
legal, and means the same thing.
In Java, multidimensional arrays can be "not square" i.e. they are just arrays of arrays, and each of those constituent
arrays can be of a different size.</p>

<subh>Construct arrays:</subh>
<p>Arrays are objects. Use the <pcode>new</pcode> keyword to construct them. For example having declared an array i:</p>
<code>int[] i;</code>
<p>you then construct the array and assign it to i as follows:</p>
<code>i = new int[10];</code>
<p>The size of the array is in the brackets (in this example 10). It is common to do both operations in one statement:</p>
<code>int i[] = new int[10];</code>

<subh>To initialize an array using loop iteration:</subh>
<p>An example:</p>
<code>	int array[] = new int[15];
	for(int j=0; j&lt;array.length;j++){
		array[j]=j;
	}</code>

<subh>Write code to initialize an array using the combined declaration and initialization format:</subh>

<p>An example:</p>
<code>char c[]= new char[] {'a','b','c','d','e'};</code>
<p>or you can use</p>
<code>char c[]= {'a','b','c','d','e'};</code>

</obj>

<obj>
<objh>Declare classes, nested classes, methods, instance variables, static variables and automatic (method local)
variables making appropriate use of all permitted modifiers (such as <pcode>public</pcode>, <pcode>final</pcode>,
<pcode>static</pcode>, <pcode>abstract</pcode> etc.).
State the significance of each of these modifiers both singly and in combination and state the effect of package
relationships on declared items qualified by these modifiers. </objh>
<p>This is fundamental Java. If you are unsure of this topic, see a textbook.</p>
<p>A good  but technical reference for these kinds of issues is the Java Language Specification (not for beginners).
It is available at the following URL:
<br/><a href="http://java.sun.com/docs/books/jls/html/index.html">http://java.sun.com/docs/books/jls/html/index.html</a></p>

<subh>Some terms and their synonyms:</subh>
<p><u>Scope/Visibility:</u> Where something can be seen / is accessable from.</p>
<p><u>Nested/Inner Class:</u> A class whose code sits inside the body of another 'outer' class. It exists 'inside' the class in that it
can see the private methods and variables.</p>
<p><u>Instance/Member:</u> Means the method/variable/nested class belongs to each object which is an instance of the class.
The term 'a member'
is often used to refer to both methods and variables of this type.
Cannot be accessed by statically i.e. without having an instance of the class.</p>

<p><u>Class/Static:</u> The method/variable/nested class belongs to the class as opposed to the instances of the class.
Can be used without creating an instance of the class, but static methods/nested class cannot use instancts variables/methods.</p>

<p><u>Local/Automatic variable:</u> A variable which is declared within a method or as a parameter to the method.
Cannot be seen outside the method.</p>

<subh>Scoping Types</subh>
<p>"default" or "friendly" - this is where no modifier is used. Means something is only visible to classes in the same package.</p>
<p><pcode>protected</pcode> - can only be accessed by classes in the same package or subclasses of this class.
This frequently surprises experienced developers, especially those with a prior backround in the mutant hybrid of object
orientated programming and assembly language known as 'C++' :-)
To fair the name is misleading, as it sounds like it restricts access, where as it in fact it adds subclasses outside
the package to the list of things that can access the item in question, as compared to using "default" access.
</p>
<p><pcode>public</pcode> - can be accessed by any other class.
</p>
<p><pcode>private</pcode> - can only be accessed from inside the class. </p>

<subh>Declare classes using the modifiers <pcode>public</pcode>, <pcode>abstract</pcode> or <pcode>final</pcode>:</subh>
<p><pcode>public</pcode> - is visible outside of its package. Without this modifier, the class cannot be accessed outside
its package.
</p><p><pcode>abstract</pcode> - cannot be instantiated, is allowed to contain <pcode>abstract</pcode> methods.
</p><p><pcode>final</pcode> - cannot be subsclassed.</p>

<subh>Using the modifiers <pcode>private</pcode>, <pcode>protected</pcode>, <pcode>public</pcode>, <pcode>static</pcode>,
<pcode>final</pcode>, <pcode>native</pcode> or <pcode>abstract</pcode>:</subh>
<p><pcode>private</pcode> - can only be accessed from inside the class. Private members are not inherited by subclasses. Inner classes
can be declared <pcode>private</pcode>.
</p><p><pcode>protected</pcode> - can only be accessed by classes in the same package or subclasses of this class.
</p><p><pcode>public</pcode> - can be accessed by any other class.
</p><p><pcode>static</pcode> - belongs to the class rather than any particular instance of the class. For variables, effectively,
there is just one copy of this variable for all instances of the class, and if an instance changes the value, the other instances see
that new value. For methods, it means the method can be called without having created an instance, but within the methodd you cannot
use the <pcode>this</pcode> keyword, or refer to instance variables and methods directly (without creating an instance and referring
to the variable/class in that instance). For inner classes, it means they can be instantiated without having an instance of the
enclosing class, but as with static methods, the methods of the inner class cannot refer to instance variables or methods of the
enclosing class directly.
</p><p><pcode>final</pcode> - cannot be changed. Variables are constants, methods cannot be overridden, classes cannot be subclassed.
Since Java1.1 you can declare the variable without assigning a value. Once you assign a value, you cannot change it. The are known as
'blank' finals, are frequently used for things like constants you wish to initialise from a configuration file.
</p><p><pcode>native</pcode> - a <b>method</b> which is not written in java and is outside the JVM in a library.
</p><p><pcode>abstract</pcode> - a <b>method</b> which is not implemented. Must be implemented in a subclass if that subclass is to be
'concrete' and allow people to instantiate it.</p>

<big>Nested Classes</big>
<subh>To define a non-static nested class either in a class or method scope:</subh>
<p>Place the class definition (for the nested class) inside another class definition (the outer class) or a method.</p>

<subh>To define, in method scope, an anonymous nested class that implements a specified interface:</subh>
<p>An anonymous nested class is defined where is it instantiated (in a method). An anonymous nested class must either
implement an interface or extend a class, but the <pcode>implements</pcode> or <pcode>extends</pcode> keywords are not used.
For example the following line causes the method to return an object which is an instance of an anonymous nested class:</p>
<code>return new SomeClass() { /*body of the anonymous class goes here*/ };</code>
<p>You might like to think of an anonymous nested class as part of a really long <pcode>new</pcode> statement, which happens to
contain a class definition, and which is why it has a ";" at the end. 
The following example calls <pcode>someMethod()</pcode>, passing an instance of the anonymous nested class:</p>
<code>someMethod(new SomeClass() { /*body of the anonymous class goes here*/ });</code>
<p>In both cases <pcode>SomeClass()</pcode> is not the name of the anonymous class (anonymous means it has no name) rather is it the name of
the class that you are extending or the interface you are implementing. 
These classes cannot define a constructor, as they do not have a name that you can use to declare the constructor method. If SomeClass()
is a class, the default constructor of that class is called, if you want to use a non-default constructor instead, you supply
arguments e.g.:</p>
<code>return new SomeClass(12) { /*body of the anonymous class goes here*/ };</code>
<p>will call the SomeClass constructor which takes an int.</p>


<subh>Write code in a non-static method of the outer class to construct an instance of the nested class.</subh>
<pcode>Inner x = new Inner();</pcode> constructs an instance of Inner where Inner is a nested class defined in the current class.

<subh>Write code to construct an instance on a nested class where either no <pcode>this</pcode> object exists,
or the current <pcode>this</pcode> object is not an instance of the outer class.</subh>
You must create an instance of the outer class first. Given a class, Outer, containing a nested class Inner:
<code>Outer.Inner y = new Outer().new Inner();</code>
<p>The above creates an instance of Inner called y, but it had to construct an instance of Outer first. 
The following example creates the Outer instance on a separate line, the syntax in the second line is the one you use when you already 
have an instance of the outer class.</p>
<code>Outer x = new Outer();
Outer.Inner y = x.new Inner();</code>
If Inner is static, you can use:
<code>Outer.Inner I= new Outer.Inner();</code>

<subh>State which variables and methods in enclosing scopes are accessible from methods of the inner class.</subh>
<p>
A non-static inner class has access to all member variables and methods of the containing class.
If the inner class is defined inside a method, it has access to those method (a.k.a. automatic or local) variables which
are declared <pcode>final</pcode>, in addition to the above.
</p>
<p>A static inner class is restricted in the same way as a static method: it cannot refer to instance variables and methods
of the containing class directly (without creating an instance and referring to the variable/class in that instance).</p>
</obj>

<obj>
<objh>For a given class, determine if a default constructor will be created and if so state the prototype of that constructor. </objh>
<p>The default constructor takes no arguments e.g. <pcode>classname()</pcode> where classname is the name of you class. 
A default constructor is automatically created only if you do not create <b>any</b> constructors in your class. 
If you create a non-default constructor (i.e. one that takes an argument), then you may have to create a default one
yourself, if you want there to be one. 
</p>
<p>All constructors call the default constructor of its parents class (if there is one), and so on up the hierarchy to Object,
unless you specify a different constructor using <pcode>super(...)</pcode> (to use a constructor in the parent) or <pcode>this(...)</pcode>. 
If you use such calls, they must be the first thing in the constructor.
</p>
</obj>
</section>

<section>
<section_title>Flow Control, Assertions and Exception Handling</section_title>
<obj><objh>Write code using <pcode>if</pcode>, and <pcode>switch</pcode> statements and identify legal argument types for these
statements.</objh>

<p>Consult a text book for the basics of these, if unsure. If you do know the basics, here are a few things to watch out for:
</p><p><u>Number 1</u>
<br/>Be wary where <pcode>if</pcode> is used without braces, and with an <pcode>else</pcode> statement. This is referred to as the 
dangling else problem, and occurs in C and C++ aswell. The following example is from Boone (p.154):</p>

<code>if (result >=0)
	if (result > 0)		
		System.out.println("positive");	
else			
	System.out.println("negative");</code>	
<p>The indentations are misleading. It might appear that the above code will print "positive" if result is greater than 0,
"negative" if is less than zero, and print nothing if result is equal to 0. In fact, it will print "positive" if result
is greater than 0, it will print nothing if is less than zero, and print "negative" if result is equal to 0. This is because
the else statement <b>belongs to the second <pcode>if</pcode> statement</b>, and only executes <pcode>if result &gt;=0</pcode>
but not <pcode>if result&gt;0</pcode>, in other words if result equals 0. Using braces (curly brackets) would fix this and is
the best practice if you want readable code that is not potentially misleading. The following indentation shows the real
relationship, of course the compiler doesn't care about indentation:</p>
<code>if (result >=0)
	if (result > 0)
		System.out.println("positive");
	else
		System.out.println("negative");</code>
<p>A good practice is to use blocks with all your <pcode>if</pcode> and <pcode>else</pcode> statements to avoid this ambiguity.</p>

<p><u>Number 2</u>
<br/>After <pcode>switch</pcode>/<pcode>case</pcode> construct has executed the correct case, it will continue to execute all
those after it (including <pcode>default:</pcode> if it is there, after the selected case) on to the end of the
<pcode>switch</pcode>/<pcode>case</pcode> block, unless you put in a <pcode>break</pcode>, <pcode>return</pcode> or <pcode>throw</pcode>
statement. This is referred to as "falling through". For example:</p>
<code>switch (a) 
{
	case 1:
		System.out.println("one");
	case 2:
		System.out.println("two");
	case 3:
		System.out.println("three");
	default:
		System.out.println("some other number");
}</code>

<p>If a is 1, this will print "one", "two", "three" and then "some other number" in succession. If a is 3, this will print "three" and
then "some other number".
</p><p>In some cases, this kind of behaviour might desirable, but here it isn't. This block of code fixes it:</p>
<code>switch (a) {
	case 1:
		System.out.println("one");
		break;
	case 2:
		System.out.println("two");
		break;
	case 3:
		System.out.println("three");
		break;
	default:
		System.out.println("some other number");
}</code>
<p>Note that in switch blocks, it is legal to put <pcode>default:</pcode> anywhere in the block, it doesn't have to be the last one.</p>
<p><u>Number 3</u>
<br/>The argument for an <pcode>if()</pcode> statement must be a boolean or an expression which evaluates to a boolean. A common
beginners mistake is to use a single <pcode>=</pcode> rather than <pcode>==</pcode> to compare values. The following gives a compiler
error:</p>
<code>public static void main(String[] args) {
	int a=1;
	if(a=2) System.out.println("a is two");
}</code>
<p><pcode>a=2</pcode> assigns the value 2 to a.
</p><p>The argument for a switch statement must be a <pcode>byte</pcode>, a <pcode>char</pcode>, a <pcode>short</pcode> or an
<pcode>int</pcode>, or an expression which evaluates to one of those.</p>
</obj>

<obj>
<objh>
Write code using all forms of loops including labeled and unlabeled,
use of break and continue, and state the values taken by loop counter variables during and after loop execution.</objh>
<p>An loop example:</p>
<code>for(int i=0;i&lt;3;i++){ 
	System.out.println("i is "+i); 
	for(int j=0;j&lt;3;j++) { 
		System.out.println("j is"+j); 
	}
}</code>
<p>Will print:</p>
<code>i is 0
j is 0
j is 1
j is 2
i is 1
j is 0</code>
<p>etc.
</p><p>Note: Don't get thrown if the <pcode>for</pcode> loop uses pre-increment instead of post-increment i.e.
<pcode>for(int i=0;i&lt;3;<hilite>++</hilite>j)</pcode> instead of <pcode>for(int i=0;i&lt;3;j<hilite>++</hilite>)</pcode>.
This does not make any difference to the behavior of a <pcode>for</pcode> loop.</p>

<p><pcode>break</pcode> will cause the current loop to be abandoned. <pcode>continue</pcode> causes execution to skip the rest of the code
in the current iteration of the loop, and start at the top of the loop with the next iteration. 
</p><p>These (unlabeled) versions will only affect the execution of loop that they are in. If you have nested loops, and want to break out
of, or skip to the next iteration of, an outer loop, from an inner loop, you used the labeled versions. These jump to the wherever the label
is, allowing you to break out of, or skip several nested loops, by placing the label in front of the outer loop.</p>
<p>Labels are a name followed by a colon, i.e. ":", placed before the loop.</p>

</obj>
<obj>
<objh>
Write code that makes proper use of exceptions and exception handling clauses (<pcode>try</pcode>, <pcode>catch()</pcode>,
<pcode>finally</pcode>) and 
declares methods and overriding methods that throw exceptions.</objh>

<p>Place code which is likely to throw an exception inside a <pcode>try { }</pcode> block. Create one or more <pcode>catch() { }</pcode>
blocks with code to deal with the types of exceptions that might be thrown in the try block. The type of exception goes inside the round
brackets of the catch() statement, as you would when declaring a method.
</p><p>Exceptions are objects, which belong to a class hierarchy. If the exception thrown is an instance of the class, or a subclass of the
class, specified in <pcode>catch()</pcode>, that catch block is the one executed. Your <pcode>catch()</pcode> block therefore can handle a
range of exceptions if they are subclasses of the class specified. If you want to handle one specific subclass one way, and all the other
subclasses differently, put a catch statement for the specific subclass first, and a more general catch block for the superclass second.
Then when an exception is thrown, if the exception is a member of the subclass, that catch block only executes, but if it is a different
subclass of the parent class, the general catch block executes. If you put the superclass first, you will get a compiler error.
</p>
<subh>Declaring exceptions in a method</subh>
<p>For example:</p>
<code>void mymethod(int i) throws Exception { }</code>
<p>Methods can throw more than one class of exception, you list all the exceptions after the <pcode>throws</pcode> keyword, separated by
commas.</p>

<subh>Overriding and exceptions</subh>
<p>Essentially, a method can throw the same or fewer, but not more, exceptions than the superclass method it is overriding. This has to
do with object orientation, if you could broaden the number of exceptions in the subclass method, anything which can deal with the
superclass might not be able to deal with the subclass, because the are new exceptions there that it was not designed to handle.
You want all members of subclasses to be able to be handled as if there were members of the parent class ("upcasting" or polymorphism).
</p><p>The hierarchy of exceptions is important here, you can replace a exception class in the overridden method with one or more of its
subclasses, but you can't replace it with its superclass. To do this would be to broaden the range of exceptions the method could throw.</p>


<subh>To create and throw a specified exception</subh>
<p>For example:</p>
<code>throw new SomeKindOfException();</code>
</obj>

<obj>
<objh>Recognize the effect of an exception arising at a specified point in a code fragment. Note: The exception may be a runtime exception,
a checked exception, or an error (the code may include try, catch, or finally clauses in any legitimate combination).</objh>
<p>If an exception is thrown, then the rest of the code in the try block is not executed. If any catch block matches the exceptions class
or a super class of the exception, that block executes.
If the exception is not caught correctly, then after the finally block executes, the rest of the code in the method is not executed.</p>

<p><pcode>finally</pcode> blocks execute no matter what, in other words, whether the code executes without an exception, or an exception
is thrown and successfully caught, or an exception is thrown and not caught. This is useful because, except for code in a finally block,
if an exception is thrown and not caught, the execution of the rest method is abandoned.
</p><p>It is legal to have a <pcode>try</pcode> block, followed by a <pcode>finally</pcode> block, without any catch blocks.
</p><p>One thing (probably not important for the exam) which could stop a finally clause from executing, is a call to
<pcode>System.exit(0)</pcode>.
</p>
<p>
<pcode>RuntimeExceptions</pcode> differ from normal exceptions in that they are not required to be declared or handled within a try block.
An <pcode>Error</pcode> indicates serious problems that a reasonable application should not try to catch. Examples are the
VM running out of memory.</p>
</obj>

<obj>
<objh>Write code that makes proper use of assertions, and distinguish appropriate from inappropriate uses of assertions.</objh>
<p>For more information see: <a href="http://java.sun.com/j2se/1.4/docs/guide/lang/assert.html">http://java.sun.com/j2se/1.4/docs/guide/lang/assert.html</a>.
<br/>
The simplest form of assertion consists of the <pcode>assert</pcode> keyword followed by an expression which evaluates to a boolean.
Example:
<code>
	assert someObject != null;
</code>
If the expression evaluates to <pcode>false</pcode> then an <pcode>AssertionError</pcode> is thrown.

The other form adds a colon followed by a second expression which evaluates to a value of some kind. 
If the assertion fails, the value is included in the <pcode>AssertionError</pcode> for information.

Example:
<code>
	assert someObject != null : "someObject should not be null at this point!";
</code>

<br />

Assertions may be enabled or disabled. Your code should work correctly in either cases.
Do not do anything in an assertion which will have side affects on the behaviour of other parts of your code (with the possible exception of
other assertions).
Sun do not recommend the use of assertions to verify the correct use of the public API of you classes. 
Instead a more specific exception such as IllegalArgumentException should be used.
However you can perform checks using assertions on the arguments provided to non-public methods, 
so long as those assertions should remain true regardless of how other classes invoke your API.
In other words use assertions to confirm your is doing internally what you intended,
rather than to check that it is being used correctly by others.
</p>
</obj>

<obj>
<objh>Identify correct statements about the assertion mechanism. </objh>
<p>See the previous objective, or look in a textbook or on the web.</p>
</obj>
</section>

<section>
<section_title>Garbage Collection</section_title>
<obj><objh>State the behavior that is guaranteed by the garbage collection system.</objh>

<p>How and when garbage collection occurs is left up to the implementation of the JVM, all you can know is that an object becomes
<b><i>eligible</i></b> for garbage collection when there are no longer any references to it. At that stage, no variable points to the
object, therefore your code has no way of accessing it and the object can safely be removed by the system.
</p><p><u>Finalize Method</u>
<br/>The <pcode>finalize()</pcode> method of a class is called before it is garbage collected. The method takes no arguments and must
return <pcode>void</pcode>, and throws <pcode>Throwable</pcode>. Do not confuse the <pcode>finalize()</pcode> method (garbage collection)
with the <pcode>finally</pcode> keyword (exception handling).</p>
</obj>

<obj>
<objh>Write code that explicitly makes objects eligible for garbage collection.</objh>
<p>My definition of <i>explicit</i> differs, as I would categorize this as implicit:
<code>
Date d = new Date();
d = null;
</code>

There is no longer a reference pointing to the Date created on the first line, therefore <i>that</i> object is eligible for garbage collection.
No matter what you do, there is no way your code could get back a reference to that object, so your code cannot be affect by its removal.
If on the other hand you had passed the object into a Collection, or it was pointed to by some class, instance or local variable somewhere,
then it is not ready for garbage collection (for example you could pass it to a method or constructor before setting d to null).
<code>
Date d = new Date();
d = new Date(0);
</code>
The new  Date created on the second line holds the value midnight, January 1, 1970. 
The previous object referred to by <pcode>d</pcode>, which held the current <pcode>Date</pcode> is now eligable for garbage collection, 
but the new value of <pcode>d</pcode> (1/1/1970) is unaffected.</p>
</obj>

<obj>
<objh>Recognize the point in a piece of source code at which an object becomes eligible for garbage collection. </objh>
<p>An object is eligible for garbage collection when there are no longer any references to it. This can happen if a variable is
assigned to a newly created object, but later is assigned to <pcode>null</pcode> or a different object, so there is nothing
pointing to the original object. Or when a method exits, all the <b>local</b> variables go out of scope, so all the objects are eligible
for garbage collection, unless there is a reference to them somewhere outside the method.</p>
</obj>
</section>


<section>
<section_title>Language Fundamentals</section_title>

<obj>
<objh>
Identify correctly constructed <pcode>package</pcode> declarations, <pcode>import</pcode> statements, class declarations
(of all forms including inner classes) interface declarations, method declarations (including the
main method that is used to start execution of a class), variable declarations, and identifiers. 
</objh>

<subh>Order of <pcode>package</pcode> declarations, <pcode>import</pcode> statements, 
public class declarations</subh>
<p>The order is as follows: <b>package</b> declarations, <b>import</b> statements, then <b>class</b> definitions. The order of
public vs. non-public class definitions does not matter. However, note that with Suns JDK, you can only have one top-level
public class per source file, and the name of the file must be the same as the name of the public class. For example;</p>
<code>	package acme.applications.userinterfaces;
	import java.awt.*;
	public class SomeClass {
 // etc.
 }
</code>
<subh>Correct declaration for a <pcode>main()</pcode> method.</subh>
<p>[<i>The following rules apply to creating a main() method, which allows you to run the class as an application. You can create any number
of methods called 'main' in a class (overloading), which take other arguments, are not public and static, or return a value. To be able to run
the class, however, there must be one method called main that takes an array of Strings as an argument, and that method must be static, and
not return a value. Otherwise you will get a runtime error when you try to execute the class</i>]
</p><p>The main() method must be static, not return a value, and take an array of strings. 
</p><p>Whether it is declared public is something of a controversy. The Java Language Specification clearly states "The method main must be
declared public, static, and void. It must accept a single argument that is an array of strings."
On the other hand, &apos;The Complete Java2 Certification Study Guide&apos; by Roberts, Heller et al. states. "The main method is declared
public by convention. However, it is a requirement that it be static...".  
Tests indicate that in Java 1.2 (and 1.3), you can execute a program whose <pcode>main()</pcode> method is <pcode>private</pcode>, as
bizarre as that may seem. You cannot do this in Java 1.1. or in Java 1.4.1.
<br/>Exam candidates should follow the Java language specification, and assume public is required, as far as answering questions is
concerned. Use the signature described below, in your code and in your exam answers.
</p><p>Either of the following two examples are accepted ways of declaring main:</p>
<code>	public static void main(String[] args) 
	public static void main(String args[])</code>
<p>Note that 'args' is just a common name for the array, and you can call it anything you like. Also:</p>
<code>static public void main(String[] args)</code>
<p>is perfectly legal and will compile.</p>
<subh>Legal and illegal identifiers</subh>
<p>Identifiers may contain only letters, numbers, dollar signs, i.e. "$", or underscores, i.e. "_". The first character <b>cannot be
a number</b>. Obviously an identifier cannot have the same spelling as a keyword or the boolean and null literals (<pcode>true</pcode>,
<pcode>false</pcode> and <pcode>null</pcode>) as described earlier.</p>
</obj>

<obj>
<objh>State the correspondence between index values in the argument array passed to a main method and command line arguments.</objh>
<p>The command line arguments, after the java command and the name of the program, are placed in the String array, starting at array
element zero.
The first command line argument is at position 0 in the array, the second at 1 etc. The java command and its various settings are not
included in the list.</p>
</obj>

<obj>
<objh>Identify classes that correctly implement an interface where that interface is either <pcode>java.lang.Runnable</pcode> or a fully
specified interface in the question.</objh>

<p>There is only one method in the interface, run(), which must be implemented in the class.</p>
<code>
public void run() {
	//Do something
}
</code>
</obj>

<obj>
<objh>Identify all Java programming language keywords. Note: There will not be any questions regarding esoteric distinctions between
keywords and manifest constants.</objh>
<p>Java keywords (check that you know what each of these does, if not, find out before you take the exam!):</p>
<loosegrid>
<item>abstract</item>
<item><hilite>assert</hilite></item>
<item>boolean</item>
<item>break</item>
<item>byte</item>
<item>case</item>
<item>catch</item>
<item>char</item>
<item>class</item>
<item><hilite>const</hilite></item>
<item>continue</item>
<item>default</item>
<item>do</item>
<item>double</item>
<item>else</item>
<item>extends</item>
<item>final</item>
<item>finally</item>
<item>float</item>
<item>for</item>
<item><hilite>goto</hilite></item>
<item>if</item>
<item>implements</item>
<item>import</item>
<item>instanceof</item>
<item>int</item>
<item>interface</item>
<item>long</item>
<item>native</item>
<item>new</item>
<item>package</item>
<item>private</item>
<item>protected</item>
<item>public</item>
<item>return</item>
<item>short</item>
<item>static</item>
<item><hilite>strictFP</hilite></item>
<item>super</item>
<item>switch</item>
<item>synchronized</item>
<item>this</item>
<item>throw</item>
<item>throws</item>
<item>transient</item>
<item>try</item>
<item>void</item>
<item>volatile</item>
<item>while</item>
</loosegrid>

<p>The keywords <pcode>goto</pcode> and <pcode>const</pcode> are reserved but not used.</p>
<p>While they are not keywords, the boolean and null literals (<pcode>true</pcode>, <pcode>false</pcode> and <pcode>null</pcode>)
cannot be used as identifiers.
So fear ye not the "manifest constants" mentioned in the objective.
<br/>[Note that Roberts &amp; Heller lists these as keywords, but they are literals, not keywords]</p>
<p>A new keyword in Java2 is <pcode>strictFP</pcode>. <pcode>strictFP</pcode> is not in versions of Java prior to Java2.
It is included here for completeness, however, I cannot say whether it is examinable and you
will have to look elsewhere for information on its syntax. This modifier tells the compiler to use a strict form of floating
point calculations, which ensures an identical result on every platform. In Java 1.1, this strict form is always used, but in
Java2, when you don't specify strictFP, the Java virtual machine can do a fast calculation, which makes the most of the performance
of the native processor without the overhead of converting to a consistent cross-platform format. 
</p><p>[Technical aside, for those interested in microprocessors:
<br/>I believe part of the reason for its introduction is that the X86 CPUs have an 80bit FPU, versus 64bits used in the Java standard
and on Suns processors. Intel complained that this gave their CPUs a disadvantage in Java]
</p>
<p><pcode>assert</pcode> is new to 1.4 - covered elsewhere in this document.</p>

<p>A brief note on some of the more obscure keywords:<br/>
<def><pcode>transient</pcode>  - indicates a field should not be serialized when the class is serialized.
<br/><pcode>volatile</pcode> - indicates the field may be changed frequently by different threads. Somewhat like a weak form of
synchronization.</def>
</p>
</obj>

<obj>
<objh>State the effect of using a variable or array element of any kind when no explicit assignment has been made to it.</objh>
<p>Class level variables (variables declared in the class, but outside of any methods, i.e. static and instance variables)
are automatically initialised to a default value, if no explicit assignment has been made. The defaults are <pcode>0</pcode>
for numerical types, <pcode>'\u0000'</pcode> for chars, <pcode>false</pcode> for booleans, and <pcode>null</pcode> for objects.</p>
<p>The elements of an array are <b>always</b> (even inside a method) initialised to their default values when no explicit
assignment has been made to the element.</p>
<p>If you do not initialise a variable declared in a method (local variables) to some value, you will get a compiler error.</p>
</obj>
<obj>
<objh>State the range of all primitive formats, data types and declare literal values for String and all primitive types using
all permitted formats bases and representations. </objh>

<subh>Range of primitive data types.</subh>
<p>A guide to understanding the ranges is to remember that if a type is x bits in size, then it can hold 2<sup>x</sup> possible
combinations of bits.
0 must be represented somehow, so that is why 1 is subtracted from the maximum value. Negative values must be represented, so you
must take one
away from the exponent. For example, a <pcode>byte</pcode> is 8 bit (2<sup>8</sup>), but one bit is needed for the positive/negative,
so the exponent is 7 (-2<sup>7</sup> to 2<sup>7</sup>). 
Then we subtract one for zero, giving -2<sup>7</sup> to 2<sup>7</sup>-1.
</p>
<p><pcode>chars</pcode> are an exception as they are unsigned, so there are no negative values. <pcode>floats</pcode> and
<pcode>doubles</pcode> are more complex. They use some
bits to store the binary digits and others to store the exponent, like a binary version of scientific notation (e.g. 1.2354*10<sup>5</sup>).
It is unlikely you will be required to know these for the exam.
</p>
<grid>
<hrow>
	<item>Primitive Type</item>
	<item>Size</item>
	<item>Range of Values</item>
</hrow>
<row>
	<item>byte</item>
	<item>8 bit</item>
	<item>-2<sup>7</sup> to 2<sup>7</sup>-1</item>
</row>
<row>
	<item>short</item>
	<item>16 bit</item>
	<item>-2<sup>15</sup> to 2<sup>15</sup>-1</item>
</row>
<row> 
	<item>int</item>
	<item>32 bit</item>
	<item>-2<sup>31</sup> to 2<sup>31</sup>-1</item>
</row>
<row> 
	<item>long</item>
	<item>64 bit</item>
	<item>-2<sup>63</sup> to 2<sup>63</sup>-1</item>
</row>
<row>
	<item>char</item>
	<item>16 bit</item>
	<item><pcode>'\u0000'</pcode> to <pcode>'\uffff'</pcode>(0 to 2<sup>16</sup>-1 )</item>
</row>
<row>
	<item>float</item>
	<item>32 bit</item>
	<item>Max. positive value: (2-2<sup>-23</sup>)*2<sup>127</sup>. Min. positive value: 2<sup>-149</sup></item>
</row>
<row>
	<item>double</item>
	<item>64 bit</item>
	<item>Max. positive value: (2-2<sup>-52</sup>)*2<sup>1023</sup>. Min. positive value: 2<sup>-1074</sup></item>
</row>
</grid>

<subh>Constructing literal numeric values using decimal, octal and hexadecimal formats.</subh>
<p>Octal literals begin with zero e.g. <pcode>013042</pcode> (and obviously only digits 0-7 are allowed).
Hexadecimal literals begin with zero and an 'x' e.g. <pcode>0x23e4A</pcode> (digits allowed are 0-9 and
a to f, the 'x' and the letters can be upper or lower case).</p>

<subh>Construct literal <pcode>String</pcode> values using quoted format.</subh>
<p><pcode>String duh = "This should be obvious, but I'll include an example anyway.";</pcode></p>

<subh>Construct a literal value of <pcode>char</pcode> type using Java's unicode escape format for a specified character code.</subh>
<p>Use \u followed by four hexadecimal digits representing the 16 bit unicode character e.g.</p>
<code>char x='\u1234'</code>
<p>Java also supports certain escape codes for special characters such as '\n' for newline. See a textbook for more.</p>
</obj>
</section>
<section>
<section_title>Operators and Assignments</section_title>

<obj>
<objh>Determine the result of applying any operator (including assignment operators and instance of) to operands of
any type class scope or accessibility or any combination of these.</objh>
<p>Most of the operators are fundamental Java, so consult a textbook or tutorial if you are unsure of them. Here is information
on some them, and notes on promotion rules.</p>

<subh>Applying the <pcode>'&gt;&gt;'</pcode>, <pcode>'&gt;&gt;&gt;'</pcode>
 and <pcode>'&lt;&lt;'</pcode> operators to an <pcode>int</pcode> value specified as a bit pattern.</subh>
<p>These operators are followed by a number which defines by how many bits the number is shifted.
</p><p>&gt;&gt; performs a <b>signed</b> right-shift, that is, if the most significant (i.e. first on the left) bit is 1, then when
it right-shifts the bits, it fills in a 1s on the left. If the most significant bit is 0, then when it right-shifts the bits, it fills
in a 0s on the left. As the first bit represents the sign of a number (positive or negative), this preserves the sign of the number.
</p><p>&gt;&gt;&gt; performs an <b>unsigned</b> right-shift, it always fills in 0s on the left.
</p><p>&lt;&lt; performs a left-shift (it always fills in 0s on the right).</p>

<subh>The <pcode>+</pcode> operator</subh>
<p>Adds. If any of the variables are Strings, it converts the non-Strings to Strings, and concatenates (joins) them.</p>

<subh>Using the <pcode>'=='</pcode> comparison operator with two objects of any type.</subh>
<p>With Objects, <pcode>==</pcode> determines whether the variables reference the same object in memory, rather than comparing
their contents in a meaningful way. If you assign <pcode>a=b</pcode>, then <pcode>a==b</pcode> will evaluate to true, where a
and b are objects.
</p><p>Note that if you construct two Strings with the same String literal, <b>without using the <pcode>new</pcode> keyword</b>, e.g.</p>
<code>	String a = "Hello"
	String b = "Hello"</code>
<p>, then Java creates only one String object, so <pcode>a==b</pcode> evaluates as <pcode>true</pcode>.</p>

<subh>Using the ternary operator.</subh>
<p>This consists of a boolean expression, followed by question mark, then two expressions, seperated from each other by a colon. If the
boolean expression before the question mark evaluates as <pcode>true</pcode>, the value from the expression before the colon is used, 
otherwise the value from the last expression is used.
Example:
<code>
int a = true ? 1 : 0;
int b = false ? 1 : 0;
</code>
<pcode>a</pcode> will be 1. <pcode>b</pcode> will be 0.
</p>

<subh>When assignment is permitted between any two variables of possibly different types.</subh>
<p>Primitives: You cannot assign booleans to any other type. With the exception that you cannot assign a byte to a char,
you can assign a variable of type X to type Y (i.e. <pcode>Y=X</pcode>) only if Y is 'wider' than X. 'Wider' means that
the primitive type can contain a wider range of values. The primitives, in order of 'width' are
<pcode>char</pcode>/<pcode>short</pcode>, <pcode>int</pcode>, <pcode>long</pcode>, <pcode>float</pcode>,
<pcode>double</pcode>. Note that you cannot assign a char to a short or vice versa.
</p><p>Objects: You can assign object X to object Y (i.e. <pcode>Y=X</pcode>) only if they are of the same class, or X
is a subclass of Y (called "upcasting").</p>

<subh>Effect of assignment and modification operations upon variables .</subh>
<p>In an arithmetic statement, variable may
be widened automatically, to evaluate the expression (note the variables themselves aren't change, i.e. byte b is still
a byte afterwards, but for its calculations Java uses a widened value). This is called promotion. Bytes, shorts and chars
are always converted to ints, in unary (e.g. <pcode>x++</pcode>)or binary operations (e.g. <pcode>x*y</pcode>). For binary
operators, if one operand is wider, the other is widened to the same type.
<br/>This has import consequences. For example:
<code>byte b = 3;
b = b + 5;</code>
will not compile, because the result of b+5 is an int.
</p>

</obj>

<obj>
<objh>Determine the result of applying the boolean <pcode>equals()</pcode> (Object) method to objects of any combination of the classes
<pcode>java.lang.String</pcode>, <pcode>java.lang.Boolean</pcode>, and <pcode>java.lang.Object</pcode>.</objh>
<p>Unless it is overridden, the <pcode>equals()</pcode> method behaviour in Object, and therefore inherited from it, performs the same
reference comparison as the <pcode>==</pcode> operator. However, the Boolean and String classes override this with a more meaningful
comparison. <pcode>equals()</pcode>returns true, in Booleans if the two objects contain the same Boolean value, and in String if the
Strings contain the same sequence of characters.
</p><p>Note that StringBuffer does not override the <pcode>equals()</pcode> method, so if you use this method, it will not compare the
actual text characters that the StringBuffers contain.</p>
</obj>
<obj>

<objh>In an expression involving the operators <pcode>&amp;</pcode>, <pcode>|</pcode>, <pcode>&amp;&amp;</pcode> and <pcode>||</pcode>,
state which operands are evaluated and determine the resulting value of the expression.</objh>
<p>Just a quick note on the second two operators: <pcode>&amp;&amp;</pcode> (AND) and <pcode>||</pcode> (OR) are the short circuit
operators, which do not evaluate the second operand if it is not necessary. AND is only true if both values are true, therefore if the
first is false, the result is false, and there is no need to evaluate the second part. OR is true if either value is true, therefore
if the first is true, the result is true, and there is no need to evaluate the second part.</p>

</obj>

<obj>
<objh>Determine the effect upon objects and primitive values of passing variables into methods and performing assignments
or other modifying operations in that method.</objh>
<p>When passed to a method, primitives may be promoted, and objects may be upcast, to the type/class that the method takes, if possible.
For example, if a method takes an int as an argument, and you pass it a byte, the value passed to the method is the byte converted to an
int. The rules for when this is allowed are as per the objective "Determine if an assignment is permitted between any two variables of
possibly different types" above.
</p>
<p>Note that primitive variables, <b>in the calling method</b>, are unaffected by modifications made in the target method. This is
called passing by value. Look at this code:
<code>void methodA() {
	int x=5;
	methodB(x);
	System.out.println(x);
}

void methodB(int x) {
	int x=10;
}</code>

If you execute <pcode>methodA()</pcode>, it will print out "5". This is because it is the <b>value</b> of the variable <pcode>x</pcode>
(which is 5), that is passed to <pcode>methodB()</pcode>. <pcode>methodB()</pcode> accepts this value into a local variable, which is
coincidentally named <pcode>x</pcode> aswell. But it is a different variable. Subsequent changes inside <pcode>methodB()</pcode> will
not change the value of <pcode>x</pcode> in <pcode>methodA()</pcode>.
<br/>This issue is more complex where objects are concerned. 
Strictly speaking, they too are passed by value, like primitives. However, the value in question, where object variables are concerned,
is in fact the memory location of the object that the variable points to.
First, lets look at an example which acts like the above, but with objects. 
The <pcode>Price</pcode> class just stores the value assigned to it (using its constructor) as a member variable. 
The <pcode>toString()</pcode> method has been overwritten to return this value. It also has a <pcode>setPrice()</pcode> method to change
its value.
<code>void methodA() {
	Price x = new Price(5);
	methodB(x);
	System.out.println(x);
}

void methodB(Price x) {
	Price x = new Price(10);
}</code>
This example, just like the one above, will print out "5". 
Note that the value being passed here to <pcode>methodB()</pcode> is in reality the location of the Price object in memory. 
In <pcode>methodB()</pcode>, the local variable <pcode>x</pcode> is re-assigned to point to a new Price object, but what
<pcode>methodA()</pcode> sees is unaffected.
This is made obvious here by the use of the <pcode>new</pcode> keyword.


On the other hand, if you do operations which modify the object in the target methods, those changes will be visible in the calling
method, as in the following example:
<code>void methodA() {
	Price x = new Price(5);
	methodB(x);
	System.out.println(x);
}

void methodB(Price x) {
	x.setPrice(10);
}</code>
This will print out "10". Again <pcode>methodB()</pcode> is passed the location of the Price object, which it holds in a local
variable x. However, when you call the <pcode>setPrice()</pcode> method, this change goes out to the actual object in memory,
and hence <pcode>methodA()</pcode> sees the same new value, 10.
</p>
</obj>
</section>

<section>
<section_title>Overloading, Overriding, Runtime Type, and Object Orientation</section_title>
<obj>
<objh>State the benefits of encapsulation in object oriented design and write code that implements tightly encapsulated classes
and the relationships "is a" and "has a".</objh>
<subh>Encapsulation</subh>
<p>Encapsulation is the principal of keeping the internal details of a classes state and behaviours hidden from the other classes that use it.
This allows you to change those details where necessary, without breaking compatibility. The interconnectness between pieces of code is called
'coupling', and minimising it makes for more reusable and maintainable classes. The expectated behaviour of a class or method is referred to 
as its 'contract'. You do not want to expose any more than the minimum required to support the contract, or you can end up with tangled
interdependent code with poor maintainabilty, and in all likelyhood, poor quality.
</p><p>Encapsulation also aids polymorphism and inheritance - if the internal details of a class are exposed and used, it is very hard to
substitute a different implementation of the same contract.
</p><p>To achieve good encapsulation, make everything have the tightest possible access control so if something should not be
used in a given context, limit the access to prohibit it. In particular, class instance variables should be private, and 
accessed only through 'get'/'set' methods (a.k.a accessors and mutators). This would allow you to do some work or checking 
before reading/writing a value to the variable. You could remove the variable entirely and derive it or obtain it from 
another source. If the variable was public, and was accessed directly, should changes would break client code.
</p>

<subh>Write classes that implement object oriented relationships specified using the clauses 'is a' and 'has a'.</subh>

<p>Briefly, 'is a' should be implemented using inheritance, 'has a' should be implemented using containment (i.e. 'composition'
or sometimes 'aggregation'). This objective is conceptual, consult a textbook for more.</p>


</obj>
<obj>
<objh>Determine at run time if an object is an instance of a specified class or some subclass of that class using the <pcode>instanceof</pcode> operator.</objh>

<code>SomeObject instanceof SomeClass</code>
<p>evaluates as <pcode>true</pcode> if SomeObject is an instance of SomeClass, or <b>is an instance of a subclass</b> of Someclass.
Otherwise it evaluates as <pcode>false</pcode>.</p>

<code>SomeObject instanceof SomeInterface</code>
<p>evaluates as <pcode>true</pcode> if SomeObject is an instance of a class which implements SomeInterface. Otherwise it evaluates as
<pcode>false</pcode>.</p>


</obj>

<obj>
<objh>Write code to invoke overridden or overloaded methods and parental or overloaded constructors; and describe the effect of invoking
these methods.</objh>

<subh>Overloaded and overridden methods.</subh>
<p>What identifies a method in the Java is not merely the name of the method, rather it is the name of the method <b>and the
arguments it takes</b>. This is called the methods signature. You must watch for any differences in the arguments list. If
the arguments are different, you are dealing with a separate method. This is <b>overloading</b>. The fact that they have the
same name is only of significance to humans. 
</p><p>The return type is not part of a methods signature. You are only <b>overriding</b> if there is a method in the parent
class with same name which takes exactly the same arguments. Then the method replaces the one from the superclass.
</p><p>You cannot define two methods within a class with the same name and the same arguments.</p>
<p>A related point is that you cannot override variables or <pcode>static</pcode> methods, rather you <b>hide</b>
them when you declare, in a subclass, a variable of the same name or static method with the same signature. This is one of these things
that occasionally surprises experienced developers. It is an important distinction as the polymorphic behaviour which happens
when overriding (see below) does not apply here.</p>
<subh>Legal return types for an overloading method</subh>
<p>Overloaded methods are really completely different and separate methods, so they can return completely different types.</p>

<subh>State legal return types for an overriding method given the original method declaration.</subh>
<p>The overriding method must return the same type as the method in the superclass. This is because in the subclass, the
overriding method replaces the method in superclass, and polymorphism or "upcasting" would not work they returned different
types (i.e. you should get the same return type as you would with the parent class, or else you can't treat the
subclass as the superclass).</p>

<subh>Invoking overridden method in base and derived classes.</subh>
<p>If the object is an instance of the derived class, then the overridden version defined in the derived class is the
one that is invoked. Look at this example:</p>
<code>class Animal {
	void sayHello() {
		System.out.println("Hello, I'm an animal.");
	}
}
class Dog extends Animal {
	void sayHello() {
		System.out.println("Hello, I'm a dog.");
	}
}</code>
<p>We are overriding the sayHello method with behaviour more specific to a dog.
</p><p>The straightforward method calls are as follows:</p>
<code>Animal i = new Animal;
i.sayHello();</code>
<p>prints "Hello, I'm an animal."</p>

<code>Dog j = new Dog();
j.sayHello();</code>
<p>prints "Hello, I'm a dog." because we have overridden sayHello, and this instance is a dog.
</p><p>However:</p>
<code>Animal k = new Dog();
k.sayHello();</code>
<p>prints "Hello, I'm a dog." Here we are creating an instance of Dog, but we are assigning it to an Animal reference
[referring to an object as the base class is called "upcasting" and is useful as you can write methods that deal with instances
of any of the subclasses]. Because the underlying object is really a Dog, the method in the derived class is the one that executes. 
</p><p>Note: This behavior only applies to instance (i.e. not static) methods. Variables and static methods do not "override", instead
they "hide" the variable/method in the parent class. This means that it is the class of the reference that matters, rather than that
of the underlying object.</p>

<subh>Write code for any overridden method that invokes the parental method, using <pcode>super</pcode>.</subh>
<p><pcode>super.someMethod()</pcode> will call the version of <pcode>someMethod()</pcode> in the immediate super class. You cannot
use something like <pcode>super.super.someMethod()</pcode> to call the method two steps up the object hierarchy.</p>

</obj>
<obj>
<objh>Write code to construct instances of any concrete class including normal top level classes and nested classes.</objh>
<p>This is fairly straight forward, just use the <pcode>new</pcode> operator. Nested classes are covered in another section.</p>

<subh>Creating constructors which use <pcode>this()</pcode> and <pcode>super()</pcode> to access overloaded or parent-class constructors.</subh>

<p>These calls must be at the very start of the code in the constructor, therefore you can only make one of these types of calls. A call
to the default constructor in the parent class is made by default, so <pcode>super(arguments)</pcode> is useful when you want to call a
version of the constructor which takes an argument instead (and there may not be a default constructor in the parent class, in which case
this call is necessary, or the code won't compile). 
</p><p><pcode>this()</pcode> with or without arguments in brackets is used to call any of the other (overloaded) constructors defined in
the class, before performing actions specific to current constructor being defined.</p>


</obj>
</section>


<section>
<section_title>Threads</section_title>
<obj><objh>Write code to define, instantiate and start new threads using both java.lang.Thread and java.lang.Runnable. </objh>

<p>To define a class that implements Runnable, you must define a <pcode>run()</pcode> method in the class e.g.</p>
<code>class MyClass implements Runnable {
	public void run () {
		// Insert the code you want to run in a thread here
	}
}</code>
<p>run() must be public, with a void return type, and not take any arguments. Note that if <pcode>run()</pcode> is defined to take any arguments, then that is a different method and the Runnable interface hasn't been implemented!
</p><p>Create an instance of the class, and construct a thread, passing the instance of the class as an argument to the constructor i.e.</p>
<code>MyClass mc = new Myclass();
Thread t = new Thread(mc);</code>

<p>To start the thread, use the <pcode>start()</pcode> method:</p>
<code>t.start();</code>
<p>Alternatively, you can create a subclass of the Thread class, and override the <pcode>run()</pcode> in the subclass:</p>
<code>class MyThread extends Thread {
	public void run () {
		// Insert the code you want to run in a thread here
	}
}</code>
<p>Then create an instance of the subclass, and start it running:</p>
<code>MyThread mt=new MyThread();
mt.start();</code>
</obj>

<obj>
<objh>Recognize conditions that might prevent a thread from executing.</objh>

<p>A thread can be in one of the following states:
<br/>a) Running
<br/>b) Ready - Waiting for a chance to run on the CPU. All threads enter this state before running. Threads with higher priorities may
be preventing the thread from getting a chance to run (this depends on how priorities have been implemented in the particular Java Virtual
machine)
<br/>c) Various waiting states (Waiting, Sleeping, Suspended &amp; Blocked)
<ul>
<li>A thread is put into a Waiting state by calling the <pcode>wait()</pcode> method. This method called can only be made in a
<pcode>synchronized</pcode> method or block. A later call in the <pcode>synchronized</pcode> code to <pcode>notify()</pcode>
tells the thread (or <pcode>notifyAll()</pcode> tells all the threads waiting on this object) the lock for this object has
become available, and when the method obtains the lock on the monitor, it goes into the Ready state.</li>
<li>The <pcode>sleep()</pcode> method puts the thread into a Sleeping state for a specified amount of time, after which it enters
a Ready state. <br/><pcode>sleep(long milliseconds)</pcode> or <pcode>sleep(long milliseconds int nanoseconds)</pcode>. This method
throws InterruptedException.</li>
<li>A thread is put into a Suspended state by a call to its <pcode>suspend()</pcode> method. It will go back to a Ready state when
its <pcode>resume()</pcode> method is called <i>by another thread.</i></li>
<li>A thread enters a Blocked state when it cannot access something it needs immediately, e.g. I/O or when it fails to get the lock
for a monitor.</li>
</ul>
d) Dead - the <pcode>run()</pcode> method has completed (the thread can never be restarted)
<br/>Note that the suspend() and resume() methods of the thread class are deprecated in Java2.</p>
</obj>

<obj>
<objh>Write code using synchronized wait, notify and notifyAll to protect against concurrent access problems and to communicate between
threads. </objh>
<p>The use of these methods, and <pcode>synchronized</pcode> methods or code blocks, ensure only one thread at a time can access parts
of a class, and control how and when threads get this access.
This is a complicated area, if it is new to you, consult a textbook.</p>

<subh>Using the <pcode>synchronized</pcode> keyword to require a thread of execution to obtain an object lock prior to proceeding.</subh>
<p>Using the <pcode>synchronized</pcode> keyword in the method declaration, requires a thread obtain the lock for this object before it
can execute the method.</p>
<code>synchronized void someMethod() { }</code>
<p>You can also make a block of code synchronized by using the <pcode>synchronized</pcode> keyword followed by the object or class, for
which a thread must obtain the lock before it can execute this block of code:</p>
<code>// .. some code before the synchronized block
synchronized (someObject) {
	// synchronized code
	}
// more code...</code>


<subh>The <pcode>wait()</pcode> method.</subh>
<p>The <pcode>wait()</pcode> method must be used in <pcode>synchronized</pcode> code. The thread releases ownership of this monitor and
waits until another thread notifies threads waiting on this object's monitor to wake up (i.e. move into Ready state) either through a
call to the <pcode>notify()</pcode> method or the <pcode>notifyAll()</pcode> method. The thread then waits until it can re-obtain ownership
of the monitor and resumes execution. </p>

<subh>The <pcode>notify()</pcode> or <pcode>notifyAll()</pcode> methods of an object.</subh>
<p><pcode>notify()</pcode> moves one thread, that is waiting the this objects monitor, into the Ready state. This could be any of the
waiting threads; the choice of which thread is chosen is an implementation issue of the virtual machine.
</p><p><pcode>notifyAll()</pcode> moves all threads, waiting on this objects monitor, into the Ready state.</p>

</obj>

<obj>
<objh>Define the interaction among threads and object locks when executing synchronized wait, notify or notifyAll.</objh>
<p>Consult a textbook or the web.</p>
</obj>
</section>


<section>
<section_title>Fundamental classes in the java.lang package</section_title>
<obj><objh>Write code using the following methods of the <pcode>java.lang.Math</pcode> class: <pcode>abs()</pcode>, <pcode>ceil()</pcode>,
<pcode>floor()</pcode>, <pcode>max()</pcode>, <pcode>min()</pcode>, <pcode>random()</pcode>, <pcode>round()</pcode>, <pcode>sin()</pcode>,
<pcode>cos()</pcode>, <pcode>tan()</pcode>, <pcode>sqrt()</pcode>.</objh>
<p>See the JavaDocs for more detail.</p>
<p><pcode>abs()</pcode> - Returns the absolute value of the argument. Overloaded for <pcode>ints</pcode>, <pcode>longs</pcode>,
<pcode>floats</pcode> and <pcode>doubles</pcode>. 
</p><p><pcode>ceil(double)</pcode> - Returns the smallest (closest to negative infinity) <pcode>double</pcode> value that is not
less than the argument and is equal to a mathematical integer. 
</p><p><pcode>floor(double)</pcode> - Returns the largest (closest to positive infinity) <pcode>double</pcode> value that is not
greater than the argument and is equal to a mathematical integer. 
</p><p><pcode>max(value1,value2)</pcode> - Returns the greater of two values. 
</p><p><pcode>min(value1,value2)</pcode> - Returns the smaller of two values. 
</p><p><pcode>random()</pcode> - Returns a random number between <pcode>0.0</pcode> and <pcode>1.0</pcode>. 
</p><p><pcode>round(double)</pcode> - Returns the closest <pcode>long</pcode> to the argument. 
</p><p><pcode>sin(double)</pcode> - Returns the trigonometric sine of an angle. The angle is in radians. 
</p><p><pcode>cos(double)</pcode> - Returns the trigonometric cosine of an angle. The angle is in radians. 
</p><p><pcode>tan(double)</pcode> - Returns the trigonometric tangent of an angle. The angle is in radians.
</p><p><pcode>sqrt(double)</pcode> - Returns the square root of a double value.</p>


</obj>

<obj>
<objh>Describe the significance of the immutability of <pcode>String</pcode> objects.</objh>

<p>String <b>objects</b> cannot be changed. They are assigned a sequence of characters when they are
constructed. Look at the following code:</p>
<code>String message = "Good";
message= message + " morning";</code>
<p>When the first line executes, a string object containing "Good" is assigned to message.
A new String object is constructed, unless the literal "Good" was used somewhere else, in which
case the existing String is re-used. 
A consequence of this is the behaviour of the <pcode>==</pcode>
operator which was describe under Language Fundamentals above, here is that information again:
</p>
<p>[Note that if you construct two Strings with the same String literal, <b>without</b> using
the <pcode>new keyword</pcode>, e.g.</p>
<code>String a = "Hello"
String b = "Hello"</code>
<p>, then Java creates only one String object, so <pcode>a==b</pcode> evaluates as <pcode>true</pcode>.]
</p>
<p>On the second line, " morning" is appended. But the String object containing "Good" cannot be changed,
so a new String, containing "Good morning" is created and assigned to message.</p>
</obj>

<obj>
<objh>Describe the significance of wrapper classes, including making appropriate selections in the wrapper classes to suit
specified behavior requirements, stating the result of executing a fragment of code that includes an instance of one of
the wrapper classes, and writing code using the following methods of the wrapper classes (e.g., <pcode>Integer</pcode>,
<pcode>Double</pcode>, etc.): 
<br/><pcode>doubleValue()</pcode>
<br/><pcode>floatValue()</pcode>
<br/><pcode>intValue()</pcode>
<br/><pcode>longValue()</pcode>
<br/><pcode>parseXxx()</pcode>
<br/><pcode>getXxx()</pcode>
<br/><pcode>toString()</pcode>
<br/><pcode>toHexString()</pcode></objh>
<p>There are two fundamental types of variables in Java: primitives and objects. Sometimes a method or a constructor takes objects, but what
what you have is a primitive. To cope with this situation, Java has a set of 'wrapper' classes which exist to hold the value of a primitive.
For example, you might want to use a <pcode>float</pcode> as a key in a Map e.g. keying some business objects representing a loan by their
respective interest rates. Using the Float class will allow you to do this. You would create a Float object for each value, and place that
object into the Map.
</p>
<grid>
<hrow>
	<item>Primitive Type</item>
	<item>Corresponding Wrapper class</item>
</hrow>
<row>
	<item>boolean</item>
	<item>Boolean</item>
</row>
<row>
	<item>byte</item>
	<item>Byte</item>
</row>
<row>
	<item>short</item>
	<item>Short</item>
</row>
<row>
	<item>char</item>
	<item><hilite>Character</hilite></item>
</row>
<row> 
	<item>int</item>
	<item><hilite>Integer</hilite></item>
</row>
<row> 
	<item>long</item>
	<item>Long</item>
</row>
<row> 
	<item>float</item>
	<item>Float</item>
</row>
<row> 
	<item>double</item>
	<item>Double</item>
</row>
</grid>

<p>The names are entirely obvious, except for the two that have been highlighted. Take a look at these classes in the JavaDocs.
The pattern tends to be pretty similar: For a primitive type x, there is one constructor taking x and another that takes a String,
which is parsed to get the value. There is a static parseX() method, which parses a string and returns the primitive type x. An
xValue() method returns the underlying primitive value held by wrapped object. The toString() method from Object is overridden appropriately. 
</p>
<p><pcode>toHexString()</pcode> is a static method on Integer and Long which creates a hexadecimal string representation of the
argument as an unsigned integer in base 16.</p>
</obj>
</section>



<section>
<section_title>The Collections Framework</section_title>
<obj>
<objh>Make appropriate selection of collection classes/interfaces to suit specified behavior requirements.</objh>
<p>As far as I can gather, and this is implied by the objective itself and the sample examination question on the Sun website,
this objective just requires a general knowledge of the classes/interfaces, in other words which to use for a given purpose.
If you want a more in-depth treatment of the subject, try the Sun tutorial:
<br/><a href="http://java.sun.com/docs/books/tutorial/collections/index.html">http://java.sun.com/docs/books/tutorial/collections/index.html</a>
</p><p><big>Set</big>
Implementations: Hashset
</p><p>A Set is a collection which cannot contain any duplicate elements and has no explicit order to its elements
(unlike, for example, an array, where every element exists at a particular index i.e. <pcode>MyArray[15]</pcode>).
</p><p><u>SortedSet</u>
<br/>Implementations: TreeSet
</p><p>A SortedSet is a Set which maintains its elements in ascending order. 
</p><p><big>List</big>
Implementations: LinkedList, ArrayList, Vector, Stack
</p><p>A List is a collection which can contain duplicate elements, and the elements are ordered (like an array,
you can add an element at a specific position, and the elements are accessed using their index).
</p><p>[Stack has come up in the examination in the past, so here is some info. on it. 
</p><p>Stack is a subset of Vector, which contains some extra methods. The idea of a stack is like its name, it acts
like a piled up stack of items: When you add an element, it goes to the top of the stack, and when you extract an
element, it is taken off the top. In other words, this is a last-in, first-out system. The methods are:
</p><p><pcode>push(object)</pcode> - Add an element onto the top of the stack.
</p><p><pcode>pop()</pcode> - Removes the object at the top of this stack and returns that object as the value of this function.
</p><p><pcode>peek()</pcode> - Looks at (i.e. returns) the object at the top of this stack without removing it from the stack.. ]
</p><p><big>Map</big>
Implementations: HashMap, Hashtable, WeakHashMap
</p><p>Maps keys to values. In other words, for every key, there is a corresponding value, and you look up the values
using the keys. Maps cannot have duplicate keys, and each key maps to at most one value.
</p><p>Note: A Map does not implement the Collection interface.
</p><p><u>SortedMap</u>
<br/>Implementations: TreeMap
</p><p>A SortedSet is a Set which maintains its mapping in ascending key order.
</p><p><u>Object Ordering</u>
</p><p>Implementations of the SortedSet and SortedMap interfaces sort their elements. To determine what criterion is
used to sort the elements you can use either the Comparable or Comparator interfaces. Using Comparable means that the
classes that you put in your SortedSet or SortedMap implement the Comparable interface, which just means that they
contain a method compareTo() which determines whether the object is "greater" or "less than" another object. To use
the Comparator interface, you pass an object which implements Comparator to your SortedSet or Sorted map, and it
will use the Comparator for ordering.
</p><p><u>BitSet</u>
<br/>For completeness, here is some information on BitSet, which isn't part of the Collections Framework, but may be examinable:
<br/> A BitSet contains elements which are bits, i.e. of the boolean primitive type. Like, for example, a Vector,
and unlike an array, a BitSet does not have a fixed size, and grows as needed when you add elements to it.</p>
</obj>

<obj>
<objh>Distinguish between correct and incorrect implementations of hashcode methods.</objh>
<p>The hashcode value of an object gives a number which can be used to in effect to 'index' objects in a collection.
A collection class can group its objects by their hashcodes, and if you called e.g. <pcode>contains()</pcode> (or <pcode>get()</pcode> in
case of a Map), it can first
find the group based on the hashcode, then search that group. This avoids the need to check every object in the collection.
</p><p>
The requirements of a <pcode>hashCode()</pcode> implementation are that if two objects are equal as determined the <pcode>equals()</pcode>
method, their hashcodes should be the same. This is why wherever you override the <pcode>equals()</pcode> method, you should 
override <pcode>hashCode()</pcode> aswell.
</p>
<p>
The reverse is not required i.e. it is permitted for two objects that are not equal to have the same hashcode. This makes sense, as
it is not always possible to ensure unique hashCodes. The method returns an <pcode>int</pcode> and there are only an finite number
of <pcode>int</pcode> values to use. However, where possible, it is desirable to have the hashcodes be distinct as this can improve
performance. If the hashcodes can be well distributed (i.e. scattered throughtout the <pcode>int</pcode> range) aswell, all the better.
</p>
</obj>
</section>

<section>
<section_title>1.2 Exam Only: The java.awt package - Components and Facilities</section_title>
<obj><objh>Write code to demonstrate the use of the following methods of the <pcode>java.awt.Component</pcode> class:
<pcode>setVisible(boolean)</pcode>, <pcode>setEnabled(boolean)</pcode>, <pcode>getSize()</pcode>, <pcode>setForeground()</pcode>
and <pcode>setBackground()</pcode>.</objh>
<p>The names of these methods are self-explanatory. Note that after you create a frame, there are not visible by default, you must use
<pcode>setVisible(true)</pcode> before it can be seen.
</p><p><pcode>getSize()</pcode> returns a <pcode>dimension</pcode> object, which contains two integer member variables,
<pcode>height</pcode> and <pcode>width</pcode>.
</p><p>Obviously <pcode>setForeground()</pcode> and <pcode>setBackground()</pcode> take a <pcode>color</pcode> argument.</p>
</obj>

<obj>
<objh>Construct a <pcode>java.awt.TextArea</pcode> or <pcode>java.awt.List</pcode> that prefers to display a specified number of
columns.</objh>
<p>As there is no mechanism to set the number of columns a list has, I would assume that the above objective contains a typo, and
should refer to rows, not columns.
</p><p>The constructors for a List are as follows:</p>
<code>List(int rows)</code>
<def>Creates a new scrolling list initialized with the specified number of visible lines. By default, multiple selections are
not allowed.</def>
<code>List(int rows, boolean multipleMode)</code>
<def>Creates a new scrolling list initialized to display the specified number of rows. If the value of <pcode>multipleMode</pcode>
is <pcode>true</pcode>, then the user can select multiple items from the list. If it is <pcode>false</pcode>, only one item at a
time can be selected.</def>
<p>The constructors for a TextArea are under the next objective.</p>
</obj>

<obj>
<objh>Construct a <pcode>java.awt.TextArea</pcode> or <pcode>java.awt.TextField</pcode> that prefers to display a specified
number of columns.</objh>
<p>A <pcode>TextArea</pcode> object is a multi-line region that displays text. The following constructors allow you to specify
the <i>preferred</i> number of rows and columns:</p>
<code>TextArea(int rows, int columns)</code>
<def>Constructs a new empty TextArea with the specified number of rows and columns.</def>
<code>TextArea(String text, int rows, int columns)</code>
<def>Constructs a new text area with the specified text, and with the specified number of rows and columns. This text area
is created with both vertical and horizontal scroll bars.</def>
<def><b><u>Note</u></b>: It is the number of <b>rows</b>, <b>then columns</b>. This is counter-intuitive, as usually in
programming you specify a horizontal dimension, then a vertical one, so this exception can catch you out.</def>
<p>A <pcode>TextField</pcode> has a single line of text:</p>
<code>TextField(int columns)</code>
<def>Constructs a new empty TextField with the specified number of columns.</def>
<code>TextField(String text, int columns)</code>
<def>Constructs a new text field initialized with the specified text to be displayed, and wide enough to hold the
specified number of characters.</def>
</obj>

<obj>
<objh>State the significance of a "column" where one of the text components is using a proportional (variable) pitch
font or a fixed pitch font.</objh>
<p>The width of a "column" is equal to the width of a character, <i>in the particular font being used</i>. In the
case of fixed pitch fonts, where all the characters are the same size, this is straightforward. For proportional fonts,
the width of a column is equal to the average of the width of all the characters in the font. This means, for example,
if you had text component with a proportional font and a width of 10 columns, if you use a narrow letter such as 'i',
more than 10 'i's could be displayed.</p>
</obj>

</section>


<section>
<section_title>1.2 Exam Only: The java.awt package - Layout</section_title>

<obj><objh>Demonstrate the use of the methods <pcode>add(Component)</pcode> and <pcode>add(String, Component)</pcode>
of the <pcode>java.awt.Container</pcode> class and recognize which classes in the <pcode>java.awt</pcode> and
<pcode>java.awt packages</pcode> are valid arguments to these methods.</objh>
<p>Note that the second form, as far as the certification exam scope is concerned, is used with BorderLayout.
The String is one of <pcode>"North"</pcode>, <pcode>"South"</pcode>, <pcode>"East"</pcode>, <pcode>"West"</pcode>
or <pcode>"Center"</pcode>, which specifies which area of the component is to added to. However, the JDK documentation
strongly advises the use of the Java 1.1 form. Which is asked in the exam I can't say, but it is probably wise to be
familiar with both. The 1.1 form, which is the only one used in Roberts &amp; Heller (Boone only uses the above form)
 is as follows:</p>
<code>public void add(Component comp, Object constraints)</code>
<def>Adds the specified component to the end of this container. Also notifies the layout manager to add the component
to this container's layout using the specified constraints object.</def>
<p>For BorderLayout, the second parameter is a String as above, or you can use one of the constants defined in the
BorderLayout class, <pcode>BorderLayout.NORTH</pcode>, <pcode>BorderLayout.SOUTH</pcode> etc.</p>
</obj>

<obj>
<objh>Distinguish between AWT classes which are directly responsible for determining component layout and those which
are responsible for implementing that layout.</objh>
<p>You set the layout manager that a container should use. That layout manger then implements the layout.</p>
</obj>

<obj>
<objh>Write code to change the layout scheme associated with an AWT container.</objh>
<code>public void setLayout(LayoutManager mgr)</code>
<def>Sets the layout manager for this container.</def>
<p>For example, in the code of an applet:</p>
<code>setLayout(new GridLayout()); </code>
<p>creates an instance of the <pcode>GridLayout</pcode> class, and makes it the layout manger for the applet.
</p><p>Worth noting are the default layout managers: <pcode>FlowLayout</pcode> for applets and panels,
<pcode>BorderLayout</pcode> for windows, frames and dialogs. Containers always use these defaults after
being created, unless you specify otherwise, they <b>do not</b> get the default layout manager from the containers
they themselves are placed in, unlike other properties such as colour, font etc.</p>
</obj>

<obj>
<objh>Use <pcode>BorderLayout</pcode>, <pcode>FlowLayout</pcode>, and <pcode>GridLayout</pcode> to achieve required
dynamic resizing behavior of a component.</objh>
<p><b><u>BorderLayout</u></b> divides the container into 5 regions, and one component at a time can be placed in each
(that component can be another container, which itself can contain multiple components). If you add a component to a
region which already contains another component, only the latest component will be displayed. Components in the
<pcode>North</pcode> and <pcode>South</pcode> are placed at the top and bottom respectively, and are allowed to
be their preferred heights but are as wide as the container. <pcode>East</pcode> and <pcode>West</pcode> are on the
right and left sides respectively, and are allowed to be their preferred widths. Their heights stretch from the
<pcode>North</pcode> and <pcode>South</pcode> regions (if there is nothing in <pcode>North</pcode> or <pcode>South</pcode>,
they go from the bottom to the top of the container). <pcode>Center</pcode> fills the remaining space, left after the other
regions, in the middle. The component is stretched to fill this area.</p>
<p><img src="Image1.gif"/></p>
<p>How to add components to the regions of a container using BorderLayout is described above, in the first object of
this section. Note that if you don't specify a region, the component is added to <pcode>Center</pcode>. Therefore, for
example, if you create a frame (default layout is BorderLayout), and add a button to it using the default <pcode>add(Component)</pcode>
method, the button will fill the entire frame.</p>
<p><b><u>FlowLayout</u></b> always allows components to be their preferred size [This is true even if the component is wider or
taller than the container. A centered portion of the component is shown, with as much of the component being made visible as can be].
It places many components as it can on a line, with the first component starting on the left, until there is no more room horizontally,
then it starts another line. By default the rows are centred in the container. You can specify how the rows are aligned using this
constructor:</p>
<code>new FlowLayout(int alignment)</code>
<def>Constructs a new Flow Layout with the specified alignment and a default 5-unit horizontal and vertical gap. The value of the
alignment argument must be one of <pcode>FlowLayout.LEFT</pcode>, <pcode>FlowLayout.RIGHT</pcode>, or <pcode>FlowLayout.CENTER</pcode></def>
<p><b><u>GridLayout</u></b> divides its area into equally sized rectangles. When components are added to it, they are made the same size
as their cell. Two constructors to be aware of are: </p>
<pcode>public GridLayout(int rows, int cols)</pcode>
<def>Creates a grid layout with the specified number of rows and columns. All components in the layout are given equal size. One,
but not both, of <pcode>rows</pcode> and <pcode>cols</pcode> can be zero, which means that any number of objects can be placed in a
row or in a column.</def>
<def>Remember: it is <b>rows, then columns</b>. If the number of components added is more than the number of cells (i.e. rows * columns)
then more columns are added as needed, but the number of rows remains the same.</def>
<pcode>public GridLayout()</pcode>
<def>Creates a grid layout with a default of one column per component, in a single row.</def>

<p><b><u>GridBagLayout</u></b>
<p>While it is not mentioned in the objectives, GridBagLayout <b>is</b> examined in SCJP 2.</p>
</p><p>There is a tutorial which includes using GridBagLayout, with AWT, at
<a href="ftp://ftp.javasoft.com/docs/tut-OLDui.zip">ftp://ftp.javasoft.com/docs/tut-OLDui.zip</a>
</p><p>GridBagLayout is like GridLayout, except that components can be different sizes (i.e. take up more than one cell in the grid)
and you have a lot more options, hence it is more complex. To use GridBagLayout, you create an instance, and set it as the layout manager
for your container, as with the other layout managers. You don't specify the number of cells when constructing an instance of
GridBagLayout, the constructor is just the default <pcode>GridBagLayout()</pcode>.
</p><p>The twist is that you specify how the component is to be displayed using an instance of GridBagConstraints. The fields in this
class contain all the options. For each component, you use the GridBagLayout setConstraints() method:</p>
<pcode><b>setConstraints</b>(Component comp,GridBagConstraints constraints)</pcode>
<p>The values for each component are read from the GridBagConstraints object, so you can change the values after each component, and
reuse the same GridBagConstraints instance for the next one. Then you add the component to the container e.g.</p>
<code>MyGridBag.setConstraints(componentX, MyConstraints); 
add(componentX);</code>
<p><b>GridBagConstraints Fields:</b>
<br/>[The constants (uppercase) listed below for use with certain fields are static fields in the GridBagConstraints class, so you refer
to them as <pcode>GridBagConstraints.EAST</pcode> for example.]
</p><p><b><pcode>anchor</pcode></b> 
<def>This field is used when the component is smaller than its display area. It determines where, within the display area, to place the
component.
<br/>one of <pcode>CENTER</pcode> (default), <pcode>EAST</pcode>, <pcode>WEST</pcode>, <pcode>NORTH</pcode>, <pcode>NORTHEAST</pcode>,
<pcode>NORTHWEST</pcode>, <pcode>SOUTH</pcode>, <pcode>SOUTHEAST</pcode> or <pcode>SOUTHWEST</pcode>)</def>
<b><pcode>fill</pcode></b> 
<def>This field is used when the component's display area is larger than the component's requested size. It determines whether to resize
the component, and if so, how. 
<br/>one of <pcode>NONE</pcode> (Default), <pcode>HORIZONTAL</pcode>, <pcode>VERTICAL</pcode>, or <pcode>BOTH</pcode>)</def>
<b><pcode>gridheight</pcode></b> 
<def>Specifies the number of cells in a column for the component's display area. 
<br/>Use <pcode>REMAINDER</pcode> to specify that the component be the last one in its column. Use <pcode>RELATIVE</pcode> to specify that
the component be the next-to-last one in its column.)</def>
<pcode><b>gridwidth</b></pcode>
<def>Specifies the number of cells in a row for the component's display area. 
<br/>Use <pcode>REMAINDER</pcode> to specify that the component be the last one in its row. Use <pcode>RELATIVE</pcode> to specify that
the component be the next-to-last one in its row.
<br/>[Here <pcode>REMAINDER</pcode> acts somewhat like a carriage return. You add elements to the row, and when you use
<pcode>REMAINDER</pcode> that marks the end of the line, and then the next components are added to the next row. Look at the examples
in the tutorial or in the JavaDocs. Alternatively, you can use gridx and gridy to specify grid position when adding a component.]</def>
<b><pcode>gridx, gridy</pcode></b> 
<def>Specifies the position of the component. The constant <pcode>RELATIVE</pcode> (which is the default) specifies that this component
be placed next (i.e. to the right for <pcode>gridx</pcode>, and below for <pcode>gridy</pcode>) to the previously added component. The top
left cell has <pcode>gridx=0</pcode>, <pcode>gridy=0</pcode>. </def>
<b><pcode>insets</pcode></b> 
<def>Specifies the external padding of the component, the minimum amount of space between the component and the edges of its display area.
This field belongs to the <pcode>Insets</pcode> class which uses the following constructor: </def>
<b><pcode>Insets(int top, int left, int bottom, int right)</pcode></b>
<def>Creates and initializes a new <pcode>Insets</pcode> object with the specified top, left, bottom, and right insets.</def>
<pcode><b>ipadx</b></pcode>
<def>Specifies the internal padding of the component, how much space to add to the minimum width of the component. </def>
<pcode><b>ipady</b></pcode> 
<def>Specifies the internal padding, that is, how much space to add to the minimum height of the component. </def>
<pcode><b>weightx, weighty</b></pcode> 
<def>Specifies how to distribute extra vertical/horizontal space respectively. This is a double, typically between 0 and 1, the default
value is 0. If all the weights are zero, and there is extra space, all the components are bunched together in the middle.</def></p>
</obj>

</section>


<section>
<section_title>1.2 Exam Only: The java.awt package - Event Handling</section_title>

<obj><objh>Write a non-abstract class that implements a specified Listener interface, given the interface definition.</objh>

<p><u>Listener Interfaces</u>
<br/>For information and comparison purposes, here is the list of Listener interfaces, and their methods. You do not need to memorize
this table. Note the relationship between the Listener interface name, the Event type (which is the argument to the methods) and the
'add' method which belongs to the component classes. </p>
<grid>
<hrow><item>
Interface Name</item>
<item>
Event</item>
<item>
Methods in interface</item>
<item>
Add method </item>
</hrow>
<row><item>
ActionListener</item>
<item>
ActionEvent</item>
<item>
actionPerformed()</item>
<item>
addActionListener()</item>
</row>
<row><item>
AdjustmentListener</item>
<item>
AdjustmentEvent</item>
<item>
adjustmentValueChanged()</item>
<item>
addAdjustmentListener()</item>
</row>
<row><item>
ComponentListener</item>
<item>
ComponentEvent</item>
<item>
componentHidden()<br/>
componentMoved()<br/>
componentResized()<br/>
componentShown()</item>
<item>
addComponentListener()</item>
</row>
<row><item>
ContainerListener</item>
<item>
ContainerEvent</item>
<item>
componentAdded()<br/>
componetRemoved()</item>
<item>
addContainerListener()</item>
</row>
<row><item>
FocusListener</item>
<item>
FocusEvent</item>
<item>
focusGained()<br/>
focusLost()</item>
<item>
addFocusListener()</item>
</row>
<row><item>
InputMethodListener </item>
<item>
InputMethodEvent</item>
<item>
caretPositionChanged()<br/> 
inputMethodTextChanged()</item>
<item>
addInputMethodListener()</item>
</row>
<row><item>
ItemListener</item>
<item>
ItemEvent</item>
<item>
itemStateChanged()</item>
<item>
addItemListener()</item>
</row>
<row><item>
KeyListener</item>
<item>
KeyEvent</item>
<item>
keyPressed()<br/>
keyReleased()<br/>
keyTyped()</item>
<item>
addKeyListener()</item>
</row>
<row><item>
MouseListener</item>
<item>
MouseEvent</item>
<item>
mouseClicked()<br/>
mouseEntered()<br/>
mouseExited()<br/>
mousePressed()<br/>
mouseReleased()</item>
<item>
addMouseListener()</item>
</row>
<row><item>
MouseMotionListener</item>
<item>
MouseEvent</item>
<item>
mouseDragged()<br/>
mouseMoved()</item>
<item>
addMouseMotionListener()</item>
</row>
<row><item>
TextListener</item>
<item>
TextEvent</item>
<item>
textValueChanged()</item>
<item>
addTextListener()</item>
</row>
<row><item>
WindowListener</item>
<item>
WindowEvent</item>
<item>
windowActivated()<br/>
windowClosed()<br/>
windowClosing()<br/>
windowDeactivated()<br/>
windowDeiconified()<br/>
windowIconified()<br/>
windowOpened()</item>
<item>
addWindowListener()</item>
</row>
</grid>
</obj>
<obj>
<objh>Select methods from the classes in the <pcode>java.awt.event package</pcode> that identify the affected component, mouse position,
nature, and time of the event.</objh>

<p>The only Event class that has methods for <i>all</i> of the above is MouseEvent.
</p><p><u><i>Affected Component:</i></u>
<br/>There are two methods that fit this description. From looking at the source code, it appears they perform the exact same function.
</p><p>All ComponentEvent subclasses implement this method:</p>
<code>public Component <b>getComponent</b>()</code>
<def><b>Returns:</b> the Component object that originated the event</def>


<p>All events implement this method:</p>
<code>public Object <b>getSource()</b></code>
<def><b>Returns:</b> the object on which the Event initially occurred.</def>


<p><i><u>Mouse Position:</u></i>
<br/>MouseEvent implements these methods:</p>
<code>public Point <b>getPoint</b>()</code>
<def><b>Returns:</b> a Point object containing the x and y coordinates relative to the source component</def>

<code>public int <b>getX</b>()</code>
<def><b>Returns:</b> x an integer indicating horizontal position relative to the component</def>

<code>public int <b>getY</b>()</code>
<def><b>Returns:</b> y an integer indicating vertical position relative to the component</def>


<p><i><u>Nature:</u></i>
<br/>All AWTEvent subclasses implement this method:</p>
<code>public int <b>getID</b>()</code>
<def>Returns the event type. This can be compared with the event mask constants defined in the class for the different types of
event e.g. <pcode>MOUSE_EVENT_MASK</pcode>.</def>


<p><u><i>Time:</i></u>
<br/>InputEvent subclasses (KeyEvent and MouseEvent) implement this method:</p>
<code>public long <b>getWhen</b>()</code>
<def>Returns the timestamp of when this event occurred.</def>


</obj>
<obj>
<objh>Demonstrate correct uses of the Listener methods in the <pcode>Component</pcode>, <pcode>TextArea</pcode>, and
<pcode>TextField</pcode> classes.</objh>

<p>For examples, see a text book, or the sites at the start of this document. Briefly, you create a class which implements one of
the listener interfaces listed above. Important listener interfaces for the components mentioned in this objective are, for example,
MouseListener, FocusListener, KeyListener or TextListener.
</p><p>Create suitable methods for the events you are interested, for the rest of the methods in the interface, just create
an empty method body. For example, if you have a button, and you just need it to respond to being clicked, in your listener
class you would put code in the mouseClicked() method, and implement the rest of the methods with empty bodies. 
</p><p>Then create an instance of the listener class and add it to the component in question using the components appropriate
add method, which is the last column in the table above.</p>
<p>[To save typing, there is the option of using Adapter classes, e.g MouseAdapter for the MouseListener interface. These are
classes which have empty methods for all the methods in the Listener. You extend them, and then overwrite the methods you are
interested in, saving the effort of typing other methods.]</p>

</obj>
<obj>
<objh>For any listener in the <pcode>java.awt.event package</pcode>, state the argument type and return type of a specified
listener method, given the name of the interface that declares the method and the name of the method itself.</objh>

<p>The argument types are listed in the "Listener Interfaces" table above, under the "Event" heading. The return type for all
methods of all listener interface methods is <pcode>void</pcode>.</p>
</obj>
</section>



<section>
<section_title>1.2 Exam Only: The java.io package</section_title>
<p>For this section, you may find the following tables useful. They list the various kinds of Streams and Readers/Writers, along
with what they "connect to", typically their constructor arguments.</p>

<grid>
<gridtitle>Low Level Streams</gridtitle>
<hrow>
<item><b><i>Input Streams</i></b></item>
<item>Arguments</item>
<item><i><b>Output Streams</b></i></item>
<item>Arguments</item>
</hrow>
<row>
<item>FileInputStream</item>
<item>File</item>
<item>FileOutputStream</item>
<item>File</item>
</row>
<row>
<item>ByteArrayInputStream</item>
<item>byte[]</item>
<item>ByteArrayOutputStream</item>
<item>(Creates an array)</item>
</row>
</grid>



<grid>
<gridtitle>High Level Streams</gridtitle>
<hrow>
<item><i><b>Input Streams</b></i></item>
<item>Arguments</item>
<item><i><b>Output Streams</b></i></item>
<item>Arguments</item>
</hrow>
<row><item>FilterInputStream</item>
<item>InputStream</item>
<item>FilterOutputStream</item>
<item>OutputStream</item>
</row>
<row>
<item>DataInputStream
<br/><i>Implements DataInput</i></item>
<item>InputStream</item>
<item>DataOutputStream
<br/><i>Implements DataOutput</i></item>
<item>OutputStream</item>
</row>
<row>
<item>BufferedInputStream</item>
<item>InputStream</item>
<item>BufferedOutputStream</item>
<item>OutputStream</item>
</row>
</grid>



<grid>
<gridtitle>Low-level Readers/Writers</gridtitle>
<hrow>
<item><i><b>Readers</b></i></item>
<item>Arguments</item>
<item><i><b>Writers</b></i></item>
<item>Arguments</item>
</hrow>
<row><item>FileReader</item>
<item>File</item>
<item>FileWriter</item>
<item>File</item>
</row>
<row>
<item>CharArrayReader</item>
<item>char[]</item>
<item>CharArrayWriter</item>
<item>Creates an array of chars</item>
</row>
<row>
<item>StringReader</item>
<item>String</item>
<item>StringWriter</item>
<item>Creates a String</item>
</row>
</grid>


<grid>
<gridtitle>High-level Readers/Writers</gridtitle>
<hrow>
<item><i><b>Readers</b></i></item>
<item>Arguments</item>
<item><i><b>Writers</b></i></item>
<item>Arguments</item>
</hrow>
<row>
<item>BufferedReader</item>
<item>Reader</item>
<item>BufferedWriter</item>
<item>Writer</item>
</row>
<row>
<item>InputStreamReader</item>
<item>InputStream</item>
<item>OutputStreamWriter</item>
<item>OutputStream</item>
</row>
</grid>



<obj><objh>Write code that uses objects of the file class to navigate a file system.</objh>

<p>Methods that support navigation:
</p><p><pcode>boolean exists()</pcode> - Tests if this File exists.
</p><p><pcode>String getAbsolutePath()</pcode> - Returns the absolute pathname of the file represented by this object. 
</p><p><pcode>String getCanonicalPath()</pcode> - Returns the canonical form of this File object's pathname. 
</p><p><pcode>String getName()</pcode> - Returns the name of the file represented by this object. 
</p><p><pcode>String getParent()</pcode> - Returns the parent part of the pathname of this File object, or null if the name has no parent part.
</p><p><pcode>String getPath()</pcode> - Returns the pathname of the file represented by this object. 
</p><p><pcode>boolean isDirectory() </pcode> - Tests if the file represented by this File object is a directory. 
</p><p><pcode>boolean isFile()</pcode> - Tests if the file represented by this File object is a "normal" file.
</p><p><pcode>String[] list()</pcode> - Returns a list (an array of Strings) of the files in the directory specified by this
<pcode>File</pcode> object. 
<def>Note: The File class <b>does not </b>provide a method to change the current working directory.</def>
</p><p>Other methods worth being aware of:
</p><p><pcode>mkdir()</pcode> - Creates a directory whose pathname is specified by this File object. 
</p><p><pcode>delete()</pcode> - Deletes the file specified by this object. 
</p><p><pcode>length()</pcode> - Returns the length of the file represented by this <pcode>File</pcode> object. 
</p><p><pcode>renameTo(File)</pcode> - Renames the file specified by this <pcode>File</pcode> object to have the pathname given by the
<pcode>File</pcode> argument. 
</p><p><pcode>canRead()</pcode> &amp; <pcode>canWrite()</pcode> -  Return <pcode>true</pcode> if the file is readable/writeable.</p>



</obj>
<obj>
<objh>Write code that uses objects of the classes <pcode>InputStreamReader</pcode> and <pcode>OutputStreamWriter</pcode> to
translate between Unicode and either platform default or ISO 8859-1 character encodings.</objh>
<p>The following constructor for InputStreamReader allows you to specify the encoding scheme:</p>
<code><b>InputStreamReader</b>(InputStream in, String enc)</code>
<p><def>Create an InputStreamReader that uses the named character encoding.
<br/><b>Parameters:</b> 
<def><pcode>in</pcode> - An InputStream 
<br/><pcode>enc</pcode> - Name of encoding to be used</def></def>
</p><p>Encoding scheme string "8859_1" is ASCII.
</p><p>The constructor for OutputStreamWriter is similar, but the first argument is an OutputStream, obviously.
</p><p>Readers (such as InputStreamReader) have the following methods for reading characters:
</p><p><pcode><b>read</b>()</pcode> -Read a single character. 
</p><p><pcode><b>read</b>(char[] cbuf)</pcode> -Read characters into an array.
</p><p><pcode><b>read</b>(char[] cbuf, int off, int len)</pcode> -Read characters into a portion of an array.
</p><p>Writers (such as OutputStreamWriter) have the following methods for writing characters:
</p><p><pcode><b>write</b>(char[] cbuf)</pcode> -Write an array of characters.
</p><p><pcode><b>write</b> (char[] cbuf, int off, int len)</pcode> -Write a portion of an array of characters.
</p><p><pcode><b>write</b>(int c)</pcode> -Write a single character.
</p><p><pcode><b>write</b>(String str)</pcode> -Write a string.
</p><p><pcode><b>write</b>(String str, int off, int len)</pcode> -Write a portion of a string.</p>


</obj>
<obj>
<objh>Destinguish between conditions under which platform default encoding conversion should be used and conditions under which a specific
conversion should be used.</objh>

<p>To avoid corruption, text should be read using the same encoding scheme that it was written with. Therefore, in general platform default
encoding may be used if the data is written on the same computer as it is going to be read. However if the text is going to be sent from one
computer to another across a network, or if a text file is created on a different computer (for example files that are installed as part of
an application), then a specific encoding scheme should be used at both ends.</p>


</obj>
<obj>
<objh>Select valid constructor arguments for FilterInputStream and FilterOutputStream subclasses from a list of classes in
the java.io.package.</objh>

<p>The correct constructor argument for FilterInputStream is an instance of a subclass of InputStream. Similarily, the correct
constructor argument for FilterOutputStream is an instance of a subclass of OutputStream.</p>
</obj><obj>
<objh>Write appropriate code to read, write and update files using FileInputStream, FileOutputStream, and RandomAccessFile objects.</objh>
<p>See a textbook, the Java tutorials or Javadocs if you are unsure of this area. Here is some brief information on RandomAccessFile:</p>
<p>RandomAccessFile is not part of the i/o stream or reader/writer hierarchies. The constructors are:</p>
<code>RandomAccessFile(String file, String mode)</code>
<code>RandomAccessFile(File file, String mode)</code> 
<p><u><b>Important:</b></u> For the RandomAccessFile constructor, the mode <b>argument must either be equal to <pcode>"r"</pcode>
or <pcode>"rw"</pcode></b>. Do not be fooled in the exam by credible sounding, but non-existent options like "<pcode>r+w</pcode>"
or "<pcode>w</pcode>".
</p><p>RandomAccessFile has a pointer which determines where to read/write in the file. getFilePointer() returns the current position
in the file, in bytes, and seek(long position) sets the pointer to a specific location. There is also a length() method. This
class implements the <pcode>DataInput</pcode> and <pcode>DataOutput</pcode> interfaces, which have read or write methods (respectively)
for all the primitives, strings, and byte arrays ( <pcode>readFully</pcode> and <pcode>write()</pcode> respectively). The
<pcode>DataInput</pcode> interface also has <pcode>skipBytes()</pcode> method. Consult the Java API Docs for more on these interfaces.</p></obj><obj>
<objh>Describe the permanent effects on the file system of constructing and using FileInputStream, FileOutputStream, and
RandomAccessFile objects.</objh><p>RandomAccessFile will create an empty file if it is constructed as "rw". Constructing a
FileOutputStream can create an empty file. 
</p><p>FileInputStream of course, never causes a file to be created or modified.</p></obj>
</section>




<section>
<section_title>1.2 Exam Only: Miscellaneous</section_title>
<obj>
<objh>Write code to demonstrate the use of the following methods of the <pcode>java.lang.String</pcode> class: <pcode>length()</pcode>,
<pcode>toUpperCase()</pcode>, <pcode>toLowerCase()</pcode>, <pcode>equals()</pcode>, <pcode>equalsIgnoreCase()</pcode>,
<pcode>charAt()</pcode>, <pcode>concat()</pcode>, <pcode>indexOf()</pcode>, <pcode>lastIndexOf()</pcode>, <pcode>substring()</pcode>,
<pcode>toString()</pcode>, <pcode>trim()</pcode>.</objh>
<p><br/><pcode>length()</pcode> - Returns the length of this string. 
</p><p><pcode>toUpperCase()</pcode> - Converts this string to uppercase.
</p><p><pcode>toLowerCase()</pcode> - Converts this String to lowercase.
<def>[Note that <pcode>toLowerCase()</pcode> and <pcode>toUpperCase()</pcode> will return a reference to original string object
if the it is already in lower case or upper case respectively. This is important for questions on the <pcode>==</pcode> operator and strings.
There appears to be a bug in Suns JDK 1.1 which causes this not to occur, but this is the behaviour described by the JavaDocs.
Java2 behaves as described in the JavaDocs.]</def>
</p><p><pcode>equals(Object)</pcode> - Compares this string to the specified object. Returns true if the strings contain the same
sequence of characters.
</p><p><pcode>equalsIgnoreCase(String)</pcode> - Compares this String to another object. Returns true if the strings contain the
same sequence of characters, ignoring case.
</p><p><pcode>charAt(int)</pcode> - Returns the character at the specified index. An index ranges from <pcode>0</pcode> to
<pcode>length() - 1</pcode>. 
</p><p><pcode>concat(String)</pcode> - Concatenates the specified string to the end of this string. 
</p><p><pcode>indexOf(int)</pcode> - Returns the index within this string of the first occurrence of the specified character.
</p><p><pcode>indexOf(int ch, int fromIndex)</pcode> - Returns the index within this string of the first occurrence of the specified
character, starting the search at the specified index.
<br/><b>Parameters:</b>
<def>ch - a character.
<br/>fromIndex - the index to start the search from.</def>
</p><p><pcode>indexOf(String)</pcode> - Returns the index within this string of the first occurrence of the specified substring. 
</p><p><pcode>indexOf(String, int)</pcode> - Returns the index within this string of the first occurrence of the specified substring,
starting at the specified index. 
</p><p><pcode>lastIndexOf(int)</pcode> - Returns the index within this string of the last occurrence of the specified character. 
</p><p><pcode>lastIndexOf(int ch, int fromIndex)</pcode> - Returns the index within this string of the last occurrence of the
specified character, searching backward starting at the specified index. 
<br/><b>Parameters:</b>
<def>ch - a character.
<br/>fromIndex - the index to start the search from.</def>
</p><p><pcode>lastIndexOf(String)</pcode> - Returns the index within this string of the rightmost occurrence of the specified substring. 
</p><p><pcode>lastIndexOf(String, int)</pcode> - Returns the index within this string of the last occurrence of the specified substring.
</p><p><pcode>substring(int)</pcode> - Returns a new string that is a substring of this string. The substring begins at the specified
index and extends to the end of this string. 
</p><p><pcode>substring(int beginIndex, int endIndex)</pcode> - Returns a new string that is a substring of this string. The substring
begins at the specified <pcode>beginIndex</pcode> and extends to the character at index <pcode>endIndex - 1</pcode>. 
<def><b>Remember</b>: substring gives you the substring from the first index<b>, to the second index minus one</b>.</def>
</p><p><pcode>trim()</pcode> - Removes white space from both ends of this string.
</p><p><pcode>toString()</pcode> - Returns a string representation of the object. This method is inherited by all classes from Object.
By default, the <pcode>toString</pcode> method for class <pcode>Object</pcode> returns a string consisting of the name of the class of
which the object is an instance, the at-sign character '<pcode>@</pcode>', and the unsigned hexadecimal representation of the hash code
of the object. You can override it in your own classes to produce some useful string e.g. for debugging info. For the Strings, toString()
returns the String object itself.</p>
</obj>

<obj>
<objh>State all operators that are legal in <pcode>String</pcode> expressions.</objh>
<p>The <pcode>+ operator</pcode> to concatenate strings.</p>
</obj>
</section>


<section>
<section_title>GNU Free Documentation License</section_title>
<code>
		GNU Free Documentation License
		   Version 1.1, March 2000

 Copyright (C) 2000  Free Software Foundation, Inc.
     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.


0. PREAMBLE

The purpose of this License is to make a manual, textbook, or other
written document "free" in the sense of freedom: to assure everyone
the effective freedom to copy and redistribute it, with or without
modifying it, either commercially or noncommercially.  Secondarily,
this License preserves for the author and publisher a way to get
credit for their work, while not being considered responsible for
modifications made by others.

This License is a kind of "copyleft", which means that derivative
works of the document must themselves be free in the same sense.  It
complements the GNU General Public License, which is a copyleft
license designed for free software.

We have designed this License in order to use it for manuals for free
software, because free software needs free documentation: a free
program should come with manuals providing the same freedoms that the
software does.  But this License is not limited to software manuals;
it can be used for any textual work, regardless of subject matter or
whether it is published as a printed book.  We recommend this License
principally for works whose purpose is instruction or reference.


1. APPLICABILITY AND DEFINITIONS

This License applies to any manual or other work that contains a
notice placed by the copyright holder saying it can be distributed
under the terms of this License.  The "Document", below, refers to any
such manual or work.  Any member of the public is a licensee, and is
addressed as "you".

A "Modified Version" of the Document means any work containing the
Document or a portion of it, either copied verbatim, or with
modifications and/or translated into another language.

A "Secondary Section" is a named appendix or a front-matter section of
the Document that deals exclusively with the relationship of the
publishers or authors of the Document to the Document's overall subject
(or to related matters) and contains nothing that could fall directly
within that overall subject.  (For example, if the Document is in part a
textbook of mathematics, a Secondary Section may not explain any
mathematics.)  The relationship could be a matter of historical
connection with the subject or with related matters, or of legal,
commercial, philosophical, ethical or political position regarding
them.

The "Invariant Sections" are certain Secondary Sections whose titles
are designated, as being those of Invariant Sections, in the notice
that says that the Document is released under this License.

The "Cover Texts" are certain short passages of text that are listed,
as Front-Cover Texts or Back-Cover Texts, in the notice that says that
the Document is released under this License.

A "Transparent" copy of the Document means a machine-readable copy,
represented in a format whose specification is available to the
general public, whose contents can be viewed and edited directly and
straightforwardly with generic text editors or (for images composed of
pixels) generic paint programs or (for drawings) some widely available
drawing editor, and that is suitable for input to text formatters or
for automatic translation to a variety of formats suitable for input
to text formatters.  A copy made in an otherwise Transparent file
format whose markup has been designed to thwart or discourage
subsequent modification by readers is not Transparent.  A copy that is
not "Transparent" is called "Opaque".

Examples of suitable formats for Transparent copies include plain
ASCII without markup, Texinfo input format, LaTeX input format, SGML
or XML using a publicly available DTD, and standard-conforming simple
HTML designed for human modification.  Opaque formats include
PostScript, PDF, proprietary formats that can be read and edited only
by proprietary word processors, SGML or XML for which the DTD and/or
processing tools are not generally available, and the
machine-generated HTML produced by some word processors for output
purposes only.

The "Title Page" means, for a printed book, the title page itself,
plus such following pages as are needed to hold, legibly, the material
this License requires to appear in the title page.  For works in
formats which do not have any title page as such, "Title Page" means
the text near the most prominent appearance of the work's title,
preceding the beginning of the body of the text.


2. VERBATIM COPYING

You may copy and distribute the Document in any medium, either
commercially or noncommercially, provided that this License, the
copyright notices, and the license notice saying this License applies
to the Document are reproduced in all copies, and that you add no other
conditions whatsoever to those of this License.  You may not use
technical measures to obstruct or control the reading or further
copying of the copies you make or distribute.  However, you may accept
compensation in exchange for copies.  If you distribute a large enough
number of copies you must also follow the conditions in section 3.

You may also lend copies, under the same conditions stated above, and
you may publicly display copies.


3. COPYING IN QUANTITY

If you publish printed copies of the Document numbering more than 100,
and the Document's license notice requires Cover Texts, you must enclose
the copies in covers that carry, clearly and legibly, all these Cover
Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
the back cover.  Both covers must also clearly and legibly identify
you as the publisher of these copies.  The front cover must present
the full title with all words of the title equally prominent and
visible.  You may add other material on the covers in addition.
Copying with changes limited to the covers, as long as they preserve
the title of the Document and satisfy these conditions, can be treated
as verbatim copying in other respects.

If the required texts for either cover are too voluminous to fit
legibly, you should put the first ones listed (as many as fit
reasonably) on the actual cover, and continue the rest onto adjacent
pages.

If you publish or distribute Opaque copies of the Document numbering
more than 100, you must either include a machine-readable Transparent
copy along with each Opaque copy, or state in or with each Opaque copy
a publicly-accessible computer-network location containing a complete
Transparent copy of the Document, free of added material, which the
general network-using public has access to download anonymously at no
charge using public-standard network protocols.  If you use the latter
option, you must take reasonably prudent steps, when you begin
distribution of Opaque copies in quantity, to ensure that this
Transparent copy will remain thus accessible at the stated location
until at least one year after the last time you distribute an Opaque
copy (directly or through your agents or retailers) of that edition to
the public.

It is requested, but not required, that you contact the authors of the
Document well before redistributing any large number of copies, to give
them a chance to provide you with an updated version of the Document.


4. MODIFICATIONS

You may copy and distribute a Modified Version of the Document under
the conditions of sections 2 and 3 above, provided that you release
the Modified Version under precisely this License, with the Modified
Version filling the role of the Document, thus licensing distribution
and modification of the Modified Version to whoever possesses a copy
of it.  In addition, you must do these things in the Modified Version:

A. Use in the Title Page (and on the covers, if any) a title distinct
   from that of the Document, and from those of previous versions
   (which should, if there were any, be listed in the History section
   of the Document).  

B. List on the Title Page, as authors, one or more persons or entities
   responsible for authorship of the modifications in the Modified
   Version, together with at least five of the principal authors of the
   Document (all of its principal authors, if it has less than five).
C. State on the Title page the name of the publisher of the
   Modified Version, as the publisher.
D. Preserve all the copyright notices of the Document.
E. Add an appropriate copyright notice for your modifications
   adjacent to the other copyright notices.
F. Include, immediately after the copyright notices, a license notice
   giving the public permission to use the Modified Version under the
   terms of this License, in the form shown in the Addendum below.
G. Preserve in that license notice the full lists of Invariant Sections
   and required Cover Texts given in the Document's license notice.
H. Include an unaltered copy of this License.
I. Preserve the section entitled "History", and its title, and add to
   it an item stating at least the title, year, new authors, and
   publisher of the Modified Version as given on the Title Page.  If
   there is no section entitled "History" in the Document, create one
   stating the title, year, authors, and publisher of the Document as
   given on its Title Page, then add an item describing the Modified
   Version as stated in the previous sentence.
J. Preserve the network location, if any, given in the Document for
   public access to a Transparent copy of the Document, and likewise
   the network locations given in the Document for previous versions
   it was based on.  These may be placed in the "History" section.
   You may omit a network location for a work that was published at
   least four years before the Document itself, or if the original
   publisher of the version it refers to gives permission.
K. In any section entitled "Acknowledgements" or "Dedications",
   preserve the section's title, and preserve in the section all the
   substance and tone of each of the contributor acknowledgements
   and/or dedications given therein.
L. Preserve all the Invariant Sections of the Document,
   unaltered in their text and in their titles.  Section numbers
   or the equivalent are not considered part of the section titles.
M. Delete any section entitled "Endorsements".  Such a section
   may not be included in the Modified Version.
N. Do not retitle any existing section as "Endorsements"
   or to conflict in title with any Invariant Section.

If the Modified Version includes new front-matter sections or
appendices that qualify as Secondary Sections and contain no material
copied from the Document, you may at your option designate some or all
of these sections as invariant.  To do this, add their titles to the
list of Invariant Sections in the Modified Version's license notice.
These titles must be distinct from any other section titles.

You may add a section entitled "Endorsements", provided it contains
nothing but endorsements of your Modified Version by various
parties--for example, statements of peer review or that the text has
been approved by an organization as the authoritative definition of a
standard.

You may add a passage of up to five words as a Front-Cover Text, and a
passage of up to 25 words as a Back-Cover Text, to the end of the list
of Cover Texts in the Modified Version.  Only one passage of
Front-Cover Text and one of Back-Cover Text may be added by (or
through arrangements made by) any one entity.  If the Document already
includes a cover text for the same cover, previously added by you or
by arrangement made by the same entity you are acting on behalf of,
you may not add another; but you may replace the old one, on explicit
permission from the previous publisher that added the old one.

The author(s) and publisher(s) of the Document do not by this License
give permission to use their names for publicity for or to assert or
imply endorsement of any Modified Version.


5. COMBINING DOCUMENTS

You may combine the Document with other documents released under this
License, under the terms defined in section 4 above for modified
versions, provided that you include in the combination all of the
Invariant Sections of all of the original documents, unmodified, and
list them all as Invariant Sections of your combined work in its