A package is a collection of similar types of classes, interfaces, and sub-packages.
Purpose of package
The purpose of the package concept is to provide common classes and interfaces for any program separately. In other words,
if we want to develop any class or interface which is common for most of the java programs then such common
classes and interfaces must be placed in a package.
Packages in Java are the way to organize files when a project has many modules. Same like we organized our files on Computer.
For example, we store all movies in one folder and songs in another folder, here also store the same type of files in a particular
package for example in awt package has all classes and interfaces for design GUI components.
Advantage of package
- The package is used to categorize the classes and interfaces so that they can be easily maintained
- Application development time is less because reuse the code
- Application memory space is less (main memory)
- Application execution time is less
- Application performance is enhanced (improve)
- Redundancy (repetition) of code is minimized
- The package provides access protection.
- Package removes naming collision.
Type of package
Package are classified into two types which are given below.
- Predefined or built-in package
- User-defined package
Predefined or built-in package
These are the package that is already designed by the Sun Microsystem and supply as a part of Java API, every predefined package is collection of predefined classes, interfaces, and sub-package.
User-defined package
If any package is designed by the user is known as a user-defined package. User-defined packages are those which are developed by java programmers and supply as a part of their project to deal with common requirements.
Rules to create user-defined package
- package statement should be the first statement of any package program.
- Choose an appropriate class name or interface name and whose modifier must be public.
- Any package program can contain only one public class or only one public interface but it can contain any number of normal classes.
- Package program should not contain any main class (that means it should not contain any main())
- modifier of constructor of the class which is present in the package must be public. (This is not applicable in the case of interface because the interface has no constructor.)
- The modifier of a method of class or interface which is present in the package must be public (This rule is optional in case of interface because interface methods by default public)
- Every package program should be saved either with the public class name or public Interface name.
- Progamming is what actually means ?
- What is software development ?
- How we categorized software development in different manner.
C Plus Plus
Python
Java Development
Web Designing
Javascript
Mysql
Oracle