Hi, Gaurav.
I store my source (*.java) files in directory C:\Java. Therefore, I have added "C:\Java" to my CLASSPATH variable. If I want to create one
Java package called "first", and another one called "second", then I need to create folders C:\Java\first and C:\Java\second.
This following code, I saved as C:\Java\first\Book.java. Notice the package statement:
This next code, I saved as C:\Java\second\Library.java. Notice its package statement, and import statement, since it references Book, a class from another package:
To compile Book.java, I go to a command prompt and change the directory to C:\Java, then type
C:\Java>javac first\Book.java
And to compile Library.java,
C:\Java>javac second\Library.java
To run Library, I type
C:\Java>java second.Library
and get back
Pages: 654 To be able to directly invoke "java" and "javac", I had added C:\jdk1.3\bin to my PATH variable. This all assumes you are running Windows on your machine, which I don't know to be true.
Perhaps you forgot to use the import statement? Note, the import statement is not needed in Library.java if you specify the full path when you reference classes from other packages:
If I remove the "first" qualifier from this example, the compiler complains, saying that it "cannot resolve symbol," pointing to class "Book". Is this the kind of error you are getting, Gaurav?
Art