Chapter 3.4
Chapter 3.4
Mr. R. M. Patil
SY CO, JPR
2023-2024
3.4. Java Package
A java package is a group of similar types of classes,
interfaces and sub-packages.
Packages are used for:
1. Preventing naming conflicts. For example there can be two classes
with name Employee in two packages, college.staff.cse.Employee
and college.staff.ee.Employee
2. Making searching/locating and usage of classes, interfaces,
enumerations and annotations easier
3. Providing controlled access: protected and default have package
level access control. A protected member is accessible by classes in
the same package and its subclasses. A default member (without
any access specifier) is accessible by classes in the same package
only.
4. Packages can be considered as data encapsulation (or data-hiding).
3.4. Java Package
3.4. Java Package
3.4. Java Package – Types of Package
3.4. Java Package – Types of Package 1. Built in Package
The Java API is a library of prewritten classes, that are free
to use, included in the Java Development Environment.
Applet.
3.4. Java Package – Types of Package 2. User Defined Package
class demo
{
public static void main(String[] args)
{
System.out.println(Math.sqrt(4));
System.out.println(Math.pow(2, 2));
System.out.println(Math.abs(6.3)); Output:
} 2.0
} 4.0
6.3
3.4. Static import
// Java Program to illustrate calling of predefined methods with static import
package Mypack;
interface base
{
public void msg();
}
Homework - 18
1. What is Package? W14,S15,W15,S17,W17 – 2M
2. List any four built-in packages from java API along with their
use. S17,W17,S15,W15 – 4M