Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Where to start with Java for OS X?

Where to start with Java for OS X?
Thread Tools
Professional Poster
Join Date: Oct 2001
Status: Offline
Reply With Quote
Jun 14, 2004, 06:02 PM
 
Hi there. I've signed up for an online course in Java. It hasn't started yet, but before it does I'd like to be prepared.

I have the latest Dev Tools installed, but am confused as to what type of Java development I should use. In Xcode there's Cocoa-Java applications and Java Swing applications (I heard that AWT is bad for some reason).

Which is better? Which is faster (ex. Limewire slow vs. Acquisition fast)? And where can I get the tutorials for getting started with the best method?

Thanks for any help in helping me understand how OS X "does" JAVA.
     
Mac Elite
Join Date: Apr 2002
Location: Here and there
Status: Offline
Reply With Quote
Jun 14, 2004, 06:08 PM
 
I'd suggest Java-Swing which will not only run on Macs but all other platforms as well (given that there's a Java VM available). There are excellent Java Tutorials on http://java.sun.com

I would however suggest not to use XCode but Eclipse and for the visual stuff, the Visual Editor Plugin.
"Life is not a journey to the grave with the intention of arriving safely in one
pretty and well preserved piece, but to skid across the line broadside,
thoroughly used up, worn out, leaking oil, shouting GERONIMO!"
     
Registered User
Join Date: Feb 2003
Status: Offline
Reply With Quote
Jun 14, 2004, 08:07 PM
 
OK - Visit developer http://developer.apple.com/java/ for info of Java on Mac OSX.

If you are learning Java, I am sure your course will recommend a basic tool to do your java coding with. Probably as simple as NotePad / TextPad and the command line to start with and then possible BlueJ or something simple like that.

If you are not an experience Java programmer then it is not recommended to start with IDE's like Eclipse or Intelij or others as these tools as great as they are hide many of the basic thing you will need to know and as add a layer of complexity to your learning which you do not need when you are stating out.

As for what IDE to use finally, try every one of them, and do not settle for any ones recommendation. Also just because an IDE is free does not mean its the best.

Imagine trying to learn to read write and speak using MS Word how much more complex it would be.

As for XCode for java development just stay away from it as it sucks for java.
     
Professional Poster
Join Date: Oct 2001
Status: Offline
Reply With Quote
Jun 14, 2004, 09:56 PM
 
Originally posted by D'Espice:
I'd suggest Java-Swing which will not only run on Macs but all other platforms as well (given that there's a Java VM available). There are excellent Java Tutorials on http://java.sun.com

I would however suggest not to use XCode but Eclipse and for the visual stuff, the Visual Editor Plugin.
I'll try Eclipse as I'm new to Java but not programming in general (have obj-c experience). So most people would recommend it over Xcode?

I'm worried about Java's notorious reputation for being overly slow on OS X. Is eclipse and swing the way to go for fast Java apps? And will I be able to create gui's with it? What is this Visual Editor plugin, does it come with it?
     
Forum Regular
Join Date: Mar 2000
Location: A drip off Lake Michigan
Status: Offline
Reply With Quote
Jun 14, 2004, 10:31 PM
 
Originally posted by itistoday:
I'm worried about Java's notorious reputation for being overly slow on OS X. Is eclipse and swing the way to go for fast Java apps? And will I be able to create gui's with it? What is this Visual Editor plugin, does it come with it?
I'd have to agree that starting with a text editor is the way to go. You can get a handle on what goes into setting up the interface that way. It is really one of the least difficult parts of java to grasp.
I've used jEdit -- www.jedit.org --, bbedit and SubEthaEdit. The latest pre-releases of jEdit have really awsome default highlighting -- although you can match it by just customizing the older, stable releases. It also has great plug-ins for just about anything -- code completions, highlighting themes, comment toggling, ftp ....

As for speed ... it doesn't seem any different to me ... although here are some benchmarks:

A simple Fibonocci recursive, timed at 40 iterations:
P4, 2.8Ghz: 8.344 sec.
Powerbook G4 867 Mhz: 17.868 sec.
PowerMac G4 533x2: 26.737 sec.

None of the java programs I run (jEdit, Art of Illusion, NetBeans) seem slow ... until I switch to my P4 and run them there--but my P4 is not only more than twice as fast, I'm sure the VM gets extra attention from SUN, who has the threat of .NET to contend with.

My rants aside, Java's speed is fine ...

Oh, and Swing is an extension to AWT -- so don't think of AWT as bad. Its not, it is just limited, but Swing fixes that!
     
Professional Poster
Join Date: Oct 2001
Status: Offline
Reply With Quote
Jun 14, 2004, 10:51 PM
 
wait. I'm still confused. What is AWT? What is Swing? I installed Eclipse and am going through the tutorials on how to use it. I still don't have any idea of where to begin, but I have a feeling that after I read the tutorial it'll be fine.

I have BBEdit, but don't understand why I should use it. I want to create gui's. Is there a way to create them like one would with Interface Builder? I know Xcode can do it...

I also heard that Xcode can use cocoa classes for Java?? What is the way to go? I'm so confused.
     
Forum Regular
Join Date: Mar 2000
Location: A drip off Lake Michigan
Status: Offline
Reply With Quote
Jun 14, 2004, 11:33 PM
 
Originally posted by itistoday:
wait. I'm still confused. What is AWT? What is Swing? I installed Eclipse and am going through the tutorials on how to use it. I still don't have any idea of where to begin, but I have a feeling that after I read the tutorial it'll be fine.

I have BBEdit, but don't understand why I should use it. I want to create gui's. Is there a way to create them like one would with Interface Builder? I know Xcode can do it...

I also heard that Xcode can use cocoa classes for Java?? What is the way to go? I'm so confused.
Here is a try:
AWT, or abstract windowing toolkit, was the original set of objects sun created for building GUIs. It was limited, though ... I don't know how limited now, because I've forgotten all that already -- but like you couldn't do certain things, like sliders maybe ... or maybe its something else altogether. However, with Java2, I think, Sun included the extended set of objects ... Swing. This allows for the more intracate UI's we've come to know and love. It also made it easier for certain interactions, I think ... like mouse tracking and stuff.

Incidentally, I fired up my hobby box, a PM7600 with a g3/350 card in it ... it is running YDL 3.0, with Blackdown's 1.3.1 JDK.

To do that very same Fabonacci (40 iterations): 717.618 seconds.

By comparison, P4 2.8, with 50 iterations: 733.266

Here, I posted it online -- try your computer:
http://www.wavemachine.net/tm588/FibonacciTest2.html

You won't get any real dents till about 30, depending on your computer.

Any G5s out there?

Anyway, the thing is, you could use Interface Builder, but then you would make a Mac-only application. If you want to harness the cross-platform aspect of Java, the you should use Swing (with AWT).

Like the other poster said, there are programs which allow you to "draw" your interface. NetBeans does this, Eclipse with the proper plug-ins, JBuilder (the free foundation), and somebody in a previous post even used QT Designer, and used the XML output somehow -- maybe with an intermediate program, to make a Java UI.

There is also AWT, which is another UI toolkit. It is what the Eclipse project uses, and it is supposed to be faster on a Mac, because it uses Carbon or something like that.

You should really try it without these tools to start off with, though. It helped me understand the OOP of Java better ... since the OOP concepts were what I had the hardest time with (I learned with Assembly and C, and still havne't really grown beyond structured programming ...)
(Last edited by Theodour; Jun 14, 2004 at 11:46 PM. )
     
Registered User
Join Date: Feb 2003
Status: Offline
Reply With Quote
Jun 15, 2004, 12:00 AM
 
F#*K - Swing F#*K - AWT do not worry about them at this time.

Also just stick with a basic text editor and the terminal then do Sun Tutorial.

Do not worry about GUI stuff or Fancy IDE's they are already confusing you.
     
Senior User
Join Date: Feb 2003
Location: USA
Status: Offline
Reply With Quote
Jun 15, 2004, 06:36 AM
 
Another recommendation for holding off on the GUI for at least a little while. Take some time to learn the language doing some simple command line apps then add the GUI into the mix. I picked Java up in a pretty short time using this approach...
MacBook 2.0 160/2GB/SuperDrive
Lots of older Macs
     
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status: Offline
Reply With Quote
Jun 15, 2004, 09:14 AM
 
Originally posted by depolitic:


Do not worry about GUI stuff or Fancy IDE's they are already confusing you.

Especially Eclipse / SWT. If there ever was an Evil Invention in the world of Java---it's that platform fragmentation causing pile of dung from IBM.

Do yourself a favor and avoid SWT like the plague until you know enough about AWT/Swing to make your own decision.
signatures are a waste of bandwidth
especially ones with political tripe in them.
     
Professional Poster
Join Date: Oct 2001
Status: Offline
Reply With Quote
Jun 15, 2004, 11:01 AM
 
ok thanks guys, looks like I'm off to the Java tutorial trail!
*rides off into the sunset, cheered on by Mexican villagers*

BTW, on my Dual 867 G4 it took 14.551 seconds to do 40 iterations? (i put 40 as the integer) using Mozilla.
(Last edited by itistoday; Jun 15, 2004 at 11:25 AM. )
     
Addicted to MacNN
Join Date: May 2001
Location: Cupertino, CA
Status: Offline
Reply With Quote
Jun 15, 2004, 12:09 PM
 
Good IDE for learning Java --> emacs
     
Registered User
Join Date: Oct 2003
Status: Offline
Reply With Quote
Jun 15, 2004, 02:06 PM
 
> Good IDE for learning Java --> emacs

Trouble is, it takes longer to learn emacs than Java. {ducks} :)

itistoday, try using jEdit for a while, along with the Terminal application. Also keep a web browser window open to the official Java docs.

From Terminal, you'll compile your code to bytecode like so:
Code:
javac Foo.java
and you'll run that program with the "java" command:
Code:
java Foo
Any GUI stuff you need you just code by-hand (you don't need a GUI builder/RAD tool/IDE or anything like that).

The whole AWT/Swing thing is confusing. It used to be that you used AWT for all drawing and GUI stuff. Then Swing came along to replace the AWT GUI classes, but you still use AWT for things, including drawing stuff. Sun really needs to just bite the bullet and make it all one package.
     
Clinically Insane
Join Date: Nov 1999
Status: Offline
Reply With Quote
Jun 16, 2004, 05:21 AM
 
For now, itistoday, do not worry about the GUI stuff. Stick with the command-line until you've mastered the basics. GUI programming can come later, once you've got a solid base to start from.
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
     
Forum Regular
Join Date: Mar 2000
Location: A drip off Lake Michigan
Status: Offline
Reply With Quote
Jun 16, 2004, 03:21 PM
 
Originally posted by Millennium:
For now, itistoday, do not worry about the GUI stuff. Stick with the command-line until you've mastered the basics. GUI programming can come later, once you've got a solid base to start from.
Why not try GUI programming? I think you should enjoy how simple it is to make a GUI with Java.
     
Addicted to MacNN
Join Date: May 2001
Location: Cupertino, CA
Status: Offline
Reply With Quote
Jun 16, 2004, 06:00 PM
 
Originally posted by Theodour:
Why not try GUI programming? I think you should enjoy how simple it is to make a GUI with Java.
Because Swing and AWT are much more about learning to use the libraries than learning Java. There are basic parts of the Java libraries that are essential to learn -- eg almost everything in java.lang, java.io, and java.util -- and are easier to start with. In contrast, knowledge of Swing/AWT isn't really necessary for many Java programmers. There are also some concepts commonly employed in Swing/AWT that require a significant level of familiarity with the language to understand (such as threading, anonymous classes, etc). And finally, there is a lot of 'overhead' involved when writing a GUI app that isn't particularly instructive when learning the language itself.
     
Forum Regular
Join Date: Mar 2000
Location: A drip off Lake Michigan
Status: Offline
Reply With Quote
Jun 16, 2004, 06:42 PM
 
Originally posted by itai195:
There are also some concepts commonly employed in Swing/AWT that require a significant level of familiarity with the language to understand (such as threading, anonymous classes, etc). And finally, there is a lot of 'overhead' involved when writing a GUI app that isn't particularly instructive when learning the language itself.
OK, I agree with that, since most of the trouble I have with Java are probably a direct result of focusing on problems that involved both functionality and a GUI. If I were doing just the functionality, I might have developed better "coping strategies" to solve given problems.

But I think the fault was mostly with my class's approach.

I propose that a well thought out class could incorporate both the core value of the language with the immediate gratification of the GUI components -- in tandem.
     
Dedicated MacNNer
Join Date: Oct 2000
Location: Copenhagen, Denmark
Status: Offline
Reply With Quote
Jun 17, 2004, 03:05 AM
 
First of all - I am in the same situation as itistoday and has found all the responses very useful, so thank you!

I have now encountered an occuring problem. I have in BBedit tried a "hello world" script but continues to get the following message when trying to run it (it compiles w/o problems):
Excepting in thread "main" java.lang.NoClassDefFoundError

I compile and run through the Terminal.
Any suggestions on whats wrong (it works at my class, where we use winXP). Has it something to do with the ClassPath? If yes, suggestions on how to fix it?

TIA,
Peter
     
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status: Offline
Reply With Quote
Jun 17, 2004, 03:08 AM
 
if you file is called HelloWorld.java, then the class would be HelloWorld.class

go to the directory of the class file and run it like this:

java HelloWorld
signatures are a waste of bandwidth
especially ones with political tripe in them.
     
Dedicated MacNNer
Join Date: Oct 2000
Location: Copenhagen, Denmark
Status: Offline
Reply With Quote
Jun 17, 2004, 04:21 AM
 
I have both the .class and the .java file in same directory, and call it just like you say

Peter
     
Senior User
Join Date: Oct 2000
Location: Midwest
Status: Offline
Reply With Quote
Jun 17, 2004, 07:33 AM
 
Peter,

Let's check you setup. When you enter
Code:
echo $JAVA_HOME
from a Terminal window, you should see /Library/Java/Home returned assuming your are running Panther. Are you compiling with
Code:
javac YourFile.java
without any problems from the Terminal? You might have a path problem, i.e. you Java installation is not being sourced as needed.

Craig
     
Dedicated MacNNer
Join Date: Oct 2000
Location: Copenhagen, Denmark
Status: Offline
Reply With Quote
Jun 17, 2004, 09:48 AM
 
Thanks for your help, suthercd :-)

Unfortunately, when I write echo $JAVA_HOME in the terminal, nothing happens:
------------------

Peter-Thorns-computer:~ java$ echo $JAVA_HOME;

Peter-Thorns-computer:~ java$

------------------

(java$ being the user java I just have created in order to be more structured...)

And I compiled just like you say "javac myfile.java" and get no errors.

Hmm???!!!

Peter
     
Dedicated MacNNer
Join Date: Oct 2000
Location: Copenhagen, Denmark
Status: Offline
Reply With Quote
Jun 17, 2004, 09:53 AM
 
Forgot to mention - the file myfile.class does also appear in the same folder as the .java file, so no problem there either?!

Peter

Could it have anything to do with that I have the QT java extensions installed? (I know that that could result in problems on windows).
     
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status: Offline
Reply With Quote
Jun 17, 2004, 10:41 AM
 
I dont think $JAVA_HOME will be assigned unless he assigned it, and he doesn't really need it unless he's using something like ANT, Tomcat, JBoss, etc.

Also, don't put a ';' after the echo command.


tell us exactly what the error is. which class is it complaining about?

if your file is called "myfile.java" and you compile it to myfile.class, then the class definition must be for a class called "myfile"

Code:
public class myfile{ ... }
signatures are a waste of bandwidth
especially ones with political tripe in them.
     
Dedicated MacNNer
Join Date: Oct 2000
Location: Copenhagen, Denmark
Status: Offline
Reply With Quote
Jun 17, 2004, 12:53 PM
 
I forgot to mention that I didn't use ; in the end when I first tried it - I just added it the second time to see if that was the thing to do.

This is the HelloWorld.java file:

----------------------
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
-----------------------

(I have also tried class HelloWorld { (without public) with the same result)

This is the content of the Terminal:

-----------------------
Peter-Thorns-computer:~ java$ javac /Users/java/Desktop/HelloWorld.java
Peter-Thorns-computer:~ java$ java /Users/java/Desktop/HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: /Users/java/Desktop/HelloWorld
Peter-Thorns-computer:~ java$
-----------------------

The file HelloWorld.class is also present at the Desktop after I have compiled.

Thanks,
Peter
     
Dedicated MacNNer
Join Date: Oct 2000
Location: Copenhagen, Denmark
Status: Offline
Reply With Quote
Jun 17, 2004, 01:10 PM
 
After some searching, I found this site that says it might have something to do with the CLASSPATH:
"When I try to run java I get: Exception in thread "main" java.lang.NoClassDefFoundError Your CLASSPATH may have been set by some other program so that it no longer includes the current working directory in the search path. Try running your program with the command line
[username:] ~/introcs/hello> java -classpath ./ HelloWorld"

The programs I have installed which has java stuff is QT and xcode, but I haven't (knowingly) changed anything concerning any CLASSPATH?

Any suggestions on how to redirect it or can anyone explain the details of the "[username:] ~/introcs/hello> java -classpath ./ HelloWorld" line?

Thanks,
Peter

Added bonus: below is what appeared when I wrote set in the Terminal (the windows guys in my class did that in the dos-prompt in order to find out stuff about the bin etc.) - don't know if it's useful.

BASH=/bin/bash
BASH_VERSINFO=([0]="2" [1]="05b" [2]="0" [3]="1" [4]="release" [5]="powerpc-apple-darwin7.0")
BASH_VERSION='2.05b.0(1)-release'
COLUMNS=80
DIRSTACK=()
EUID=503
GROUPS=()
HISTFILE=/Users/java/.bash_history
HISTFILESIZE=500
HISTSIZE=500
HOME=/Users/java
HOSTNAME=Peter-Thorns-computer.local
HOSTTYPE=powerpc
IFS=$' \t\n'
LINES=24
LOGNAME=java
MACHTYPE=powerpc-apple-darwin7.0
MAILCHECK=60
OPTERR=1
OPTIND=1
OSTYPE=darwin7.0
PATH=/bin:/sbin:/usr/bin:/usr/local/bin:/usr/sbin
PIPESTATUS=([0]="0")
PPID=3585
PS1='\hw \u\$ '
PS2='> '
PS4='+ '
PWD=/Users/java
SECURITYSESSIONID=6bcb2700
SHELL=/bin/bash
SHELLOPTS=braceexpand:emacs:hashall:histexpand:his tory:interactive-comments:monitor
SHLVL=1
TERM=xterm-color
TERM_PROGRAM=Apple_Terminal
TERM_PROGRAM_VERSION=100
UID=503
USER=java
_=/etc/bashrc
__CF_USER_TEXT_ENCODING=$'0x1F7:0:9\n'
(Last edited by peterthorn; Jun 17, 2004 at 01:20 PM. )
     
Addicted to MacNN
Join Date: May 2001
Location: Cupertino, CA
Status: Offline
Reply With Quote
Jun 17, 2004, 01:23 PM
 
The command you want to use is java -cp /Users/java/Desktop HelloWorld

The java command takes a fully qualified class name, not a file path.
     
Mac Elite
Join Date: Oct 2001
Location: Umbrella Research Center
Status: Offline
Reply With Quote
Jun 17, 2004, 01:31 PM
 
you should just change your directory to your the correct directory... that or just use ant
     
Dedicated MacNNer
Join Date: Oct 2000
Location: Copenhagen, Denmark
Status: Offline
Reply With Quote
Jun 18, 2004, 04:56 AM
 
I couldn't get it to run via the terminal, and just before giving up and using Virtual PC, I downloaded jGrasp (the editor we use at the class), and noticed that they have a OS X version too. And when I use that, I can compile and run the files, for some strange reason?!
So I have given up trying to get it to work with the Terminal, and stick to jGrasp. Otherwise I wouldn't be able to get to do my homework, just in order to make it work :-)

Thanks for all the great advices!

Peter
     
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status: Offline
Reply With Quote
Jun 18, 2004, 10:48 AM
 
Because that editor is smart enough to know where the file is.
Read the last few posts.

You were trying to compile it from another directory. You never mentioned that little bit of all important information.

In that case, you need to specify the classpath just as ital said.

Or, you need to change to the correct directory just as Phanguye said.

You are missing some very basic aspects of the Java platform. If you don't understand why it wasn't working, you will get lost in the future when it comes to packaging, etc.
signatures are a waste of bandwidth
especially ones with political tripe in them.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:35 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2