Java Reference
In-Depth Information
example, consider the statement System.out.println(2); . Static variable out
of class System is an instance of class PrintStream , which belongs to package
java.io , and println is a method of this class.
Package java.text Contains classes for formatting numbers.
Package java.util Contains a number of useful utilities, e.g. classes that repre-
sent dates, provide a Gregorian calendar, give methods for processing Strings
into “tokens”, provide dynamic arrays, and provide random numbers.
The Swing package, package javax.swing Provides replacements for some of
the GUI classes in package java.awt and introduces some new GUI classes.
For example, class javax.swing.JFrame is now used instead of class java.-
awt.Frame . See Chap. 17 for a discussion of writing GUIs in Java.
11.4
Key concepts
• Package. A package is a collection of files for Java classes —perhaps organ-
ized as subpackages— that reside in one directory on a hard drive.
• Package name. A package name is a suffix of the path-name on your comput-
er of the directory of the package. However, periods are used to separate com-
ponents on the path, not / or \.
• Class path. You can set variable CLASSPATH in your operating system to con-
tain some paths to directories that contain packages.
• Using a class in a package. To reference a class in a package, use the form
< package-name > . < class-name >. Some path in variable CLASSPATH catenated
with < package-name > must yield the actual path on your computer to the direc-
tory the package.
• Import statement. To remove the need to use the form < package-
name > . < class-name > everywhere in your program, use an import statement
import < package.name > .*; . Thereafter, you can just use < class-name >.
• Java packages. Java comes with hundreds of prewritten classes organized into
tens of packages. Package java.lang is automatically imported in every Java
program.
• Your packages. Your classes are placed in a default package. If you want to
place a class in another package, put a package statement on the first line of the
file for the class —then store the file in the appropriate directory.
 
Search WWH ::




Custom Search