File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes basic instantiation question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "basic instantiation question" Watch "basic instantiation question" New topic
Author

basic instantiation question

Brad Clouser
Greenhorn

Joined: Sep 08, 2009
Posts: 4
Hello,
I'm just learning Java, and can't figure out why I'm getting an error on this. I've read several tutorials, and it seems like everything is OK, but obviously it must not be. The file2.java file won't compile, generating a "Cannot Find Symbol" error. Does anyone see what I'm doing wrong here? Thanks!

file1.java

file2.java

I've created these two files on my desktop, and added /home/brad/Desktop to my $CLASSPATH. (I'm using Linux). I compile file1.java first, which works fine. Then I try to compile file2.java, which doesn't compile.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
If you use a package named testpkg, your files need to be located in a folder called testpkg.


JDBCSupport - An easy to use, light-weight JDBC framework -
Brad Clouser
Greenhorn

Joined: Sep 08, 2009
Posts: 4
Thanks!!! That worked perfectly.
Do you know if there is any alternative to modifying the classpath when working with multiple classes? Is there any other way to tell the java compiler where to look? My goal with this question is to avoid the need for someone else to modify their CLASSPATH if I send them my java files. Thanks for your help!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Generally you don't want to use the CLASSPATH environment variable at all. Both the Java compiler and the runtime accept a -classpath command-line switch; rather than setting CLASSPATH, you can and should always use the -classpath argument instead:

java -classpath c:\myclasses file2



[Jess in Action][AskingGoodQuestions]
Brad Clouser
Greenhorn

Joined: Sep 08, 2009
Posts: 4
Thanks! I will use the -classpath switch in the future. Thanks for your help.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
If you are just beginning Java, it might be easier to miss out package names until you are more experienced.
Brad Clouser
Greenhorn

Joined: Sep 08, 2009
Posts: 4
Thanks for the tip. I took out the package names. I only had them in there because a lot of the tutorials I read started with "Assuming the files are in the same package..." Everything is working perfectly now. Thanks everyone!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: basic instantiation question