Packages in java


As the name goes it quite obvious that, Packages are collection of set or collection of something that are of same type. They are invoked in the first line of code.

There are basically two types of packages.

Type 1: Built in type or system defined.
Type 2: User defined or customized version.

What can be done with packages in JAVA.

1.It can be used to categorize and maintain the classes that are used frequently.
2.It helps in providing ACCESS protection and removes NAMING collision.

HOW TO USE packages:
Packages can be considered as a per-structured frame layout which contains many classes that  a user can invoke by calling in the initial lines of the code.There is basically two ways in which a package can be imported.

1.By using –import java.util.Arrays; —  this line imports the necessary settings needed for creating arrays, while this line of code imports ONLY the settings that are required to build array.

2.By using — import java.util.*; — imports the complete package.

The optimized way of using packages are  by importing only the the required class i.e., by using the 1st method, as it makes the program lightweight and fast.

Leave a comment