The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
To make types easier to find and use, to avoid naming conflicts, and to control access, programmers bundle groups of related types into packages.为了使类型更易于查找和使用,避免命名冲突,并控制访问,程序员将相关类型的组捆绑到包中。
The types that are part of the Java platform are members of various packages that bundle classes by function: fundamental classes are in 作为Java平台一部分的类型是按函数捆绑类的各种包的成员:基本类在java.lang
, classes for reading and writing (input and output) are in java.io
, and so on. Java.lang
中,用于读写(输入和输出)的类在Java.io
中,等等。You can put your types in packages too.您也可以将类型放入包中。
Suppose you write a group of classes that represent graphic objects, such as circles, rectangles, lines, and points. 假设您编写了一组表示图形对象的类,例如圆、矩形、直线和点。You also write an interface, 您还编写了一个接口Draggable
, that classes implement if they can be dragged with the mouse.Dragable
,如果可以用鼠标拖动类,则类将实现该接口。
//in the Draggable.java file public interface Draggable { ... } //in the Graphic.java file public abstract class Graphic { ... } //in the Circle.java file public class Circle extends Graphic implements Draggable { . . . } //in the Rectangle.java file public class Rectangle extends Graphic implements Draggable { . . . } //in the Point.java file public class Point extends Graphic implements Draggable { . . . } //in the Line.java file public class Line extends Graphic implements Draggable { . . . }
You should bundle these classes and the interface in a package for several reasons, including the following:出于以下几个原因,您应该将这些类和接口捆绑在一个包中: