Java Reference
In-Depth Information
The reason we could use the constants from class Color is that they were declared public. As
opposed to other fields (about which we commented earlier that they should never be declared
public), declaring constants public is generally unproblematic and sometimes useful.
Exercise 5.68 Write constant declarations for the following:
A public variable that is used to measure tolerance, with the value 0.001.
A private variable that is used to indicate a pass mark, with the integer value of 40.
A public character variable that is used to indicate that the help command is 'h' .
Exercise 5.69 Take a look at the LogEntry class in the weblog-analyzer project from Chapter 4.
How have constants been used in that class? Do you think that this is a good use of constants?
Exercise 5.70 Suppose that a change to the weblog-analyzer project meant that it was no
longer necessary to store year values in the dataValues array in the LogEntry class. How
much of the class would need to be altered if the month value were now to be stored at index
0 , the day value at index 1 , and so on? Do you see how the use of named constants for spe-
cial values simplifies this sort of process?
5.14
Summary
Dealing with class libraries and class interfaces is essential for a competent programmer. There
are two aspects to this topic: reading class library descriptions (especially class interfaces) and
writing them.
It is important to know about some essential classes from the standard Java class library and to
be able to find out more when necessary. In this chapter, we have presented some of the most
important classes and have discussed how to browse the library documentation.
It is also important to be able to document any class that is written, in the same style as the li-
brary classes, so that other programmers can easily use the class without the need to understand
the implementation. This documentation should include good comments for every project,
class, and method. Using javadoc with Java programs will help you to do this.
Terms introduced in this chapter
interface, implementation, map, set, javadoc, access modifier, information hiding,
coupling, class variable, static, constant, final
Concept summary
Java library The Java standard class library contains many classes that are very useful. It is
important to know how to use the library.
library documentation The Java class library documentation shows details about all classes
in the library. Using this documentation is essential in order to make good use of library classes.
 
 
Search WWH ::




Custom Search