wood burning stoves 2.0*
The moose likes Mac OS and the fly likes newbie needs direction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Mac OS
Bookmark "newbie needs direction" Watch "newbie needs direction" New topic
Author

newbie needs direction

karron lane
Greenhorn

Joined: Sep 25, 2008
Posts: 6
hello. i'm taking a novice java class where everyone else is working on a pc so i'm on my own to get set up on mac to work on my projects. after reading and googling for a coupla hours i'm really confused. what i'd like is some info on the simplest way to set up my mac. i have no experience or understanding of java or any programming language. i am, however, pretty good on the mac.

am i on the right track with this thinking?

1. i can write the code in a text editor such as tex-edit.
2. compile in eclipse? (i downloaded eclipse-java-ganymede-SR1-macosx-carbon.tar.gz)
3. then what? how do i get the program to run?

a big issue is that i don't understand the sequence of events in programming, like what happens first followed by what. i found of lot of detailed info (tomcat, xcode, et al) but i don't understand how it all fits together.

we are also required to turn in flowcharts so i'm wondering what software you might recommend.

i hope i'm making sense.

thanks for being here, i was very happy to find a place for mac os x greenhorns!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Originally posted by karron lane:
1. i can write the code in a text editor such as tex-edit.
Yes. Just be sure to save as text (not something like RTF) and to save the file with the file type of .java (not .txt, or .java.txt or something).

2. compile in eclipse? (i downloaded eclipse-java-ganymede-SR1-macosx-carbon.tar.gz)
Sure. You can also do it from the command line or other IDEs.

3. then what? how do i get the program to run?
I'm not an Eclipse user, but I assume there's a way for it to run the current project. We have a forum on IDEs here for Eclipse questions.

a big issue is that i don't understand the sequence of events in programming, like what happens first followed by what.
Generally, you write the code, then compile it into class files, then run the class files.

i found of lot of detailed info (tomcat, xcode, et al) but i don't understand how it all fits together.
Xcode is the Apple IDE. I'm not sure how great it is for Java. (I personally use IntelliJ IDEA). Tomcat is a servlet and JSP container, so you won't be messing with that unless you are writing Java web applications.

we are also required to turn in flowcharts so i'm wondering what software you might recommend.
I like OmniGraffle for diagramming.

Be sure to read through previous threads. Some people have already written a lot of good info on using Java under OS X.
[ September 25, 2008: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

The current version of Eclipse I've played with (Europa) seems pretty much the same between Windows and Mac. The "run" button is a green circle with a white triangle that will compile and run your code. There's a dropdown arrow to the right of this button that allows you to "Open Run Dialog" to configure your options. This is where you specify the main class (the class that contains the main method) for your project.


"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
sscce.org
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

For help using TextEdit and Terminal, see this thread.

If you need an IDE, think a Java beginner would be better off using Eclipse rather than Xcode, especially if that's what your Windows classmates are using.
karron lane
Greenhorn

Joined: Sep 25, 2008
Posts: 6
hi everyone, thanks so much for the info. i talked to my prof so i have a little better understanding of what my pc classmates will be doing. he said they will be writing and compiling the code from notepad. i don't know how that works out but that's what he said.

an ide is a compiler? do i understand that correctly?

ok, i think i understand the 'big picture' a little bit better but i do have another question. so, i write the code in tex-edit, and compile (or translate the source code) in an app like eclipse, et al, and then . . . . that's my question. after the code is compiled is it now ready to run as an executable (i don't know if that's the right language for the mac platform). will it then be an icon that one dbl clicks on to run from the desktop?

thanks to your posts i think i understand that another step is needed if the java app is to run online. that makes sense.

ok, thanks for your help with the big picture. i work better if i understand the process. we start coding next week so i'm very happy to have your input. this is a BIG adventure for me, totally uncharted territory.

i'm not terminal-ly experienced so will take the text editor route and will probably work with eclipse as it seems to have a rep for ease of use. someone mentioned a particular version of eclipse, i just downloaded the latest/greatest version on the site.

my understanding is that the class will be given 4 very small java apps where the code for the beginning and the end is furnished and we have to write the code in the middle. i confess i'm a little nervous about it.

thanks again.
karron lane
Greenhorn

Joined: Sep 25, 2008
Posts: 6
marc, thanks for the thread, i'm going to try out the mac version of Hello World after mid-terms.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Originally posted by karron lane:
hi everyone, thanks so much for the info. i talked to my prof so i have a little better understanding of what my pc classmates will be doing. he said they will be writing and compiling the code from notepad. i don't know how that works out but that's what he said.

Your classmates use notepad, and you will use text-edit. There are no difference here, they are both 'just' text editors.
an ide is a compiler? do i understand that correctly?

It is not just a compiler. An IDE is a programming tool where you do your code, and the code will normally be compiled automatically - but again an IDE is much more then a compiler.
ok, i think i understand the 'big picture' a little bit better but i do have another question. so, i write the code in tex-edit, and compile (or translate the source code) in an app like eclipse, et al, and then . . . . that's my question. after the code is compiled is it now ready to run as an executable (i don't know if that's the right language for the mac platform). will it then be an icon that one dbl clicks on to run from the desktop?

If you have gone through the thread that Marc refer to, you will see that to compile you need the command javac, and to run the compiled code you need the command java - it is the same on both Windows and Mac.

i'm not terminal-ly experienced so will take the text editor route and will probably work with eclipse as it seems to have a rep for ease of use. someone mentioned a particular version of eclipse, i just downloaded the latest/greatest version on the site.

Just be careful that you understands how java compile and running programs works, when you are using an IDE like Eclips, that do all the important stuff for you


So as a final comment...
There are no difference between how java works on a windows PC or on a Mac.
If you in your class get some java commands or other java related stuff - it will work on both Windows and Mac.


Regards, Rene Larsen
Dropbox Invite
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Your classmates using Windows will write in Notepad and compile using Command Prompt. On a Mac, you will write in TextEdit and compile using Terminal. Other than that, it's basically the same.

An IDE (like Eclipse) provides both of these functions (and more) within one application. As a text editor, the IDE provides extra features like syntax highlighting, line numbering, indentation formatting, etc. An IDE also compiles, either by tapping into the javac tool or by using its own compiler. As Rene mentioned, an IDE can even do more -- and sometimes that is not a good thing for beginners, because it "hides" the details you need to know.

My recommendation is to stick with a text editor and Terminal for now. Do no confuse things with an IDE.

(Note: For a cool text editor on the Mac, download the free TextWrangler. This provides handy syntax highlighting and line numbering without all the overhead of a big IDE.)
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by karron lane:
...after the code is compiled is it now ready to run as an executable (i don't know if that's the right language for the mac platform). will it then be an icon that one dbl clicks on to run from the desktop? ...

The short answer is no.

When you compile Java code, the result is class files. These contain bytecode that can be executed by a Java Virtual Machine (JVM). You can run the code using the java command-line tool, as described in the other topic I linked to above.

(Actually, you might notice that on a Mac you can run by just double-clicking on the Java class file. But your Windows friends won't have this luxury.)

To package a Java application inside a neat, executable icon, you need to do more work. In Java, this usually means packaging all your resources (class files, graphics, etc.) in a JAR (Java Archive) and making that JAR "executable" with a double-click. This is probably more advanced than what you will be doing in this class.
karron lane
Greenhorn

Joined: Sep 25, 2008
Posts: 6
wow, thanks for all of the great info. i def have a better big picture understanding now and that's important in how i learn so your comments are very much appreciated. monday, we did hello world on the pc's in the lab. i'm going to set up my mac this weekend so i can bring it to class. i'm going to start off without an ide and then switch over to see the difference.

i enjoyed this:

<<<Actually, you might notice that on a Mac you can run by just double-clicking on the Java class file. But your Windows friends won't have this luxury>>>

i asked my pc prof about this on monday and he said dbl clicking doesn't work to run the file. i'm not at all surprised to learn that it does on a mac. hee.

thanks again to all, i'm sure i'll be back with other questions as the semester goes on.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Originally posted by karron lane:
<<<Actually, you might notice that on a Mac you can run by just double-clicking on the Java class file. But your Windows friends won't have this luxury>>>

i asked my pc prof about this on monday and he said dbl clicking doesn't work to run the file. i'm not at all surprised to learn that it does on a mac. hee.


Just for your information...

I am not able to run a java class by double-clicking on it.

On my system the default Application for a class file is "Jar Launcher.App"
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Rene Larsen:
...I am not able to run a java class by double-clicking on it.

On my system the default Application for a class file is "Jar Launcher.App"

Hmmm... Did you change the association? I think the default for OS X is to launch the JVM. According to Java Deployment Options for Mac OS X...
You can double-click on a Java class file to launch your application...

I discovered this accidentally when I double-clicked a class file instead of the source file. I expected my associated IDE to open, but the program ran instead.

Of course, this is not the way to deploy. It's just mildly interesting.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Marc, what Application is assigned as default for a class file on your system??

The link you posted is about double-clicking on a jar-file - and this works on both Windows and Mac the same way.
karron lane
Greenhorn

Joined: Sep 25, 2008
Posts: 6
well, i didn�t get very far. i typed my hello world app in textwrangler and now i�m trying to compile it in terminal. my hello world app is located on my desktop in a folder named Hello World which is inside a folder named Java Projects. i can�t seem to find instructions online about how to properly type a path to my directory if it�s on the desktop or perhaps i�ve missed something else. here�s what i used:

Macintosh:~ kll$ desktop/Java Projects/Hello World/HelloWorldApp.java
-bash: desktop/Java: No such file or directory

also, why can�t i correct a typo or add type into terminal? so far i�m not happy with terminal but maybe it�s just me.

will terminal tell me if there is a problem with my source code?

thanks, as always.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

First, you probably want to change directories to where your source file is located. The command to change directories is "cd" (just like on a Windows machine), followed by the directory path. The new prompt that appears will show the current directory.

Edit: See Rene's post below. To avoid confusion, I corrected my post by putting single quotes around the path below, but I missed these the first time. Thanks for the correction!

From this directory, you want to run javac, which is the Java compiler. Type "javac" followed by the name of the source file you want to compile...

If your file compiles successfully, you will get a fresh prompt with no messages. Otherwise, error messages will be displayed. Let us know if these don't make sense.

To run your compiled file, type "java" followed by the class name (without any extension)...

On the current command line (not a previously executed one), you should be able to correct typos in Terminal using the backward/forward arrow keys to move the cursor. You should be able to insert/delete. What exactly is not working?

[ October 08, 2008: Message edited by: marc weber ]
[ October 10, 2008: Message edited by: marc weber ]
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Rene Larsen:
... The link you posted is about double-clicking on a jar-file...

Thanks for making me look into this, because I learned something.

Yes, that page talks about making executable JAR files, but also notes as an aside that...
You can double-click on a Java class file to launch your application, but this is not a recommended method for application deployment.

I know that I've done this in the past, but when I tested it tonight, I had the same experience you reported: None of the class files I tried would run by double-clicking.

So I did some digging, and it turns out that Jar Launcher is the associated app, but this only works on class files for a GUI app. That's what I happened to be working on when I accidentally discovered this, and I assumed (wrongly) that it worked for any class file.

According to Wikipedia - Jar Launcher...
Jar Launcher is the program in Mac OS X that launches Java JAR files into the Aqua/Java runtime environment when the JAR file is double clicked. Jar Launcher also launches a class in the same manner... Java programs without any GUI should be run from the command line as they may not properly execute without a pseudo terminal.

So this little feature turns out to be less interesting than I thought.
karron lane
Greenhorn

Joined: Sep 25, 2008
Posts: 6
marc, thanks for the nfo. i'll give this a go in the morning when i'm not so tired. i'll post back about the insert/delete too.

good dreaming to you.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Originally posted by karron lane:
Macintosh:~ kll$ desktop/Java Projects/Hello World/HelloWorldApp.java
-bash: desktop/Java: No such file or directory


When you want to change directory in Terminal, and there are spaces in the path, you need to escape the spaces.

or instead of putting this escape character in the path, you can put the hole path inside single quotes (').

[ October 09, 2008: Message edited by: Rene Larsen ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: newbie needs direction
 
Similar Threads
java db on a mac-getting started
New to Java
Development environment
The best IDE
Eclipse + Tomcat + JSP's on the Mac