/* related posts with thumb nails */

packages in Java & its advantages:

In simple terms, package is a group of classes created in a unique directory. Upon importing a package in a program, we will be able to access the classes defined in that package.

Creating packages is way of achieving the reusability in Java, therefore, is to use packages. Packages are Java's way of grouping a variety of classes and/or interfaces together. The grouping is usually done according to functionality. With the help of packages, we can use classes from other programs without physically copying them into the program under development. Packages concept is similar to "class libraries" in other languages.

By organizing our classes into packages we achieve the following benefits:

1. The classes contained in the packages of other programs can be easily reused.

2. In packages, classes can be unique compared with classes in other packages. That is, two classes in two different packages can have the same name. They may be referred to by their name, comprising the package name and the class name.

3. Packages provide a way to "hide" classes thus preventing other programs or packages from accessing classes that are meant for internal use only.

4. Packages also provide a way for separating "design" from "coding". First we can design classes and decide their relationships, and then we can implement the Java code needed for the methods. It is possible to change the implementation of any method without affecting the rest of the design.

5. A package may have another sub package.

Related Topics:


Post a Comment