PDA

View Full Version : Cocoa: Java or Objective-C?




MacDonaldsd
Apr 11, 2006, 05:57 AM
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.



Eraserhead
Apr 11, 2006, 06:14 AM
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.

MacDonaldsd
Apr 11, 2006, 08:34 AM
Are there any reasons why I should use object c ?

jakeOSX
Apr 11, 2006, 08:38 AM
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.

bousozoku
Apr 11, 2006, 08:51 AM
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.

SilentPanda
Apr 11, 2006, 09:11 AM
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 (http://bignerdranch.com/products/) 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?

crackpip
Apr 11, 2006, 09:23 AM
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

caveman_uk
Apr 11, 2006, 09:42 AM
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. (http://www.bignerdranch.com/Resources/Java.html)

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

dr_lha
Apr 11, 2006, 09:46 AM
Using Java will make it easier to run whatever you create on multiple platforms.
Not if you're using Cocoa bindings though.

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.

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.

MacDonaldsd
Apr 11, 2006, 09:52 AM
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 ?

caveman_uk
Apr 11, 2006, 10:04 AM
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.

peharri
Apr 11, 2006, 10:04 AM
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.

caveman_uk
Apr 11, 2006, 10:11 AM
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.

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.

bousozoku
Apr 11, 2006, 10:15 AM
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.

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: )

peharri
Apr 11, 2006, 10:32 AM
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.

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.

HiRez
Apr 11, 2006, 12:40 PM
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.

dr_lha
Apr 11, 2006, 01:03 PM
Personally out of Objective-C and Java for Cocoa programming I choose..... python.

HiRez
Apr 11, 2006, 01:47 PM
Personally out of Objective-C and Java for Cocoa programming I choose..... python.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.

dr_lha
Apr 11, 2006, 02:30 PM
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.
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". ;)

AlmostThere
Apr 11, 2006, 03:04 PM
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.

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.

Mord
Apr 11, 2006, 03:57 PM
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.

Stella
Apr 11, 2006, 08:03 PM
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.

dr_lha
Apr 11, 2006, 08:25 PM
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.
Agreed. It would be really nice if Apple picked up Python and PyObjC as their "managed code" programming environment.

SC68Cal
Apr 12, 2006, 06:56 PM
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.

janey
Apr 13, 2006, 03:31 PM
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.
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)

Josh
Apr 13, 2006, 03:46 PM
I'm going through a C++ course now, and I have a good book on C, so I am slightly familiar with that.

I want to learn ObjC really, really badly, and I plan to once I feel very comfortable with C++. I'm mildly comfortable with some things, but I'm not moving on until I feel very confident in the language.

Then I plan on to go through the C book I've got again, then on to ObjC, then Cocoa.

Mac/Cocoa developing is something I absolutely want to do so badly that I doubt I could explain it :o

HiRez
Apr 13, 2006, 05:56 PM
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)Kind of, but one thing that I will say is that if you're doing a lot of Objective-C, you'll also be doing a lot of straight C as well, and that's probably a good thing. There's still a lot of APIs that aren't wrapped for Cocoa, and even while using Cocoa you use a lot of C. And C skills can be put to use in lots of places (and much of Java is based on C as well).

Catfish_Man
Apr 14, 2006, 12:41 PM
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.

Also, we're using it in Adium 1.0 to bridge to a Java library.