Cocoa: Java or Objective-C?

Discussion in 'Mac Programming' started by MacDonaldsd, Apr 11, 2006.

  1. macrumors 65816

    MacDonaldsd

    Joined:
    Sep 8, 2005
    Location:
    London , UK
    #1
    Im wondering what is the differences or benefits of using java rather than object c to build cocoa applications. Or indeed is java the language of choice.
     
  2. macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #2
    java has no real benifits of Obj C, the only reason to use it is if, like me you don't know how to use objective C.
     
  3. thread starter macrumors 65816

    MacDonaldsd

    Joined:
    Sep 8, 2005
    Location:
    London , UK
    #3
    Are there any reasons why I should use object c ?
     
  4. macrumors regular

    Joined:
    Mar 24, 2005
    #4
    it depends on what you are doing.

    java will provide portability to other platforms. after java 1.4 it also includes some cocoa bindings. however, the java-cocoa bridge is no longer being updated by Apple.

    objective C will let you use the full abilities of cocoa.
     
  5. Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #5
    Using Java will make it easier to run whatever you create on multiple platforms.

    Using Objective-C is a great way to write applications for Mac OS X but they will generally stay there because, with the exception of GNUStep, there isn't much else out there that's code compatible in the least.

    Both languages are quite amazing and are more similar in thought than in style. Java is growing but Objective-C is holding steady after 20+ years.
     
  6. Moderator emeritus

    SilentPanda

    Joined:
    Oct 8, 2002
    Location:
    The Bamboo Forest
    #6
    Wow... everything I had read on the web and in books was to go the Objective-C route. Then again by "books" I mean Cocoa Programming for Mac OS X by Aaron Hillegass.

    I do Java at work (under Windows) but I am trying to learn Obj-C/Cocoa at home. Probably just doing it that way for the learning though. If your Java gets too bound up in Cocoa it's not really portable anymore is it?
     
  7. macrumors regular

    Joined:
    Jul 23, 2002
    #7
    Also don't forget that Apple has ceased updating the Cocoa-Java bridge.

    From Developer Doc's:

    Important: Cocoa-Java technology is only a learning tool. Applications targeted for release to customers must be developed using Objective-C to take advantage of all the programming interfaces available in Cocoa. Programming interfaces added to Cocoa in Mac OS X versions later than 10.4 will not be available to Cocoa-Java applications.


    crackpip
     
  8. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #8
    There are no benefits in using java and cocoa instead of using objective-C cocoa cocoa unless you already know java and don't want to learn another language. The Cocoa frameworks were designed with objective-C in mind and made a number of design assumptions because of it. The java cocoa bridge was there just to help java programmers. It's a clever kludge that never fully supported the entire Cocoa framework anyway. It's no longer supported.

    For a more technical description why you shoudln't use Java with cocoa see here.

    Besides, one big advantage of Java is portability. If you use it with Cocoa you've lost that advantage.
     
  9. macrumors 68000

    Joined:
    Oct 8, 2003
    #9
    Not if you're using Cocoa bindings though.
    Again you could say the same about writing Cocoa apps in Java.

    Just as you can write Java apps that are portable to other platforms by not using Cocoa, you could write Objective-C programs that are portable to other platforms.

    As the guy wants to write Cocoa apps, I'm guessing cross system portability is not high on his agenda.
     
  10. thread starter macrumors 65816

    MacDonaldsd

    Joined:
    Sep 8, 2005
    Location:
    London , UK
    #10
    I want to learn cocoa.

    Im currently doing C++ at university and next year I will be learning java.

    Do you think I can pick up object c from C++ easily ?
     
  11. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #11
    Objective-C is a superset of C. It's a lot easier than C++. The power of the language comes from the Cocoa frameworks not the language itself.
     
  12. macrumors 6502a

    Joined:
    Dec 22, 2003
    #12
    Don't

    Java is a "better" language than Objective C. It's fully managed and strongly typed, whereas Objective C gives you a lot of rope to hang yourself without really giving you any benefits over Java. Both languages are largely equals when it comes to OO features, Java is just safer. There are subjective points about the readibility of both languages, but I don't think there's much to it.

    But as others have pointed out, the Cocoa bindings for Java have been frozen. So my advice would be:

    Either:
    - write your app in Objective C
    - write in Java, but use the Java libraries where possible rather than Cocoa. You can still make Java applications that look, feel, and run like Cocoa programs unless you're doing something very obscure.

    The benefits of the former are slightly better integration with OS X (if you want to create Services, for instance (you know, the "Services" submenu of the application name's menu. What? You never use that? Wow, and I thought it was just me ;-) Additionally, XCode integrates very well with it.

    The benefits of the latter are much greater platform independence. No need to care about "Universal Binary" type issues (well, you still need to check the box, but the notion something you missed might cause the program to work fine under PPC but not under Intel is, well, not an issue.) You can take advantage of tools like WebStart. Debugging is easier. While XCode isn't really the best tool for this, Netbeans is getting really good at the moment.

    Cocoa under Java though? Nope, I wouldn't do it. It's a nice idea, but if Apple's going to deprecate the API, then it's probably best left alone.
     
  13. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #13
    Of course you wouldn't have cocoa bindings, core data, spotlight, or .mac integration as well as a ton of other stuff that Objective-C/cocoa developers take as a given. Saying it's just the services menu you get from using Cocoa is ignorant and misleading.
     
  14. Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #14
    Of course, that's true. I've never suggested to anyone to bother with the Cocoa-Java bridge. It was a quick-and-dirty thing to allow people who didn't understand Objective-C to get by.

    Using Objective-C is the best way to write Cocoa applications.

    (You'd think that I hadn't fixed the thread title. :rolleyes: )
     
  15. macrumors 6502a

    Joined:
    Dec 22, 2003
    #15
    Did I say it's just the Services menu? Nope. Saying I did is ignorant and misleading.

    Saying you don't get cocoa bindings though is a little ridiculous. That's like saying if you use Objective C you can't get SWING bindings. Except, of course, that you can get them in Java, it's just not wise to use them.
     
  16. macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #16
    I can see how learning C, Onjective-C, and Cocoa all together could be very intimidating, if you are let's say coming from a Java-only backgraound. So perhaps using Cocoa-Java (which should be called Mocha! Duh!) would be a more gentle introduction to the Cocoa APIs. After doing some projects this way maybe it would then be easier to switch over to Objective-C with Cocoa, as you'd already have some familiarity with the basics in a form that you're comfortable with.

    Having said that, I learned Cocoa and Objective C coming from a mostly Java background, with very little C experience. It can be a steep learning curve at first but it doesn't take that long to get it. Start with the Hillegass book.
     
  17. macrumors 68000

    Joined:
    Oct 8, 2003
    #17
    Personally out of Objective-C and Java for Cocoa programming I choose..... python.
     
  18. macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #18
    I love Python, I just wish for two things from it:

    1. Native Cocoa API for it. The Py-ObjC bridge kind of works, but isn't exactly elegant.

    2. A real, modern, comprehensive framework for web applications á la Ruby on Rails.

    I love the Python language but it's lacking in terms of strong built-in GUI support and web platform services. I haven't tried much with Ruby yet, but I don't like the syntax nearly as much as Python.
     
  19. macrumors 68000

    Joined:
    Oct 8, 2003
    #19
    Yeah, I wasn't being entirely serious :) - although I do code everything these days python, most of the stuff I need to write are command line tools, and the only GUI stuff I've done with it is some minor Tkinter stuff.

    Still I use python all the time for "mission critical" programming, and when I say "mission" I mean "mission" as in "NASA mission", not "real estate mission". ;)
     
  20. macrumors 6502a

    #20
    1. I am not sure how the first point would be addressed without creating a maintenance nightmare. While it does feel a little odd to start with, I have found that it actually becomes very easy to use especially with the wealth of existing Cocoa documentation. It would be nice if Apple took it on formally as a RAD environment, which OS X seems to lack at the moment. It seems like it would be a lot of effort for not much, if any, benefit but feel free to elucidate.

    2. Django? Turbogears?

    For the last bit though ... well IMHO I am quite happy having external modules involved rather than built-in functionality. It means existing knowledge can rapidly be brought to bear rather than learning yet another interface to do the same thing again, plus offers the reusability of existing tutorials and documentation. Not to say that a built-in option wouldn't be nice but all too often these just seem to be lowest common denominator feature sets that result in programmes that never really properly mesh with the native environment.

    Tools like py2app and py2exe dispose of many of the dependency worries that modular distribution often implies.
     
  21. macrumors G4

    Mord

    Joined:
    Aug 24, 2003
    Location:
    Old York
    #21
    objective c is a superset of c, which will run on anything, if you learn objective c while noteing what wont work in plain c you'll get the best of both.
     
  22. macrumors 603

    Stella

    Joined:
    Apr 21, 2003
    Location:
    Canada
    #22
    Depends what you want to do.

    Java would be the most useful - if you want platform independence - where as Objective C ( Cocoa ) would restrict you to OSX. If you want to create GUIs under OSX then ObjC is the way to go - far easier than Java, imo - I hate Swing, SWT etc.

    Also, if you learn Java, then you can get into J2EE etc. Java would have the possibility of broadening your horizons more so than ObjC.
     
  23. macrumors 68000

    Joined:
    Oct 8, 2003
    #23
    Agreed. It would be really nice if Apple picked up Python and PyObjC as their "managed code" programming environment.
     
  24. macrumors 68000

    Joined:
    Feb 23, 2006
    #24
    It's a tough decision. I come from a Java-only background because that's what they use for the AP Computer Science courses now, I plan on using Java as much as possibly and slowly wean myself of it. Frankly though, I'm not programming at a very high level though, so I imagine that the whole cocoa library/ java library conflict is very much over my head in terms of application. Most of the stuff I import are math functions like the Random number generator, array lists, so on and so forth.
     
  25. macrumors 603

    janey

    Joined:
    Dec 20, 2002
    Location:
    sunny los angeles
    #25
    Objective-C isn't as widely used as Java (not that that's a good or bad thing), and there's almost no incentive to use objc for development without using open/gnustep or cocoa, which would lead to the fact that it's pretty much only the Mac OS X people who are using objc for anything (sorta lame)

    so like, if you don't know either language, java would be better (unless you plan on only OS X development), both would be best, and cocoa+java nullifies one benefit of java.

    not to say objc sucks, i'm plodding through the kochan and hillegass books, and i'm liking it so far :) just, sorta useless when it comes to most of the stuff I end up doing in school and outside of class (where java and C++ tend to be more popular)
     

Share This Page