Your SlideShare is downloading. ×
0
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

iPhone development from a Java perspective (Jazoon '09)

517

Published on

Based on experience gained in developing the popular Zurich train/tram/bus/ship timeplan transport application, wemlin, senior software engineer Ognen Ivanovski describes development for the iPhone …

Based on experience gained in developing the popular Zurich train/tram/bus/ship timeplan transport application, wemlin, senior software engineer Ognen Ivanovski describes development for the iPhone from the perspective of an Enterprise Java developer - covering aspects about differences in the language, the architecture, the user experience, the tools, and the market.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
517
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Where do I work, experience
  • make jokes about ridiculous data roaming charges blatant commercial
  • maybe more details about this...
  • (performance of a unix workstation 10 years ago) - fast startup - use for few seconds, switch off - start where you left off - fingers are fat, not mouse - people wear glasses (paraphrase) - no man pages, no manual
  • Joke: “lets get this behind us”
  • Image of tools / technologies involved, a diagram that will be used throughout the presentation
  • the UI designer is an inegral part of the system
  • also enthusiasm not finished
  • perhaps with some images talk about unix scripts; compare with java - cost of abstracting away the OS Demo here?
  • Demo - not finished - parallel to smalltalk
  • screenshot
  • talk about syntactic vs. semantic similarities what does this mean for a java developer
  • ... of the standard library (very annoying and hindering) (i learned java by looking at the standard library sources)
  • Close up the first impressions; intro about the platform and the langauge; old, been a while
  • will talk about differences more than about similarities
  • 2 things to remember; method call a.k.a. sending message syntax parameters embedded in the method signature verbosity. mention similarity to java in terms of references vs. primitives mention class objects, string literals,
  • compiler here when you need it dynamic productivity
  • Mention null-safe handling .?
  • mention that we usually don’t use a prefix for the main application
  • - talk about argument passing here - verbosity
  • you can inherit constructors
  • talk again about the dynamic nature of Objective-C
  • NSString is usually the prime target e.g. UIKit adds drawing methods to the string class splitting a class into parts Visible when you compile / link against the framework that adds it
  • compare with java
  • THE biggest issue: - difficult to comprehend - constant cause of trouble - the source of almost every nasty bug we had
  • wrapup
  • Give a short talk about patterns in CocoaTouch. put an image
  • events - UI events chain of command
  • Compare to SAX parsing - handler - events (notifications) Extending through delegate instead of inheritance/composition one-to-one events
  • Transcript

    • 1. Development for the iPhone from a Java Perspective <ul><li>The Tools, The Language, The Experience </li></ul>Ognen Ivanovski Netcetera 9140
    • 2.
    • 3. Background <ul><ul><li>Software Architect; @Netcetera since 2001 </li></ul></ul><ul><ul><li>2000 - present: Java (enterprise, web, swing, RCP) </li></ul></ul><ul><ul><li>2008 - present </li></ul></ul><ul><ul><ul><li>Mobile Development: Android, iPhone OS </li></ul></ul></ul><ul><ul><ul><li>Technical Lead for Wemlin </li></ul></ul></ul>
    • 4. <ul><ul><li>iPhone App </li></ul></ul><ul><ul><li>Covers the Zürich greater area </li></ul></ul><ul><ul><li>See departure times for public transport </li></ul></ul><ul><ul><li>Completely offline app </li></ul></ul><ul><ul><li>Database holds roughly 1.2M records </li></ul></ul><ul><ul><ul><li>but it’s fast </li></ul></ul></ul><ul><ul><li>http://mobile.netcetera.ch/wemlin </li></ul></ul>
    • 5. Switching <ul><ul><li>Team of four developers </li></ul></ul><ul><ul><li>Published 1.0 of Wemlin (then Tramdroid) on October 3rd 2008 </li></ul></ul><ul><ul><li>1 - 3 weeks adaptation time </li></ul></ul><ul><ul><li>1st internal build after 4 weeks </li></ul></ul>
    • 6. New Priorities <ul><ul><li>Performance </li></ul></ul><ul><ul><li>Start-up time </li></ul></ul><ul><ul><li>UI </li></ul></ul><ul><ul><li>Simplicity </li></ul></ul>
    • 7. F.A.Q. <ul><ul><li>No, you can’t use Eclipse for development </li></ul></ul><ul><ul><li>No, you cannot use Java either </li></ul></ul><ul><ul><li>Yes, you do need a Mac (Intel based) </li></ul></ul><ul><ul><li>iPhone SDK </li></ul></ul><ul><ul><ul><li>http://developer.apple.com/iphone </li></ul></ul></ul><ul><ul><ul><li>xCode enhanced with iPhone specific frameworks and tools </li></ul></ul></ul><ul><ul><ul><li>Registration is free, you can download, develop &amp; test in the simulator </li></ul></ul></ul><ul><ul><ul><ul><li>a fee is required if you want to test on the device and to distribute </li></ul></ul></ul></ul>
    • 8. The Stack <ul><ul><li>OS X (FreeBSD, Mach 3) </li></ul></ul><ul><ul><li>libc (POSIX) </li></ul></ul><ul><ul><li>Core Services </li></ul></ul><ul><ul><li>Objective-C </li></ul></ul><ul><ul><li>CocoaTouch </li></ul></ul>
    • 9. First Impressions: Toolbox
    • 10. First Impressions: xCode <ul><ul><li>Yes, you are going to miss Eclipse </li></ul></ul><ul><ul><ul><li>Refactoring support in infancy but progressing </li></ul></ul></ul><ul><ul><ul><li>SCM support is quite poor (NetBeans is comparable) </li></ul></ul></ul><ul><ul><ul><li>Code browsing is poor </li></ul></ul></ul><ul><ul><ul><li>No compile as you type </li></ul></ul></ul><ul><ul><ul><li>Takes some will to switch </li></ul></ul></ul>
    • 11. xCode: What’s Interesting <ul><ul><li>Multi-window support </li></ul></ul><ul><ul><li>Great documentation browser </li></ul></ul><ul><ul><li>Extensive documentation (1.5GB) </li></ul></ul><ul><ul><li>Built on top of OpenSource technologies </li></ul></ul><ul><ul><ul><li>gcc </li></ul></ul></ul><ul><ul><ul><li>gdb </li></ul></ul></ul><ul><ul><ul><li>Unix scripts to enhance (stdin, stdout) </li></ul></ul></ul><ul><ul><ul><li>in any scripting language </li></ul></ul></ul>
    • 12. Interface Builder <ul><ul><li>Integral part of the SDK </li></ul></ul><ul><ul><li>Probably the second visual editor I actually use(d) </li></ul></ul><ul><ul><li>Integrates with xCode </li></ul></ul><ul><ul><ul><li>information about classes and their features </li></ul></ul></ul><ul><ul><ul><li>Outlets, actions, connections </li></ul></ul></ul><ul><ul><li>NIB / XIB files </li></ul></ul><ul><ul><ul><li>very similar to Java .ser (serialized) files used in the early days of Swing by IDEs </li></ul></ul></ul><ul><ul><ul><ul><li>Forte 4 Java </li></ul></ul></ul></ul>
    • 13. First Impressions: Build system <ul><ul><li>The same build system is used from both the IDE and command line </li></ul></ul><ul><ul><ul><li>xcodebuild </li></ul></ul></ul><ul><ul><ul><li>one project file </li></ul></ul></ul><ul><ul><ul><li>low build maintenance cost </li></ul></ul></ul><ul><ul><li>You don’t actually miss maven much </li></ul></ul><ul><ul><ul><li>Builds are easy to set up and maintain </li></ul></ul></ul><ul><ul><ul><li>Advice: don’t reinvent the wheel (use the standard tool box) </li></ul></ul></ul><ul><ul><li>Frameworks </li></ul></ul><ul><ul><ul><li>no central repository </li></ul></ul></ul><ul><ul><ul><li>no out of the box “materialization” of frameworks </li></ul></ul></ul><ul><ul><ul><ul><li>reliance on shared drives to achieve the goal </li></ul></ul></ul></ul>
    • 14. First Impressions: Instruments <ul><ul><li>It’s Just GREAT </li></ul></ul><ul><ul><li>It’s based on DTrace </li></ul></ul><ul><ul><li>DTrace is present on the devices too </li></ul></ul><ul><ul><li>Almost real-time profiling &amp; analysis both in Simulator and device </li></ul></ul><ul><ul><ul><li>Just “attach” on a running process </li></ul></ul></ul>
    • 15. Objective-C / Java connection? <ul><ul><li>OpenStep API specification </li></ul></ul><ul><ul><ul><li>Developed jointly by NeXT and Sun Inc. @1993-1994 </li></ul></ul></ul><ul><ul><ul><li>Direct predecessor to Cocoa and CocoaTouch </li></ul></ul></ul><ul><ul><li>Java (probably) was strongly influenced by Objective-C </li></ul></ul><ul><ul><ul><li>http://www.virtualschool.edu/objectivec/influenceOnJava.html </li></ul></ul></ul><ul><ul><li>At least a common Smalltalk heritage </li></ul></ul>
    • 16. One Big Difference No Source Code
    • 17. Should I learn it? <ul><ul><li>NeXT -&gt; didn’t reach a wide audience </li></ul></ul><ul><ul><li>Macs too (more or less) -&gt; 8% world PC market </li></ul></ul><ul><li>but </li></ul><ul><ul><li>Installed base of OS X including iPhones and iPod touches: </li></ul></ul><ul><ul><ul><li>grown from 25M to nearly 75M in the last 2 years </li></ul></ul></ul><ul><ul><li>The platform has reached an incredible number of developers and users in the last 2 years </li></ul></ul><ul><ul><li>Customers asked for it :-) </li></ul></ul>
    • 18. Diving Deeper: The Platform
    • 19. Devices <ul><ul><li>iPhone </li></ul></ul><ul><ul><li>iPhone 3G </li></ul></ul><ul><ul><li>iPod Touch </li></ul></ul><ul><ul><li>iPod Touch 2nd generation </li></ul></ul><ul><ul><li>iPhone 3GS </li></ul></ul><ul><li>ARM11 ~ 400 MHz </li></ul><ul><li>128MB RAM (~50MB available to an app) </li></ul><ul><li>Hardware Graphics Accelerator </li></ul><ul><li>Slightly faster </li></ul><ul><li>ARM Cortex V8 ~ 600 MHz </li></ul><ul><li>256MB RAM </li></ul>
    • 20. Objective-C <ul><ul><li>Shared (Smalltalk) heritage with Java </li></ul></ul><ul><ul><ul><li>compiled </li></ul></ul></ul><ul><ul><ul><li>late bound </li></ul></ul></ul><ul><ul><ul><li>single inheritance </li></ul></ul></ul><ul><ul><ul><li>one root class </li></ul></ul></ul><ul><ul><ul><li>Pass-by-reference for objects, pass-by-value for “primitives” </li></ul></ul></ul><ul><ul><ul><li>camelCase convention </li></ul></ul></ul>
    • 21. Syntax <ul><ul><li>Strict superset of ANSI C </li></ul></ul><ul><ul><li>Object syntax is borrowed from Smalltalk </li></ul></ul><ul><ul><ul><li>[object method] </li></ul></ul></ul><ul><ul><ul><ul><li>instead of </li></ul></ul></ul></ul><ul><ul><ul><li>object.method() </li></ul></ul></ul><ul><ul><ul><li>[dictionary setValue:aValue forKey:key] </li></ul></ul></ul><ul><ul><ul><li>[location setDistanceInMeters:3 from:zurich] </li></ul></ul></ul><ul><ul><ul><li>[location setDistanceInKiloMeters:3 from:zurich] </li></ul></ul></ul><ul><ul><ul><li>NSString *s = [NSString stringWithFormat: @&amp;quot;height %2i&amp;quot; , height]; </li></ul></ul></ul>
    • 22. Type System <ul><ul><li>Dynamically typed, late bound </li></ul></ul><ul><ul><ul><li>Sending messages opposed to method invocation </li></ul></ul></ul><ul><ul><ul><li>messages (selectors) have a type and can be passed around </li></ul></ul></ul><ul><ul><li>Type annotations are just “hints” to the compiler, can be added after the fact </li></ul></ul><ul><ul><ul><li>type id is like Object in Java (every object is of type id) </li></ul></ul></ul><ul><ul><ul><li>you can send any message to an object of type id </li></ul></ul></ul><ul><ul><li>“ object variable declaration”: </li></ul></ul><ul><ul><ul><li>NSString *variable = ...; </li></ul></ul></ul><ul><ul><ul><li>id variable = ...; (id is like void *) </li></ul></ul></ul>
    • 23. Nil <ul><ul><li>You can send any message to the nil object </li></ul></ul><ul><ul><ul><li>It will always succeed </li></ul></ul></ul><ul><ul><li>Return value is always with negative semantics </li></ul></ul><ul><ul><ul><li>depends on the method signature / call site </li></ul></ul></ul><ul><ul><ul><li>[ nil isCreated] will return NO </li></ul></ul></ul><ul><ul><ul><li>[ nil numberOfCopies] will return 0 </li></ul></ul></ul><ul><ul><li>Is this good? </li></ul></ul>
    • 24. Namespace handling <ul><ul><li>There isn’t any </li></ul></ul><ul><ul><li>Prefixes are used instead (2 to 4 letters) on classes and global functions </li></ul></ul><ul><ul><ul><li>NSString (Foundation, historical, for NextStep) </li></ul></ul></ul><ul><ul><ul><li>UIView (UI = UIKit) </li></ul></ul></ul><ul><ul><ul><li>CLLocation (CL = CoreLocation) </li></ul></ul></ul>
    • 25. Classes: MyClass.h <ul><li>#import &lt;Foundation/Foundation.h&gt; </li></ul><ul><li>@interface MyClass : NSObject { </li></ul><ul><li>int age; </li></ul><ul><li>NSString *name; </li></ul><ul><li>} </li></ul><ul><li>@end </li></ul>
    • 26. Classes: MyClass.m <ul><li>#import &amp;quot;MyClass.h&amp;quot; </li></ul><ul><li>@implementation MyClass </li></ul><ul><li>@end </li></ul>
    • 27. Methods <ul><li>#import &lt;Foundation/Foundation.h&gt; </li></ul><ul><li>@interface MyClass : NSObject { </li></ul><ul><li>int age; </li></ul><ul><li>NSString *name; </li></ul><ul><li>} </li></ul><ul><li>- ( id )init; </li></ul><ul><li>- ( id )initWithName:(NSString *)name; </li></ul><ul><li>+ ( id )myClassWithName:(NSString *)name age:( int )age; </li></ul><ul><li>- (NSString *)name; </li></ul><ul><li>@end </li></ul>
    • 28. Methods: implementation <ul><li>#import &amp;quot;MyClass.h&amp;quot; </li></ul><ul><li>@implementation MyClass </li></ul><ul><li>+ ( id )myClassWithName:(NSString *)name age:( int )age </li></ul><ul><li>{ </li></ul><ul><li>return [[MyClass new] autorelease]; </li></ul><ul><li>} </li></ul><ul><li>- (NSString *)name </li></ul><ul><li>{ </li></ul><ul><li>return name; </li></ul><ul><li>} </li></ul><ul><li>@end </li></ul>
    • 29. Selectors <ul><ul><li>The message </li></ul></ul><ul><ul><li>Dynamic invocation </li></ul></ul><ul><li>SEL notification = @selector (jobDone:); </li></ul><ul><li>id callback = // ...; </li></ul><ul><li>[callback performSelector:notification withObject:result]; </li></ul>
    • 30. Instantiation <ul><li>MyClass *instance = [[MyClass alloc] init]; </li></ul><ul><li>// same as </li></ul><ul><li>MyClass *instance = [MyClass new ]; </li></ul>
    • 31. Protocols <ul><li>#import &lt;Foundation/Foundation.h&gt; </li></ul><ul><li>@protocol StateHandling </li></ul><ul><li>- ( void )handleState:( id )state; </li></ul><ul><li>@optional </li></ul><ul><li>- ( id )provideState; </li></ul><ul><li>@end </li></ul><ul><li>#import &amp;quot;StateHandling.h&amp;quot; </li></ul><ul><li>@interface MyClass &lt;StateHandling&gt; : NSObject { </li></ul><ul><li>// ... </li></ul><ul><li>} </li></ul><ul><li>// ... </li></ul><ul><li>@end </li></ul>
    • 32. Protocols <ul><li>id &lt;StateHandling&gt; handler = // ...; </li></ul><ul><li>[handler handleState:aState]; </li></ul><ul><li>if ([handler respondsToSelector: @selector (provideState)]) { </li></ul><ul><li>id newState = [handler provideState]; </li></ul><ul><li>} </li></ul>
    • 33. Categories <ul><ul><li>Every existing class can be extended with new methods using categories </li></ul></ul><ul><ul><ul><li>open classes </li></ul></ul></ul><ul><ul><ul><li>limitation: no instance variables can be added </li></ul></ul></ul><ul><ul><li>Used quite often </li></ul></ul>
    • 34. NSObject <ul><ul><li>The main root class </li></ul></ul><ul><ul><li>Methods: </li></ul></ul><ul><ul><ul><li>class </li></ul></ul></ul><ul><ul><ul><li>superclass </li></ul></ul></ul><ul><ul><ul><li>description (toString) </li></ul></ul></ul><ul><ul><ul><li>hash </li></ul></ul></ul><ul><ul><ul><li>isEqual: </li></ul></ul></ul><ul><ul><ul><li>isKindOfClass: </li></ul></ul></ul>
    • 35. Reflection <ul><li>id anObject; </li></ul><ul><li>[anObject respondsToSelector: @selector (handleTouch:)] </li></ul><ul><li>[anObject isKindOfClass:[UITableView class]] </li></ul><ul><li>[anObject isMemberOfClass:[UITableView class]] </li></ul><ul><li>[anObject conformsToProtocol: @protocol (Copying)] </li></ul><ul><ul><li>C based API (Objective-C runtime) for full blown introspection </li></ul></ul>
    • 36. Memory Management <ul><ul><li>Manual Reference Counting </li></ul></ul><ul><ul><li>Autorelease pools </li></ul></ul><ul><li>anObject = [argumentObject retain] </li></ul><ul><li>[anObject release] </li></ul><ul><li>return [anObject autorelease] </li></ul><ul><ul><li>THE biggest issue we had and still have </li></ul></ul><ul><ul><ul><li>dangling pointers </li></ul></ul></ul>
    • 37. Objective-C <ul><ul><li>Dynamically Typed, late bound </li></ul></ul><ul><ul><li>Semantically very similar to Java </li></ul></ul><ul><ul><ul><li>root class </li></ul></ul></ul><ul><ul><ul><li>single inheritance </li></ul></ul></ul><ul><ul><li>Protocols are just like interfaces </li></ul></ul><ul><ul><ul><li>have optional methods </li></ul></ul></ul><ul><ul><li>Classes can be extended through categories </li></ul></ul><ul><ul><li>Classes cannot be nested’ </li></ul></ul><ul><ul><li>Verbose </li></ul></ul>
    • 38. Patterns
    • 39. Application Model <ul><ul><li>SpringBoard </li></ul></ul><ul><ul><li>Single Running Application </li></ul></ul><ul><ul><li>Familiar (Swing) </li></ul></ul><ul><ul><li>Main Thread w/ event loop </li></ul></ul>
    • 40. Key-Value Coding (KVC) <ul><ul><li>A convention similar to the JavaBean convention </li></ul></ul><ul><ul><ul><li>properties </li></ul></ul></ul><ul><ul><ul><li>observing </li></ul></ul></ul><ul><ul><li>A bit more verbose and powerful </li></ul></ul><ul><ul><li>You get a lot for free </li></ul></ul><ul><ul><ul><li>automatic observer notification </li></ul></ul></ul><ul><ul><ul><li>very easy to use </li></ul></ul></ul><ul><ul><li>Accessor Methods </li></ul></ul><ul><li>[anObject setName: @&amp;quot;name&amp;quot; ]; </li></ul><ul><li>[anObject name]; </li></ul><ul><li>[anObject isHidden]; </li></ul>
    • 41. Notification Center / Events <ul><ul><li>Notification Center </li></ul></ul><ul><ul><ul><li>broadcast notifications </li></ul></ul></ul><ul><ul><li>Events </li></ul></ul><ul><ul><ul><li>user events </li></ul></ul></ul><ul><ul><ul><li>responder chain </li></ul></ul></ul>
    • 42. Delegate Pattern
    • 43. Target / Action Pattern <ul><ul><li>Interface Builder </li></ul></ul><ul><ul><ul><li>Outlets </li></ul></ul></ul><ul><ul><ul><li>Actions </li></ul></ul></ul><ul><ul><ul><li>Connections </li></ul></ul></ul>
    • 44. MVC <ul><ul><li>extension through inheritance </li></ul></ul><ul><ul><li>mixed behavior and view construction </li></ul></ul>
    • 45. MVC (classic) <ul><ul><li>views composed out of stock components in interface builder </li></ul></ul><ul><ul><li>behavior in controllers </li></ul></ul><ul><ul><li>connections in interface builder (outlets, actions) </li></ul></ul>
    • 46. Take Away <ul><ul><li>A Java developer is likely to feel at his/her uncle’s house on the iPhone </li></ul></ul><ul><ul><li>Memory management will grow some gray hairs on you </li></ul></ul><ul><ul><li>Love thy garbage collector </li></ul></ul><ul><ul><li>Objective-C is a unique, intoxicating mix of high-level language and raw power </li></ul></ul><ul><ul><li>Scroll speed is important </li></ul></ul>
    • 47. <ul><li>Ognen Ivanovski http://mobile.netcetera.com </li></ul><ul><li>Netcetera [email_address] </li></ul>

    ×