iphone 4 java developer: "what the hack is ..."

64
iPhone 4 Java Developers „What the hack is ...?“ Lars Röwekamp open knowledge GmbH Dienstag, 10. Mai 2011

Upload: open-knowledge-gmbh

Post on 27-Jun-2015

1.436 views

Category:

Technology


0 download

DESCRIPTION

Was Sun Microsystems mit Java (ME) über Jahre hinweg vergeblich versuchte, ist Apple mit dem iPhone, iPod und iPad in nur wenigen Monaten gelungen: die Erschließung eines riesigen Marktes für mobile Anwendungen (Apps) – aber leider nicht für den klassischen Java Developer. Stellt sich die Frage, ob die Entwicklung von iOS-basierten Anwendungen mit Objective-C sich wirklich so stark von Java unterscheidet. Die Session erläutert den typischen Entwicklungsprozess für iOS Apps, geht auf die gängigen Tools und die Sprache Objective-C ein und zeigt darüber hinaus, wie "einfach" es ist, eine selbst geschriebene Anwendung im App Store zu platzieren. Und das alles natürlich alles aus der Sicht eines Java Guys.

TRANSCRIPT

Page 1: iPhone 4 Java Developer: "What the hack is ..."

iPhone 4 Java Developers„What the hack is ...?“

Lars Röwekamp open knowledge GmbH

Dienstag, 10. Mai 2011

Page 2: iPhone 4 Java Developer: "What the hack is ..."

iPhone 4 Java Developers„What the hack is ...?“

Lars Röwekamp open knowledge GmbH

@mobileLarson@_openknowledge

Dienstag, 10. Mai 2011

Page 3: iPhone 4 Java Developer: "What the hack is ..."

Dienstag, 10. Mai 2011

Page 4: iPhone 4 Java Developer: "What the hack is ..."

Dienstag, 10. Mai 2011

Page 5: iPhone 4 Java Developer: "What the hack is ..."

Dienstag, 10. Mai 2011

Page 6: iPhone 4 Java Developer: "What the hack is ..."

Dienstag, 10. Mai 2011

Page 7: iPhone 4 Java Developer: "What the hack is ..."

Dienstag, 10. Mai 2011

Page 8: iPhone 4 Java Developer: "What the hack is ..."

Dienstag, 10. Mai 2011

Page 9: iPhone 4 Java Developer: "What the hack is ..."

WTH ... iOS?

Dienstag, 10. Mai 2011

Page 10: iPhone 4 Java Developer: "What the hack is ..."

WTH ... Objective-C?

Dienstag, 10. Mai 2011

Page 11: iPhone 4 Java Developer: "What the hack is ..."

WTH ... Tools?

Dienstag, 10. Mai 2011

Page 12: iPhone 4 Java Developer: "What the hack is ..."

WTH ... Apple?

Dienstag, 10. Mai 2011

Page 13: iPhone 4 Java Developer: "What the hack is ..."

Dienstag, 10. Mai 2011

Page 14: iPhone 4 Java Developer: "What the hack is ..."

„WTH ... iOS?“

– iOS Verständnis ist Voraussetzung – Liefert Basis-Infrastruktur für Apps

– „must-understand“ App Life-Cycle– „should-know“ Frameworks– „well-defined“ Design Patterns

Dienstag, 10. Mai 2011

Page 15: iPhone 4 Java Developer: "What the hack is ..."

App Event LoopDienstag, 10. Mai 2011

Page 16: iPhone 4 Java Developer: "What the hack is ..."

- applicationDidFinishLaunch... {...}

- applicationDidBecomeActive {...}

- applicationWillResignActive {...}

- applicationWillTerminate {...}

App Life-CycleDienstag, 10. Mai 2011

Page 17: iPhone 4 Java Developer: "What the hack is ..."

Dienstag, 10. Mai 2011

Page 18: iPhone 4 Java Developer: "What the hack is ..."

- applicationDidFinishLaunch... {...}

- applicationDidBecomeActive {...}

- applicationWillResignActive {...}

- applicationWillTerminate {...}

- applicationDidEnterBackground {...}

- applicationWillEnterForeground {...}

App Life-Cycle (eXtended)Dienstag, 10. Mai 2011

Page 19: iPhone 4 Java Developer: "What the hack is ..."

Dienstag, 10. Mai 2011

Page 20: iPhone 4 Java Developer: "What the hack is ..."

Framework Layers

Core OS Layer

Core Services Layer

Media Layer

Cocoa Touch Layer

SL

OSL

ML

CTL

Dienstag, 10. Mai 2011

Page 21: iPhone 4 Java Developer: "What the hack is ..."

Cocoa Touch Layer

– UIKit– App Management– Graphics & Windowing– UI Views & Controls– Touch Event Handling– Text Handling– Web Content– Device Feature Bibliotheken

(z.B. Acclerometer, Kamera, Video)

CTL

Dienstag, 10. Mai 2011

Page 22: iPhone 4 Java Developer: "What the hack is ..."

Cocoa Touch Layer

– Foundation– Wrapper Klassen (string, number, binary ...)– Collection Klassen (array, sets, dictionary, ...)– Bundles (dynamisch geladene App Module)– User Preferences– Threads & Run Loops– File Streams und URLs– Bonjour (dynamisches Discovery)

CTL

Dienstag, 10. Mai 2011

Page 23: iPhone 4 Java Developer: "What the hack is ..."

Core App ObjectsDienstag, 10. Mai 2011

Page 24: iPhone 4 Java Developer: "What the hack is ..."

Dienstag, 10. Mai 2011

Page 25: iPhone 4 Java Developer: "What the hack is ..."

„WTH ... Objective-C?“

– Brad Cox & Tom Love (stepstone)– Basiert auf den Ideen von Smaltalk – striktes Superset von ANSI C

Dienstag, 10. Mai 2011

Page 26: iPhone 4 Java Developer: "What the hack is ..."

Objective-C

– Objektorientiert– State-of-the-Art Compiler– sehr gute Performance– ABI kompatibel, d.h. „C for free“– Dynamisch– Mesage orientiert

– Minimalistisch

Dienstag, 10. Mai 2011

Page 27: iPhone 4 Java Developer: "What the hack is ..."

Objective-C 2.0

– Mit Mac OS 10.5 eingeführt– GC, aber nicht auf iOS

– Fast-Enumeration– Weak-Linking– Selectors– Blocks

Dienstag, 10. Mai 2011

Page 28: iPhone 4 Java Developer: "What the hack is ..."

Objective-C 2.0

– Mit Mac OS 10.5 eingeführt– GC, aber nicht auf iOS

– Fast-Enumeration– Weak-Linking– Selectors– Blocks ?

Dienstag, 10. Mai 2011

Page 29: iPhone 4 Java Developer: "What the hack is ..."

public void setSize( Dimension size ) {

if (size.height!=0 && size.width!=0) { if (!this.size.equals(size)) { super.setSize(size); for ( MapItem i: mapItems ) i.resize(); } } }

The „Java“ WayDienstag, 10. Mai 2011

Page 30: iPhone 4 Java Developer: "What the hack is ..."

- (void)setFrameSize:(NSSize)size { if (size.height!=0.0 && size.width!=0.0) { if (!NSEqualSizes(self.size,size)) { [super setFrameSize:size]; [mapItems makeObjectsPerformSelector: @selector(resize)]; } } }

The „Ojective-C“ WayDienstag, 10. Mai 2011

Page 31: iPhone 4 Java Developer: "What the hack is ..."

- (void)setFrameSize:(NSSize)size { if (size.height!=0.0 && size.width!=0.0) { if (!NSEqualSizes(self.size,size)) { [super setFrameSize:size]; [mapItems makeObjectsPerformSelector: @selector(resize)]; } } }

The „Ojective-C“ WayDienstag, 10. Mai 2011

Page 32: iPhone 4 Java Developer: "What the hack is ..."

- (void)setFrameSize:(NSSize)size { if (size.height!=0.0 && size.width!=0.0) { if (!NSEqualSizes(self.size,size)) { [super setFrameSize:size]; [mapItems makeObjectsPerformSelector: @selector(resize)]; } } }

The „Ojective-C“ WayDienstag, 10. Mai 2011

Page 33: iPhone 4 Java Developer: "What the hack is ..."

- (void)setFrameSize:(NSSize)size { if (size.height!=0.0 && size.width!=0.0) { if (!NSEqualSizes(self.size,size)) { [super setFrameSize:size]; [mapItems makeObjectsPerformSelector: @selector(resize)]; } } }

The „Ojective-C“ WayDienstag, 10. Mai 2011

Page 34: iPhone 4 Java Developer: "What the hack is ..."

- (void)setFrameSize:(NSSize)size { if (size.height!=0.0 && size.width!=0.0) { if (!NSEqualSizes(self.size,size)) { [super setFrameSize:size]; [mapItems makeObjectsPerformSelector: @selector(resize)]; } } }

The „Ojective-C“ WayDienstag, 10. Mai 2011

Page 35: iPhone 4 Java Developer: "What the hack is ..."

person.setFirstName(“John“);

„send Message“statt Methoden-Aufruf

[person setFirstName:@“John“];

Java

Objective-C

Dienstag, 10. Mai 2011

Page 36: iPhone 4 Java Developer: "What the hack is ..."

Person person = new Person();

Objects sind dyn. allokierte StructsAchtung: D.h. keine Constructors

Person *p = [[Person alloc] init];

Java

Objective-C

Dienstag, 10. Mai 2011

Page 37: iPhone 4 Java Developer: "What the hack is ..."

Objects sind dyn. allokierte StructsAchtung: gezeigte Steps sind Pflicht

- (id)init{ self = [super init]; if (self != nil) { ... // spezifischer Code } return self; }  

Objective-C

Dienstag, 10. Mai 2011

Page 38: iPhone 4 Java Developer: "What the hack is ..."

java.lang.String s = new String(“Java“)

Wer braucht schon NamespacesAchtung: Framework-Prefix

NSString *s = [[NSString alloc] initWithString:@“Objective-C“];

Java

Objective-C

Dienstag, 10. Mai 2011

Page 39: iPhone 4 Java Developer: "What the hack is ..."

Objective-C Methoden

– Deklaration in .h– Implementierung in .m

– Instanzmethoden mit Prefix „-“– Klassenmethoden mit Prefix „+“

– Kein Overloading, da Runtimeüber den Namen geht

Dienstag, 10. Mai 2011

Page 40: iPhone 4 Java Developer: "What the hack is ..."

person.addAddress(address);

person.addAddress(address, AdrType.HOME);

Kein Methode Overloading ...

[person addAddress:address]

[person addAddress:address withType:ADHome];

Java

Objective-C

Dienstag, 10. Mai 2011

Page 41: iPhone 4 Java Developer: "What the hack is ..."

person.addAddress(address);

person.addAddress(address, AdrType.HOME);

Kein Methode Overloading ...

[person addAddress:address]

[person addAddress:address withType:ADHome];

Java

Objective-C

Dienstag, 10. Mai 2011

Page 42: iPhone 4 Java Developer: "What the hack is ..."

public void addAddress(Address adr, AdrType adrType);

Kein Methode Overloading ...Methodenname: addAddress:withType

- void addAddress:(Address*)adr withType:(ADType)adrType;

Java

Objective-C

Dienstag, 10. Mai 2011

Page 43: iPhone 4 Java Developer: "What the hack is ..."

Objective-C Klassen

– Deklaration in .h– Implementierung in .m

– @interface ... @end– @implementation ... @end

– Instanzvariablen innerhalb { ... }– Methoden außerhalb { ... }

Dienstag, 10. Mai 2011

Page 44: iPhone 4 Java Developer: "What the hack is ..."

Objective-C Interface (.h)

@interface Person: NSObject { int age; }

- (int)age; - (void)setAge:(int)newAge;

@end;

Objective-C

Dienstag, 10. Mai 2011

Page 45: iPhone 4 Java Developer: "What the hack is ..."

Objective-C Implementation (.m)

#import “Person.h“

@implementation Person

- (int)age {return age}; - (void)setAge:(int)newAge { age = newAge; } ...

@end;

Objective-C

Dienstag, 10. Mai 2011

Page 46: iPhone 4 Java Developer: "What the hack is ..."

property & synthezise

@interface Person: NSObject { BOOL aduld; } @property BOOL adult (...); @end;

@implementation Person @synthesize adult; @end;

Objective-C

Dienstag, 10. Mai 2011

Page 47: iPhone 4 Java Developer: "What the hack is ..."

Objective-C Qualifier

– @private Sektion– @protected Sektion– @public Sektion

– „private“ via fehlende Deklaration in .h

Dienstag, 10. Mai 2011

Page 48: iPhone 4 Java Developer: "What the hack is ..."

Objective-C „Fun-Club“

– Pointer – Memory Management – Missing GC (iOS Autorelease Pool)

– Protocol (wie Java Interfaces)– Blocks („Closure-like“)– Selector („Reflection-like“)– Weak Linking („wenn-dann“)

Dienstag, 10. Mai 2011

Page 49: iPhone 4 Java Developer: "What the hack is ..."

Objective-C „Fun-Club“

– Pointer – Memory Management – Missing GC (iOS Autorelease Pool)

– Protocol (wie Java Interfaces)– Blocks („Closure-like“)– Selector („Reflection-like“)– Weak Linking („wenn-dann“)

Dienstag, 10. Mai 2011

Page 50: iPhone 4 Java Developer: "What the hack is ..."

Objective-C Memory Management

alloc: retain count =1copy: retain count =1retain: retain count +1release: retain count -1autorelease: retain count -1 (future)

Dienstag, 10. Mai 2011

Page 51: iPhone 4 Java Developer: "What the hack is ..."

Objective-C Memory Management

Dienstag, 10. Mai 2011

Page 52: iPhone 4 Java Developer: "What the hack is ..."

Objective-C Memory Management

Dienstag, 10. Mai 2011

Page 53: iPhone 4 Java Developer: "What the hack is ..."

Objective-C Memory Management

Dienstag, 10. Mai 2011

Page 54: iPhone 4 Java Developer: "What the hack is ..."

Dienstag, 10. Mai 2011

Page 55: iPhone 4 Java Developer: "What the hack is ..."

xCode InterfaceBuilder Instruments

Dienstag, 10. Mai 2011

Page 56: iPhone 4 Java Developer: "What the hack is ..."

Code Diving ...

>> xCode>> IB>> Instruments

Dienstag, 10. Mai 2011

Page 57: iPhone 4 Java Developer: "What the hack is ..."

Dienstag, 10. Mai 2011

Page 58: iPhone 4 Java Developer: "What the hack is ..."

Dienstag, 10. Mai 2011

Page 59: iPhone 4 Java Developer: "What the hack is ..."

Dienstag, 10. Mai 2011

Page 60: iPhone 4 Java Developer: "What the hack is ..."

Dienstag, 10. Mai 2011

Page 61: iPhone 4 Java Developer: "What the hack is ..."

Alles halb so schlimm, aber ...

... ungewohnte Umgebung

... ungewohnte Sprache

... ungewohnte Tools

... ungewohnte Strategie

Dienstag, 10. Mai 2011

Page 62: iPhone 4 Java Developer: "What the hack is ..."

Und nicht vergessen, ...

... fast launch, short use

... tune your code

... tune your network

„Build cool stuff and have fun!“

Dienstag, 10. Mai 2011

Page 63: iPhone 4 Java Developer: "What the hack is ..."

Dienstag, 10. Mai 2011

Page 64: iPhone 4 Java Developer: "What the hack is ..."

Gibt es noch Fragen?

Dann los ...

Dienstag, 10. Mai 2011