1.

Advantages of Packages in Java

Answer»

A package in Java is a group of different sub-packages, interfaces, classes etc. that are of a similar type. The two types of packages are build-in packages and user defined packages. Some of the build-in packages are awt, swing, lang, util. javax, SQL etc.

Some of the advantages of packages in Java are given as follows:

  1. Packages are quite USEFUL as they group together similar sub-packages, interfaces, classes etc. This helps the programmers to understand which of the enumerations, sub-packages, annotations, interfaces, classes etc. are related.
  2. Related classes in Java can be easily located using Packages.
  3. Access Control can be provided easily using packages.
  4. Individual packages can be defined by programmers to group together enumerations, sub-packages, annotations, interfaces, classes etc.
  5. There are no name conflicts with names in other packages as a package creates a new namespace.

A PROGRAM that demonstrates a package in Java is given as follows:

package packageExample; public class Demo {   public static VOID main(String args[]) {      System.out.println("This is a package example");   }   }

The OUTPUT of the above program is as follows:

This is a package example


Discussion

No Comment Found