Documentation

The Java™ Tutorials
Hide TOC
Summary of Creating and Using Packages创建和使用包的小结
Trail: Learning the Java Language
Lesson: Packages
Section: Creating and Using Packages

Summary of Creating and Using Packages创建和使用包的小结

To create a package for a type, put a package statement as the first statement in the source file that contains the type (class, interface, enumeration, or annotation type).要为类型创建包,请将package语句作为包含该类型(类、接口、枚举或注释类型)的源文件中的第一条语句。

To use a public type that's in a different package, you have three choices: (1) use the fully qualified name of the type, (2) import the type, or (3) import the entire package of which the type is a member.要使用另一个包中的公共类型,您有三种选择:(1)使用类型的完全限定名,(2)导入类型,或(3)导入类型为其成员的整个包。

The path names for a package's source and class files mirror the name of the package.包的源文件和类文件的路径名镜像了包的名称。

You might have to set your CLASSPATH so that the compiler and the JVM can find the .class files for your types.您可能必须设置CLASSPATH,以便编译器和JVM能够找到您的类型的.class文件。


Previous page: Managing Source and Class Files
Next page: Questions and Exercises: Creating and Using Packages