Google News
logo
Java User Defined Packages
User defined packages
1) The packages which are declared by the user are called user defined packages. 

2) In the single source file it is possible to take the only one package. If we are trying to take two packages at that situation the compiler raise a compilation error. 

3) In the source file it is possible to take single package. 

4) While taking package name we have to fallow some coding standreds.
Whenever we taking package name don't take the names like pack1, pack2, sandhya, sri these are not a proper coding formats.
Rules to fallow while taking package name:-(not mandatory but we have to fallow)
1) The package name is must reflect with your organization name. the name is reverse of the organization domain name.
Domain name :  www.freetimelearning.com
Package name :  Package com.freetimelearning

2) Whenever we are working in particular project(Bank) at that moment we have to take the package name is as fallows.
Project name : java
package : Package com.freetimelearning.java

3) The project contains the module (deposit) at that situation our package name should reflect with the module name also.
Domain name :  www.freetimelearning.com
Project name :  java
Module name :  package
package name :  Package com.freetimelearning.java.package

package program
package com.freetimelearning
class Test 
{ 
static void s(){ 
System.out.println("hi"); 
} 
}
Output :
output:Compilation : javac d . Test.java com->freetimelearning->Test.class
Import session:-
The main purpose of the import session is to make available the java predefined support into our program.
Predefined packages support:-
Ex1:-
Import java.lang.String;
String is a predefined class to make available predefined string class to the our program we have to use import session.
Ex 2:-
Import java.awt.*;
To make available all predefined class present in the awt package into our program. That * represent all the classes present in the awt package.
User defined packages support:-
I am taking two user defined packages are

package program
import java.freetimelearning.* //or import com.freetimelearning.Test
class pack{
public static void main(String args[]){
Test.s();
}
}
Output :
output :    hi