0% found this document useful (0 votes)
5 views2 pages

Experiment 5

Uploaded by

sheetdbtest2202
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Experiment 5

Uploaded by

sheetdbtest2202
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Anish Dharnidhar AI & DS Batch S23 Roll no : 129

Aim: Programs demonstrating packages (LO2)

Theory
A package in Java is a namespace that organises a set of related classes and interfaces.
Packages serve several important functions:
• Organisation: They help in organising classes and interfaces into a namespace, making it
easier to locate and use them.
• Access Control: They provide access protection to the classes and their members. For
example, classes within the same package can access each other's package-private
members.
• Avoiding Name Conflicts: Packages prevent name conflicts. For example, you can have
two classes with the same name in different packages.

Types of Packages
There are two main types of packages in Java:
• Built-in Packages: These are predefined packages that come with the Java API. For
example:
o java.util: Contains the collections framework, legacy collection classes, event model,
date and time facilities, and miscellaneous utility classes.
o java.io: Provides classes for system input and output through data streams,
serialisation, and file system operations.
o java.lang: Contains fundamental classes, such as String, Math, Integer, System, and
Thread, which are essential to Java programming.
• User-defined Packages: These are custom packages created by the programmer to
group related classes and interfaces together. For example:
o package myutils: Could contain utility classes like FileUtils, StringUtils, etc.

Code
Anish Dharnidhar AI & DS Batch S23 Roll no : 129

Output

You might also like