Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile...

41
1 Developing Mobile Applications 2G1722 Johan Montelius Developing Mobile Applications J2ME – Java 2 Micro Edition

Transcript of Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile...

Page 1: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

1Developing Mobile Applications 2G1722 Johan Montelius

Developing Mobile Applications

J2ME – Java 2 Micro Edition

Page 2: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

2Developing Mobile Applications 2G1722 Johan Montelius

Virtual machines

hardware

operating system

virtual machine

portable appsnative apps

Page 3: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

3Developing Mobile Applications 2G1722 Johan Montelius

Java - important issues

• Symbolic language– not a random access memory– dynamic memory allocation– garbage collection

• implemented using a virtual machine– portability– sand box

• Multi threaded, concurrent processes• Large library!

Page 4: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

4Developing Mobile Applications 2G1722 Johan Montelius

Java sources

• Java Community Process www.jcp.org– JSR, java specification request– reference implementations

• Sun java.sun.com– SDK, tools, community

• Your favorite phone manufacturer– SDK, tools, community, device

emulators

Page 5: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

5Developing Mobile Applications 2G1722 Johan Montelius

Compiling and emulating (J2SE)

: : iconst_5 istore_1 iload_1 bipush 2 iadd istore_1 return

foo.class

public class foo { int i; i = 5; i = i + 2; }

foo.java

readeval

verify

Page 6: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

6Developing Mobile Applications 2G1722 Johan Montelius

pros and cons

• Pros– Simpler: it's simpler to build a compiler and

emulator than to build a native code compiler.– Portability; porting an emulator is simpler than

porting a native code compiler.

• Cons– slower since wee need to do a read-eval-loop– limited access to OS and hardware

Page 7: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

7Developing Mobile Applications 2G1722 Johan Montelius

Flavors of Java 2

• J2SE - standard edition– the most used on laptops and

desktops• JSEE – enterprise edition

– additional support for running large servers

• J2ME – micro edition– mobile devices– set top boxes– embedded systems

Page 8: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

8Developing Mobile Applications 2G1722 Johan Montelius

J2ME specification

• a configuration– defines the minimum required complement of Java

technology components and libraries for small connected devices,

– Java language and virtual machine features, core libraries, security, input/output, and networking

– no optional libraries

• a profile– defines additional libraries and features for a particular

vertical market, device category or industry– optional libraries

Page 9: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

9Developing Mobile Applications 2G1722 Johan Montelius

J2ME

• The J2ME version that we are most interested in is the one for mobile phones.

• CLDC– Connected Limited Device Configuration– minimum 128Kbyte available– CDC (Connected device configuration) is a larger

configuration for more powerful terminals. Some mobile phones now support CDC.

• MIDP– Mobile Information Device Profile

Page 10: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

10Developing Mobile Applications 2G1722 Johan Montelius

CLDC - Connected Limited Device Configuration

• CLDC 1.0– defined in May 2000, JSR 30 – basic java.lang– subset of java.lang/util/io/..

• CLDC 1.1– defined in Dec 2002, JSR 139– adds support for float in java.lang– java.util.Calendar/Date/TimeZone/...– bug fixes and more

Page 11: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

11Developing Mobile Applications 2G1722 Johan Montelius

MIDP - Mobile Information Device Profile

• MIDP 1.0 - defined in Dec 2000, JSR 37– java.microedition.midlet– java.microedition.rms– java.microedition.lcdui– java.microedition.io.HttpConnection

• MIDP 2.0 - defined in Nov 2002 JSR 118– java.microedition.io.SocketConnection– java.microedition.media – java.microedition.lcdui.game

• MIDP 3.0 in pipe-line Q3 2006

Page 12: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

12Developing Mobile Applications 2G1722 Johan Montelius

MIDP 1.0/2.0/3.0

• The numbers does not mean that MIDP evolves and that “older” versions become obsolete.

• New devices can still be MIDP 1.0 devices because of limited resources.

• MIDP 2.0 does not imply CLDC 1.1!

Page 13: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

13Developing Mobile Applications 2G1722 Johan Montelius

Phones on the market

• older J2ME phones: – CLDC 1.0/MIDP 1.0

• most J2ME phones released since Q2 2004: – CLDC 1.1/ MIDP 2.0

• some phones also support additional libraries

Page 14: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

14Developing Mobile Applications 2G1722 Johan Montelius

Optional libraries

• JSR 82 Bluetooth – connect to BT devices

• JSR 120 Wireless Messaging API– sending and receiving SMS messages

• JSR 135 Mobile Media API– high-level interface to sound and

multimedia capabilities

• JSR 184 Mobile 3D Graphics– interactive 3D graphics

Page 15: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

15Developing Mobile Applications 2G1722 Johan Montelius

Even more ....

• JSR 177 Security and Trust Services API• JSR 179 Java Location API• JSR 180 Session Initiation Protocol (SIP) • JSR 205 Wireless Messaging API (WMA) 2.0 • JSR 226 Scalable 2D Vector Graphics API

Page 16: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

16Developing Mobile Applications 2G1722 Johan Montelius

MIDP 3.0

• Let Java applications start and run in the back ground

• Several applications in the same JRE.• Let applications talk to each other.• Rules for firewalls.• .... is the sandbox a sandbox?

Page 17: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

17Developing Mobile Applications 2G1722 Johan Montelius

SonyEricsson

• T610, T630– CLDC1.0/MIDP1.0 – Color 128x160 pixel, up to 60KB jar, up to 256 KB heap

• F500– CLDC1.1/ MIDP 2.0 + MMAPI, WMA, 3D ... color 128x160

pixel, 1.5MB heap

• Z1010, K700, – CLDC1.1/ MIDP 2.0 + MMAPI, WMA, 3D ... 176 x 220

pixels, 1.5MB heap

• P910i: – CLDC1.1/CDC1.0/MIDP2.0 color 208x320 pixels,

X MB jar , ...

Page 18: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

18Developing Mobile Applications 2G1722 Johan Montelius

Nokia

• Series 30– CLDC1.0/MIDP1.0 – monochrome/color, 95x65 pixel, 32/64KB jar

• Series 40– CLDC1.0/MIDP1.0 or CLDC1.1/MIDP2.0– Color 128x128 pixel, >64KB jar, up to 200KB heap

• Series 60– CLDC1.1/MIDP2.0 + more – Color 176x208 pixel, up to 4MB jar, up to 1MB heap

• Series 80 and Series 90– CLDC1.1/MIDP2.0 + more

Page 19: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

19Developing Mobile Applications 2G1722 Johan Montelius

How do we find out?<prf:JavaEnabled>Yes</prf:JavaEnabled><prf:JavaPlatform> <rdf:Bag> <rdf:li>CLDC</rdf:li> <rdf:li>MIDP</rdf:li> <rdf:li>Profile/MIDP-2.0</rdf:li> <rdf:li>Configuration/CLDC-1.1</rdf:li> </rdf:Bag></prf:JavaPlatform><prf:JavaPackage> <rdf:Bag> <rdf:li>jsr-75</rdf:li> <rdf:li>jsr-234</rdf:li> : <rdf:li>vscl-2.1</rdf:li> </rdf:Bag></prf:JavaPackage>

Page 20: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

20Developing Mobile Applications 2G1722 Johan Montelius

Developing Mobile Applications

J2ME : Midlets and program development

Page 21: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

21Developing Mobile Applications 2G1722 Johan Montelius

What you need

• a good editor (why not emacs)• development tools from java.sun.com

– Java 2 Platform SDK 1.4– the J2ME Wireless Toolkit (1.x or 2.x)

• from your local phone manufacturer – an emulator for your phone – a complete SDK

• IDE, debugger tools, ...

Page 22: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

22Developing Mobile Applications 2G1722 Johan Montelius

Pre-verifying

readeval

: : iconst_5 istore_1 iload_1 bipush 2 iadd istore_1 return

foo.class

public class foo { int i; i = 5; i = i + 2; }

foo.java

: : iconst_5 istore_1 iload_1 bipush 2 iadd istore_1 return

foo.class

pre-verify(opt. obfuscate)

Page 23: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

23Developing Mobile Applications 2G1722 Johan Montelius

environment

compiler

emulator

device explorer

pre-verifier IrDA/Bluetooth

WS P/HTTP

java VM

Page 24: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

24Developing Mobile Applications 2G1722 Johan Montelius

Midlet

• Similar to a Applet• An application that is controller by

– create the object– startApp– pauseApp– destroyApp

• Interactive – javax.microedition.lcdui.Screen– javax.microedition.lcdui.Canvas

Page 25: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

25Developing Mobile Applications 2G1722 Johan Montelius

Life of a Midlet

Start

Paused

Call the constructor.

Shutdown

destroyApp()

destroyApp()pauseApp()Running

startApp()

Page 26: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

26Developing Mobile Applications 2G1722 Johan Montelius

JAR – Java Archive

• A JAR file contains one or more .class files and the images, sounds etc files that the midlet is using.

• MIDlets in a JAR file can share the same resources. This is one reason why you might want to include several midlets in one JAR.

Page 27: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

27Developing Mobile Applications 2G1722 Johan Montelius

RMS record management system

RMS

Midlet A Midlet B

RecordStore rs = RecordStore.openRecordStore("Foo",true);

Persistent storageFoo

App.jar

1: Hello2: World

Page 28: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

28Developing Mobile Applications 2G1722 Johan Montelius

JAR Manifest

• The JAR file also contains a manifest file (META-INF/MANIFEST.MF) that describes the content:– MIDlet-Name: The Hello App– MIDlet-Version: 1.0– MIDlet-Vendor: Your company– MIDlet-1: Hello, img/hello.gif , demo.Hello– MicroEdition-Profile: MIP-1.0– MicroEdition-Configuration: CLDC-1.0

Page 29: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

29Developing Mobile Applications 2G1722 Johan Montelius

JAR Manifest

• The manifest can also contain user defined parameters that can be access from the midlet.

• This is useful for to keep constants separate form the Java code.

• The manifest information is accessible to all midlets in the JAR file.

Page 30: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

30Developing Mobile Applications 2G1722 Johan Montelius

Developing Mobile Applications

J2ME: Provisioning

Page 31: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

31Developing Mobile Applications 2G1722 Johan Montelius

Over the air

• As with all larger files we would like to know what is about to be downloaded before we actually download it.

• A JAD – Java application description – file is very similar to a manifest file but is delivered in plain text and contains information about the jar-file.

Page 32: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

32Developing Mobile Applications 2G1722 Johan Montelius

JAD

MIDlet-1: HelloWorld, , HelloWorldMIDlet-Name: HelloWorldMIDlet-Vendor: Your CompanyMIDlet-Version: 1.0MIDlet-Jar-URL: http://www.compmy.com/HelloWorld.jarMIDlet-Jar-Size: 1801MicroEdition-Profile: MIDP-1.0MicroEdition-Configuration: CLDC-1.0MIDlet-Description: HelloWorld Example

Page 33: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

33Developing Mobile Applications 2G1722 Johan Montelius

Deploy

• Place the .jar and .jad file on a web server.• Patch the .jad file to point to the .jar file• Have the .jad file referred to from a WML

or XHTML file. • When downloaded the user will be

prompted.• Download and execute.

Page 34: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

34Developing Mobile Applications 2G1722 Johan Montelius

JAD user defined parameters

• The JAD file can also contain user defined parameters.

• Can be access in the same way as manifest parameters.

• You can change JAD parameters with out repacking the JAR file.

• Could be useful for device specific information.

• JAD parameters override manifest parameters (unless the midlet is signed)

Page 35: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

35Developing Mobile Applications 2G1722 Johan Montelius

OTA – MIDP 2.0 provisioning

GET JAR

GET JAD

JAD

JAR

Page 36: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

36Developing Mobile Applications 2G1722 Johan Montelius

JADMIDlet-1: HelloWorld, , HelloWorldMIDlet-Name: HelloWorldMIDlet-Vendor: jmMIDlet-Version: 1.0MIDlet-Jar-URL: http://www.compny.com/HelloWorld.jarMIDlet-Jar-Size: 1801MicroEdition-Profile: MIDP-1.0MicroEdition-Configuration: CLDC-1.0MIDlet-Description: HelloWorld ExampleMIDlet-Install-Notify: http://www.company.com/installed.php

Page 37: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

37Developing Mobile Applications 2G1722 Johan Montelius

OTA – MIDP 2.0 provisioning

GET JAR

GET JAD

JAD

JAR

POS T 900 S ucess

Page 38: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

38Developing Mobile Applications 2G1722 Johan Montelius

Security (MIDP 2.0)

• MIDlets are divided into trusted and untrusted applications:– untrusted applications can not (or only after user

acceptance) access for example network resources etc.

• There are several domains, each with a set of rights:– manufacturer– operator – third party

• MIDlets are digitally signed and can be verified by certificates for each domain.

Page 39: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

39Developing Mobile Applications 2G1722 Johan Montelius

Security (MIDP 2.0)

• The JAD and manifest file should contain the description of the rights that an application needs:– MIDlet-Permissions: javax.microedition.io.Connector.http– MIDlet-Permissions-Opt:

javax.microedition.io.Connector.https

• Verifying signatures is done at installation, the MIDlet can still be executed even if the certificate has expired.

Page 40: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

40Developing Mobile Applications 2G1722 Johan Montelius

Native

• If the support is not there in the Java libraries you will have to do a native code implementation:

• SymbianOS – Nokia Series 60/80– SonyEricsson P900

• Microsoft Mobile– Qtek, Palm Treo, ...

• Qualcomm BREW• Linux Mobile

Page 41: Developing Mobile Applications - KTHjohanmon/attic/2g1722/lectures/08 j2me.pdfDeveloping Mobile Applications 2G1722 Johan Montelius J2ME specification • a configuration – defines

41Developing Mobile Applications 2G1722 Johan Montelius

Lab session 5

• Write, compile, debug and deploy a small J2ME application (yes more than Hello World)