How-to crossplatform java in Xcode?

Discussion in 'Mac Programming' started by treck, Jul 12, 2005.

  1. treck macrumors newbie

    Joined:
    Jul 12, 2005
    Location:
    Thomasville, GA
    #1
    Hi,
    I just started my Java programming (new to programming) class tonight and I have a question or two. My college is a Windows only school and I would rather use my PowerBook to do the classwork. So, my question is: If I write a java program and compile it in Xcode will it work in windows as well? Do I have to change any lines of code to make it cross platform? I noticed in my textbook that all of the examples are in Windows format so, that got me wondering, if I write the code as it is in the text; will the program look like an OSX program? Meaning, will the control buttons be on the top left corner of the window.
     
  2. therevolution macrumors 6502

    Joined:
    May 12, 2003
    #2
    You'll be fine using Xcode. Everything should compile just fine on both platforms as long as you don't call any platform-specific code, which I doubt you will in an intro programming course.

    Yes, by default, you'll get the Mac OS look and feel when running a Swing application on a Mac. Be aware that platform-specific look and feels don't carry over to other platforms. It will look like a Mac app when you run it on your Powerbook, and it will look like a Windows app on Windows. If you don't want that, you can explicitly declare a look and feel that will work on both platforms - like Metal, for example. That will give you a consistent UI whether you're using Windows and Mac (though the control buttons will still be on the top left of the window on Mac OS; that's an OS thing and you can't change that).

    To be on the safe side, it wouldn't hurt to test your programs on a Windows machine before you turn them in just to verify everything looks okay. Chances are that in an intro Java class, you won't run into any issues, but better safe than sorry.
     
  3. treck thread starter macrumors newbie

    Joined:
    Jul 12, 2005
    Location:
    Thomasville, GA
    #3
    thanks for the info. Ever since I switched to Mac this past April, I try not use Windows as much as possible. It's funny, my instructor said that of all his years of teaching, I'm the first Mac user he has had.
     
  4. jeremy.king macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #4
    Figuring you won't even touch GUI programming in a beginner course, you should be just fine.

    Curious, what program is your professor pushing to code Java in Windows. If Eclipse/Netbeans/ Java Studio - they are also available for OS X.

    If just plain old text editor with command line compiling, it wouldn't hurt doing the same so you can learn the intricacies of the SDK.

    Actually, while I think XCode is great for Carbon/Cocoa/Obj-C development - I would recommend Eclipse for Java Development - if you must use an IDE - its quickly becoming the industry standard for enterprise Java development.
     
  5. treck thread starter macrumors newbie

    Joined:
    Jul 12, 2005
    Location:
    Thomasville, GA
    #5
    textpad is what they will be using. Actually this is a comprehensive course. going from command line to applets, servlets, and GUI. The downside is that all of this will be done in only 10 weeks.
     
  6. whooleytoo macrumors 603

    whooleytoo

    Joined:
    Aug 2, 2002
    Location:
    Cork, Ireland.
    #6
    You shouldn't have any problems Java coding on your Mac.

    I haven't done much, but the only serious problem I had was when needing to do J2ME coding (mobiles, PDAs etc). There is no (official) J2ME toolkit for the Mac.
     
  7. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #7
    If you want to keep it simple, I would recommend TextWrangler (free), it's a nice code editor (and plain-text editor in general) with syntax highlighting and great search and replace features. I can't believe they're using TextPad...painful. Xcode is a great development tool, but may have a lot of junk in there you don't want to be dealing with when learning the basics. If your professor is teaching using only text files and command-lines, I'd use TextWrangler and Terminal, you can always go to Xcode or Eclipse later if you want. TextWrangler will also deal very well with any auxiliary text files you may need, such as HTML, XML, or Ant build files.
     
  8. treck thread starter macrumors newbie

    Joined:
    Jul 12, 2005
    Location:
    Thomasville, GA
    #8
    Finally we were able to start coding tonight but I ran into a few problems. For our first project we were to code a comand line application. So, I start up Xcode and I notice there are a ton of java templates to choose from. Well, I didn't know which one to use so I just used the Textpad app in windows :mad: Now, I get home and take the file I created, put on my mac, and tried to figure some things out. I double clicked my .java file and it opens in Xcode but nearly all of the options are greyed out. Such as compile, debugg, ect. What's going on?!! I even tried TextWrangler and the same thing is happening. I went to Apple's Dev page and got J2SE 5.0 and then it tells me in order to use 5.0 I have to open a target (no idea what that is) and click this and that and now I'm ready to pull my hair out. I appologize if these questions seem obvious and/or bothersome to you all. I tried to do this on my own for about 3 hours and I have decided I need some help.
     
  9. gekko513 macrumors 603

    gekko513

    Joined:
    Oct 16, 2003
    #9
    Xcode is powerful and flexible, but it isn't the easiest IDE to get used to.

    I would have recommended Netbeans before version 3.6 for cross platform Java development, but as of Netbeans version 4.0, they started doing file management in a very weird way. I haven't understood it yet, so I cant' recommend it fully. I still think you will find it easier for small projects than Xcode is. Netbeans version 4.0 was quite well integrated into OS X, too, as opposed to version 3.6, so you might want to give the current version of Netbeans (4.1) it a try. I haven't tried the latest version, yet.

    One tip (for version 4.0 at least), Netbeans is quite a resource hog, but on OS X you can make it go a lot faster by disabling text antialiasing.

    http://netbeans.org
     
  10. therevolution macrumors 6502

    Joined:
    May 12, 2003
    #10
    Xcode is definitely not easy to jump into. I still haven't sat down and figured it out for myself, so I can't really help out there.

    Netbeans is nice. I use Eclipse. Play with one or both of those and see if they work better for you. Feel free to post here again with questions on either of those, and I'll help as best I can (I'm sure others will too).

    If neither one works out, perhaps a simple text editor and Terminal combo will do the job.
     
  11. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #11
    That's because you need a project first; you can open a single source file for viewing or editing, but you can't compile it in Xcode until you create a project, configure build settings, and add source files to it.

    Same thing here -- TextWrangler is simply a text editor, it can't compile your code (and opening the file in Xcode gives you the same thing as above). As gekko said, Xcode can be very confusing and tricky to get set up, especially if you're trying to use pre-release APIs as you seem to be with Java 5.

    Frankly, I would keep it really basic and simple at first and use TextWrangler to edit your source files and Terminal.app (javac) to compile them into your Java apps. It's good to know how it all works at a low level before you start using more advanced IDEs and build tools such as Ant, Eclipse, NetBeans, and Xcode.
     
  12. treck thread starter macrumors newbie

    Joined:
    Jul 12, 2005
    Location:
    Thomasville, GA
    #12
    Last night I opened up eclipse and went through the tutorial and it worked fine. I then open my .java file from class and it wouldn't compile. Before I fell asleep I remembered that I didn't bring the .class file with me. Would that have anything to do with my problem?
     
  13. jeremy.king macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #13
    Skip the IDE for now - you will just confuse yourself - but that seems to already happened.

    Write your code in a text editor. Textwrangler wasn't a bad choice and I would suggest you go back to it.

    Compile/Run using terminal the "old fashioned" way. The commands are the same on windows and OS X.


    cd /path/to/your/working/directory

    javac YourTestClass.java

    java YourTestClass
    (notice no extension).

    I highly recommend you take the time to understand what you are doing and by using command line to compile/run, you are forced to have some understanding.
     
  14. gamestriker macrumors regular

    Joined:
    Dec 18, 2004
    #14
    For beginning java, stick to any regular text editor, or google for some free text editors that have some basic java support (i.e. syntax coloring). Once you understand the basic stuff, try BlueJ; its got some of the advanced features like project management, but a lot of beginners use it. Once you get advanced, try out one of the IDEs. The ones I use are Eclipse (primary) and Xcode (secondary primary :p ).

    I have my beefs with each of them though. Here are my main likes and dislikes of each:

    Xcode Likes:
    - Loads fast and is very responsive
    - OS Integration
    - Slick interface
    - Good project management
    - Project Symbols
    - Data modeling (I've seen it but not tried it yet)
    - Predictive Compilation
    - CVS compatible (I should be setting up a CVS repository for my growing number of project very soon)

    Xcode Dislikes:
    - Code Completion (not intuitive IMHO)
    - Targets/Products can be confusing (at first)
    - Documentation (as in javadoc commenting and API generating) is lacking

    Eclipse Likes:
    - Code Completion
    - Build automatically feature a.k.a. "Compile as you go"
    - Generates Javadoc comments for methods
    - Very customizable workspace
    - Quick Fix feature for compiler errors/warnings (and customizing which errors/warnings to displays)
    - Navigator (great when moving utility classes between projects/folders)

    Eclipse Dislikes:
    - (Very) Slow loading and very slow responsiveness
    - Code completion popup is so slow to come up, I rarely use it anymore
    - Workspace can easily look/feel cluttered or "messy"
    - Too much baggage in general
    - Preferences can be confusing to customize sometimes

    I'd say Eclipse would be easier to move into out of the 2.

    I'm thinking about making an IDE (in Java) thats a cross between Xcode and Eclipse, though its a lot of work for a single programmer (i.e. me), and with college around the corner, I doubt I could get a lot proper planning/work done on it. That's so far is the only reason why I haven't already started.
     
  15. treck thread starter macrumors newbie

    Joined:
    Jul 12, 2005
    Location:
    Thomasville, GA
    #15
    Problem Solved!!!

    It was kind of simple if you think about it. I opened eclipse, created a new project, opened my .java from class (shows up in the work space as *book.java), I then renamed the file to match the project name (book.java)and the class was automatically created and I could then compile and run it. Thanks every one for your time and effort.
     

Share This Page