Java Reference
In-Depth Information
class Date1 {
public static void main(String[] args) {
java.util.Date now = new java.util.Date();
System.out.println(now);
}
}
And here is a version that uses import to declare the type Date :
import java.util.Date;
class Date2 {
public static void main(String[] args) {
Date now = new Date();
System.out.println(now);
}
}
When the compiler comes to the declaration of now it determines that
the Date type is actually the java.util.Date type, because that is the only
Date type it knows about. Import statements simply provide information
to the compiler; they don't cause files to be "included" into the current
file.
The name collision problem is not completely solved by the package
mechanism. Two projects can still give their packages the same name.
This problem can be solved only by convention. The standard convention
is to use the reversed Internet domain name of the organization to pre-
fix the package name. For example, if the Acme Corporation had the
Internet domain acme.com , it would use package names starting with
com.acme , as in com.acme.tools .
Classes are always part of a package. A package is named by providing
a package declaration at the top of the source file:
 
Search WWH ::




Custom Search