Lecture Summary for 211 on 3/26/04 -- Barat Section
 
Review Questions
Explain the difference between an accessor method and a mutator method.
Match the method types in Column 1 with the items in Column 2.
Column 1
Column 2
Mutator
One return value
Accessor
No return value
 
One parameter
 
No parameter
Which type of method does not specify a return type
in its header.
What is wrong with this constructor definition?
public MyClass()
{
    MyClass x = MyClass();
}
What is garbage? How do you create it and get rid of it?
What gets printed?
Kid x = new Kid("Mary", 'F', 12);
Kid y = new Kid("Tom", 'M', 10);
Kid temp;
temp = x;
x = y;
y = temp;
System.out.println(x);
System.out.println(y);
Write lines of Java code that print "yes" if x is female and
"no" otherwise. Assume the class definition Kids2. Do not hardcode
your answer for this particular x.
Write lines of Java code that print the length of the name for
y. Do not hardcode your answer for this particular y.
Write an equals method for the Point class. Two Point objects p and q
are equal if p.x == q.x and q.x == q.y.
Write a main method to test your equals method in the previous problem.
 
The StringTokenizer
A token is a string with a meaning for an application.
Use a StringTokenizer object to extract tokens from a string.
Example 1: the string "345,34,21,5,2341" contains the tokens
345, 34, 21, 5, and 2341. Since the tokens are separated by commas,
the string is called a "comma delimited string."
Example 2: the string "Jane F 13" contains the tokens Jane, F, and
13. The original string is a space delimited string.
Look at the StringTokenizer Example in Debugging
(Debugging.zip or Debugging.txt).
Look at the KidArray and IntSorting Examples in Arrays.
Look at the Phone Example in Arrays.
This application looks up
a name entered in an array and prints the associated phone number.
The Art of Debugging
Debugging is often more of an art than it is a science.
Avoid the temptation to experiment on a buggy program before
understanding the bugs.
The best weapon for finding bugs is thinking.
 
The Steps of Inductive Debugging
Collect data about the bug. When does the program perform
correctly and when does it perform incorrectly.
Organize the data. Answer these questions:
what, when, and where. When does an error occur and when does
it not occur?
Formulate a hypotheses about what is causing the bug.
Prove the hypotheses.
Fix the bug and continue to look for more bugs. Resist the urge to
skip directly from Step 3 to Step 5.
 
The BlueJ Debugger
Invoke the debugger by selecting the main menu item
View, then checking the box Show Debugger.
Set breakpoints in the code window by clicking with the mouse
in the left border of the code window. The code will pause in its
execution when it reaches a breakpoint.
Continue to step through the code by clicking the Step button
at the bottom of the debugger. Step continues to the next line of
the code. Step Into steps into the code of a method if one is
invoked on the next line.
Values of all variables, including instance variables and
local variables, are shown.
Some people do not like to use debuggers. The effect of a debugger
can be simulated by placing strategic print or println statements in
the code.
 
Debugging Examples
Debug the WagesForMonth and MaxSalary
Examples in Debugging (Debugging.zip or Debugging.txt).
Here are the
errors in the examples and the
main method to test the English
method in MetricConverter.