Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Learning Java on Mac Air Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Learning Java on Mac Air" Watch "Learning Java on Mac Air" New topic

Learning Java on Mac Air

V Leandro

Joined: Jul 27, 2012
Posts: 3
Yes...I know...I'm insane. I could easily fire up my Windows machine...but where's the fun in that.

I'm using the "Head First Java" book. Wrote "MyFirstApp" and it compiled with no problem.

However, when I try to run it, I'm getting a series of errors:

I think this has something to do with Classpath...but how do I set that on a Mac. Yes...I'm new to Mac too...Java and Mac all at once!

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60810

Welcome to the Ranch!

V Leandro wrote:Yes...I know...I'm insane.

You have plenty of company in the asylum. There are a lot of Java developers using Macs.

However, when I try to run it, I'm getting a series of errors:

Tell us exactly how you are trying to run the program and what setup you have done.

I assume you're doing this from the command line?

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

This looks like an ordinary classpath problem, just like the ones that everybody else has when they start learning Java.

As for "how to do it on Mac", when the tutorial shows you how to do it on Unix, that's how. You are following a tutorial or some other guide which shows you how to run Java programs at the command line, aren't you?
Alix Ollivier
Ranch Hand

Joined: Jun 04, 2012
Posts: 71

Can you show us what you wrote in the file?

"The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!', but 'That's funny...' "
- Isaac Asimov
Alix Ollivier
Ranch Hand

Joined: Jun 04, 2012
Posts: 71

When you opened terminal, did you cd to the right directory? If not, use the command cd /file/path/here, or cd and drag in your file.
V Leandro

Joined: Jul 27, 2012
Posts: 3
Getting closer! From terminal I changed to the directory where MyFirstApp.class resides. I then ran the following:

The error has now changed....

Here's the code of my class:

Thanks for all the replies so far and your patience!

V Leandro

Joined: Jul 27, 2012
Posts: 3
Okay...disregard that previous post!

The command I tried first this morning was javac which is the compiler! Doh!

I then reran the correct command of:

This worked! So the "trick" so far is to change into the directory where my class resides when running it in Java.

Thanks to everyone for your suggestions! For anyone else, I came across this site which jogged my memory." target="_new" rel="nofollow">Common Problems

Nitish Bangera
Ranch Hand

Joined: Jul 15, 2009
Posts: 537

V Leandro, just be careful when you program to put your class in packages. If you plan to change your code to the following in future(which you will) and then run it

Then simply running won't help.

Java stores class files as fully qualified names and hence would be used to run the class.

[ SCJP 6.0 - 90% ] , JSP, Servlets and Learning EJB.
Try out the programs using a TextEditor. Textpad - Java 6 api
Consider Paul's rocket mass heater.
subject: Learning Java on Mac Air
Similar Threads
Connecting to an Oracle DB
running jar files in MAC
A exception of java.lang.SecurityException
Runtime Error :(
How Do I Do Classes In Packages from the Command-Line?