Y3
Y3
9
9
PDA
PDA
D
D
evelopment of Java ME
evelopment of Java ME
application
application
Jan
Jan VystrVystrččilil
České vysoké učení technické v Praze
Content
Content
What is Java ME
Low Level a High Level API
What is JSR
LBS
Jan Vystrčil
Development of Java ME application
3/29
Is Java ME still important?
What is Java ME?
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
Jan Vystrčil
Development of Java ME application
What is KVM?
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
Jan Vystrčil
Development of Java ME application
7/29
Configurations CDC and CLDC
Configurations CDC and CLDC
CDC - Connected Device Configuration
CLDC - Connected, Limited Device
Configuration CDC
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.
Jan Vystrčil
Development of Java ME application
9/29
Configuration CLDC
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
Profile MIDP
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
Jan Vystrčil
Development of Java ME application
11/29
Low Level and High Level API
Low Level and High Level API
Java ME supports two approaches of GUI
development
– Low Level API
•javax.microedition.lcdui.Canvas
– High Level API
Difference between Low Level and High Level API (1)
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)
Jan Vystrčil
Development of Java ME application
13/29
Difference between Low Level and High Level API
Difference between Low Level and High Level API (2)(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)
Difference between Low Level and High Level API
Jan Vystrčil
Development of Java ME application
15/29
Other
Other
UI
UI
toolkits
toolkits
Based on Low Level API
(javax.microedition.lcdui.Canvas)
LWUIT
(Lightweight User Interface Toolkit) J2ME Polish
LWUIT
LWUIT
Inspired by the architecture of Java Swing MVC Features
– Basic set of components – Flexible layouts – Style – Theming Runs on – JavaME – Android – BlackBerry
Jan Vystrčil
Development of Java ME application
17/29
What is JSR?
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
Jan Vystrčil
Development of Java ME application
19/29
Useful
Useful
JSR
JSR
’
’
s
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
LBS
LBS
–
–
Location Based Services
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
Jan Vystrčil
Development of Java ME application
21/29 NMEA
NMEA -- National Marine Electronics AssociationNational 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
NMEA
NMEA -- National Marine Electronics AssociationNational 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)
Jan Vystrčil
Development of Java ME application
23/29
LBS
LBS
–
–
using of Location API
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(); }
MIDlet
MIDlet
vs. Java ME application
vs. Java ME application
start paused active destroyed startApp() pauseApp() destroyApp() not supported by S40, S60
public class Test extends MIDlet{ private boolean once = false; Pokus() { }
public void startApp() { if ( once == false ) {
once = true;
// resource allocation }
// other resource allocation // logic
}
public void pauseApp() { // resource release }
public void destroyApp() { // all resource release }
Jan Vystrčil
Development of Java ME application
25/29
MIDlet
MIDlet
vs. Java ME application
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
MIDlet
MIDlet
vs. Java ME application
vs. Java ME application
start paused active destroyed startApp() pauseApp() destroyApp() start running main() end
Jan Vystrčil
Development of Java ME application
27/29
Java ME
Java ME
Architecture
Architecture
for
for
BlackBerry
BlackBerry
HW
Java Virtual Machine
BlackBerry API Java ME API
(MIDP 2.0, CLDC 1.1)
Java Application
Mixing Java ME GUI and BlackBerry GUI not possible • javax.microedition.lcdui
Java ME code performance
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
Jan Vystrčil
Development of Java ME application
29/29
Java ME application deployment
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
More
More
Resources
Resources
and
and
inspiration
inspiration
http://pda.felk.cvut.cz
Martin Rýzl - Úvod do Java Micro Edition
Jan Vystrčil
Development of Java ME application
31/29