Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Create Subpackages (i.e. A Package inside another package) 
 

We can also put a package inside an another package. The packages that comes lower in the naming hierarchy are called "subpackage" of the corresponding package higher in the hierarchy i.e. the package that we are putting into another package is called "su

 

Create Subpackages (i.e. A Package inside another package)

                         

We can also put a package inside an another package. The packages that comes lower in the naming hierarchy are called "subpackage" of the corresponding package higher in the hierarchy i.e. the package that we are putting into another package is called "subpackage". The naming convention defines how to create a unique package name, so that packages that are widely used with unique namespaces. This allows packages to be easily managed. Suppose we have a file called "HelloWorld.java". and  want to store it in a subpackage "subpackage", which stays inside package "importpackage". The "HelloWorld" class should look something like this:

 

package importpackage.subpackage;

public class HelloWorld {
  public void show(){
    System.out.println("This is the function of the class HelloWorld!!");
  }
}

Now import the package "subpackage" in the class file "CallPackage" shown as:

 

import importpackage.subpackage.*;

class CallPackage{
  public static void main(String[] args){
  HelloWorld h2=new HelloWorld();
    h2.show();
  }
}

Out of the program:

C:\nisha>javac C:\nisha\importpackage\subpackage\HelloWorld.java

C:\nisha\importpackage\subpackage>cd..

C:\nisha\importpackage>cd..

C:\nisha>javac CallPackage.java

C:\nisha>java CallPackage
This is the function of the class HelloWorld!!

Make sure to the directory structure for this program shown as:

 

 

                         

» View all related tutorials
Related Tags: c class io nested definition source while ini member e il it not init art ce in no part as

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

kindly help me with a more clear example with how to create a package and a sub package and accessing the methods in each package

Posted by krishna on Wednesday, 03.26.08 @ 20:54pm | #54419

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.