Java contains many packages which are basically some predefined classes grouped into categories of related classes.
Java API stands for Java applications programming interface, also known as the Java class library.
In your code, import statements specify the classes required to compile a Java program.
For example when using:
import javax.awt.event; |
you tell the compiler to load the event class from the javax.awt package.
One of the great things about Java is the large number of classes in the packages of the Java API that programmers can reuse.
We gathered a subset of the many packages in the Java API and tried to provide a brief description of each package.
When learning Java, you should spend time reading the descriptions of the packages and classes in the Java API documentation, just because of the large number and the variety of reusable components available in the Java API.
| Package | Description |
| java.applet | The Java Applet Package. This package contains the Applet class and several interfaces that enable the creation of applets, interaction of applets with the browser and playing audio clips. |
| java.awt | The Java Abstract Windowing Toolkit Package. This package contains the classes and interfaces required to create and manipulate graphical user interfaces. |
| java.awt.event | The Java Abstract Windowing Toolkit Event Package. This package contains classes and interfaces that enable event handling for GUI components in both the java.awt and javax.swing packages. |
| java.io | The Java Input/Output Package. |
| java.lang | The Java Language Package. |
| java.net | The Java Networking Package. |
| java.text | The Java Text Package. |
| java.util | The Java Utilities Package. |
| javax.swing | The Java Swing GUI Components Package. This package contains classes and interfaces for Java's Swing GUI components that provide support for portable GUIs. |
| javax.swing.event | The Java Swing Event Package. This package contains classes and interfaces that enable event handling for GUI components in the javax.swing package. |
The core packages in J2SE 6.0 are:
In Java source files, you specify the package you want to use with the 'package' keyword.
For us to use a package inside a Java program, we should first import the classes from the package with an 'import' statement.
By using the statement :
we tell the compiler to import all the classes from the java.awt.event package, while when using :
it only imports the ActionEvent class from the package. After either of these import statements, the ActionEvent class can be referenced using its simple class name:
Classes can also be used directly without an import statement by using the fully-qualified name of the class. For example,
doesn't require a preceding import statement.
Nobody posted any comments regarding this story. Be the first!
Discuss