Introduction about packages:-
- Package is nothing but it is folder.
- In java we use packages for better Maintains of the application, project search easily.
- Every package can have direct classes or it can have again package (sub packages).
- To access any member (instance variable, instance method etc) outside the package but the member should be public.
- Within package we no need to import class of the package.
- * will import all the class which is directly under the package (not a sub package).
- We can’t import more than same java file having the different package.
- All 3000+ inbuilt java class. Modularizes many packages.
- Ex. - java.lang.*;
- -java.sql.*;
- - java.io.*;
- - java.util.*;
- - java.awt.*;
- All the class which is under java.lang package will be available implicitly and we don’t have to import.
- Package declaration must be first executable statement.
- De-referred object which are present in heap will be collected by Garbage Collector and re-uses memory.
- When object in which is present in heap can have multiple reference.
- But single reference can refer or point to only one object at same time or given time.
- When an instance is of primitive Data type that is called as HAS-A Relationship.
- When an instance of variable is non-primitive data type that is called as Association Relationship.
Example
9:- Package
public class Person{
// instance variable
int
age=25; //HAS-Relationship
String name="JNext Training &
Development !!!!!! SUPER"; // Association Relationship
Mobile m; //Association Relationship
// some
Method
}
public class Mobile
{
double price; //HAS-Relationship
String company_name; // Association
Relationship
// some method }