A software package is used in object-oriented programming to name a group of related classes of a program. Packages are useful to measure and control the inherent coupling of a program.

In a modular program, even outside object-oriented programming, a software package may refer to any component (module) that can be integrated into the main program. Typically this is done by the end user in a well-defined interface. In other contexts the integration must occur at source code level of a given programming language.

Contents

Import

An example of a package is the java.io package which contains or groups together all the classes in the Java programming language that aid input and output of data, such as the buffered reader class which is used to accept user input from the keyboard. When a class is imported the user is free to use as if it were in their local directory.

A single class can be imported like so:

import java.io.BufferedReader;
import java.io.FileReader;
...
BufferedReader br = new BufferedReader(new FileReader("fooo.bar"));

A user can also import all classes within a package by adding replacing the class name with a *.

import java.io.*;
...
BufferedReader br = new BufferedReader(new FileReader("fooo.bar"));

Creating a package

Creating a package in java is as simple as placing related classes into one folder. The following package shows just how easy it is to create a package.

Consider having a group of painter classes which include classes like fencePainter, housePainter, carPainter, etc. It would be nice to organize all of these classes into one package, which we will call painter. All that needs to be done is to place all of these classes into a folder called painter. Once that is done, place the following line at the top of each class.

package painter;

Packages can also be organized further by putting then in subdirectories. In the previous example the painter package can be put in a worker package, by making it a subdirectory of a folder called worker. Then the following line of code can be added to add a class to this package.

package worker.painter;

References

External links

This computer science article is a stub. You can help Wikipedia by expanding it.

Categories: Computing terminology |

 

The above information uses material from Wikipedia and is licensed under the GNU Free Documentation License.
Some facts may not have been fully verified for accuracy. [Disclaimers]
This page was last archived by our server on Mon Sep 7 03:05:06 2009. [ refresh local cache ]
Displaying this page or its contents does not use any Wikimedia Foundation's resources.
The owners of this site proudly support the Wikimedia Foundation.