Class 1, Part 2 |
Intro to Java 30-IT-396 |
|
Packages
-
You can store your classes in a package for easier use.
-
Think of packages as a library.
-
A package name directly corresponds to a directory name. Each directory
name is separated by a period.
-
You import packages when you need a class or classes that reside in that
package.
-
You can either import the entire package, or specify the class or classes
you wish to import individually.
-
Remember import javax.swing.*; or import javax.swing.JOptionPane;
when we used the JOptionPane class?
-
Using the * imports all of the classes that reside in that package,
but not all of the packages that reside in that package. You need
to specify them separately.
-
By default, a class can use any other public classes from its own package.
-
You are permitted to have classes with the same name in different packages.
This is the only way you can have classes of the same name.
-
Having classes of the same name is generally not a good idea.
-
If you need both of them in your program, you must specify the package
name each time you use them.
-
Example: java.util.Date and java.sql.Date are two different
classes of the same name.
-
To guarantee uniqueness, it is often advisable to use your domain name
in reverse.
-
package edu.uc.oz.jonesbr would be a good starting package for
me.
More About Packages


Created by: Brandan
Jones January 4, 2002