Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

yg17

macrumors Pentium
Original poster
Aug 1, 2004
15,028
3,003
St. Louis, MO
I'm taking Java programming in college and have a question on how to get started. I was browsing through documents online for the class before the first day of class tomorrow, and it seems that all of our Java programs will be command line-type programs. The instructor provides instructions for installing and using the Sun Java SDK on Windows. Obviously, I'd rather not go to a campus computer lab and torture myself with Windows (it was bad enough last semester when they forced us to use Visual Studio for C++)

How do I get started with Java on Tiger? I've got Xcode installed, but don't think it has what I want, as the only command line type stuff is for C++. More importantly, will any Java code that works on my Mac work on a Windows box with the Sun SDK and vice versa? I don't want to get points on assignments taken off because my OSX compatible code doesn't work on the grader's Windows computer.

Also, on the back cover of my Java textbook, it says "This edition uses the latest features of Java version 5.0, also known as Tiger." Does that have anything at all to do with OSX 10.4? The screenshots in the book are from Windows XP, so I doubt it.

Thanks.
 

Mitthrawnuruodo

Moderator emeritus
Mar 10, 2004
14,657
1,465
Bergen, Norway
For simple exercise command line programs just use a nice, free text editor with color coding, like TextWrangler (my current favorite) or SubEthaEdit and compile with Terminal (javac to compile and java to run).

Or get a nice educational IDE like BlueJ witch also has UML support.

Eclipse, as mentioned above is excellent, but not needed for the first year, really. Learn the basics first. :)
 

superbovine

macrumors 68030
Nov 7, 2003
2,872
0
it shouldn't matter with java 101 class which system do your command line programs in, but i would still do a test run on a windows machine before you turn it in because of two things. first when you run your program, you have to make sure the formatting of your text output is correct. the next thing you should check is to make sure your homework looks correct in the editor they are looking at your source code in.
 

VanMac

macrumors 6502a
May 26, 2005
914
0
Rampaging Tokyo
Hey.

Go with eclipse.
http://www.eclipse.org

It is a nice and clean IDE, so not much of a learning code involved or anything. Very basic out the gate, but will simplify development.

Good experience also, as tools like IBM Websphere Studio Application Developer are based on eclipse. It has a real nice 'pluggin' architecture.

Happy coding!
 

Compile 'em all

macrumors 601
Apr 6, 2005
4,131
359
yg17 said:
I'm taking Java programming in college and have a question on how to get started. I was browsing through documents online for the class before the first day of class tomorrow, and it seems that all of our Java programs will be command line-type programs. The instructor provides instructions for installing and using the Sun Java SDK on Windows. Obviously, I'd rather not go to a campus computer lab and torture myself with Windows (it was bad enough last semester when they forced us to use Visual Studio for C++)

How do I get started with Java on Tiger? I've got Xcode installed, but don't think it has what I want, as the only command line type stuff is for C++. More importantly, will any Java code that works on my Mac work on a Windows box with the Sun SDK and vice versa? I don't want to get points on assignments taken off because my OSX compatible code doesn't work on the grader's Windows computer.

Also, on the back cover of my Java textbook, it says "This edition uses the latest features of Java version 5.0, also known as Tiger." Does that have anything at all to do with OSX 10.4? The screenshots in the book are from Windows XP, so I doubt it.

Thanks.

Okay, just to clear things up, Java 5.0 (aka Tiger) has nothing to do with
Mac OS X 10.4 (aka Tiger). It is just a name clash nothing more.

Mac OS X 10.4 currently ships with Java 2 (1.4.2). You can check the java
version by typing the command "java -version" in Terminal.

Java is supposed to be platform independant, that is compile once run
everywhere, however this is not always correct. For example, if in your
program you deal with the filesystem (i.e write files) you have to pay
careful attention to file path delimiters. That is slashes (/) in *NIX versus
backslashes (\) in Windows.

As well, Java programs that uses special classes from Java 5.0 won't run
(read ClassNotFoundException) on machines running older Java versions.
So if your college will use classes only present in Java 5.0 then you are in a
problem because OS X ships with 1.4.2 and I don't have any idea how to
get 1.5 installed on OS X.

Bottom line, as long as you take care of filesystem specfic stuff in your
program and stay away from Java 5.0-only classes there would be no
problem.

Answering the question of how to get started with Java, you can take a look here.

Have fun and happy programming :)
 

yg17

macrumors Pentium
Original poster
Aug 1, 2004
15,028
3,003
St. Louis, MO
Compile 'em all said:
Okay, just to clear things up, Java 5.0 (aka Tiger) has nothing to do with
Mac OS X 10.4 (aka Tiger). It is just a name clash nothing more.

Mac OS X 10.4 currently ships with Java 2 (1.4.2). You can check the java
version by typing the command "java -version" in Terminal.

Java is supposed to be platform independant, that is compile once run
everywhere, however this is not always correct. For example, if in your
program you deal with the filesystem (i.e write files) you have to pay
careful attention to file path delimiters. That is slashes (/) in *NIX versus
backslashes (\) in Windows.

As well, Java programs that uses special classes from Java 5.0 won't run
(read ClassNotFoundException) on machines running older Java versions.
So if your college will use classes only present in Java 5.0 then you are in a
problem because OS X ships with 1.4.2 and I don't have any idea how to
get 1.5 installed on OS X.

Bottom line, as long as you take care of filesystem specfic stuff in your
program and stay away from Java 5.0-only classes there would be no
problem.

Answering the question of how to get started with Java, you can take a look here.

Have fun and happy programming :)


Thanks :)

The Windows boxes in the lab say this:

java version "1.5.0_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)
Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode, sharing)

so that means its Java 5.0?
 

yg17

macrumors Pentium
Original poster
Aug 1, 2004
15,028
3,003
St. Louis, MO
Mitthrawnuruodo said:
To upgrade to Java 5.0 (aka 1.5**) get this.

Also, it's a good idea to read Apple's Java FAQ. :)

** The version number is 1.5 but Sun renamed it to 5.0 for marketing reasons...

Thanks.

I was reading the FAQ page and it says:

The standard command-line commands such as java and javac use 1.4 on any system which has a 1.4 JDK installed, including systems which also have JDK 1.5.

So the java compiler will still be 1.4?
 

Compile 'em all

macrumors 601
Apr 6, 2005
4,131
359
yg17 said:
Thanks.

I was reading the FAQ page and it says:



So the java compiler will still be 1.4?

I have checked the FAQ and it means that if you have Java 1.5 installed, it
will co-exist with Java 1.4. However. when you try using java (running) and
javac (compiling) Java programs, 1.4 will be used. In order to use the
installed 1.5 you have to explicitly mention that you will be using 1.5 via
some argument.
Summary, in a system with 1.4 and 1.5 installed, java and javac will invoke
1.4. To use 1.5, an argument has to be specified.
 

mspock

macrumors newbie
Aug 26, 2003
23
0
question about java and os x technologies

I, im learning java as my first oop programming languages. Im using "beginning programming with java 2 for dummies, 2nd edition" and i love it. I also have "programming in objective-c".

I have a question about java on os X. Is there a way to use coreimage and corevideo stuff in my program if i write it in java ? or are those technologies reserve to objective-c/cocoa programming ?

thanks
 

MacFan26

macrumors 65816
Jan 8, 2003
1,219
1
San Francisco, California
Compile 'em all said:
In order to use the
installed 1.5 you have to explicitly mention that you will be using 1.5 via
some argument.
Do you know how to do that? Or is there I way I can have this automatically set to compile with 1.5 every time?
 

Converted2Truth

macrumors 6502a
Feb 6, 2004
608
0
Hell@HighAltitude
mspock said:
I, im learning java as my first oop programming languages. Im using "beginning programming with java 2 for dummies, 2nd edition" and i love it. I also have "programming in objective-c".

I have a question about java on os X. Is there a way to use coreimage and corevideo stuff in my program if i write it in java ? or are those technologies reserve to objective-c/cocoa programming ?

thanks
You can write cocoa apps in Java, but from what i understand almost nobody does it. Kinda redundant if you think about it. The whole point of Java is compatibility. If you were to integrate OSX technologies into your java app, the only thing you gain is a performace hit! Make it fast... make it right... make it 100% cocoa. Or if you want your app to be cross-platform, go Java with openGL.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
mspock said:
I, im learning java as my first oop programming languages. Im using "beginning programming with java 2 for dummies, 2nd edition" and i love it. I also have "programming in objective-c".

I have a question about java on os X. Is there a way to use coreimage and corevideo stuff in my program if i write it in java ? or are those technologies reserve to objective-c/cocoa programming ?

thanks

I believe that the new Core* technologies introduced in 10.4 are not available over the Java bridge. I no for a fact that CoreData is not available to Cocoa/Java programmers.
 

GilGrissom

macrumors 65816
Mar 13, 2005
1,042
1
Compile 'em all said:
Please read here .Good luck.
Thanks for the link...(now for the dum ass question!) what exactly does it involve though?? How to I actually do what it says with the command line?!
I appologise for the embarrasing stupid question! :eek:
 

Compile 'em all

macrumors 601
Apr 6, 2005
4,131
359
Gil_Grissom said:
Thanks for the link...(now for the dum ass question!) what exactly does it involve though?? How to I actually do what it says with the command line?!
I appologise for the embarrasing stupid question! :eek:

Okay, so as you know Java 1.4.2 is used by default. To use Java 1.5 you
have to specify the absolute path to java. This means that to run
your program using 1.5 you do

/System/Library/Frameworks/JavaVM.framework/Versions/1.5/java YourMainJavaClass

and for compiling it should be

/System/Library/Frameworks/JavaVM.framework/Versions/1.5/javac YourMainJavaClass.java

To use the J2SE 5.0 version of any command-line Java utility, such as java or javac, specify the full path to the J2SE 5.0 version of the command. This usually means prepending the command with the path /System/Library/Frameworks/JavaVM.framework/Versions/1.5/.
 

GilGrissom

macrumors 65816
Mar 13, 2005
1,042
1
Compile 'em all said:
Okay, so as you know Java 1.4.2 is used by default. To use Java 1.5 you
have to specify the absolute path to java. This means that to run
your program using 1.5 you do

/System/Library/Frameworks/JavaVM.framework/Versions/1.5/java YourMainJavaClass

and for compiling it should be

/System/Library/Frameworks/JavaVM.framework/Versions/1.5/javac YourMainJavaClass.java
Thanks for that! It's not working for me, saying "no such file or directory", even though I have 1.5 installed (mind you its the 3rd revision from ADC and not the normal one...I'm guessing this is why?! I shall install the normal one and get back to you!!

Many Thanks for your help!! :)
 

Compile 'em all

macrumors 601
Apr 6, 2005
4,131
359
Gil_Grissom said:
Thanks for that! It's not working for me, saying "no such file or directory", even though I have 1.5 installed (mind you its the 3rd revision from ADC and not the normal one...I'm guessing this is why?! I shall install the normal one and get back to you!!

Many Thanks for your help!! :)

You have to know where did you install the Java 1.5. It need not to be
located in /System/Library/Frameworks/JavaVM.framework/Versions/1.5/.
The Apple doc mentioned that it usually resides there but that doesn't
mean it should be there.
You can use spotlight (if you are on 10.4) to locate it or simply use tabbing
while you're in Terminal to auto-complete the path. That is when typing in
Terminal the path just type the 1st two or three letters and hit Tab to
complete it for you.
Good luck.
 

GilGrissom

macrumors 65816
Mar 13, 2005
1,042
1
Compile 'em all said:
You have to know where did you install the Java 1.5. It need not to be
located in /System/Library/Frameworks/JavaVM.framework/Versions/1.5/.
The Apple doc mentioned that it usually resides there but that doesn't
mean it should be there.
You can use spotlight (if you are on 10.4) to locate it or simply use tabbing
while you're in Terminal to auto-complete the path. That is when typing in
Terminal the path just type the 1st two or three letters and hit Tab to
complete it for you.
Good luck.
I have a "/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0" directory. Note, the folder is actually "1.5.0", there is a shortcut named "1.5" which simply points to the "1.5.0" folder. This is the only location I can find on my PB that has java 1.5. (btw, yes, 10.4.2 is being run!...gotta love spotlight!)

I've found "javac" in the "command" folder underneath "1.5.0", this comes up with a different error. When I try and compile now it says:

"error: cannt read: myJava.java
1 error"

I'm getting there!! Any further suggestions?? Many thanks for your help!
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Gil_Grissom said:
I have a "/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0" directory. Note, the folder is actually "1.5.0", there is a shortcut named "1.5" which simply points to the "1.5.0" folder. This is the only location I can find on my PB that has java 1.5. (btw, yes, 10.4.2 is being run!...gotta love spotlight!)

I've found "javac" in the "command" folder underneath "1.5.0", this comes up with a different error. When I try and compile now it says:

"error: cannt read: myJava.java
1 error"

I'm getting there!! Any further suggestions?? Many thanks for your help!

myJava.java is not in the folder you are currently in? The suggestion is to type /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Commands/javac <filename> in the folder with the Java file in it, not to cd to the folder with javac in it.
 

GilGrissom

macrumors 65816
Mar 13, 2005
1,042
1
robbieduncan said:
myJava.java is not in the folder you are currently in? The suggestion is to type /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Commands/javac <filename> in the folder with the Java file in it, not to cd to the folder with javac in it.
No no...I'm not cd'ing into the directory...im in my normal java directory...myJava.java was just an example of a file name.

I'm doing exactly what you say, with the extra "commands" at the end I get that latest error message...the java file Im trying to compile is in my current directory (not /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Commands/ etc!!)
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Gil_Grissom said:
No no...I'm not cd'ing into the directory...im in my normal java directory...myJava.java was just an example of a file name.

I'm doing exactly what you say, with the extra "commands" at the end I get that latest error message...the java file Im trying to compile is in my current directory (not /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Commands/ etc!!)


OK I just tried this:

create file called test.java in my home dir.

/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Commands/javac test.java

results in test.class as expected.

Check capitalisation etc?
 

GilGrissom

macrumors 65816
Mar 13, 2005
1,042
1
robbieduncan said:
OK I just tried this:

create file called test.java in my home dir.

/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Commands/javac test.java

results in test.class as expected.

Check capitalisation etc?
Yes...I am now fully compiling in 1.5!! Many thanks to all your help robbieduncan and Compile 'em all! Looks like it was a slight error like a capitalisation. Grrrr, if its not that its "}" or ";" !!!

One more happy java 1.5 compiler here!! :)
 

MarkCollette

macrumors 68000
Mar 6, 2003
1,559
36
Toronto, Canada
Only use the Java 1.5 compiler if you're using Java 1.5 specific language features or library classes or methods. Always try to use the lowest Java version possible, that can accomodate what you need, for greater portability. That might mean using Java 1.3 in some instances.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.