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

Packages

A package is a collection of classes, interfaces and nested packages that is used to organize Java projects, applications, and libraries by placing related classes and interfaces into a directory structure, and the package statement and import statement allow classes within a package to be accessed and used by other classes through the classpath environment variable or command line option. Packages provide a namespace for classes and interfaces, and public classes and interfaces must be saved in files with the same name as the class or interface within the package directory.

Uploaded by

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

Packages

A package is a collection of classes, interfaces and nested packages that is used to organize Java projects, applications, and libraries by placing related classes and interfaces into a directory structure, and the package statement and import statement allow classes within a package to be accessed and used by other classes through the classpath environment variable or command line option. Packages provide a namespace for classes and interfaces, and public classes and interfaces must be saved in files with the same name as the class or interface within the package directory.

Uploaded by

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

package

--------
A package is a collection of classes,
interfaces and nested packages.
Why Packages?
--------------
A package is used to make
* Java Projects/Applications
* Java Libraries
To create a package:
-------------------
Create a directory of the same name
as of the package.
To put classes and interfaces in the package:
---------------------------------------
* Define the classes and interfaces with package statement as their first statem
ent.
* Place the classes and interfaces in the package directory.
How to use a package?
--------------------
If the package is representing a project/application
then generally it is executable/deployable.
If the package is representing a library
then its "public" classes and interfaces
are "imported" and used by other classes
and interfaces.
What is import?
---------------
"import" is a java statement that allows
a class to access public classes/interfaces
of an available package.
How to use import?
-----------------
import is used as follows:
import pckgName.className;
import pckgName.*;
How is package statement resolved?
--------------------------------
To resolve the package statement
system uses :-
environment variable "classpath"
or
"-classpath" compilation and execution option.
-------------------------------------
To set classpath
Right click on my computer
Click on properties
Select Advanced
Select Environment Variables
Under System
Edit/Create
variable name : CLASSPATH
variable value : <existing entries>;locationWherePackageIsPlaced
OK to all windows
---------------------------------------------
To set classpath as compilation/execution option
c:\java>javac -classpath "%classpath%";e: AboutProgramming.java
c:\java>java -classpath "%classpath%";e: AboutProgramming
---------------------------------------------
Rule for public class/interface
It must be saved in a file that has
same name as of the class/interface.

You might also like