You are on page 1of 11

 From

 K.Anjani prasad

cse 3rd year


Indur college
&

T.Rahul reddy
Cse 3rd year
Indur college
Packages

Defination of Package
Use of import statement
Advantage of Package
Types of packages
Built in packages
User defined packages
What is Package ?

 Way to group a related class and interface into


one unit
 To resolve the name conflicts between class
names
Use of import Statement

import
import packageName.className
packageName.className;;

 Include all the classes in package


 import packageName.*;

import
import java.io.*;
java.io.*;
Advantages of packages

 Grouping related classes and interface.


 Accidental deletion of class and interfaces
doesn’t take place.
 The classes and interfaces of a package are
isolated from the classes and interfaces of
another package.
 Reusability nature of package
Types of packages

 There are two different types of packages in


java:-
 1.User-defined packages.
 2.Built-in packages.
Built in packages

Some of the built in packages are:-

 Java.lang
 Java.io
 Java.awt
 Javax.swing
 Java.net
 Java.applet
 Java.util
User defined packages

 The users of the java language can also


create their own package.

 Declaration of a userdefined package


 package packagename;
 Ex:-package pack;
 The above statement create a directory
with the given package name we can add
classes and interfaces to this directory.
Adding new classes to
userdefined packages

A new class substraction can add to the userdefined


pakcage pack as follows
package pack;
public static substraction
{
public static double sub(double
a,double b)
{
return (a-b);
}
}

You might also like