Java Reference
In-Depth Information
The following program tests the class Person :
public class TestProgPerson
{
public static void main(String[] args)
{
Person name = new Person();
//Line 1
Person emp = new Person("Donald", "Jackson");
//Line 2
System.out.println("Line 3: name: " + name);
//Line 3
name.setName("Ashley", "Blair");
//Line 4
System.out.println("Line 5: name: " + name);
//Line 5
System.out.println("Line 6: emp: " + emp);
//Line 6
emp.setName("Sandy", "Smith");
//Line 7
System.out.println("Line 8: emp: " + emp);
//Line 8
} //end main
}
Sample Run:
Line 3: name:
Line 5: name: Ashley Blair
Line 6: emp: Donald Jackson
Line 8: emp: Sandy Smith
Debugging—Designing and Documenting a Class
Before moving to the design phase, a problem must be thoroughly understood so that the
focus is on solving the problem. As emphasized in earlier chapters, especially, as a
beginner we must learn to solve the problem completely on a piece of paper before
writing a single line of code. Furthermore, as noted in earlier chapters, a Java program is a
collection of classes and a class is a collection of variables, methods, and sometimes other
classes. So in Java, a class is a fundamental entity. Therefore, once a class is designed, it
must be properly documented. Typically in a large project, the designer of a class and the
programmer need not be the same person. Even if the designer and the programmer are
the same person, it is possible that after some time the person currently working on the
problem may move to another project or even to a different job. So the person replacing
the person leaving must know exactly what the designer intended to do with the class.
Therefore, it is very important to document the class so that it can be correctly
programmed in Java, and if needed, in the future it can be modified.
DEBUGGING
 
 
Search WWH ::




Custom Search