• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Setting up on the Mac

 
Greenhorn
Posts: 1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 > TextEdit.app). 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 "HelloWorld.java" (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 > Terminal.app). At the prompt, use the command cd (change directory) to go to the folder where you saved HelloWorld.java. 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 HelloWorld.java
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$
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
I brought this back from the farm where they grow the tiny ads:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic