• 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

Starting wth Java on Mac

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay... I'm totally lost!!!

I don't have a programming background. I have a macbook.

I've just picked up Head First Java 2nd Edition and I don't know how to begin.

There is reference to textedit and to the terminal and I don't know how to use both in conjunction... bummer... I don't even know how to set the path... or why I should set the path... in fact I think I'm going to implode.

Please help. Step by step instructions will be appreciated. I promise to dedicate a kick ass app to you once I get started with this stuff
 
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
I use iTerm on the Mac; it's nicer than the built-in "terminal" app.

The Java executables should be on your path by default. You can use any text editor you want as long as it can save files as plain text, or use an IDE (which is another, separate learning curve).

You might want to spend some time getting to know your Mac and learning what tools are available before tackling more complex issues... familiarity with the command line is *very* handy, and a small amount of time on the web will give you some ideas as to which editors people like (I use either an IDE, TextMate, or Emacs for the bulk of my editing).
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chances are your mac is set up and ready to go out of the box. Just follow the below steps to test it.

1. Right click on your desktop, and create a new folder. Name the folder Java.2
2. If you aren't familiar with spotlight, open it up by pushing and holding the command key (key with an apple on it) and the space bar. Spotlight will spew forth from the upper right hand corner of your screen most likely.
3. Type the world terminal. You'll see it work at first, then you see a bunch of sub areas within spotlight such as Top Hit, Applications, Definition, so on and so forth. Next to applications you'll see a little black box and the word terminal. Click it, that's the one you want.
4. Your terminal application will open and you'll see your prompt. Mine looks like
5. Type the following My prompt changed to nathans-macbook-pro: Java Nathan$
6. Type pico HelloMac.java
7. Your terminal app will morph into what appears to be a text editor. Type the following into it
8. Push and hold control, then the x button. Then hit enter. Your prompt should return to normal.
9. Type javac HelloMac.java
10. Type java HelloMac and you should see Hello, Mac! displayed in your terminal. Doing that let's you know it works. That should also set you up for using your terminal and spotlight.

If you want to use TextEdit for your editor, you'll need to set it up a bit at first before you can effectively use it to start going through the book. But before you do that, you'll want to open up your Java folder, and drag the HelloMac.java and HelloMac.class files you see into the trash.

1. Using spotlight, open textedit
2. With textedit open, select the preferences, or use the keyboard shortcut by pressing and holding the command key and pushing the comma key.
3. Under the word Format, make sure the button next to plain text is highlighted. By default the one next to rich text most likely is.
4. Go the to Open and Save tab, and make sure you select the option to automagically at .txt if you don't specify a file extension. This will save you heartache if you use .txt files a lot.
5. You can make sure the above will now work for you by pushing and holding the command key, then hitting the q key after you save your changes to your preferences. command q is the mac keyboard shortcut for quit. After you do that reopen textedit, copy and paste the above code into it, then from the file menu choose save as.
6. Navigate to your Java folder, and save it as HelloMac.java and remember that you have to type out .java after the name of the file in order to let the computer know that's the extension you want it as. If you don't, it will add .txt and make it into a simple text file, and when you try to use your compiler it won't be happy.
7. After saving your file, open up your terminal and navigate to your java folder if you aren't there already. Unless you hard closed it it should already be there though.
8. Follow steps 9 and 10 above, and you should see Hello, Mac! displayed once again.

As mentioned there are better text editors and there are IDEs to use as well. Also as David Newton said you should become familiar with some of the features on your mac as they can save you time and help you get around. Also reading a good bash tutorial and saving it in your favorites would be good.

If you have any problems don't hesitate to ask. Good luck and happy coding.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This topic also had good advice on getting started with Java using the command line on OS X.

In due course, the http://faq.javaranch.com/java/MacOsxFaq may be useful as well.
 
Tarun Durga
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all... you've been superbly helpful. @ Nathan... it worked perfectly.

I now have a few more questions.

1. So I use Textedit to write the code and I use Terminal to activate it, but is this going to be the case with all code? Let's say I'm making a game, would I be using the Terminal there too?

2. I've been learning Processing, and that's a java based lingo too (more high level though), can I use the Processing IDE to code and compile?

Cheers,
Tarun
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1. So I use Textedit to write the code and I use Terminal to activate it, but is this going to be the case with all code? Let's say I'm making a game, would I be using the Terminal there too?


You can use the Terminal (I, too, prefer iTerm, by the way) to start all desktop application, so if your game is a desktop app, then the answer is yes. Other kinds of code (like web apps) need other kinds of runtime environments (like a servlet container).

2. I've been learning Processing, and that's a java based lingo too (more high level though), can I use the Processing IDE to code and compile?


I'm only superficially familiar with Processing, but I know that an OS X version is available. I don't think you can use that for general-purpose Java development, though (and it's in any case stuck at Java 1.4 level, so you wouldn't really want to). But highly capable free Java IDEs are available (like NetBeans and Eclipse) - those should cover your needs.
 
Ranch Hand
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just my two cents: You can use TextEdit and Terminal to write any Java application, no matter how large or small. However, using an IDE, like one of the ones Ulf mentioned, makes it a little easier to manage larger projects. My suggestion is you should spend a lot of time becoming familiar with TextEdit and Terminal...only when you feel you've mastered them should you move to an IDE.
 
Tarun Durga
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you... thank you...

You've got me started on Java. All questions answered for now and I'm sure I'll have a lot more as I go along.

This is a fantastic forum!
 
Bring me the box labeled "thinking cap" ... and then read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic