Site MapHelpFeedbackChapter Overview
Chapter Overview
(See related pages)

The static modifier is used for identifiers that apply to a class as a whole, rather than to a particular instance of a class. Constants should be declared to be static, because then there will be only one copy of the constant, instead of one copy for each instance of the class. To access a static identifier outside of its class, the class identifier— rather than an object—is the qualifier.

An exception is an object that signals a special situation, usually that an error has occurred. An exception can be handled with try/catch blocks. The sequence of statements in the try block is executed. If, during execution, an exception is thrown (indicating that an error has occurred), the appropriate catch block is executed to specify what, if anything, is to be done.

File output is similar to console-oriented output, except that a PrintWriter object is explicitly created to write to the specified output file. The output is not immediately sent to the output file, but rather to a buffer. At the conclusion of file processing, the buffer is flushed to the output file by a call to the close method.

To increase a programmer’s confidence that a method is correct—that is, satisfies the method’s specifications—the method can be tested in a program that repeatedly invokes the method with a variety of argument values. For testing all of a class’s methods in concert, a program called a driver is created. Testing is bottomup: low-level classes are tested first; ultimately, the entire project is run against system tests.

The Java run-time, also known as the Java Virtual Machine, is a program that interprets and executes the bytecode output from a Java compiler. Among other tasks, the Java Virtual Machine is responsible for preinitialization of fields and deallocation of inaccessible objects.

A package is a collection of related classes. An identifier with no visibility modifier is said to have default visibility. Java is “package friendly.” That is, an identifier with default visibility can be accessed by any object (or class, in the case of a static member) in the same package as the class in which the identifier is declared. If a given class’s identifier has protected visibility, that identifier can be accessed in any subclass of the given class, even in a different package. Unfortunately, that identifier may also be accessed in any class—even if not a subclass—within the given package’s class.

The equals method in the Object class should be overridden for any class C whose instances might become elements of a collection. The overriding method invokes the instanceof method to return false for any argument object that is not an instance of class C, and then casts the Object class to class C in order to make the appropriate comparisons.








CollinsOnline Learning Center

Home > Chapter 2 > Chapter Overview