You are on page 1of 26

Learn how to develop applications for the next generation of wireless devices using the Mobile Information Device

Profile ( MIDP ). The Big Picture Java 2 Enterprise Edition (J2EE): Designed for heavy weight and scalable business server application. Java 2 Standard Edition (J2SE): Designed for a tradition and well-established desktop application. Java 2 Micro Edition (J2ME): Designed for the new generation of applications that target consumer electronics and embedded devices.

Profile J2EE

Profile J2SE

Foundation Profile

Personal Profile CDC

RMI Profile

PDA Profile

MID Profile

Profile Configur ation Edition Virtual Machine

CLDC J2ME

HotSpot VM

JVM

CVM 1MB

KVM 512KB to

Memory: 10MB

32KB

J2ME is a lean Java platform targeted specifically at applications running on small device such as mobile phones, PDAs, Internet Screenphones, digital television set-top boxes, automotive entertainment and navigation systems, Network switches, home automation components and so on.

Java Virtual Machine Layer : This layer is an implementation of a Java machine that is customized for a particular devices host operation system and supports a particular J2ME configuration are CodeWarrior Virtual Machine (CVM), Kilo (bytes) Virtual Machine (KVM). Configuration Layer: A J2ME configuration define class libraries for a Horizontal category or grouping of devices based on similar requirements for a total memory budget and processing power are Connected Device Configuration (CDC), Connected Limited Device Configuration (CLDC).

Profile Layer: Built on top of a specific configuration, a J2ME profile defines class libraries to address the specific demands of a certain vertical market segment are Personal Digital Assistant Profile (PDAP), Mobile Information Device Profile (MIDP), Foundation Profile (FP), Personal Profile (PP), RMI (Remote Method Invocation) profile.

Configurations and profiles are the two main building blocks in J2ME. The overall purpose of configurations and profiles is to have virtual machines and class libraries optimized for each group of target devices. The configuration define the minimum set of Java virtual machine features and Java class libraries available on a particular category of devices representing a particular horizontal market.

There are two: Connected Devices Configuration (CDC) and the Connected Limited Device Configuration (CLDC). These two configurations target two categories of devices with similar total memory budgets and processing power.
CDC devices can be described as shared, fixed, connected information devices and have large range of user interface capabilities, memory budgets in the range of 2 to 16 megabytes, a 32-bit or better CPU and persistent, high-bandwidth network connection most often using TCP/IP. Example of CDC devices include TV set-top boxes, Internet TVs, Internet-enabled screenphones, highend communicator and automobile entertainment/ navigation system.

CLDC devices can be described as personal, mobile, connected information devices which memory budgets in the range of 128 Kilobytes to 1 megabyte, a 16-bit or 32-bit CPU, and lowbandwidth, intermittent networks which generally dont use TCP/IP. Typically examples of CLDC devices include lowend cell phones, two-way pagers, and Palm OS handheld.

The class libraries in a profile allow developer to access device-specific functionality such as the graphical user interface, network communications, persistent storage, and so on.
Foundation profile in CDC is intended to be used by devices requiring a complete implementation of the Java virtual machine up to and including the entire Java 2 Platform, standard Edition API. RMI (Remote Message Interface) profile is a CDC profile that define the minimal subset of the J2SE 1.3 RMI API. Personal Profile is a CDC profile that is extended from Suns PersonalJava environment.

PDAP (Personal Digital Assistant Profile) is a CLDC profile that provides user interface and data storage APIs for small, resource-limited handheld devices powered by The Palm OS. MIDP (Mobile Information Device Profile) is a CLDC profile that provide the user interface, persistence storage, networking, and application Model APIs for wireless devices such as low-end cell phones and two-way pager.

MID hardware layer Refers to cell phones or two-way pager (Blackberry 950). Native System Software Layer Contains the native operating System and System Libraries provided by the device manufacturer. KVM Layer Provides the runtime environments for Java applications. CLDC Layer Provides core Java () APIs for wireless application. MIDP Layer Provides the GUI libraries, persistent storage libraries, networking libraries and timer classes.

MIDP Application

Devices-Specific Application MIDP Class CLDC Classes KVM Native System Software MID Hardware Device-Specific Class

Native Applicat ions

FILE MENU NEW PROJECT JAVA ME MOBILE APPLICATION

import javax.microedition.midlet.MIDlet; import javax.microedition.lcdui.*; public class LifeCycle extends MIDlet{ public LifeCycle(){// Constructor } public void pauseApp(){} public void startApp(){} public void destroyApp(boolean unconditional){} }

public class ChEx1 extends MIDlet { private Display dis; private TextBox MainScreen=null; public void ChEx1(){ dis= Display.getDisplay(this); MainScreen=new TextBox("First Test","HELLO CABMODIA!",512,0); } public void startApp() { dis.setCurrent(MainScreen); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } }

import javax.microedition.midlet.MIDlet; import javax.microedition.lcdui.*; public class ChEx1 extends MIDlet implements CommandListener { private Display dis; private TextBox MainScreen=null; private Command exit; public void ChEx1(){ dis= Display.getDisplay(this); MainScreen=new TextBox("First Test","HELLO CABMODIA!",512,0); exit = new Command("Exit", Command.EXIT, 0); MainScreen.addCommand(exit); MainScreen.setCommandListener(this); }

public void commandAction(Command c, Displayable s){ if (c==exit) { destroyApp(false); notifyDestroyed(); } } public void startApp() { dis.setCurrent(MainScreen); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } }

Displayable is an object that encapsulates device-specific graphics rendering and can be placed on the display. There are three categories of displays:
Structured-predefined Screen (Alert, List, TextBox): these screens usually encapsulate complex interface component. Applications cant add other components to these screens. Generic Screen (Form): Applications can populate these screens with text, images, and simple sets of related UI components. Canvas: Applications have full control of the appearance of components and can directly access low-level events.

Displayable

Screen

Canvas

Structure-Defined Screen

Form

List

TextBox

Alert

Here are the method defined in a Displayable class: Void addCommand (Command cmd) Boolean isShown () Void removeCommand (Command cmd) Void setCommandListener (CommandListener l)

The Screen is a subclass of Displayable that implements the high-level API. It is the super class of Alert, Form, List, and TextBox. A screen can contain an optional title and ticker-tape. The following methods are provided for a Screen class:
Ticker getTicker () String getTitle () Void setTicker (Ticker ticker) Void setTitle (String s) Ticker.setString(String str) or Ticker.getString()

The canvas class is a subclass of Displayable that implements the low-level API. Using class, applications have full control over what to display and how to display it. Application can also directly access low-level events, such as key events. Canvas is an abstract class. Application have to subclass the canvas class in order to use it.

The Display class represents the display manager. It provides the following method for retrieving properties of the device and for requesting objects to be displayed on the device:
Void callSerially (Runnable r) Displayable getCurrent() Static Display getDisplay(MIDlet m) Boolean isColor() Int numColors() Void setCurrent(Alert alert, Displayable nextDisplayable) Void setCurrent(Displayable nextDisplayable) Display.setCurrent() or Display.getCurrent()

class ScreenTestRun implements Runnable{ import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class Midlet extends MIDlet { private Display display; private Form s1,s2; public Midlet(){ s1 = new Form("Screen 1"); s2 = new Form("Screen 2"); Ticker t=new Ticker("This is a test for switch screen." + "Screen 1 and 2 are switched every 5 seconds."); s1.setTicker(t); s2.setTicker(t); } public void startApp() throws MIDletStateChangeException{ display = Display.getDisplay(this); display.setCurrent(s1); new Thread(new ScreenTestRun()).start(); } public void run(){ while(true){ try{ Thread.sleep(5000); display.setCurrent(s2); } else{ display.setCurrent(s1); } }catch(Exception e){} } } } public void destroyApp(boolean unconditional) { display =null; s1 =null; s2 =null; } } if (display.getCurrent()==s1){

public void pauseApp() { }

You might also like