Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

robbo91

macrumors newbie
Original poster
Feb 11, 2010
15
0
Hey guys. I've studied computer science at uni for one year with Haskell for first semester and java for second semester. In my second semester class, our major assignment was a computer game in Java using Jcomponent, Actionlistener etc.

I've started looking into the C language and might move onto Objective C after that. I would like to one day translate the game I made into a Cocoa application. Could translating my existing code into Cocoa be a good learning experience or should I go a bit slower and learn other things first?
 

PatrickCocoa

macrumors 6502a
Dec 2, 2008
751
149
Go Slower

Go slower and learn what Cocoa and Objective-C are all about first. Depending on how much time you have, this may be a couple hours a day for about a month.

Then take your existing code and try to translate it.
 

robbo91

macrumors newbie
Original poster
Feb 11, 2010
15
0
I have about 3 months of spare time depending on how much part time work I get, so I can spend a couple of hours a day learning stuff for a month, then get into programming fun stuff like games later.

Thanks for the help guys.
 

BadWolf13

macrumors 6502
Dec 17, 2009
271
0
I'm with Patrick on this one. I am a recent Obj-c learner myself, having come from a background that includes Basic, C, C++ and Touring. The hardest thing for me with Cocoa & Obj-C was not the actual language, which is really just a matter of terms and context, but the way that Cocoa does things, which put everything I'd done before out the window.
 

mfram

Contributor
Jan 23, 2010
1,304
341
San Diego, CA USA
I agree, the main problem with "translating" an existing app is not so much converting from Java to C/Obj-C. They are very similar syntactically. The bigger problem is that the design of Cocoa apps is very different than Java.

You can hack your way through it for simple apps. But eventually you'll realize a Cocoa app probably needs a different design in order to be implemented effectively.
 

whooleytoo

macrumors 604
Aug 2, 2002
6,607
716
Cork, Ireland.
If I were you, I'd just pick a relatively simple project, and try to do it in Cocoa. For example - one I did myself when learning - a iTunes-like media player. You would need to break this down into the tasks needed:

- read a preferences file to get the location of your movies and song files.
- scan that folder, to get an array of files.
- Draw a list view, displaying that list of files.
- Add a movie view, to play the movies.
- Add play/pause/mute buttons, as necessary.

Between the Apple Cocoa documentation, and the online tutorials for each, you should have little time learning the above, if you're patient and take it step by step. In doing so, you'll learn lots of other things - using NSStrings, how to use outlets and actions, the MVC architecture etc.
 

ulbador

macrumors 68000
Feb 11, 2010
1,554
0
I wouldn't necessarily do this. While java and Objective C are similar in many respects, they are also hugely dissimilar in other respects. Everything in Java is an object, where with Objective C, this is not always a case. The whole concept of ActionListeners and such is handled in a completely different manner than in Objective C. Even the basics of laying out a form in Java are wildly (and THANKFULLY) different in Objective C.

As previous posters have mentioned, start with the basics and build up to the program instead of trying to directly replicate functionality. Even if you were porting the program and had experience in both languages already, you would probably still do things completely different because of how the languages differ.
 

PatrickCocoa

macrumors 6502a
Dec 2, 2008
751
149
I agree with myself

I'll just chime in again to agree with my earlier post. And to clarify somewhat.

You shouldn't try to port your current Java project into Objective-C/Cocoa AS A LEARNING PROJECT. As several others have said, particularly mfram, the design of projects is different in Objective-C/Cocoa. Once you spend a month or two on learning the basics with a smaller project or a set of tutorials, you can then take a whack at porting your Java project.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,706
8,348
A sea of green
... Everything in Java is an object, ...

This is incorrect.

Java has primitive types as well as objects. The primitive types are: boolean, byte, char, short, int, long, float, double.

In many cases the primitive types can and will be automatically boxed and unboxed (converted to and from object types), but this can also fail in certain subtle cases, so it pays to be aware of it.

Java also has enum as a declarator for enumerated types.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.