+ All Categories
Home > Documents > 4. J2ME Overview

4. J2ME Overview

Date post: 04-Apr-2018
Category:
Upload: ewofkewofk
View: 222 times
Download: 0 times
Share this document with a friend
20
7/29/2019 4. J2ME Overview http://slidepdf.com/reader/full/4-j2me-overview 1/20 J2ME Overview
Transcript
Page 1: 4. J2ME Overview

7/29/2019 4. J2ME Overview

http://slidepdf.com/reader/full/4-j2me-overview 1/20

J2ME Overview

Page 2: 4. J2ME Overview

7/29/2019 4. J2ME Overview

http://slidepdf.com/reader/full/4-j2me-overview 2/20

What is JVM?

• A Java Virtual Machine (JVM) is a virtual machine that can

execute Java bytecode.

• Sun Microsystems stated that there are over 5.5 billion JVM

enabled devices in the world.

• Other Virtual Machines: CLR is the Virtual Machine of 

Microsoft’s .NET Framework.

Page 3: 4. J2ME Overview

7/29/2019 4. J2ME Overview

http://slidepdf.com/reader/full/4-j2me-overview 3/20

What is JRE?

• JVM is distributed along with Java application programminginterface (API).

• APIs bundled together with JVM form the Java Runtime

Environment (JRE).

• APIs are a set of standard class libraries.

• The Java Runtime Environment (JRE) contains a just-in-time

(JIT) compiler which converts intermediate bytecode intonative machine code on the fly.

Source Code Byte Code Native Machine Code

Page 5: 4. J2ME Overview

7/29/2019 4. J2ME Overview

http://slidepdf.com/reader/full/4-j2me-overview 5/20

J2ME•

J2ME can be divided into 3 parts:• Configuration

• Profile

• Optional Packages

• Configuration contains the JVM and some basic set of libraries.

• Profile is a subset of Configuration. It builds on top of these basic classlibraries by providing a useful set of APIs.

• Optional Packages are optional set of APIs that you may or may not usewhen creating apps.

• Configuration & Profiles are supplied by device manufacturers and theyare embedded in the devices while Optional Packages are not packaged bythe device manufacturers and you have to distribute them with yourapplication.

Page 6: 4. J2ME Overview

7/29/2019 4. J2ME Overview

http://slidepdf.com/reader/full/4-j2me-overview 6/20

The J2ME Stack 

Page 7: 4. J2ME Overview

7/29/2019 4. J2ME Overview

http://slidepdf.com/reader/full/4-j2me-overview 7/20

General APIs

The Core APIs defined by the CLDC system are:

•  javax.microedition.io

(For Input/Output operations)

•  javax.microedition.lcdui

(For GUI)

• Javax.microedition.rms

(For Record Management System; database for the mobile device)

• Javax.microedition.midlet(Contains base classes for Java ME apps, allows apps to be notified of changes to their

state)

Page 8: 4. J2ME Overview

7/29/2019 4. J2ME Overview

http://slidepdf.com/reader/full/4-j2me-overview 8/20

What is a MIDlet?

• J2ME applications are also known as MIDlets.

• A MIDlet is an application written using the MIDP.

• Typical applications include games running on mobile deviceswhich have small graphical displays, simple numeric keypad

interfaces and limited network access over HTTP.

Page 9: 4. J2ME Overview

7/29/2019 4. J2ME Overview

http://slidepdf.com/reader/full/4-j2me-overview 9/20

Coding a Midlet 

• Each MIDlet must extend the abstract MIDlet class found

in the javax.microedition.midlet package.

• At the minimum, your MIDlet must override three

methods of this abstract class:• startApp()

• pauseApp()

• destroyApp (boolean unconditional)

Page 10: 4. J2ME Overview

7/29/2019 4. J2ME Overview

http://slidepdf.com/reader/full/4-j2me-overview 10/20

 

Page 11: 4. J2ME Overview

7/29/2019 4. J2ME Overview

http://slidepdf.com/reader/full/4-j2me-overview 11/20

The MIDlet Lifecycle

• Mobile Devices interact with a MIDlet using their own

software called AMS (Application Management Software).

• AMS is responsible for initializing, starting, pausing, resuming

and destroying a MIDlet.

• MIDlet can be in one of three states:

• Active

• Paused

• Destroyed

Page 12: 4. J2ME Overview

7/29/2019 4. J2ME Overview

http://slidepdf.com/reader/full/4-j2me-overview 12/20

DateTimeApp.javaimport java.util.Date;

import javax.microedition.lcdui.Alert;

import javax.microedition.lcdui.Display;

import javax.microedition.midlet.MIDlet;

public class DateTimeApp extends MIDlet {

Alert timeAlert;

public DateTimeApp() {

timeAlert = new Alert("Alert!");

timeAlert.setString(new Date().toString());

}

public void startApp() {

Display.getDisplay(this).setCurrent(timeAlert);

}

public void pauseApp() {

}

public void destroyApp(boolean unconditional) {

}}

Page 13: 4. J2ME Overview

7/29/2019 4. J2ME Overview

http://slidepdf.com/reader/full/4-j2me-overview 13/20

How a MIDlet gets into a Paused

State?• A MIDlet can enter Paused State when the AMS calls

the pauseApp() method on an active MIDlet.

• It can also enter this state when the MIDlet pauses itself by

calling the notifyPaused() method.

• The pauseApp() method is called by the AMS, while the

notifyPaused() method is called by the MIDlet.

Page 14: 4. J2ME Overview

7/29/2019 4. J2ME Overview

http://slidepdf.com/reader/full/4-j2me-overview 14/20

What exactly is happening with the

MIDlet in the Paused State?• In a Paused State, the MIDlet is waiting for a chance to get into the

Active State.

• In Paused State, it should not be holding or using any of the device

resources and should be passive in nature.

• Entering the Paused State is necessary when the device requires app

to consume fewer resources, because these resources may be

required for handling other device functions, like an incoming call.

This is when the device invokes the pauseApp() method through the

AMS.

• If the MIDlet should inform the AMS that it has paused, it should

invoke the notifyPaused() method, which tells the AMS that the

MIDlet has indeed paused. 

Page 15: 4. J2ME Overview

7/29/2019 4. J2ME Overview

http://slidepdf.com/reader/full/4-j2me-overview 15/20

Active State

• The active state is where every MIDlet wants to be.

• This is when the MIDlet can do its functions, hold the deviceresources and generally do what it is supposed to do.

• A MIDlet is in an active state when the AMS callsthe startApp() method.

• A paused MIDlet can request to go into the active state by calling themethod resumeRequest(), which informs the AMS that the MIDlet

wishes to become active.

• The AMS may of course, choose to ignore this request or,alternatively, queue it if there are other MIDlets requesting thesame.

Page 16: 4. J2ME Overview

7/29/2019 4. J2ME Overview

http://slidepdf.com/reader/full/4-j2me-overview 16/20

Destroyed State

• The destroyed state is entered when a MIDlet'sdestroyApp(boolean unconditional) method is called either from anactive or paused state.

• This method is called by the AMS when it feels that there is no need

for the MIDlet to keep running and is the place the MIDlet mayperform cleanup and other last minute activities.

• The MIDlet can enter this state itself, by calling the notifyDestroyed()method, which informs the AMS that the MIDlet has cleaned up its

resources and is eligible for destruction.

• Of course, since in this case, thedestroyApp(boolean unconditional)method is not called by the AMS, any last-minute activities must bedone before this method is invoked.

Page 17: 4. J2ME Overview

7/29/2019 4. J2ME Overview

http://slidepdf.com/reader/full/4-j2me-overview 17/20

Destroyed State (boolean

unconditional)• What happens if the AMS calls the destroyApp(boolean unconditional)

method in the middle of an important step that the MIDlet may be doing.

• This is where the Boolean unconditional flag comes into the picture.

• If this flag is set to true, the MIDlet will be destroyed, irrespective of what

the MIDlet is doing.

• However, if this flag is false, effectively, the AMS is telling the MIDlet that

it wants the MIDlet to be destroyed, but if the MIDlet is doing somethingimportant, it can raise a MIDletStateChangeException, and the AMS will

not destroy it just yet.

Page 18: 4. J2ME Overview

7/29/2019 4. J2ME Overview

http://slidepdf.com/reader/full/4-j2me-overview 18/20

Destroyed State (contd.)

• Note that a destroyed state means that the MIDlet instance

has been destroyed, but not uninstalled from the device.

• The MIDlet remains installed in the device, and a new instance

of it may be created later.

Page 19: 4. J2ME Overview

7/29/2019 4. J2ME Overview

http://slidepdf.com/reader/full/4-j2me-overview 19/20

Sequence of Events

Page 20: 4. J2ME Overview

7/29/2019 4. J2ME Overview

http://slidepdf.com/reader/full/4-j2me-overview 20/20

destroyApp() VS

notifyDestroyed()• The MIDlet should never call its own destroyApp() method. It is the system's job to do

so when the MIDlet is stopped by the system.

• If the MIDlet wishes to terminate by its own will, it must call notifyDestroyed().

• Before calling notifyDestroyed() the same clean-up actions as done in destroyApp()

should be performed. The system will not call destroyApp() after notifyDestroyed().

cleanUpActions();

notifyDestroyed();

public void destroyApp(boolean b) {

cleanUpActions();}

Source: http://www.coderanch.com/t/229975/JME/Mobile/destroyApp-true-notifyDestroyed 


Recommended