aspose file tools*
The moose likes Beginning Java and the fly likes Starting wth Java on Mac Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Starting wth Java on Mac" Watch "Starting wth Java on Mac" New topic
Author

Starting wth Java on Mac

Tarun Durga
Greenhorn

Joined: Jun 17, 2009
Posts: 5
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
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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).
Nathan Leniz
Ranch Hand

Joined: Nov 26, 2006
Posts: 132
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.


The very existence of flamethrowers proves that at some time, some where, some place, someone once said to themselves "I'd really like to set those people on fire over there, but I just can't get close enough".
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39530
    
  27
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.


Ping & DNS - updated with new look and Ping home screen widget
Tarun Durga
Greenhorn

Joined: Jun 17, 2009
Posts: 5
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
Marshal

Joined: Mar 22, 2005
Posts: 39530
    
  27
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.
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 272

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.


SCJP 6 || SCWCD 5
Tarun Durga
Greenhorn

Joined: Jun 17, 2009
Posts: 5
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Starting wth Java on Mac
 
Similar Threads
Servlets
I need to step thru another war that I link to...
classpath for a very beginner on Mac
Confusion with Javac Compiler
Taking community college online course in Java 1