• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

How do I do this?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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.
 
A berm makes a great wind break. And Iwe all like to break wind once in a while. Like this tiny ad:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!