This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
This is very basic, but without it, I can't do a thing. I want to do simple programming in Java (ie exercises out of a teach yourself book). I know how (thankfully) to use a text editor to save text as a text file. But, where do I save it when I'm asked? How do I access javac to compile the text file? Where does the resulting class file go? How do I run the class file. I have a Powerbook with MacOS X now. I know how to do the above with MSDOS. Thanks, George Chen
I don't really understand the question. Save the .java file to any directory you want. In the unix shell, cd to that directory and type "javac Foo.java" (replacing "Foo" by the name of your class). If the compile succeeds, it will create a file called "Foo.class". To run it, type "java Foo". Make sure that your CLASSPATH environment variable includes ".", which means "the current directory." If the class is in a package, or the file contains more than one class, things get a bit more complicated, but let's not go there yet.
Welcome to JavaRanch George. Have you got it working yet? Just a another little detail... Your display name doesn't quite fit the famous JavaRanch naming policy. Could you please take a minute to change your display name to show 2 names, preferably your real name. (It's all about maintaining our professional image - don't let the one-eyed moose fool you!). Thanks and hope you'll be visiting the ranch often, Pauline
Joined: Jan 19, 2001
Originally posted by Ron Newman:
Make sure that your CLASSPATH environment variable includes ".", which means "the current directory."
I'm not sure this is always necessary, if you cd to the directory where your .java file is, or specify the path of the file when you compile it. I've been able to compile certain programs without setting CLASSPATH...
Joined: Jun 06, 2002
I think that not having a CLASSPATH is equivalent to having a CLASSPATH of ".", but if you have a CLASSPATH, it needs to explictly include "." I could be wrong on this.