Skip to main content

how to create java package and use it

java creating simple package containing class and display method in another program accessing that package using import keyword video tutorial





A package is a collection of related classes. it helps improve re-usability.

It helps Organize your classes into a folder structure and make it easy to locate and use them.
Syntax used to create package is 
package;

 Step 1) Consider the following code,

·       Save as demo.java
·       Compile using javac demo.java
·       Re comple
·       javac -d . demo.java
·       Packge name folder created
·       Java p1.c1 fully qulified name is used to run mehtod 


package p1;

class c1{
public void m1()
{
System.out.println("pakge class ");
}

public static void main(String s[])
{
c1 obj=new c1();
obj.m1();
}

}



lets take example in above video follow steps in video copy below code 


Save as 
Emp.java

package prakash;
public class Emp
{
 public void display()
 {
  System.out.println("hi its method display of pkg Prakash");
 }

}

1) Sve program in C Drive
2)Comple using Javac Emp.java
3) Re comple using  Javac -d . Emp.java
after 2nd compilation folder prakash created on D drive 


Creat another program Save and Comple using
Javac PkgDemo.java 
Run using java PkgDemo.



save as 
PkgDemo.java 

import prakash.*;

class PkgDemo
{
public static void main(String s[] )
{
prakash.Emp obj=new prakash.Emp();
obj.display();
}


}


Comments

Labels

Show more

Popular posts from this blog

Basic java

java java java, learn java online free, classroom java tutorial, beginners java, java beginners, java programming,  basic java , basic java Tutorial,  basic java  Assignment           Hello friends ,       I am learning Basic java . my motive behind this blog is to help those want to learn Basic java online free of cost and grab each and every basic aspect of java programming .     you can find java tutorial from basic on this blog i will post each and every assignment of basic java with source code .          we will divide our course  in to Day work .          Let's start Day One  Basic Java Assignment for  Beginners      Basic Requirement to learn Java Programming Download following software             1. Text Editor (Notepad, Notepad++, Edit pad, Eclipse...

java ms access connectivity

java ms access connectivity java ms access connectivity Step by Step jdbc odbc driver for ms access java database connectivity with ms access 2007 java ms access connectivity steps how to connect java with ms access 2007 database with an example how to connect ms access database in java without dsn how to connect ms access database in java without using dsn Hi Friends in this article i am using ms access 2007 database as a back end, using java simple code we will connect to emp database created in ms access , after connecting with emp we are going to perform operation like display records from emp using java simple code, add record to emp using java simple code, delete record from emp using java simple code , update /edit emp using java simple code , i am using simple because vary basic code you found here . follow steps you can watch video or download PDF very Soon  for this article .  First  Create Table  use MS ACCESS 2007 or later as shown in imag...

java MS ACCESS insert,update delete using PreparedStatement

java program delete record from table using  PreparedStatement java MS ACCESS  insert,update  delete using  PreparedStatement import java.sql.*; class DeletePreparest {   public static void main(String s[])   {     try {   int cno=Integer.parseInt(s[0]);  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  Connection con=DriverManager.getConnection("jdbc:odbc:demodb"); // Statement smt=con.createStatement();  PreparedStatement psmt=con.prepareStatement("delete from demo where id=?");  psmt.setInt(1,cno);  int result=psmt.executeUpdate();       System.out.println("record deleted"+result);  con.close(); } catch(Exception e){    System.out.println("exce"+e);}         } }