What is a package?
A package is a directory that contains related groups of classes and interfaces. Packages hides its class and interfaces in a separate directory.
A package is a kind of directory that contains a group of related classes and interfaces. Java has many such packages it its library. If you want to use a classes, you have to import it into your program. If you want to use a method, then you have to import the corresponding class or interface.
A group of package is called library. Any class and interface inside a package is reusable.
When a package is imported, its sub packages are not automatically imported into a program. A separate import statement should be written to for every package or sub package
Java library
|
Packages
|
Classless and interfaces
|
methods
There are two different types of pacakges
1. build-in
2. User defined
Build -in Packages
Build -in packages are already available in Java. these pacakes provide all necessary classes, interfaces and methods to perform tasks. Some important packages are:
java.lang: This package has primary classes and interfaces for developing a basic Java program.
java.util: It has many useful collections. Date, time operations, victors...
java.awt:awt stands for Abstract Window Toolkit.Tis pacakge is useful for develiping GUI-color, paintings, images etc.It consists one important sub-package java.awt.event . It provides actions like select radio button, menu.
javax.swing: Helpful for GUI. It is an extended package of java,awt(package developed from another package by adding new features). 'x' represents it as an extended package.
java.net: Useful for authentication for network, creating sockets, to establish communication between client-server.
java.applet: Related to Java applets.
java.text: It contains two important classes. 'DateFormat' is to format date and time. 'Numberformat' is to format numeric values.
java.sql: Helps to connects to the database like oracle, retrieve and use data in Java program.
User-Defined Package:
Package created by user. User defined package can be used exactly same way as the build-in package.
The keyword to create a package is package.