Java Reference
In-Depth Information
Chapter 7 describes the structure of a program, which is organized into packages similar
to the modules of Modula. The members of a package are classes, interfaces, and subpack-
ages. Packages are divided into compilation units. Compilation units contain type declara-
tions and can import types from other packages to give them short names. Packages have
names in a hierarchical name space, and the Internet domain name system can usually be
used to form unique package names.
Chapter 8 describes classes. The members of classes are classes, interfaces, fields (vari-
ables) and methods. Class variables exist once per class. Class methods operate without
reference to a specific object. Instance variables are dynamically created in objects that are
instances of classes. Instance methods are invoked on instances of classes; such instances
become the current object this during their execution, supporting the object-oriented pro-
gramming style.
Classes support single implementation inheritance, in which the implementation of each
class is derived from that of a single superclass, and ultimately from the class Object . Vari-
ables of a class type can reference an instance of that class or of any subclass of that class,
allowing new types to be used with existing methods, polymorphically.
Classes support concurrent programming with synchronized methods. Methods declare the
checked exceptions that can arise from their execution, which allows compile-time check-
ing to ensure that exceptional conditions are handled. Objects can declare a finalize method
that will be invoked before the objects are discarded by the garbage collector, allowing the
objects to clean up their state.
For simplicity, the language has neither declaration “headers” separate from the implement-
ation of a class nor separate type and class hierarchies.
A special form of classes, enums, support the definition of small sets of values and their
manipulation in a type safe manner. Unlike enumerations in other languages, enums are
objects and may have their own methods.
Chapter 9 describes interface types, which declare a set of abstract methods, member types,
and constants. Classes that are otherwise unrelated can implement the same interface type.
A variable of an interface type can contain a reference to any object that implements the
interface. Multiple interface inheritance is supported.
Annotation types are specialized interfaces used to annotate declarations. Such annotations
are not permitted to affect the semantics of programs in the Java programming language in
any way. However, they provide useful input to various tools.
Search WWH ::




Custom Search