Chapter 7: Package and Interface
6-2
Outline
Package
Interfaces
3-3
Class Libraries
A class library is a collection of classes that we can use when developing programs
The Java standard class library is part of any Java development environment
Its classes are not part of the Java language, but we rely on them heavily
Various classes we've already used (System , Scanner, String) are part of the Java standard class library
Other class libraries can be obtained through third party vendors, or you can create them yourself
3-4
Packages
The classes of the Java standard class library anized into packages
Some of the packages in the standard class library are:
Package
Purpose
General support
Creating applets for the web
Graphics and graphical user interfaces
Additional graphics munication
Utilities
XML document processing
3-5
The import Declaration----use classes from a package
When you want to use a class from a package, you could use its fully qualified name
Or you can import the class, and then use just the class name
import ;
To import all classes in a particular package, you can use the * wildcard character
import .*;
3-6
The import Declaration
All classes of the package are imported automatically into all programs
It's as if all programs contain the following line:
import .*;
That's why we didn't have to import the System or String classes explicitly in earlier programs
The Scanner class, on the other hand, is part of the package, and therefore must be imported
Define Packages
A way of grouping and naming a collection of related classes
they do not have to be in the same directory as your program
The first line of each class in the package must bethe keyword package followed by the name of the package:package ;
Package Naming Conventions
Use lowercase
The name is the file pathname with
java课件——第7章 来自淘豆网m.daumloan.com转载请标明出处.