Scope determines where variables, methods, and other symbols are visible in a program. Outside of a symbol’s scope, the symbol is not visible at all and cannot be used. We’ll go over the major aspects of scope in this section, starting with the highest level.
Java packages provide a mechanism for grouping related types together in a universally unique namespace. Such grouping prevents identifiers within the package namespace from colliding with those created and used by other developers in other namespaces.
A typical Java program is made up of code
from a forest of packages. The standard Java Runtime Environment
supplies packages like
java.util. In addition, the
program may depend on other common libraries like those in the
org.apache tree. By convention,
application code—code you create—goes into a package whose name is
created by reversing your domain name and appending the name of the
program. Thus, if your domain name is
the root of your package tree will be
and you will put your code into packages like
com.androidhero.geohottness.service. A typical package
layout for an Android application might have a package for
persistence, a package for the UI, and a package for application
logic or controller code.
In addition to providing a unique namespace, packages have implications on member (field and method) visibility for objects in the same package. Classes in the same package may ...