This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "basic instantiation question" Watch "basic instantiation question" New topic

basic instantiation question

Brad Clouser

Joined: Sep 08, 2009
Posts: 4
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 file won't compile, generating a "Cannot Find Symbol" error. Does anyone see what I'm doing wrong here? Thanks!

I've created these two files on my desktop, and added /home/brad/Desktop to my $CLASSPATH. (I'm using Linux). I compile first, which works fine. Then I try to compile, 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

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

Joined: Jul 08, 2003
Posts: 24199

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

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

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

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:
subject: basic instantiation question
It's not a secret anymore!