aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Package problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Package problem" Watch "Package problem" New topic
Author

Package problem

John Farrell
Greenhorn

Joined: Sep 14, 2003
Posts: 6
I am working through a book called Sun Certified Programmer & Developer for Java 2 by Kathy Sierra and Bert Bates(Osborne books). The chapter of the book that I am working on called Declarations and Modifiers(Exam Objective 1.2). The section that I am working on is called Public Members. The book example is:
package book;
import cert.*; // Import all classes in the cert package
class Goo {
public static void main(String [] args) {
Sludge o = new Sludge();
o.testIt();
}
}

second file:
package cert;
public class Sludge {
public void testIt() {
System.out.println("sludge");
}
Goo should be able to invoke the method in Sludge without problems because both the sludge class and its testIt () method are marked public.
But this the result:
Attempt to compile:
D:\j2sdk1.4.2_01\bin\cert\book>javac Goo.java
Goo.java:2: package cert does not exist
import cert.*; // Import all classes in the cert package
^
Goo.java:7: cannot resolve symbol
symbol : class Sludge
location: class book.Goo
Sludge o = new Sludge();
^
Goo.java:7: cannot resolve symbol
symbol : class Sludge
location: class book.Goo
Sludge o = new Sludge();
^
3 errors
D:\j2sdk1.4.2_01\bin\cert\book>
Where am I going wrong?
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Have you set the CLASSPATH.


Groovy
John Farrell
Greenhorn

Joined: Sep 14, 2003
Posts: 6
Do you mean dos path?
D:\j2sdk1.4.2_01\bin\cert\book> path
Path=D:\WINNT\system32;D:\WINNT;D:\WINNT\System32\Wbem;D:\j2sdk1.4.2_01\bin\;D:\
j2sdk1.4.2_01\bin\cert
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
John Farrell
Greenhorn

Joined: Sep 14, 2003
Posts: 6
Is there a difference between setting the path and class path?
Karen Liu
Greenhorn

Joined: Sep 14, 2003
Posts: 16
It is not your Path problem. You didn't set the pkg well.
first:
cert and book are different pkgs. you should not put book inside cert.
second: when you compile you should do it at D:\j2sdk1.4.2_01\bin> javac book/Goo.java and java book/Goo.
John Farrell
Greenhorn

Joined: Sep 14, 2003
Posts: 6
That works. Thanks.
Another question.
Is it possible to access the program Goo without specifying the directory book?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Package problem