Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
With programmers all over the world writing classes, interfaces, enums and annotations using the Java programming language, it is likely that two programmers will use the same name for two different classes. In fact, the previous example does just that: It defines aRectangle
class when there is already aRectangle
class in thejava.awt
package. Yet the compiler allows both classes to have the same name. Why? Because they are in different packages, and the fully qualified name of each class includes the package name. That is, the fully qualified name of theRectangle
class in thegraphics
package isgraphics.Rectangle
, and the fully qualified name of theRectangle
class in thejava.awt
package isjava.awt.Rectangle
.This generally works just fine unless two independent programmers use the same name for their packages. What prevents this problem? Convention.
By Convention: Companies use their reversed Internet domain name in their package names, like this:com.company.package
. Name collisions that occur within a single company need to be handled by convention within that company, perhaps by including the region or the project name after the company name, for example,com.company.region.package
.
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.