Thursday, 19 May 2011

Packages In Java...


This is a general program explaining how to make use of packages in JAVA...
/****************************** pk.java *****************************/
                        // creating package 
package pack;
public class pk
{
public void show()
{
System.out.println("You are in Package now........");
}
}
/*
(1) In Command Prompt Compile pk.java
C:\jdk1.5.0_12\bin>javac pk.java
(2) It makes class file as pk.class in C:\jdk1.5.0_12\bin\ folder..
(3) Now Make a folder named pack in this directory..
(4) Copy & paste this pk.class file in pack folder.
*/
/****************************** pkg.java *****************************/
                   // importing file from package
import pack.pk;
class pkg
{
public static void main(String[] args) 
{
pk p=new pk();
System.out.println("Hi..........");
p.show();
}
}
/***************************** Output **********************************
C:\jdk1.5.0_12\bin>javac pk.java


C:\jdk1.5.0_12\bin>javac pkg.java


C:\jdk1.5.0_12\bin>java pkg
Hi..........
You are in Package now........
*/

No comments:

Post a Comment