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

JPL - Expt No.10 - Minor Manual

This document discusses user-defined packages in Java. It explains that packages are used to organize classes and interfaces, and that there are built-in and user-defined packages. To create a user-defined package, the package keyword is used along with specifying the destination directory for the class files using the -d switch with javac. User-defined packages must be executed using the fully qualified name. Packages provide benefits like reusability by allowing classes to be created and imported for reuse, better organization by grouping related classes, and avoiding name conflicts by defining classes with the same name in different packages.

Uploaded by

idon't have name
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)
65 views2 pages

JPL - Expt No.10 - Minor Manual

This document discusses user-defined packages in Java. It explains that packages are used to organize classes and interfaces, and that there are built-in and user-defined packages. To create a user-defined package, the package keyword is used along with specifying the destination directory for the class files using the -d switch with javac. User-defined packages must be executed using the fully qualified name. Packages provide benefits like reusability by allowing classes to be created and imported for reuse, better organization by grouping related classes, and avoiding name conflicts by defining classes with the same name in different packages.

Uploaded by

idon't have name
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

Subject: Java Lab Class: SE-IT

Semester: III A.Y. 2022-2023

Experiment No. 10
Aim : Write a Java Program to demonstrate user defined packages in java .
Software used : jdk 1.6.0
Theory :
➢ A package as the name suggests is a pack(group) of classes, interfaces and other
packages.

➢ In java we use packages to organize our classes and interfaces.


➢ We have two types of packages in Java:
built-in packages and

user defined package ( the packages we can create )

➢ There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql
etc.
for example when we need user input, we import a package like this:
import java.util.Scanner

Here,
→ java is a top level package
→ util is a sub package
→ and Scanner is a class which is present in the sub package util.

CREATING A USER-DEFINED PACKAGES :

➢ The package which is created by user is called user-defined package.


➢ In java, the package keyword is used to create a package.
➢ To compile a user-defined packaes, one must use the following syntax :
javac -d directory javafilename
- The -d switch specifies the destination where to put the generated class file.
- we can use any directory name like /Desktop (in case of Linux), d:/abc (in case of
windows) etc.

Department of Information Technology | APSIT


If we want to keep the package within the same directory, we can use . (dot).

➢ User-defined java package program can be executed by using fully qualified name.
i.e. We need to specify the actual package name given to the created package to excecute
program, as shown in following syntax.
e.g. Package Name.class name

Advantages of using a package in Java :


These are the reasons why you should use packages in Java:
• Reusability: While developing a project in java, we often feel that there are few things that
we are writing again and again in our code. Using packages, you can create such things in
form of classes inside a package and whenever you need to perform that same task, just
import that package and use the class.
• Better Organization: Again, in large java projects where we have several hundreds of
classes, it is always required to group the similar types of classes in a meaningful package
name so that you can organize your project better and when you need something you can
quickly locate it and use it, which improves the efficiency.
• Name Conflicts: We can define two classes with the same name in different packages so to
avoid name collision, we can use packages

CONCLUSION : summarize what you understood from this lab.

Department of Information Technology | APSIT

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy