The package Statement in Java Programming
Previous | Home | Next |
A Java package is a mechanism for organizing Java classes into namespaces similar to the modules of Modula.
Java packages can be stored in compressed files called JAR files, allowing classes to download faster as a group rather than one at a time. Programmers also typically use packages to organize classes belonging to the same category or providing similar functionality.
A package provides a unique namespace for the types it contains.
Classes in the same package can access each other's package-access members.
In a Java source file, the package that this file's class or classes belong to is specified with the package keyword.
This keyword is usually the first keyword in source file
To use a package's classes inside a Java source file,
it is safe to import the classes from the package with an import declaration.
import java.awt.event.|*;
how to create a packagepackage com.mycompany.myproject;
import java.util.*;
class MyClass {
}
java.lang — for basic language functionality and fundamental types
java.util — for collection data structure classes
javax.swing — for hierarchy of packages for platform-independent rich GUI components
java.math — for multiprecision arithmetics
java.sql — for Java Database Connectivity (JDBC) to access databases
java.net — for networking operations, sockets, DNS lookups, ...
java.security — for key generation, encryption and decryption
java.applet — for classes for creating an applet
java.awt — for basic hierarchy of packages for native GUI components
java.io — for file operations
Previous | Home | Next |