aspose file tools*
The moose likes Beginning Java and the fly likes JAVA packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JAVA packages " Watch "JAVA packages " New topic
Author

JAVA packages

Ray Tam
Greenhorn

Joined: Mar 01, 2003
Posts: 12
Hello, I am trying to get JAVA certified and using the K & B as my study guide. Presently, I am trying to learn about packages and I am having the following problem. I used one of the examples from the book.

In one file called permit.java, I have the following.

package test;
public class permit
{
public void callit()
{
System.out.println ("calling package permit");
}
}

The other file called client.java has the following:

package driver;
import test.*;
public class client
{
public static void main(String[] something)
{
permit checking = new permit();
checking.callit();
}
}

Both these files reside in the java\bin directory. When I try to compile the client.java, I get the following error messages.

C:\java\bin\client.java:2: package test does not exist
import test.*;
^
C:\java\bin\client.java:7: cannot resolve symbol
symbol : class permit
location: class driver.client
permit checking = new permit();
^
C:\java\bin\client.java:7: cannot resolve symbol
symbol : class permit
location: class driver.client
permit checking = new permit();

Any help would be appreciated. Thank you.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

In a word: CLASSPATH. The java compiler can only find other java files which it can access via the CLASSPATH. So to find the package "test" this needs to be in the CLASSPATH. I'm sure the "K & B" (whatever that is) will tell you how to do this - otherwise read about the CLASSPATH at Sun

A word of advice here; if you are running java etc. from the java/bin directory I can assume you have not set your operating system's PATH environment variable up to include Java? Its not a good idea in the long run to be developing stuff in the /bin directory. Far better is to define a directory outside your java/* directory for developing stuff, since it reduces confusion.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 805
I'm sure "K & B" is Kathy and Bert, as in Kathy Sierra and Bert Bates' Java certification book.


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JAVA packages