 |
 |
Java vs. Objective-C
|
 |
|
 |
|
Forum Regular
Join Date: Jan 2003
Location: Jersey City, NJ
Status:
Offline
|
|
Hi,
I'm very comfortable coding in Java; however, I've been interested in learning something new...I pick Objective-C.
Do you guys recommend this? What's the pros and cons of using Objective-C over Java?
Another thing, are the majority of applications written for OSX using Objective-C?
Thanks.
|
|
PB.17.1Ghz - iPod.10G
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Sep 1999
Location: Ottawa, ON, Canada
Status:
Offline
|
|
Originally posted by javabeans:
Hi,
I'm very comfortable coding in Java; however, I've been interested in learning something new...I pick Objective-C.
Do you guys recommend this? What's the pros and cons of using Objective-C over Java?
Another thing, are the majority of applications written for OSX using Objective-C?
Pros of Obj-C:[list=a][*]faster than java[*]can intermix C and C++ (and even Java) easily[*]you can do your own memory management[*]Interface Builder[/list=a]
Cons:[list=a][*]have to do your own memory management[*]hardly used on other platforms[/list=a]
(yes, the memory management items were intentional)
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
You can use IB with Java and Cocoa.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Edmond, OK USA
Status:
Offline
|
|
Originally posted by javabeans:
Hi,
I'm very comfortable coding in Java; however, I've been interested in learning something new...I pick Objective-C.
Do you guys recommend this? What's the pros and cons of using Objective-C over Java?
Another thing, are the majority of applications written for OSX using Objective-C?
Thanks.
We really don't need another holy war pitting Java versus Objective-C - there are already plenty of threads on that. If you understand Java well and just want to write an OS X App, then use Java-Cocoa and you can use all of your existing Java libraries. If, however, you want to learn what makes Cocoa tick on OS X then you should learn Obj-C and use that. If you are looking for a generally marketable language then I would probably use C or C++ and program in Carbon.
Bottom line: If you want to learn Obj-C then go ahead - it certainly won't hurt you.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
If you know java, Objective C is a pretty easy language to learn. I got a good Objective C book and have been working through it.
If you're looking to write Mac apps, Objective C and Cocoa are the way to go. If you're looking to write cross-platform apps or web applications, stick with java.
|
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: May 2001
Location: Oviedo, Floriduh USA
Status:
Offline
|
|
Java and Objective-C share the Smalltalk runtime idealism, so besides memory management, they're close. Memory management isn't so difficult, especially if you've dealt with C and C++.
The syntax to use Objective-C objects is even similar to Smalltalk with all the colons in-between arguments. You are able to label your arguments, which is quite nice.
The Cocoa framework is more stable, even with Apple adding to it periodically. You're unlikely to see 60 percent more objects as we did with Java v1.4.1.
Java and Objective-C string handling works somewhat different. Objective-C/Cocoa uses NSRange, which contains the start and end positions of your substring unlike Java needing the position beyond the end.
If you have something that will be Mac OS X only, write it in Objective-C. If it's a cross-platform application, Java is a great choice, but Carbon and C++ work quite well if you design your objects properly to hide the operating system details.
|
|
folding@home is good for you.
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
Originally posted by bousozoku:
Java and Objective-C share the Smalltalk runtime idealism, so besides memory management, they're close. Memory management isn't so difficult, especially if you've dealt with C and C++.
Memory management is such a pain in C or C++. Objective C is a lot better, but it's still more work than Java. Java uses mark-and-sweep, whereas Objective C uses reference counts. Either method is fine. Mark-and-sweep is generally more complete, but slower.
In Objective C, when you create an object you do an "alloc" to allocate it. If you want to keep a handle to an object, you send it the "retain" message, which increments the reference count. If you want to decrement, you send it "release". If the reference count goes to zero, the object is deallocated.
There is also a concept of "auto deallocate in the future", which is a convenience tool for passing an object between methods or objects without having pointer-pass problems.
It's pretty interesting stuff.
|
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: May 2001
Location: Cupertino, CA
Status:
Offline
|
|
Java doesn't use mark and sweep, AFAIK all Java implementations use generational garbage collection. Granted, it can superficially look a little like mark and sweep. You CAN still have memory problems in Java programs, though they're not really proper memory leaks... If your program runs for a long time and keeps initializing new objects, while not dereferencing old ones, your memory usage will grow. This may seem plainly obvious to most people, but some program designs can lead to memory problems even in Java.
Strictly speaking, Objective-C on OS X does not do garbage collection. It will deallocate objects for you when their reference count reaches zero, but it does not maintain the reference counts. The programmer must manaully maintain the reference counts by calling retain/release. This, along with the paradigm of doing an alloc & init or using the autorelease pool, makes memory management in Obj-C easier than in C or C++, but it's still strictly in the realm of the programmer.
I don't think it's necessary to have a big battle over languages. Learning Obj-C, for an experienced Java programmer, will not take you very long. Not to sound conceited or something, but a professional programmer should be somewhat language independent, and picking up languages like Obj-C should be quick. If you have a genuine interest in programming languages then it's always nice to "expand your horizons." The real issue is whether you want to invest months of time into Obj-C/Cocoa and try to make a career out of it. Just learning the basics of Obj-C and Cocoa is simple, but really learning the ins and outs is a long term commitment. Objective-C isn't a particularly marketable language, so make of that what you will. If you're a novice programmer looking to build a career, I'd personally recommend learning C over learning Objective-C.
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Jan 2003
Location: Jersey City, NJ
Status:
Offline
|
|
Thanks for all of your answers. I primarily want to learn Objective-C for pleasure coding.
I love coding in Java and that's what I do at work. 
|
|
PB.17.1Ghz - iPod.10G
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
Originally posted by javabeans:
Thanks for all of your answers. I primarily want to learn Objective-C for pleasure coding.
I love coding in Java and that's what I do at work.
Sounds like me! I can't seem to get anyone to pay me to write Mac software, but that's all I want to write in my free time. I got sick of Realbasic (cool though it is) and set out into the world of Cocoa.
|
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|