Java Assignment 2
Java Assignment 2
package com.example.mypackage;
3. Naming Conventions
4. Types of Packages
a. System Packages
System packages are built-in packages that are provided by Java. They
contain classes and interfaces that are commonly used in Java
programming. Some of the commonly used system packages in Java
include:
ii. java.util: This package contains utility classes and interfaces that are used
to handle data structures, such as lists, sets, and maps.
iii. java.io: This package contains classes and interfaces that are used for
input and output operations, such as reading and writing files.
iv. java.net: This package contains classes and interfaces that are used for
networking operations, such as connecting to servers and sending data
over the internet.
import java.util.*;
b. User-defined Packages
i. Defining a Package
i. Defining a Package
package com.example.mypackage;
Once the package has been defined, it can be used to group related classes
and interfaces.
Once the class has been defined within the package, it can be used within
other classes or programs that import the package.
For example, the following code defines a class called "MyClass" that is
marked as "private" within the "com.example.mypackage" package:
package com.example.mypackage;
Classes that are marked as "private" can only be accessed within the same
package, and they cannot be imported or used by other classes outside of
the package.
Conclusion: