Core Java Tutorial


Total available pages count: 51
Subject - Java Technologies

Packages

A package is a group of similar datatypes of classes, sub-packages, and interfaces. It can be categorized in two forms: user-defined package and built-in package.

There are some built-in packages such ad java, awt, lang, javax, net, io, swing, util ,sql etc. Packages used to categorize the interface and class so that it can be easily maintained. It provides access protection and removes the naming collision.

Java_Packages

Three ways we can access the package from outside,

  • Import package. * ;
  • Import package.classname;
  • Fully qualified name

When we use package.* then it means all classes and interfaces of the same package will be accessible except sub-packages. the import keyword is used to make the class and interface of another package accessible to the active package.
When we use package. the class name then it means only declares class of the same package will be accessible.
In sense of a fully qualified name, it only declared class of the same package will be accessible. There no requirement to import any class.it usually used when two packages have the same class name. for example java. util & java.sql package that contains date class.

Package_Import_Class


Comments