This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Hello, I'm working with Mac OS X 10.5.8. I followed the guide on this website to create my first java program, and saved a file called "MooseGreetings.java" with this text copied from the guide:
I then proceeded to open a terminal window and type "javac MooseGreetings.java"
It had one error, it could not read it. I neglected doing the PATH thing, if that's the problem I'd be gracious for a short guide on how to do that. If not, any other thoughts would help.
One of the great things about java is that its error messages tend to be very informative; once one understands what to look for, the error messages tend to tell you exactly what is wrong and where.
One of the great things about people that read this forum is that, among us, we've all made most of the mistakes people are likely to make, and recognize the error messages, etc.
So please, now and in general: don't paraphrase the error message(s). Tell us what it says. Because you're learning, what you think it's talking about may be wrong, and we can correct that most easily if we have the information from the compiler (and, as you progress through your learning, the runtime).
"It had one error, it could not read it" just has too many 'its' (itss?)
I thought Macs came with Java™ already installed. Are you sure it is a PATH problem?
As for setting the PATH, I googled and found this. It appears very similar to how one does it on Linux.
Joined: Jan 29, 2011
Thanks for the reply. The Terminal message said
"error: cannot read: MooseGreetings.java
When I inputted something random, like "sdkfchsdn.java", the same message, with "MooseGreetings.java" replaced by "sdkfchsdn.java" came up.
I don't think I'm even on the right track here. It probably has something to do with skipping the PATH step.
Joined: May 29, 2005
I don't think it has to do with skipping the "PATH step". I am not familiar with the Mac, but it appears the compiler is attempting to read the file and cannot. That suggests that the compiler is, in fact, being invoked, and setting PATH is for ensuring that the command can invoke the compiler.
This would happen if your default directory is not the same one that contains your MooseGreetings.java file. Assuming the Mac terminal window uses Unix-like commands, execute "ls" and see if the source file is there. If not, find out where you put it, and do a "cd" (for change directory) to that directory.