It's not a secret anymore!
The moose likes Beginning Java and the fly likes package declaration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "package declaration " Watch "package declaration " New topic

package declaration

sam mitwa

Joined: Mar 27, 2005
Posts: 13
i want to make one package of my own classes that i have made
i know that classes of package are in one directory
and i saw syntax package name (that u want to give )
i know this much ;

now i m making one new class
and than i want to import all the classes that i have made earlier
by using package name ; one answer might be put all the classes tht u have made in the same directory
than how can i import classes by package name
my question is how can i make package of classes
suppose i have 5 classes
how can i put these classes in one package whose name is p
now im making one new class z and now i want to use those classes(a,b,c,d,e)
that i have put in package p how can i import ?

i think that u can understand what i want to say ;
i have already declared that how much knowledge i have about package
im totally confused whether anyone can understand what i want to say :

if anyone can understand what i want to ask
please reply
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Moving to Java in General (Beginner).

SCJP Tipline, etc.
Carol Enderlin
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
import p.*;

//or import each one:

import p.a;
import p.b;
import p.c;
import p.d;
import p.e;

public class Z {
Raghu Shree
Ranch Hand

Joined: Mar 18, 2005
Posts: 143
you should define the package statement in a first executable line of the class file. If u have all classes in a single file then u should declared like below
package p;
class a{}
class b{}
class f{}
and all the class are should be placed in a folder p. or if u have individual files od each of class u should place the package p statement in every class file.

If u want to import all the class in your file then u include following any one of the lines.
import p.*; //It import all the class availabe in package p;
import p.a;
import p.b;
import p.e; // It import specified package class only.
class z {} // Declaration of class Z

I hope it will be useful to u. If u have any more dubts reply me.



Raghu J<br />SCJP 1.4<br /> <br />The Wind and waters are always<br />on the side of the ablest navigators.<br /><a href="" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="" target="_blank" rel="nofollow">SCWCD Group</a>
I agree. Here's the link:
subject: package declaration
It's not a secret anymore!