Java Packages
Java Packages:
A Java Package is a simple kind of a folder which contain a similar kind of classes, Suppose a classes which are belongs to some functionality will be there in one package the other classes which are belongs to other functionality belongs to other packages. And later if you want to get that class in some other class we will refer that class by using Package Name, So a Java Package is a collection of classes,Interfaces or some files.
In realTime the PackageName are like com.ProjectName.CompanyName like this .
So If there are two packages with classes:
Package1 {classA, classB,….} & Package2{classX, classY,….}: To access classA from Package2 we need Import & extend keywords
Syntax: Import PackageName.className;
classX extend classA
{
// here we can use classA
}
How to create Sub-Package:
Right click on parent package and click on New—>Package: give name as
“Parent-PackageName.Sub-PackageName” and Finish.
These are two different Packages:
1) userDefined Packages:Packages created by user.
2) Built-in Packages: we can get this class by using Import keyword at the beginning of the program .
It's very Helpful thank you very much.
ReplyDelete