0% found this document useful (0 votes)
72 views

Java Package

The document discusses the steps to create and import packages in Java. It outlines how to: 1) Create a package by making a directory and adding the package declaration to a class file. 2) Compile the class file within the package. 3) Import the package and use classes from that package by creating objects and calling methods.

Uploaded by

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

Java Package

The document discusses the steps to create and import packages in Java. It outlines how to: 1) Create a package by making a directory and adding the package declaration to a class file. 2) Compile the class file within the package. 3) Import the package and use classes from that package by creating objects and calling methods.

Uploaded by

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

JAVA

by

ArguS academy

STEPS OF CREATING PACKAGE


cd\ [to goto starting]
load till bin
C:\Program Files\Java\jdk1.7.0_02\bin>md pack1 (package-name)
C:\Program Files\Java\jdk1.7.0_02\bin>cd pack1 (package-name)
C:\Program Files\Java\jdk1.7.0_02\bin>pack1>edit First.java (class-name.java)

Then write program


package pack1;
public class First
{
public void input()
{
----------------;
--------------;
}
}

STEPS OF IMPORTING PACKAGE


Then save as First.java (class-name.java)
C:\Program Files\Java\jdk1.7.0_02\bin>pack1>cd..
C:\Program Files\Java\jdk1.7.0_02\bin>javac pack1(package-name)\First.java(classname.java)
C:\Program Files\Java\jdk1.7.0_02\bin>edit Second.java(class-name.java)
Then write program with main method and load pack1(package-name) and create
object of First.java(class-name.java)
import pack1.First ; (pack1(package-name).First(class-name)
public class Second
{
public static void main(String ar[])
{
First obj=new First();
Obj.input();
{
----------------;
--------------;
}
}

CREATING PACKAGE

IMPORTING PACKAGE

package a;
import java.util.Scanner;
public class Na {int c;
public void raj(){
int a,b;
Scanner e=new Scanner(System.in);
System.out.println("enter first no:");
a=e.nextInt();
System.out.println("enter 2nd no:");
b=e.nextInt();
c=a+b;
}
public void result(){
System.out.println("result:" +c );
}
}

import a.Na;
public class CallNa {
public static void main (String a[]){
Na r=new Na();
r.raj();
r.result();
}
}

You might also like