Java Reference
In-Depth Information
Naming Packages (continued)
For example, Wiley Publishing's Web site URL is www.wiley.com. If you write a Vehicle class
as an employee of Wiley, your package name would be similar to:
package com.wiley.rich;
public class Vehicle
{
//Your Vehicle class
}
I work for a company whose Web site is www.javalicense.com. The package name for
my Vehicle class would include com.javalicense:
package com.javalicense.rich;
public class Vehicle
{
//My vehicle class
}
Even though we both picked rich as part of our package name, the two Vehicle classes
no longer have a naming conflict. One of the classes is named com.javalicense.rich.Vehicle,
and the other is named com.wiley.rich.Vehicle.
Many of the packages in the J2SE begin with java, to denote their role in the standard
Java language. Most of the packages in the J2EE APIs begin with javax in the their name,
such as javax.servlet and javax.ejb. The “x” is for extension, denoting that the package is an
extension of the Java language.
The import Keyword
If a class wants to use another class in the same package, the package name
does not need to be used. Classes in the same package “find each other” with-
out any special syntax.
For example, suppose a class named Boss is added to the payroll package
that already contains Employee. The Boss can then refer to the Employee class
without using the payroll prefix, as demonstrated by the following Boss class.
package payroll;
public class Boss
{
public void payEmployee(Employee e)
{
e.mailCheck();
}
}
Search WWH ::




Custom Search