Wednesday, December 21, 2016

Package Section(JAVA Programming Format)

2. Package section

--------------------------------------------------------------------------------------------------------------------------
Definition : 

1. package is collection of related classes and interface as a single unit.
2. package is a folder contains .class representing related classes and interfaces.

In JAVA application , package are able to provide the following advantages:
1. Modularity
2. Abstraction
3. Security
4. Share-ability
5. Re-usability

There are two types of packages in JAVA application.
1. Predefined package
2. User defined packages

1. Predefined package: 

---------------------------------------
These packages are defined by JAVA programming language and provided along with java software.
EX:
--------------
java.io
java.util
java.awt

2. Userdefined packages:

---------------------------------------------
These packages are defined by developers as per their application requirements.

To declare user defined packages , we have to use the following syntax...

package package_name;


where package name may be either single name or main package and sub package names with '.' operator.

EX:
---------
package p1;
package p1.p2.p3;

if we want to use package declaration statement in java file then we must use the following two condition...
1. package declaration statement must be first statement in java file after comment section.
2. package names must be unique, they must not be shareable and they must not be duplicated.

------------------------------------------------------------------------------------------------------------------------

Q. is it possible to provide more than one package declaration statement within a single java            file?
------------------------------------------------------------------------------------------------------------------
Ans: No, it is not possible to provide more than one package declaration statement within a single java file, because package declaration statement must be first statement in java file. if we provide more than one package declaration statement in a java file, where only first package declaration as first statement, remaining package declaration statement are not first statement.
EX:  File Name: abc.java
--------
package p1; -------> valid
package p2; -------> invalid
package p3; -------> invalid
------
------
-------


--------------------------------------------------------------------------------------------------------------------------

Package Naming Convention:

----------------------------------------------------
To provide package name, java has provided a separate convention like to inclue our company domain name in reverse in package name.
EX:  package com.durgasoft.icici.transation.deposit;
com.durgasoft ------> company domain name in reverse.
icici ------------------> client name / project name
transactions ---------> module name.
deposit ---------------> sub module name.

No comments:

Post a Comment