Y39PDA Development of Java ME application České vysoké učení technické v Praze Fakulta Elektrotechnická
Content What is Java ME Low Level a High Level API What is JSR LBS Java ME app. life-cycle 2/29
Is Java ME still important? 3/29
What is Java ME? Officially Java Platform, Micro Edition Formerly known as J2ME, Platform for devices with limited computing power Cell phones Handheld devices Industrial controls Set-top boxes Subset of Java SE?? 4/29
5/29
What is KVM? KVM virtual machine for mobile devices Supports only subset of JVM functions For ex. no floating point operation support Written in C K in KVM stands for Kilobyte Running on kilobytes of memory 40 kilobytes to 80 kilobytes of memory for VM core 6/29
Configurations CDC and CLDC CDC - Connected Device Configuration CLDC - Connected, Limited Device Configuration 7/29
Configuration CDC Using full Java VM Typical requirements 32-bit processor Minimum 512K for the runtime environment at least 256K to hold and run applications. PDA devices 8/29
Configuration CLDC Using KVM Typical requirements 160 to 512 KB total memory available for the Java platform 16-bit or 32-bit processor low power consumption, often battery powered intermittent network connectivity (often wireless) with potentially limited bandwidth 9/29
Profile MIDP screen size of approximately (at least) 96x54 pixels display color depth of 1 bit one- or two-handed keyboard or touch screen input device 128 KB nonvolatile memory for MIDP components 8 KB nonvolatile memory for application-persistent data 32 KB volatile runtime memory for Java heap two-way wireless connectivity 10/29
Low Level and High Level API Java ME supports two approaches of GUI development Low Level API javax.microedition.lcdui.canvas High Level API javax.microedition.lcdui.screen 11/29
Difference between Low Level and High Level API (1) Low Level API Fully control graphical design of application (drawing on canvas) More difficult application development Depends on target device (display size) Limited portability on other devices Possible usage of numerical keypad (0-9) for controlling application (keypressed events) 12/29
Difference between Low Level and High Level API (2) High Level API Application build up from set of UI components and user controls (forms, text boxes, check boxes etc.) Easy and rapid app. development Functionality independent on target device Easy portability on other devices (high compatibility) Impossible to fully control graphical design of app. (depends on device and implementation of MIDP in device) Impossible -> left/right soft key (controlled by application manager) Impossible to use num. keyboard (0-9) for controlling app. 13/29
Difference between Low Level and High Level API (3) 14/29
Other UI toolkits Based on Low Level API (javax.microedition.lcdui.canvas) J2ME Polish LWUIT (Lightweight User Interface Toolkit) 15/29
LWUIT Inspired by the architecture of Java Swing MVC Features Basic set of components Flexible layouts Style Theming Runs on JavaME Android BlackBerry LWUIT Resource Editor 16/29
What is JSR? JSR = Java Specification Requests Formal documents that describe proposed specifications and technologies for adding to the Java platform. Final JSR provides a reference implementation that is a free implementation of the technology in source code form and Technology Compatibility Kit to verify the API specification 17/29
18/29
Useful JSR s JSR 75 - PIM and FileConnection API Calendars Filesystem JSR 82 - APIs for Bluetooth communication JSR 179 - Location API Connection to GPS (A-GPS) Internal Bluetooth Acquiring coordinates 19/29
LBS Location Based Services Parsing of NMEA-0183 messages Used by GPS for communication with other devices Complicated development Using Location API (JSR 179) if target device implements it Development for Location API is easy 20/29
NMEA - National Marine Electronics Association $GPRMC,162352,A,5053.10,N,00849.14,E,150.0,2 35.3,301294,,*10 $GPRMB,A,0.42,L,EDFN,EDFQ,5102.20,N,00840.80,E,010.5,330.1,-018.6,V*08 $GPWPL,5052.50,N,00848.88,E,EDFN*41 $GPGLL,5053.10,N,00849.12,E*6F $PGRMZ,635,f,3*1B $GPXTE,A,A,0.41,L,N*6B $GPBWC,162352,5102.20,N,00840.80,E,330.2,T,, M,010.5,N,EDFQ*3C 21/29
NMEA - National Marine Electronics Association NMEA message $GPGLL,4916.45,N,12311.12,W,225444,A,*1D Where: GLL Geographic position, Lat and Lon 4916.46,N Latitude 49 deg. 16.45 min. North 12311.12,W Longitude 123 deg. 11.12 min. West 225444 Fix taken at 22:54:44 UTC A Data Active or V (void) *id checksum data 22/29
LBS using of Location API... // Set criteria for selecting a location provider: // accurate to 500 meters horizontally Criteria cr= new Criteria(); cr.sethorizontalaccuracy(500); // Get an instance of the provider LocationProvider lp= LocationProvider.getInstance(cr); // Request the location, setting a one-minute timeout Location l = lp.getlocation(60); Coordinates c = l.getqualifiedcoordinates(); if(c!= null ) { // Use coordinate information double lat = c.getlatitude(); double lon = c.getlongitude(); }... 23/29
MIDlet vs. Java ME application start public class Test extends MIDlet{ private boolean once = false; Pokus() { } not supported by S40, S60 paused startapp() pauseapp() destroyapp() active public void startapp() { if ( once == false ) { once = true; // resource allocation } } // other resource allocation // logic public void pauseapp() { // resource release } destroyed public void destroyapp() { // all resource release } } 24/29
MIDlet vs. Java ME application start running main() class Test extends net.rim.device.api.ui.uiapplication { public static void main(string[] args) { // resource allocation // logic // resource release } } end 25/29
MIDlet vs. Java ME application start start startapp() main() paused active running pauseapp() destroyapp() end destroyed 26/29
Java ME Architecture for BlackBerry Java Application BlackBerry API Java ME API (MIDP 2.0, CLDC 1.1) Java Virtual Machine HW Mixing Java ME GUI and BlackBerry GUI not possible javax.microedition.lcdui net.rim.device.api.ui 27/29
Java ME code performance use local variables faster access than to class members use threads for operation longer than 0.1 seconds filesystem, network, bluetooth, etc. access and declaration of data structures everything what can be private declare it as private use final declaration memory allocation do not relay on efficiency of garbage collection do not allocate to much memory at once -> reuse objects use scalar types (int) instead of objects (Integer) optimize algorithms do not use recursion if not necessary 28/29
Java ME application deployment JAR vs. JAD JAR: Manifest, Java classes, resource files JAD: description about Java application needed for downloading Java application via network On BlackBerry JAR -> COD On Android -> MicroEmulator http://microemu.blogspot.com/2009/08/converting-javame-applications-to.html 29/29
More Resources and inspiration http://pda.felk.cvut.cz Martin Rýzl - Úvod do Java Micro Edition http://www.avc-cvut.cz/avc.php?id=3849 30/29
Thank you for attention 31/29