views:

138

answers:

6

Hi,

I am looking to learn Java to make a few Android apps but what I am wondering is if I learn Java, will Objective-C make alot more sense to me? I did hear something like this a while ago on some tutorial but am not sure.

Thanks

+3  A: 

It depends on the current programming background that you have. If you have no object oriented programmin experience of course the answer is yes!

I would say that learning Java will help you with Obj-C for some aspects:

  • thinking with objects
  • how to use APIs in general (since all of them are quite similar, C#, Java, Obj-C)

Apart from that the two paradigms are not so similar because one it's based on method calling while the other is based on message passing.

Jack
i come from a background in php
superman
which php version? Already 5? Because PHP5 already has objects so this might help too.. The big difference between Java, Obj-C and PHP is not the syntax (since there maybe different synctactic sugar but we always speak about similar statements) but the type system which is significantly different for each one.
Jack
+1  A: 

Learning more languages is always a good idea, but I wouldn't bother learning Java if you need to learn Objective-C.

Java was directly derived from Objective-C and, thus, has a very similar class model and other attributes. Learning Java isn't really going to help with Objective-C and it will likely confuse you more than it helps.

If you want to program for iOS or Mac OS X, you'll need to know Objective-C and might as well just stick to it from the start. There are some great docs and tutorials out there.

If you then want to expand your horizons, learn a radically different language from Objective-C. Say, Erlang, Scheme, Clojure, Go, or something else.

bbum
Have you got a link to the place that says "Java was directly derived from Objective-C"?
James Raybould
@James "directly derived" is probably a bit too strong, but many have claimed that objective-c had a large influence on oak/java. Eg. one of the designers of Java (!) Patrick Naughton (http://cs.gmu.edu/~sean/stuff/java-objc.html)
Ben Schwehn
Nope -- directly derived. I chatted with Gosling and he said it quite directly.
bbum
http://www.gotw.ca/publications/c_family_interview.htm: Random quote -- Gosling: "... A lot of the design of interfaces was borrowed pretty straightforwardly from Objective C. ..."
bbum
+2  A: 

Well it depends on what you already know.

I found knowing C had the biggest impact on my understanding of Objective-C but Java helped in the way that its easier to understand a different object oriented language if you already know an object oriented language...

James Raybould
+2  A: 

I suppose not really. There are fundamental differences between the two languages. The most fundamental ones:

  • Objective-C is dynamic and Java is static.
  • in Java, nearly everything is an Object and autoboxing transparently integrates primitives, while Objective-C is a superset of pure C. To fully understand and use Objective-C, you need to have a good understanding of C itself
  • Objective-C is a truly object oriented language, such as Smalltalk, while Java is more like C with inheritance and polymorphism and the syntactic sugar of methods. This nuance is probably not of so much importance for more than 90% of the code you write, but it makes Objective-C a far more powerful language.

However, if you're having general problems understanding serveral programming concepts, such as maybe OOP, than Java is a good choice.

edit: If you come from a PHP background, Ruby might be of interest to you. Semantically, it is extremely close to the OO part of Objective-C, it can be used for the same tasks as PHP, and it is relatively easy to learn.

greetz
back2dos

back2dos
Curious about this "Objective-C is a truly object oriented language, such as Smalltalk, while Java is more like C with inheritance and polymorphism and the syntactic sugar of methods". Should that be the other way around?
Nader Shirazie
@Nader Shirazie: Java took structs, called them classes and added mentioned features. Java objects are not true objects. True objects employ message passing, instead of vtables. True objects do not expose variables, but in Java, they have to, otherwise the lack of distinction between structs and objects would result in too much of a performance loss. Unlike Java, Objective-C does not try to enhance C by turning everything into an object, but rather adds the semantics of actual objects to C, while leaving the original language untouched.
back2dos
@dos: Interesting... While I disagree that a technique (message passing vs dispatch) makes an object a _true_ object, I can kinda understand the point you're trying to make. I also don't understand what you mean by "True objects do not expose variables".
Nader Shirazie
@Nader Shirazie: One of the major advantages achieved by OOP is encapsulation. Any object is abstracted to its behavior, while it is the responsibility of the object to determine the behavior. However in Java, you cannot call a method an object doesn't have, in Objective-C, an object may choose to respond to **any** message in **any** way it wants to, all the while from the outside, this is absolutely transparent. Similarly, the implementation of properties through public variables violates the principle, because it takes the responsibility away from the object.
back2dos
@dos: ok, that helps. I'm learning about objective-c :). It looks like you're making two arguments. 1) ObjC allows handling arbitrary messages, while java limits you to a contract, which is an improvement in encapsulation on the part of ObjC, and 2) Properties implemented as public variables is not good OO. Now I thought that public variables as properties in Java were heavily discouraged -- methods were to be used instead. As for (1), I don't understand how a dynamic vs static argument makes a language more OO than another (though I _can_ see how it would be useful to handle any message).
Nader Shirazie
@Nader Shirazie: Objective-C leaves ALL responsibility concerning an object to the object itself. Java doesn't. Let's try with a crappy comparison: In an Objective-C world, at any time, I can decide to transparently act as a rockstar (by either actually learning to be one, by "proxying" an existing one or by "delegating" the task to playback). In a Java world, the "laws of physics" just wouldn't let me, because in my DNA, which originates from design time, it doesn't say I am one. Java interferes with the responsibility of what it considers objects, which I think misses the whole point of OOP.
back2dos
@dos. fair enough, point taken. thanks. but this is a criticism that you would have against _any_ statically compiled language (eg C#), rather than specifically Java...
Nader Shirazie
@Nader Shirazie: True. But I suppose in C++ for example you could go as far as reclassing objects at runtime for a little flexibility. I don't know about C#, but OTOH C# is quite obviously heavily inspired by Java, so Java is to blame :P I'm not saying, this makes Java a bad language per se, but only not fully OO. For at least 90% of all cases you will not notice the difference. Maybe the most important aspect of OOP is polymorphism, allowing decoupling through dependency inversion (http://tinyurl.com/pu7b87). Java can do that, so it's really good enough. Just some fancy stuff missing. ;)
back2dos
+3  A: 

If you learn objective-c, objective-c will make a lot more sense to you.

thekaido
I suppose, OP could figure that out for himself. The question is **how** to learn Objective-C, one option being the detour through another language, such as Java.
back2dos
I was only partially being funny. But honestly the best way is to learn it directly, not by learning a different language. There is tons of material on Android/Java development, and Objective-C/iPhone development, no sense learning one by learning the other. They are pretty different.
thekaido
A: 

Following on to back2dos, I think you'll find that Java really doesn't help you with some of the aspects of Objective-C.

In teaching Objective-C over the past several years, I found that folks who were familiar with C to some level (i.e. pointers and what they meant) and dynamic languages (either Python or Ruby) that had some object oriented structure around them were the fastest to pick up on Objective-C and the "way of thinking" that used the frameworks to the fullest extent. Of all the dynamic languages, I think I'd recommend "Ruby" as the closest, as it uses and has the concept of blocks (passing around anonymous functions to do things) that is now coming into iOS 4.0 and will be pervasive in the near future.

The places where Java, C++ and C# programmers usually stumble are getting used to Objective-C's dynamic typing and runtime, especially around the GUI programming. To be fair, I've seen this bite C++ programmers more in the past, but some of the java-background folks had issues there as well.

The real win and power-boost in doing things with Objective-C is getting comfortable and familiar with the frameworks that you're using, and learning where to plug in your own code to the best effect, and what patterns to follow to make that really effective. Delegation, MVC, and a few other specific patterns are pervasive. If you don't have much background with object oriented programming, Objective-C frankly isn't a bad language to learn it with. If that's where you're finding yourself, I'd recommend the book iPhone Programming: The Big Nerd Ranch Guide as a means of getting into it that covers all the basics really well. Aaron's book Cocoa Programming for Mac OS X is probably a little gentler introduction into Objective-C and object oriented programming - and the first five chapters apply beautifully to either Mac or iPhone development.

The place where folks stumble out of Objective-C is when they get heavily into graphics programming, which quickly drops down into the C frameworks (CoreGraphics) and the interface between the straight-up C libraries and the Objective-C equivalents. They do a pretty good job of keeping that reasonably painless, but when you get into the details it can get a little more tricky.

heckj