Java in detail: basic organizational structure July 25, 2008
Posted by crystalchangdin in education and career in Sweden.trackback
packages
Each package contains the definition of one or more closely related classes. A class defined in a particular package can make use of other classes defined in the same package. By default, classes defined in one package are not accessible (not visible) to classes defined in another package. (Such classes are sometimes called “packages private.”) We make a class accessible throughout the entire system by explicitly marking the class public. For example, if we wanted Room objects to be visible throughout the entire system but wanted Wall objects to be visible only within their package, we would define the classes as follows:
public class Room{…}
class Wall{…}
Finally, we hsould mention that one package can contain another package as a member. There is no semantic significance to this structure. A package’s classes are not more or less visible because the package is contained in another. However, the name of a package includes the name of a package of which it is a member. For example, the standard package javax includes as a member the package swing, which includes the package border. The actual name of this last package is javax.swing.border. This package contains a class LineBorder. So the fully qualified name of this class is
javax.swing.border.LineBorder
Compilation units
A package is made up of one or more files(compilation units), each containing the definition of one or more classes. The package statement at the beginning of the file determines the package that classes belong to. If the file does not contain a package statement, the classes belong to an “unnamed package”.
At most one class in a compilation unit can be public.
Comments»
No comments yet — be the first.