File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Mac OS and the fly likes Setting up on the Mac Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Mac OS
Bookmark "Setting up on the Mac" Watch "Setting up on the Mac" New topic

Setting up on the Mac

Jen Bartloff

Joined: Aug 15, 2010
Posts: 1
I'm just trying to get everything ready on my mac so I can start programming in Java. It's supposed to already have the SDK, but I can't find the compiler. How do I find/run the compiler on the mac? Thanks.
David Newton

Joined: Sep 29, 2008
Posts: 12617

What happens if you just type in "java -version" in a shell window? Worst-case scenario is you have to download it, but at least one version of the JDK should already be installed.
marc weber

Joined: Aug 31, 2004
Posts: 11343

Java should be ready to go on the Mac, so you shouldn't have to download, install, or configure anything.

Here are step-by-step instructions for Hello World on a Mac...

You can write Java code using TextEdit (Finder > Applications > When you launch TextEdit, the default is probably for Rich Text. Under the TextEdit's Format menu, select "Make Plain Text." Type the following code letter for letter (Java is case sensitive) in TextEdit...

From TextEdit's File menu, select Save As, and select a folder to save in. For the file name, type "" (without the quotes). When you save, TextEdit will ask if you want to use the .java extension instead of .txt. Use the .java extension.

Next open Terminal (Finder > Applications > Utilities > At the prompt, use the command cd (change directory) to go to the folder where you saved For example...

computerName:~ userName$ cd java/tests
computerName:~/java/tests userName$

Next, compile your .java file by typing javac followed by a space and the file name (including the .java extension).

computerName:~/java/tests userName$ javac
computerName:~/java/tests userName$

If the prompt returns without error, then the file has compiled. You will have a new HelloWorld.class file in the folder along with your original .java file. To run the .class file, type java followed by a space and the class name (without the .class extension). Your output should display on the following line.

computerName:~/java/tests userName$ java HelloWorld
Hello World from a Mac!
computerName:~/java/tests userName$

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Don Bailey

Joined: Sep 01, 2010
Posts: 7
Hi! I was referred to this thread, and I successfully completed your instructions above (I have an intel iMac 2.4GHz) I, too, am brand-spanking new to this. I have the "Head First Java" book as well as the suggested "Just Java 2." I checked my version and have 1.6.0_21. Is there anything else I would need to get started? Thanks for any and all help you can give! I'm very anxious to get going but want to start out correctly...
Regards, Don

One by one, the penguins steal my sanity...
I agree. Here's the link:
subject: Setting up on the Mac
It's not a secret anymore!