Loading, please wait...

A to Z Full Forms and Acronyms

Java - Package concept

Jul 07, 2018 paca, subpack, package, 1970 Views
This Program is used to demonstrate the Package concept.
Package: Package is the collection of classes, methods and interfaces. It is divided into two types, namely:



Pre Defined Package
User Defined Package
 

Pre Defined Package: Pre Defined Packages are already some of the existing packages.

Examples are,

java.io.*;
java.net.*;
java.lang.*;
java.awt.*; and etc.,
 

User Defined Package

User Defined Packages are the programs, which can define their own packages to bundle the group of classes/interfaces, etc. It is a good practice to group the related classes implemented by you, so that a programmer can easily determine that the classes, interfaces, enumerations, annotations are related.

 

Simple Program

Create a sub directory pack and save the file ‘one.java’.



package pack;  

public class one  

 {  

   public static void temp()  

    {  

       System.out.println("Welcome");  

    }  

 } 



Create a sub directory subpack in the package directory and save the file ‘two.java’.

package pack.subpack;  

  

public class two  

 {  

   public static void temp1()  

    {  

       System.out.println("Have a Nice Day...");  

    }  

 } 



Save file ‘three.java’ into the main directory.

import pack.*;  

import pack.subpack.*;  

  

class three  

 {  

   public static void main(String arg[])  

    {  

       one.temp();  

       two.temp1();  

    }  

 } 
A to Z Full Forms and Acronyms

Related Article