Title: J2ME Introduction
1J2ME - Introduction
2What is J2ME?
- NEITHER a specific piece of software /
specification - A collection of Java classes, interfaces
dedicated to small, mobile devices
http//java.sun.com/j2me/docs/index.html
3Advantages of J2ME
- Easy to learn
- Learning J2ME is like learning Java programs
- Platform independent
- WAP applications are highly device dependent
(need a WAP-enabled phone including components
for supporting the WAE and communication
protocols) - The layering architecture of the J2ME programming
model allows MIDlets (applications for mobile
devices) to run on different mobile devices (Java
systems). Build on top of an operating system and
all lower levels components are hided by the OS - Integration with other Java components
- Can build complex mobile applications using with
least effort by integration with other Java
components - Good for security-oriented applications, which
use cryptographic classes - Can build wireless Internet applications
4J2ME System Model
- J2ME framework is divided into Configurations and
Profiles
http//java.sun.com/j2me/docs/index.html
5Scope of J2ME
- J2ME defines
- A series of Java virtual machines each for use on
different types of small devices - A group of libraries and APIs that can be run
under each of the virtual machines - Various tools for deployment and device
configuration - Configuration
- Mobile devices have different capabilities
(limitations). J2ME defines configurations for a
horizontal grouping of devices based on
availability of memory and processing power of
the devices - Profiles
- defines a set of APIs that reside on top of a
configuration that offers the program access to
device-specific capabilities
6Scope of J2ME
- MIDP (mobile information device profile) is
designed to be used with the configuration
(CLDC), and provides a set of APIs for use by
limited resources devices, i.e., mobile phones
7J2ME System Model Configurations
- Designed for a specific kind of device based on
memory constraints and processor power (i.e.
defines a minimum Java platform for a family of
devices) - Usually specifies a JVM that can be easily ported
to devices supporting the configuration (called
KVM) - Specifies the characteristics and features of
virtual machine present, minimum Java libraries
that are supported and minimum set of features
for a category of devices - Major Configurations in current specification
include - Connected Device Configuration (CDC)
- Connected, Limited Device Configuration (CLDC)
8Connected Device Configuration (CDC)
- Device requirements A connected device (CD) has
a minimum 512KB of ROM, 256KB of RAM, 32-bit
processors, and some network connection with
limited bandwidth - CDC is designed for "more powerful" wireless
devices like TV set-top boxes, car navigation
systems, and high-end PDAs. - CDC specifies that a full-featured Java Virtual
Machine (JVM) (defined in J2EE) is supported
9Connected, Limited Device Configuration (CLDC)
- Covers mobile devices like mobile phones, PDAs,
pagers, and other "tiny" wireless devices - For smaller devices than CDC, with limited
capacity and network connection (e.g., lt 9.6Kbps
for mobile phones) - For devices with 160KB to 512 KB of memory
available for Java platform - For devices with limited power supply
- Built on "scale-down" version of JVM called KVM
(Sun 'K Virtual Machine, with size in tens of
kilobytes, rather than JVM with tens of
megabytes)
10MIDP Requirements
- A Mobile Information Device (MID) has the
following characteristics - 128KB of non-volatile memory for MIDP
implementation - 32KB of volatile memory for runtime heap
- 8KB of non-volatile memory for persistent data
- A screen of a least 96 x 54 pixels
- Some capacity for input, either by keypad,
keyboard, or touch screen - Two-way network connection, possible
intermittent - Detail information about MIDP (Mobile Information
Device Profile) can be found in
http//java.sun.com/products/midp/
11MIDP Targets and MIDlets
- MIDP enables application development with mobile,
wireless-connected devices like cellular phones
and two-way pagers - Main features of the supported devices
- small displays
- limited input devices
- limited local storage
- limited battery life
- limited CPU power
- MIDlets
- Small applications that run under the MIDP are
called MIDlets - A MIDlet is a Java application that uses the MIDP
and the CLDC - In a mobile phone, application management
software (AMS) controls start, stop and execute
MIDlet (controls the entire lifecycle) - Device manufacturer provides the AMS Software
12MIDP Implementation Model
- The APIs available to MIDP application are
provided by the packages in CLDC and MIDP
13MIDP Implementation Model
- CLDC
- Defines the "core" of MIDP APIs (mainly came from
the J2SE world) - Includes fundamental language classes in
java.lang, stream classes from java.io, and
utility APIs from java.util - Specifies a generalized wireless network API in
javax.microedition.io
14MIDP Implementation Model
- MIDP
- javax.microedition.lcdui
- Provides a set of features for implementation of
user interfaces (UI) - The central abstraction of the MIDP's UI is that
of a screen - A screen is an object that encapsulates
device-specific graphics rendering user input.
The user can traverse through the items on that
screen - The screen takes care of all events that occur as
the user navigates in the screen, with only
higher-level events being passed on to the
application
15MIDP Implementation Model
- MIDP
- javax.microedition.midlet
- Defines MIDP applications, as well as the
interactions between the application and the
environment - Core API of MIDP
- An application of the Mobile Information Device
Profile is called a MIDlet - javax.microedition.rms
- Provides a mechanism for MIDlets to persistently
store data and later retrieve it - Modeled after a simple record oriented database
- Called the Record Management System
16MIDlet State Model
- MIDlets transition to different states during
their lifetime - The following diagram shows a state transition
diagram that represents these MIDlet states and
the events that cause transition from one state
to another
17(No Transcript)
18Installation Sequences
- Install J2SE SDK (version 1.4 - J2SE v
1.4.2_11 SDK) from - http//java.sun.com/j2se/1.4.2/download.html
- Install J2ME Wireless Toolkit (version 2.2 ) from
- http//java.sun.com/products/sjwtoolkit/download-
2_2.html - Install J2ME Patch (Patch 200511 ) from
- http//java.sun.com/products/sjwtoolkit/download-
2_2.html
19J2ME Default Directory
- C\WTK22
- All projects are stored at
- C\WTK22\apps\ltprjNamegt
- All programs within a project are stored at
- C\WTK22\apps\ltprjNamegt\src
- MIDlets document is stored at
- C\WTK22\docs\api\midp\index.html
20J2ME Interface
21J2ME Interface
package cs4289.j2me2_2 - first statement within
helloMidlet.java public class helloMidlet extends
MIDlet
Try demo01_howToCompile project
22MIDlet states
23MIDlet states
- Paused
- When MIDlet has just been started new
ltmidletObjgt() - As a result of pauseApp() and then notifyPaused()
- Active
- MIDlet is running
- As a result of startApp() and then
resumeRequest() - Destroyed
- MIDlet will terminate and release resources
- As a result of destroyApp(boolean unconditional)
and then notifyDestroyed()
true terminate immediately false can not
terminate (throw MIDletStateChangeException )
24MIDlet states
- notifyPaused(), resumeRequest(),
notifyDestroyed() - AMS (Application Management Software) / JAM (Java
Application Manager) download, execute and
remove MODlet suite - Request AMS to change state
- AMS may have chance to refuse these requests
Try demo02_showLifeCycle
Try demo03_JAMMIDletComm
25MIDlet states
- In Paused state, AMS is free to execute other
thread
Interface Runnable
- public void run()
- extends MIDlet implements Runnable
Try demo04_threadMIDlet
26How to get information from MIDlet suite
- javax.microedition.midlet.MIDlet
- String getAppProperty(String key)
Try demo06_midletResource
27MIDlet User Interface
28Display class
- public static Display getDisplay(MIDlet m)
- Gets the Display object that is unique to this
MIDlet - Display display_scr
- display_scr Display.getDisplay(this)
29Display class
- public void setCurrent(Displayable
nextDisplayable) - Requests that a different Displayable object be
made visible on the display - display_scr.setCurrent(xxx)
- xxx Displayable object
- Such as Screen, List, Alert, TextBox, Form
30Interface CommandListener
- Used by MIDlet to receive high-level events
- xxxx implements CommandListener
- void commandAction(Command c, Displayable d)
- Indicates that a command event has occurred on
Displayable d
31Command class
- Command(String label, int commandType, int
priority) - Creates a new command object with the given short
label, type, and priority. - The defined types are BACK, CANCEL, EXIT, HELP,
ITEM, OK, SCREEN, and STOP.
32Command class
- javax.microedition.lcdui.Displayable
- public void addCommand(Command cmd)
- tbl_msg.addCommand(cmd_exit)
33Displayable class
- public void setTicker(Ticker ticker)
- Sets a ticker for use with this Displayable
- public void setTitle(String s)
- Sets the title of the Displayable
- public void setCommandListener(CommandListener l)
- Sets a listener for Commands to this Displayable
Running Text
Title
Content
34Ticker class
- Ticker(String str)
- Constructs a new Ticker object, given its initial
contents string
35Form class
- Form(String title)
- Creates a new, empty Form
- public int append(Item item)
- Adds an Item into the Form. The newly added Item
becomes the last Item in the Form, and the size
of the Form grows by one