Developing Mobile Applications J2ME Java 2 Micro Edition 1
Virtual machines portable apps virtual machine native apps operating system hardware 2
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! 3
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 4
Compiling and emulating (J2SE) foo.java public class foo { int i; i = 5; i = i + 2; } foo.class : : iconst_5 istore_1 iload_1 bipush 2 iadd istore_1 return verify read eval 5
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 6
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 7
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 8
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 9
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 10
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 11
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! 12
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 13
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 14
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 15
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? 16
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,... 17
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 18
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> 19
Developing Mobile Applications J2ME : Midlets and program development 20
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,... 21
Pre-verifying foo.java public class foo { int i; i = 5; i = i + 2; } read eval foo.class : : iconst_5 istore_1 iload_1 bipush 2 iadd istore_1 return foo.class : : iconst_5 istore_1 iload_1 bipush 2 iadd istore_1 return pre-verify (opt. obfuscate) 22
environment WS P/HTTP device explorer emulator pre-verifier IrD A/B luetooth compiler java VM 23
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 24
Life of a Midlet Start Call the constructor. Paused destroyapp() startapp() Shutdown pauseapp() Running destroyapp() 25
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. 26
RMS record management system RMS Foo 1: Hello 2: World Persistent storage App.jar Midlet A Midlet B RecordStore rs = RecordStore.openRecordStore("Foo",true); 27
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 28
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. 29
Developing Mobile Applications J2ME: Provisioning 30
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. 31
JAD MIDlet-1: HelloWorld,, HelloWorld MIDlet-Name: HelloWorld MIDlet-Vendor: Your Company MIDlet-Version: 1.0 MIDlet-Jar-URL: http://www.compmy.com/helloworld.jar MIDlet-Jar-Size: 1801 MicroEdition-Profile: MIDP-1.0 MicroEdition-Configuration: CLDC-1.0 MIDlet-Description: HelloWorld Example 32
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. 33
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) 34
OTA MIDP 2.0 provisioning GE T JAD JAD GE T JAR JAR 35
JAD MIDlet-1: HelloWorld,, HelloWorld MIDlet-Name: HelloWorld MIDlet-Vendor: jm MIDlet-Version: 1.0 MIDlet-Jar-URL: http://www.compny.com/helloworld.jar MIDlet-Jar-Size: 1801 MicroEdition-Profile: MIDP-1.0 MicroEdition-Configuration: CLDC-1.0 MIDlet-Description: HelloWorld Example MIDlet-Install-Notify: http://www.company.com/installed.php 36
OTA MIDP 2.0 provisioning GE T JAD JAD GE T JAR JAR POS T 900 S ucess 37
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. 38
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. 39
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 40
Lab session 5 Write, compile, debug and deploy a small J2ME application (yes more than Hello World) 41