0% found this document useful (0 votes)
13 views

Java Lec-27 Package - Dbaf88a

The document discusses packages in Java. Packages allow organization of Java files into directories and help avoid naming conflicts. They provide maintenance of large projects with many files, reusability of common code, and access protection. There are predefined packages developed by Sun Microsystems and user-defined packages containing custom classes and interfaces. Packages are a physical folder structure that groups related classes and interfaces according to functionality.

Uploaded by

Dnyanesh Chopade
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Java Lec-27 Package - Dbaf88a

The document discusses packages in Java. Packages allow organization of Java files into directories and help avoid naming conflicts. They provide maintenance of large projects with many files, reusability of common code, and access protection. There are predefined packages developed by Sun Microsystems and user-defined packages containing custom classes and interfaces. Packages are a physical folder structure that groups related classes and interfaces according to functionality.

Uploaded by

Dnyanesh Chopade
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Course: Java Programming, Prepared By: Atul Kabra, 9422279260

Java Lecture-27
Topic: Packages

Package
 In small projects, all the java files have unique names. So, it is not difficult
to put them in a single folder.

 But, in the case of huge projects where the number of java files is large, it is
very difficult to put files in a single folder because the manner of storing
files would be disorganized.

 Moreover, if different java files in various modules of the project have the
same name, it is not possible to store two java files with the same name in
the same folder because it may occur naming conflict.

 This problem of naming conflict can be overcome by using the concept of


packages.

 In Java, APIs consist of one or more packages where packages consist of


many classes, classes contain several methods and fields.

Package in Java
 A package is nothing but a physical folder structure (directories) that
contains a group of related classes, interfaces, and sub-packages according
to their functionality.

 It provides a convenient way to organize your work. The Java language has
various in-built packages.

 For example, java.lang, java.util, java.io, and java.net. All these packages
are defined as a very clear and systematic packaging mechanism for
categorizing and managing.

Course: Java Programming, Info Planet Programming Classes Prepared By: Atul Kabra, 9422279260
Course: Java Programming, Prepared By: Atul Kabra, 9422279260

Advantage of using packages in Java


1. Maintenance: Java packages are used for proper maintenance. If any
developer newly joined a company, he can easily reach to files needed.

2. Reusability: We can place the common code in a common folder so that


everybody can check that folder and use it whenever needed.

3. Name conflict: Packages help to resolve the naming conflict between


the two classes with the same name. Assume that there are two classes
with the same name Student.java. Each class will be stored in its own
packages such as stdPack1 and stdPack2 without having any conflict of
names.

4. Organized: It also helps in organizing the files within our project.

5. Access Protection: A package provides access protection. It can be used


to provide visibility control. The members of the class can be defined in
such a manner that they will be visible only to elements of that package.

Types of Packages in Java


There are two different types of packages in Java. They are:
1. Predefined Packages in Java (Built-in Packages)
Predefined packages in java are those which are developed by Sun
Microsystem. They are also called built-in packages in java. These
packages consist of a large number of predefined classes, interfaces, and
methods that are used by the programmer to perform any task in his
programs.

2. User-defined Package
The package which is defined by the user is called a User-defined
package. It contains user-defined classes and interfaces.

Course: Java Programming, Info Planet Programming Classes Prepared By: Atul Kabra, 9422279260

You might also like