MY mENU


Friday 10 February 2012

Packages in Java


Package is a namespace that contains a set of related classes and interfaces.

Basic Packages :

java.lang : Fundamental classes are presnt in this package.
java.io : classes for reading and writing (input and output) are presnt in this package.

For Example:

Library is a package with collection of maths and science and social books.

Creating Package:
                                 To create a Package, you choose a name for the Package (i.e., naming conventions) and put a Package statement with that name at the top of every source file that contains the types (classes, interfaces) that you want to include in the Package.

The package statement must be the first line in the source file. There can be only one package statement in each source file.

Example 
:

package Library;
Class Maths
{
----
----
}

To create a Package we execute this Class with javac command like as

javac - d . Maths.java

No comments:

Post a Comment