Java question

Discussion in 'Mac Programming' started by yg17, Aug 21, 2005.

  1. yg17 macrumors G5

    yg17

    Joined:
    Aug 1, 2004
    Location:
    St. Louis, MO
    #1
    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.
     
  2. haym37 macrumors newbie

    Joined:
    Feb 19, 2005
    #2
    As for a Java IDE, I'd recommend Eclipse or NetBeans.
     
  3. Mitthrawnuruodo Moderator emeritus

    Mitthrawnuruodo

    Joined:
    Mar 10, 2004
    Location:
    Bergen, Norway
    #3
    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. :)
     
  4. superbovine macrumors 68030

    superbovine

    Joined:
    Nov 7, 2003
    #4
    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.
     
  5. VanMac macrumors 6502a

    VanMac

    Joined:
    May 26, 2005
    Location:
    Rampaging Tokyo
    #5
    Hey.

    Go with eclipse.
    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!
     
  6. Compile 'em all macrumors 601

    Compile 'em all

    Joined:
    Apr 6, 2005
    #6
    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 :)
     
  7. yg17 thread starter macrumors G5

    yg17

    Joined:
    Aug 1, 2004
    Location:
    St. Louis, MO
    #7

    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?
     
  8. Mitthrawnuruodo Moderator emeritus

    Mitthrawnuruodo

    Joined:
    Mar 10, 2004
    Location:
    Bergen, Norway
    #8
    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...
     
  9. yg17 thread starter macrumors G5

    yg17

    Joined:
    Aug 1, 2004
    Location:
    St. Louis, MO
    #9
    Thanks.

    I was reading the FAQ page and it says:

    So the java compiler will still be 1.4?
     
  10. Compile 'em all macrumors 601

    Compile 'em all

    Joined:
    Apr 6, 2005
    #10
    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.
     
  11. mspock macrumors newbie

    Joined:
    Aug 26, 2003
    #11
    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
     
  12. MacFan26 macrumors 65816

    MacFan26

    Joined:
    Jan 8, 2003
    Location:
    San Francisco, California
    #12
    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?
     
  13. Compile 'em all macrumors 601

    Compile 'em all

    Joined:
    Apr 6, 2005
    #13
    Please read here .Good luck.
     
  14. Converted2Truth macrumors 6502a

    Converted2Truth

    Joined:
    Feb 6, 2004
    Location:
    Hell@HighAltitude
    #14
    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.
     
  15. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #15
    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.
     
  16. GilGrissom macrumors 65816

    GilGrissom

    Joined:
    Mar 13, 2005
    #16
    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:
     
  17. Compile 'em all macrumors 601

    Compile 'em all

    Joined:
    Apr 6, 2005
    #17
    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

     
  18. GilGrissom macrumors 65816

    GilGrissom

    Joined:
    Mar 13, 2005
    #18
    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!! :)
     
  19. Compile 'em all macrumors 601

    Compile 'em all

    Joined:
    Apr 6, 2005
    #19
    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.
     
  20. GilGrissom macrumors 65816

    GilGrissom

    Joined:
    Mar 13, 2005
    #20
    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!
     
  21. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #21
    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.
     
  22. GilGrissom macrumors 65816

    GilGrissom

    Joined:
    Mar 13, 2005
    #22
    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!!)
     
  23. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #23

    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?
     
  24. GilGrissom macrumors 65816

    GilGrissom

    Joined:
    Mar 13, 2005
    #24
    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!! :)
     
  25. MarkCollette macrumors 68000

    MarkCollette

    Joined:
    Mar 6, 2003
    Location:
    Calgary, Canada
    #25
    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.
     

Share This Page