Tuesday, 1 April 2014

JAVA Programming : Package

Follow the steps for creating package

 1. create a folder called "student"
  2. change to the student folder then create a java file package1.java,package2.java and studentpackdemo.java
3. compilation:
          i)  move out of existing student folder using "cd.."
          ii) to compile use the below code
                  javac student/package1.java
                   javac student/package2.java
                  javac student/studentpackdemo.java

4. to run only the main package which is called studentpackdemo.java
                  java student/studentpackdemo

5. here the codes are given for all the packages

------------------------------------------------------------------------------------
 package student;
class studpackdemo{
public static void main(String[] args)
{
package1 p1=new package1();
p1.printop();
package2 p2=new package2(45,"jack","Madurai");
}
}

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



 package student;
import java.io.*;

 class package1
{
int tot, m1,m2,m3;
String stu=new String();
String name=new String();
String grade=new String();
public  package1()
{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try
{
System.out.println("Enter your name\n");
name=br.readLine();
System.out.println("Enter your score in JAVA subject\n");
stu=br.readLine();
m1=Integer.parseInt(stu);
System.out.println("Enter your score in LINUX subject\n");
stu=br.readLine();
m2=Integer.parseInt(stu);
System.out.println("Enter your score in AI subject\n");
stu=br.readLine();
m3=Integer.parseInt(stu);
tot=m1+m2+m3;
grade="*****";
}
catch(Exception e)
{System.out.println("Student details are not given in correct format\n");}
}

 public void printop()
{
System.out.println("Name of the student is :  \n"+name);
System.out.println("Total Mark is \t " + tot  +"grade is \n"+ grade);
}
}


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

package student;

 class package2
{

 public  package2(int stno,String stname,String city)
{
System.out.println("Address : "+stno+"  "+stname+"   " +city);

}
}
----------------------------------------------------------------------------------------------


No comments:

Post a Comment