Adnan
You cannot compile or run a package in
java.
Package is something used to avoid name collisions. Its like a namespace and has an hierarchy.
for example....
in my .jar file there are two classes
Person.class - under com/prasad
Person.class - under com/prasad/Misc
if this jar file is in the classpath and I try to compile the following code I get compiler errors
Person = new Person();
because the compiler doesnot know which Person to refer.
to make it clear to the compiler I refer them I can refer like this....
com.prasad.Person n = new com.prasad.Person();
or
com.prasad.Misc.Person n = new com.prasad.Misc.Person();
another way to do this is.. importing the specific package
forexample
import com.prasad.*;
Person = new Person();
or
import com.prasad.Misc.*;
Person = new Person();
but you cannot import both packages when you create a new Person Object
import com.prasad.*;
import com.prasad.Misc.*;
Person = new Person();
The compiler complains about the ambiguity.
Now how to create a package?
Just write this statemet at the begining of your .java file
package <packagename>
example:
package com.prasad;
public class Person
{
....
}
package com.prasad.Misc;
public class Person extends xxx
{
.....
}
Hope this helps
cheers
Siva