New to Java, need help.
Hello,
I am new to Java, but not new to programming. However, it has been quite a long while since I actually programmed anything (like about five years). I would really appreciate some help just getting my Java environment up and running. I am running on a Mac OS X Panther. If anyone could help a newbie out I would appreciate it.
Thanks,
Eric
Thanks for all of your help.
First I will supply the version my mac comes with via copy from terminal.
java version "1.4.2_09"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_09-233)
Java HotSpot(TM) Client VM (build 1.4.2-56, mixed mode)
Now, the biggest problem I am having is that I can't seem to understand how to get the compiler to recognize my first program. I have no idea if anyone here is familiar with Macs to know what this means, but I created a folder on my desktop called Java. Inside Java I created a text document called myfirstjavaprog.java using TextEdit (kind of like notepad). I made sure to eliminate the .txt and I know it is recognizing it as a java doc because it associated a java icon to the file. The problem comes when I try to compile it. I am going from a hello world tutorial from-
http://www.javacoffeebreak.com/tutorials/gettingstarted/part2.html
Now, from near as I can tell I have not entered any code in wrong. However I will directly copy it just so it can be verified.
class myfirstjavaprog
{
public static void main(String args[])
{
System.out.println("Hello World");
}
}
I have saved the program I said above, as myfirstjavaprog.java. Later in the tutorial I am told to enter-
javac myfirstjavaprog.java
for compiling. When I do I get this error message from terminal.
error: cannot read: myfirstjavaprog.java
1 error
So this is where I am stuck. If anyone can help I would greatly appreciate it.
You should type this command under the directory containing this file.
For windows, C:\Document and Settings\USERNAME\Desktop\
Then type your command, javac -cp . myfirstjavaprog.java.
Comments
1) A java compile option -cp . is added to tell the compiler where the class is located.
2) Better to use CamelCase for your program name. (Code Convention)
3) You should post your code wrapped with code tag (Button between Spell Check and Quote Original, above textarea when you post your reply)