How Java Package is useful

As we know each component of Java has special feathers. Among all Package is one of them, which is a collection of classes and interfaces grouped together as a logic unit.

There are some special feathers that a package holds. Such as:

Abstraction:
While developing large Java software we will arrange classes in a logical in a package. This can be achieved using Package. Actually we group the bunch of classes and interfaces together in a package but we behave it as a unit. For example we have imported java.util, java.awt etc many times.

Protection:
The use of package in java allows choosing which classes may be used outside the package and which one can’t. We may also give the class protection to be access and method protection to be overridden.

There are four level of protection :

  1. Public
  2. Default (friendly)
  3. Protected
  4. Private

This can be represented in package as shown in table:

Access is available to:

public

protected

default

private

All Classes

X

     

All Subclasses

X

X

   

Classes in the Same Package

X

X

X

 

The Class Itself

X

X

X

X

Convenience:
Convenience to work on team, using package programmers doesn’t need to bother about arranging and giving the name.

Name Space Control:
Two classes can have same name if they are in different package, which make programmers to not to concerned about using name already used in other package.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: