• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do I do this?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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...
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic