2. Reading a Quick Reference Entry
Each quick-reference entry contains
quite a bit of information. The
sections that follow describe the structure of a quick-reference entry,
explaining what information is available, where it is found,
and what it means.
While reading the descriptions that follow,
you will find it helpful to flip through the reference
section itself to find examples of the features being described.
2.1. Class Name, Package Name, Availability, and Flags
Each quick-reference entry begins with a four-part title that
specifies the name, package, and availability of the class, and
may also
specify various additional flags that describe the class. The
class name appears in bold at the upper-left of the title. The
package name appears, in smaller print, in the lower-left, below
the class name.
The upper-right portion the title indicates
the availability of the class; it
specifies the earliest release that
contained the class. If a class was introduced in Java 1.1, for
example, this portion of the title reads "Java 1.1".
If a class was introduced in Version 1.2 of the Java 2 platform,
the availability reads "Java 1.2", for
simplicity's sake. The availability section of the title is also
used to indicate whether a class has been deprecated, and, if
so, in what release. For example, it might read "Java 1.1;
Deprecated in Java 1.2".
In the lower-right corner of the title you may find a list of
flags that describe the class. The possible
flags and their meanings are as follows:
-
accessible
-
The class, or a superclass, implements javax.accessibility.Accessible. This flag may be followed by a parenthesized list that specifies the specific types of accessibility supported by this class. The possible accessibility types are action, selection, value, text, and hypertext. When present, a type indicates that the javax.accessibility.AccessibleContext for this class can return an accessiblity object of that type. For example, a class that is accessible(action,selection) has an AccessibleContext whose getAccessibleAction() and getAccessibleSelection() methods return non-nulljavax.accessibility.AccessibleAction and javax.accessibility.AccessibleSelection objects, respectively. The AccessibleContext for an accessible component has a getAccessibleComponent() method that returns an AccessibleComponent object. Because this is true for all components, however, it is not specially flagged here.
AccessibleContext classes are typically implemented as protected inner classes of the accessible class itself. This book does not contain reference entries for these classes because all the necessary information about them is contained in the accessible class flag of the accessible class, in the single-line inner class synopsis that appears in the containing accessible class, and in Chapter 22, "The javax.accessibility Package".
-
AWT component
-
The class extends
java.awt.Component, but does not
extend javax.swing.JComponent.
-
bean container
-
The class may contain JavaBeans components.
-
checked
-
The class is a checked exception, which means that it
extends java.lang.Exception, but not
java.lang.RuntimeException.
In other words, it
must be declared in the throws
clause of any method that may throw it.
-
cloneable
-
The class, or a superclass, implements
java.lang.Cloneable.
-
collection
-
The class, or a superclass, implements
java.util.Collection or
java.util.Map.
-
comparable
-
The class, or a superclass, implements
java.lang.Comparable.
-
error
-
The class extends java.lang.Error.
-
event
-
The class extends
java.util.EventObject.
-
event adapter
-
The class, or a superclass, implements
java.util.EventListener, and the
class name ends with "Adapter".
-
event listener
-
The class, or a superclass, implements
java.util.EventListener.
-
layout manager
-
The class, or a superclass, implements
java.awt.LayoutManager.
-
model
-
The class is Swing class whose name ends with
"Model".
-
PJ1.1
-
The class or interface is part of the
Personal Java 1.1 platform.
-
PJ1.1(mod)
-
The class or interface is supported, in modified
form, by the Personal Java 1.1 platform.
-
PJ1.1(opt)
-
The class or interface is an optional part of the
Personal Java 1.1 platform. Support for the class is
implementation-dependent.
-
remote
-
The class, or a superclass, implements
java.rmi.Remote.
-
runnable
-
The class, or a superclass, implements
java.lang.Runnable.
-
serializable
-
The class, or a superclass, implements
java.io.Serializable
and may be serialized.
-
shape
-
The class, or a superclass, implements
java.awt.Shape.
-
swing component
-
The class extends
javax.swing.JComponent.
-
unchecked
-
The class is an unchecked exception, which means it extends
java.lang.RuntimeException and
therefore does not need to be declared in the
throws clause of a method that
may throw it.
2.2. Description
The title of each quick-reference entry is followed by a short
description of the most important features of the class or
interface. This description may be anywhere from a couple of
sentences to several paragraphs long.
2.3. Synopsis
The most important part of every quick-reference entry is the
class synopsis, which follows the title and description. The
synopsis for a class looks a lot like the source code for the
class, except that the method bodies are omitted and some
additional annotations are added. If you know Java syntax, you
know how to read the class synopsis.
The first line of the synopsis contains information about the
class itself. It begins with a list of class modifiers, such as
public, abstract, and
final. These modifiers are followed by the
class or interface keyword
and then by the name of the class. The class name may be
followed by an extends clause that specifies
the superclass and an implements clause
that specifies any interfaces the class implements.
The class definition line is followed by a list of the
fields and methods that the class defines. Once again, if you
understand basic Java syntax, you should have no trouble making
sense of these lines. The listing for each member includes the
modifiers, type, and name of the member. For methods, the
synopsis also includes the type and name of each method
parameter and an optional throws clause
that lists the exceptions the method can throw. The member
names are in boldface, so that it is easy to scan the list of
members looking for the one you want. The names of method
parameters are in italics to indicate that they are not
to be used literally. The member listings are printed on
alternating gray and white backgrounds to keep them visually
separate.
2.3.1. Member availability and flags
Each member listing is a single line
that defines the API for that member. These listings use
Java syntax, so their meaning is immediately clear to any
Java programmer. There is some auxiliary information
associated with each member synopsis, however, that requires
explanation.
Recall that each quick-reference entry begins with a title
section that includes the release in which the class was first
defined. When a member is introduced into a class after the
initial release of the class, the version in which the member
was introduced appears, in small print, to the left of the
member synopsis. For example, if a class was first introduced
in Java 1.1, but had a new method added in Version 1.2 of Java 2, the
title contains the string "Java 1.1",
and the listing for
the new member is preceded by the number "1.2".
Furthermore, if a member has been deprecated, that fact is
indicated with a hash mark (#) to the left
of the member synopsis.
The area to the right of the member synopsis is used to
display a variety of flags that provide additional
information about the member. Some of these flags indicate
additional specification details that do not appear in the
member API itself. Other flags contain
implementation-specific information. This information can be
quite useful in understanding the class and in debugging your
code, but be aware that
it may differ between implementations. The
implementation-specific flags displayed in this book are based
on Sun's implementation of Java for Microsoft Windows.
The following flags may be displayed to the right of a
member synopsis:
-
native
-
An implementation-specific flag that indicates
that a method is implemented in native code. Although
native is a Java keyword and can
appear in method signatures, it is part of the method
implementation, not part of its specification.
Therefore, this information is included with the
member flags, rather than as part of the member
listing. This flag is useful as a hint about the
expected performance of a method.
-
synchronized
-
An implementation-specific flag that indicates that a
method implementation is declared
synchronized, meaning that it
obtains a lock on the object or class before executing.
Like the native keyword, the
synchronized keyword is part of the
method implementation, not part of the specification,
so it appears as a flag, not in the method
synopsis itself. This flag is a useful hint
that the method is probably implemented in
a thread-safe manner.
Whether or not a method is thread-safe is part of the
method specification, and this information
should appear (although it often
does not) in the method documentation. There are a
number of different ways to make a method thread-safe,
however, and declaring the method with the
synchronized keyword is only one
possible implementation. In other words, a method
that does not bear the synchronized
flag can still be thread-safe.
-
Overrides:
-
Indicates that a method overrides a method in one of
its superclasses. The flag is followed by the name of
the superclass that the method overrides. This is a
specification detail, not an implementation detail.
As we'll see in the next section,
overriding methods are usually
grouped together in their own section of the class
synopsis. The Overrides: flag is
only used when an overriding method is not grouped in
that way.
-
Implements:
-
Indicates that a method implements a method in
an interface. The flag
is followed by the name of the interface
that is implemented. This is a specification detail, not
an implementation detail. As we'll see in the next
section, methods
that implement an interface are usually grouped into a
special section of the class synopsis. The
Implements: flag is only used for
methods that are not grouped in this way.
-
empty
-
Indicates that the implementation of the method
has an empty body. This can be a hint to the programmer
that the method may need to be overridden in a subclass.
-
constant
-
An implementation flag that indicates that a method has
a trivial implementation. Only methods with a
void return type can be truly empty.
Any method declared to return a value must have at least a
return statement. The
"constant" flag indicates that the method
implementation is empty except for a
return statement that returns a
constant value. Such a method might have a body like
return null; or return
false;. Like the "empty" flag,
this flag indicates that a method may need to be
overridden.
-
default:
-
This flag is used with property accessor methods that
read the value of a property (i.e., methods whose names
begins with "get" and take no arguments). The
flag is followed by the default value of the property.
Strictly speaking, default property values are a
specification detail. In practice, however, these
defaults are not always documented, and care should be
taken, because the default values may change between
implementations.
Not all property accessors have a
"default:" flag. A default value is
determined by dynamically loading the class in question,
instantiating it using a no-argument constructor, and
then calling the method to find out what it returns.
This technique can be used only on classes that can be
dynamically loaded and instantiated and that have
no-argument constructors, so default values are shown
for those classes only. Furthermore, note that when a
class is instantiated using a different constructor, the
default values for its properties may be different.
-
bound
-
This flag is used with property accessor methods for
bound properties of JavaBeans components.
The presence of this
flag means that calling the method generates a
java.beans.PropertyChangeEvent. This
is a specification detail, but it is sometimes not
documented. Information about bound properties is
obtained from the BeanInfo object for
the class.
-
constrained
-
Indicates that a JavaBeans component
property is constrained. In other
words, the method may throw a
java.beans.PropertyVetoException. This
is a specification detail, not an implementation detail.
-
expert
-
Indicates that the BeanInfo
object for this class specifies that this method is
intended for use by experts only. This
hint is intended for visual programming tools, but users of
this book may find the hint useful as well.
-
hidden
-
Indicates that the BeanInfo
object for this class specifies that this method
is for internal use only. This is a hint that
visual programming tools should hide the property or
event from the programmer. This book does
not hide these methods, of course, but
this flag does
indicate that you
should probably avoid using the method.
-
preferred
-
Indicates that the BeanInfo object
for this class specifies that this method is an accessor
for a default or preferred property or event.
This is a hint to visual programming tools to display
the property or event in a prominent way, and it may
also be a useful hint to readers of this book.
-
=
-
For static final fields, this flag is
followed by the constant value of the field. Only
constants of primitive and String
types and constants with the value
null are displayed. Some
constant values are specification details, while others
are implementation details. The reason that symbolic
constants are defined, however, is so you can write code
that does not rely directly upon the constant value. Use
this flag to help you understand the class, but do not
rely upon the constant values in your own programs.
2.3.2. Functional grouping of members
Within a class synopsis, the members are not listed in strict
alphabetical order. Instead, they are broken down into
functional groups and listed alphabetically within each
group. Constructors, methods, fields, and inner classes are
all listed separately. Instance methods are kept separate
from static (class) methods. Constants are separated from
non-constant fields. Public members are listed separately
from protected members. Grouping members by category breaks a
class down into smaller, more comprehensible segments, making
the class easier to understand. This grouping also makes it
easier for you to find a desired member.
Functional groups are separated from each other
in a class synopsis with Java comments, such as "// Public
Constructors", "// Inner Classes",
and "// Methods
Implementing Servlet". The various functional categories are
as follows (in the order in which they appear in a class
synopsis):
-
Constructors
-
Displays the constructors for the class. Public
constructors and protected constructors are displayed
separately in subgroupings. If a class defines no
constructor at all, the Java compiler adds a default
no-argument constructor that is displayed here. If a
class defines only private constructors, it cannot be
instantiated, so a special, empty grouping entitled
"No Constructor" indicates this
fact. Constructors are listed first because the first
thing you do with most classes is instantiate them by
calling a constructor.
-
Constants
-
Displays all of the constants (i.e., fields that are
declared static and
final) defined by the class. Public
and protected constants are displayed in separate
subgroups. Constants are listed here, near the top of
the class synopsis, because constant values are often
used throughout the class as legal values for method
parameters and return values.
-
Inner Classes
-
Groups all of the inner classes and interfaces
defined by the class or interface. For each inner class,
there is a single-line synopsis. Each inner class also
has its own quick-reference entry that includes a full class
synopsis for the inner class. Like constants, inner
classes are listed near the top of the class synopsis
because they are often used by a number of other members
of the class.
-
Static Methods
-
Lists the static methods (class methods) of the class,
broken down into subgroups for public static methods
and protected static methods.
-
Event Listener Registration Methods
-
Lists the public instance methods that register and
deregister event listener objects with the class. The
names of these methods begin with the words
"add" and "remove" and end
in "Listener". These methods are always
passed a java.util.EventListener
object. The methods are typically defined in pairs,
so the pairs are listed together. The methods are
listed alphabetically by event name, rather than by
method name.
-
Property Accessor Methods
-
Lists the public instance methods that set or query
the value of a property or attribute of the class.
The names of these methods begin with the words
"set", "get", and
"is", and their signatures follow the
patterns set out in the JavaBeans specification.
Although the naming conventions and method signature
patterns are defined for JavaBeans, classes and
interfaces throughout the Java platform define
property accessor methods that follow these
conventions and patterns. Looking at a class in terms
of the properties it defines can be a powerful tool
for understanding the class, so property methods are
grouped together in this section.
Property accessor methods are listed alphabetically by
property name, not by method name. This means that
the "set", "get", and
"is" methods for a property all appear
together. This book defines a property accessor
method in a somewhat more general way than the
JavaBeans specification does. A method is considered
to be a property accessor if it follows the JavaBeans
conventions itself or if it has the same name as a
method that follows those conventions. Consider the
setSize() method of the
Component class. There are two
versions of this method, and, since they have the same
name, they obviously share a purpose and deserve to be
grouped together. However, only one version of the
method strictly follows the JavaBeans signature
patterns. The relaxed definition of what constitutes
a property accessor method allows these two methods to
be listed together, as they should be.
-
Public Instance Methods
-
Contains all of the public instance methods that are not
grouped elsewhere.
-
Implementing Methods
-
Groups the methods that implement the same
interface. There is one subgroup for each interface
implemented by the class. Methods that are
defined by the same interface are almost always
related to each other, so this is a useful functional
grouping of methods.
Note that if an interface method is also an event
registration method or a property accessor method, it
is listed both in this group and in the event or
property group. This situation does not arise often,
but when it does, all of the functional groupings are
important and useful enough to warrant the duplicate
listing. When an interface method is listed in the
event or property group, it displays an
"Implements:" flag that specifies the
name of the interface of which it is part.
-
Overriding Methods
-
Groups the methods that override methods of a
superclass broken down into subgroups by
superclass. This is typically a useful grouping,
because it helps to make it clear how a class modifies
the default behavior of its superclasses. In practice,
it is also often true that methods that override the
same superclass are functionally related to each
other.
Sometimes a method that overrides a superclass is also
a property accessor method or (more rarely) an event
registration method. When this happens, the method is
grouped with the property or event methods and
displays a flag that indicates which superclass it
overrides. The method is not listed with other
overriding methods, however. Note that this is
different from interface methods, which, because they
are more strongly functionally related, may have
duplicate listings in both groups.
-
Protected Instance Methods
-
Contains all of the protected instance methods that are not
grouped elsewhere.
-
Fields
-
Lists all the non-constant
fields of the class, breaking them down
into subgroups for public and protected static fields
and public and protected instance fields. Many classes
do not define any publicly accessible fields. For
those that do, many object-oriented programmers prefer
not to use those fields directly, but instead to use
accessor methods when such methods are available.
-
Deprecated Members
-
Deprecated methods and deprecated fields are grouped at
the very bottom of the class synopsis. Use of these
members is strongly discouraged.
2.4. Class Hierarchy
For any class or interface that has a non-trivial
class hierarchy, the class synopsis is followed by a Hierarchy section. This section lists all
of the superclasses of the class, as well as any interfaces
implemented by those superclasses. It may also list any
interfaces extended by an interface. In the hierarchy listing,
arrows indicate superclass to subclass relationships, while the
interfaces implemented by a class follow the class name in
parentheses. For example, the following hierarchy indicates
that java.awt.AWTException extends
Exception which extends
Throwable (which implements
Serializable) which extends
Object:
Object-->Throwable(Serializable)-->Exception-->AWTException
If a class has subclasses, the "Hierarchy" section is followed by a
"Subclasses" section that lists
those subclasses. If an interface has implementations, the
"Hierarchy" section is followed by
an "Implementations" section that
lists those implementations. While the "Hierarchy" section shows ancestors of the
class, the "Subclasses" or
"Implementations" section shows
descendants.
2.5. Cross References
The class hierarchy section of a quick-reference entry is
followed by a number of optional "cross reference"
sections that
indicate other, related classes and methods that may be of
interest. These sections are the following:
-
Passed To
-
This section lists all of the methods and constructors
that are passed an object of this type as an argument.
This is useful when you have an object of a given type
and want to figure out what you can do with it.
-
Returned By
-
This section lists all of the methods (but not
constructors) that return an object of this type. This is
useful when you know that you want to work with an object
of this type, but don't know how to obtain one.
-
Thrown By
-
For checked exception classes, this section lists all of
the methods and constructors that throw exceptions of this
type. This material helps you figure out when a given
exception or error may be thrown. Note, however, that
this section is based on the exception types listed in the
throws clauses of methods and
constructors. Subclasses of
RuntimeException
and Error do not have to be
listed in throws clauses, so it is not
possible to generate a complete cross reference of methods
that throw these types of unchecked exceptions.
-
Type Of
-
This section lists all of the fields and constants that
are of this type, which can help you figure out how to
obtain an object of this type.
2.6. A Note About Class Names
Throughout the quick reference, you'll notice that classes are
sometimes referred to by class name alone and at other times
referred to by
class name and package name. If package names were always used,
the class synopses would become long and hard to read. On the
other hand, if package names were never used, it would sometimes
be difficult to know what class was being referred to. The
rules for including or omitting the package name are complex.
They can be summarized approximately as follows, however:
-
If the class name alone is ambiguous, the package
name is always used.
-
If the class is part of the java.lang
package or is a very commonly used class like
java.io.Serializable or
java.awt.Component, the package
name is omitted.
-
If the class being referred to is part of the current package
(and has a quick-ref entry in the current chapter), the
package name is omitted. The package name is also omitted
if the class being referred to is part of a package that
contains the current package.
| | |
Finding a Quick Reference Entry | | 8. The java.applet Package |
Copyright © 2001 O'Reilly & Associates. All rights reserved.
|