Search This Blog

Friday, January 15, 2010

J2ME Technical discussion part-2

J2ME Technical discussion part-2

As I have mention in my previous article (J2ME technical discussion part-1).

Here I am going to give presentation about the MIDP architecture and API.

Outline:

>> MIDP Introduction

- Hardware and Software Requirements

- MID Profile Architecture

- MIDlet Suite

>> Basics of MIDlet

- MIDlet

-MIDlet StateChangeException

-Display

-Displayable

H/W and S/W Requirement

>> H/W Requirement

-Screen size 96*54 pixels

-At least one type of user input(keyboard, touch screen)

-128 KB non-volatile memory for MID component.

-8KB non-volatile memory for storing persistence data.

-32 KB of volatile memory to running java.

-Wireless N/W connectivity

>> S/W Requirement (OS S/W)

- Minimal scheduling, Exception handling and processing of interrupts software.

- support for displaying bitmapped graphics

- Must accept I/P and pass to JVM

- Data Persistence S/W.

- Software must be capability to read and write to/from non volatile memory.

- There must be access to the networking on the device.

MID Profile Architecture



MID- To visually portrait the architecture of the application begin with the Hardware

Native OS – One step up running on the H/W is the Native OS.

Native apps - first reference to an application running on an MID.

- example are configuring application (i.e. Date,Time, Ring setting)

- Before J2ME only one type of apps will run in mobile that’s are native app.

CLDC installed on the native operating system and is the foundation for the for MIDP.

MIDP applications have access to both the libraries of CLDC and MIDP.

OEM-specific (original equipment manufacturer) classes are provided by the manufactory of the company

MIDlet Suite

MIDlet is a java application designed to be run on a mobile device.

It has as its core java classes the CLDC and MIDP.

MIDlet suite consists of one or more MIDlet packaged together usings a JAR file.

>> Runtime environment and application manager

-- Application manager is the software on a mobile device that is responsible for installing, running and removing MIDlet suite.

-- Application manager is a device – dependent software(ie., designed and implemented by Manufacture of device).

When application manager start the MIDlet , It will make all the following available to the application:

-- Access to the CLDC and JVM

-- Access to the MIDP-define classes : user interfaces , persistence storage ,networking support using HTTP,timer and managing user interaction with the device.

-- Access to JAR file

-- Access to JAD (Java Application Descriptor) file

>>Java Archive File (JAR)

-- Bundle all the information(Class file , images and application information) related to project into single entity known as a JAR file.

-- In addition to classes and resource file , a JAR contains a file known as a manifest.

-- manifest describe the content of the JAR file.

-- manifest file has the name manifest.mf and is stored as the part of JAR file itself.

>> JAR Manifest Attributes

--Manifest has totally nine attribute , no need to define all attribute.

--If the following six attribute are inside the manifest , the application manager will refuse to load the JAR:

      1. MIDlet-Name
      2. MIDlet-Version
      3. MIDlet-Vendor
      4. MIDlet-(one entry for each MIDlet in the JAR file)
      5. MicroEdition-Profile
      6. MicroEdition-Configuration

>> JAR –MIDlet Attribute




>> Sample manifest entry

MIDlet-Name: Todo List

MIDlet-Version: 1.0

MIDlet-Vendor: Core J2ME

MIDlet-1: TodoList, /images/Todo.png, Todo.TodoMIDlet

MicroEdition-Profile: MIDP-1.0

MicroEdition-Configuration: CLDC-1.0

>>> JAD(Java Application Descriptor)

>> JAD file may be available as part of the MIDlet suite to provide information about the MIDlet(s) within the JAR.

>> The rational behind including a JAD file is as follow.

1. To provide information to the application manager about the contents of a JAR. With this information, decisions can be made as to whether or not a MIDlet(s) is suitable for running on the device.

2. Provide a means for parameters to be passed to a MIDlets(s) without having to make changes to the JAR file.

>> JAD Attribute

-- JAD have set pre-define attribute

-- You can also define your own attributes as you see necessary for your application.

-- Simply create names that do not start with "MIDlet-" and you are good to go

-- As with the manifest file, there is a required set of attributes that must be defined in the JAD file:

    1. MIDlet-Name
    2. MIDlet-Version
    3. MIDlet-Vendor
    4. MIDlet- for each MIDlet
    5. MIDlet-Jar-URL





MIDlet

MIDlet is the application that is build-upon the MIDlet Class.

The application manager communicates with a MIDlet through methods in this class.

This communication is a two-way street.

As an example, just as the application manager can pause a MIDlet (e.g., to allow a user to answer an incoming phone call), a MIDlet can make a request to be paused (and later restarted).

MIDlet API






MIDlet StateChangeException

During the course of a MIDlet's lifecycle, if an error occurs when changing states, this exception is thrown.

Two methods(startApp(), destoryApp()) in MIDlet class are throw this Exception

Constructer

Description

MIDletStateChangeException()

Create exception object with no text

MIDletStateChangeException(String s)

Create exception object with text

There are two constructors for creating this exception, one with and without a text message.

Eg. TestException

Display

Each MIDlet has a reference to one Display object

Retrieve information about the current display (e.g., the range of colors supported) and includes methods for requesting that objects (Forms, TextBoxes, etc.) be displayed.

display controlling what is shown on the device and when

Note

- only one display object per MIDlet

Creating a Display object

A Display object is made available to a MIDlet through a call to a static method declared inside the Display class.

Structure

public class DisplayStats extends MIDlet

{

private Display display; // Reference to Display object

// MIDlet constructor

public DisplayStats()

{

display = Display.getDisplay(this);

...

}

...

}

Display API

Display Class: javax.microedition.lcdui.Display

Method

Description

static Display getDisplay(MIDlet m)

Get Display object for this MIDlet

Displayable getCurrent()

Displayable getCurrent() Get current Displayable object

void setCurrent(Alert alert, Displayable

nextDisplayable)

Show an Alert followed by the specified

Displayable object

void setCurrent(Displayable nextDisplayable)

Show a new Displayable object

boolean isColor()

Does the device support color?

int numColors()

How many colors (or shades of gray) are available?

void callSerially(Runnable r)

Request a runnable object be called after repainting

Displayable

Display can show any number of Displayable objects.

a Displayable object can be viewed on a device

The MIDP includes two subclasses of Displayable: Screen and Canvas.

Screen object(Textbox, List, Form and Alert) are all high-level user interface components, as their implementation and presentation on the device are handled for you.

The Canvas object is used for custom graphics and low-level event handling, such as when writing games, and requires a little more finesse on your part to update the display.

Creating Displayable Object

We don't create Displayable objects directly; instead, we reference subclasses of Displayable

Screen and Canvas extend the Displayable class

Using API

Method

Description

void addCommand(Command cmd)

Add Command to Displayable object

void removeCommand(Command cmd)

Remove Command from Displayable object

void setCommandListener(CommandListener l)

Add CommandListener to Displayable object

boolean isShown()

Is the Displayable object visible on the screen?

Event Handling

Event Handling in Mobile device

Command Object

Item Object

Command and Command Listener

Item and Item Listener

Event Handling in Mobile Device

event handling is nothing more than recognizing when an event occurs and taking an action based on that event.

there are three key steps to successfully managing an event.

- The hardware (the physical device itself) must recognize that something has occurred.

- The software on the device (the application manager) needs to be notified of the event

- A message from theapplication manager will be sent to the MIDlet. This message will contain information about the event so we can make decisions as to how to proceed

Command Object

A Command is an object that holds information about an event.

The simplest way to think of a Command is as a "button," something that you press or select

Processing events requires a little legwork up front. Here are the steps:

1. Create a Command object to hold information about an event.

2. Add the Command to a Form, Textbox, List or Canvas.

3. Add a "listener" to the above Form, Textbox, and so forth.

Command Object Creation

private Form fmMain; // A Form

private Command cmExit; // A Command to exit the MIDlet

...

fmMain = new Form("Core J2ME"); // Form object

cmExit = new Command("Exit", Command.EXIT, 1); // Command object

...

fmMain.addCommand(cmExit); // Add Command to Form

fmMain.setCommandListener(this); // Listen for Form events

...

public void commandAction(Command c, Displayable s)

{

if (c == cmExit)

{

destroyApp(true);

notifyDestroyed();

}

}

Item Object

An Item is any component that can be added to a Form. ChoiceGroup, DateField, Gauge and TextField are all subclasses of Item and each can process events.

Items are accessible only as part of a Form, whereas Commands areavailable on Forms, as well as a Textbox, List, or Canvas.

Once you add an Item to a Form, as with Commands, you must add a listener

Once there is a change to an Item (e.g., a Gauge has been incremented or a DateField has been changed), the listener object will be notified (sent a message).

Thursday, January 14, 2010

J2ME Technical discussion part-1

J2ME Technical discussion part-1

When I was involved in development of small ERP package for our client, we got the requirement to send their critical / decision making information to their MD mobile phone from web application.

So I have started exploring about the J2ME technology. For that project I am the technical co-coordinator, I have to teach my entire colleague about the J2ME and I have to complete the same as soon as possible.

Even I have taken some class about J2ME in different coaching center as guest lecture.

For that I have prepared some presentation and slide.

I want to share to all who are looking to start learning about J2ME.

So I have given name as technical discussion part-1. Soon you can expert part 2., 3,4…

Let’s enjoy….

For presentation I have referred the following book:

1. Core J2ME Technology & MIDP - John W. Muchow

Part-1 we are going to look the following topics:

>>Introduction of mobile Technology

>>Software Technology for Mobile device

>> Java 2 Platforms

>>J2ME Introduction

-- Architecture

-- Configuration (CLDC, CDC)

-- Profile (MIDP, PDAP –CLDC & FP, PBP, PP-CDC)

-- Optional Packages (RMI-FP, Bluetooth-CLDC, JDBC- FP)

>> Setting up J2ME Development Environment

Introduction of mobile Technology

>> The goals of mobile Technology

-- Connecting people

-- Information sharing

-- Internet access and

-- Entertainment

>> Includes

-- Mobile phone, PDAs, Note book, Set top box

With the most important words “at any time any where

>> The internet scenario of retrieving information in a wireless network




>> Mobile Networking

-- GSM,GPRS,EDGE

>> Generation

-- 1G,2G,2.5G,2.75G,3G and 4G.

-- IEEE802.11

-- Infrared and Bluetooth

Mobile networking

Short Form

Cellular Type

Data Transfer speed

GSM

Global system for mobile communication

Digital cellular system

9.6 kbps

EDGE

Enhanced Data GSM Environment

Faster version of GSM wireless service

384 kbps

GPRS

General Packet Radio Service

Its an standard for wireless communication

115 kbps

Generation

Technology

Description

First generation(1G)

Analog system designed for only voice communication.

-

Second Generation(2G)

Use GSM network for voice communication

-

2.5G and 2.75 G

GPRS-2.5G

EDGE-2.75G

It allows higher rate of data transmission

Third Generation(3G)

UMTS- Europe

CDMA2000- North America and Part of Asia

Higher data transmission (2Mbps).allow video conference

Fourth Generation(4G)

Combined the wireless local area network and 3G

-

Software technology for mobile device

>> Mobile application development software package

-- Windows mobile

-- Symbian

-- Embedded visual C++ and .Net

-- J2ME

>> Windows Mobile

-- Windows Mobile is Microsoft's software platform for Pocket PCs and Smart phones. Windows Mobile extends the familiarity of the Windows desktop to personal devices.

-- Windows Powered mobile devices include Pocket PC, Pocket PC Phone Edition, Smart phone, and Handheld PC

>> Symbian

-- OS for mobile device

-- It provide low level function for application development.

>> Embedded Visual C++ and .net

-- It is a programming language

-- Allow programmer to develop application on windows mobile platform

Java 2 Platform

>> Java 2 platform includes three edition of java

-- Java 2 Standard Edition (J2SE)

-- Java 2 Enterprise Edition (J2EE)

-- Java 2 Micro Edition (J2ME)



>>J2SE

-- Provide a complete environment for application development on desktop and server.

-- Its foundation of J2EE.

>>J2EE

-- Targeted for business use

-- Large scale of the system which may contain tens of servers millions of users

-- Web bases services

-- Machines are high performance

>> J2ME

-- used for less memory and low processing power device .

-- Java platform for small devices.

-- For programming the mobile devices.

-- Using J2ME we can develop the application for small devices ie., Extremely limited memory , small screen size , alternative input method, and slow process.

J2ME introduction

Java platform for small devices

A subset of Java 2 Standard Edition

For programming the palm

For programming the mobile device (e.g mobile phones or WinCE…)





















CDC (Connected Device Configuration)

CLDC (Connected Limited Device Configuration)

>> Different Layers of J2ME


J2ME Architecture

>> To increase the flexibility design, J2ME consists of four distinct layers

-- Kilo byte virtual machine

-- Configurations

-- Profiles

-- Optional packages

Kilo Byte Virtual Machine(KVM Archi.,)

>> Its used for small program

>> Its sub set of JVM

>> A pool for running java code o the device

>> 40-80 kilo byte in size

>>For devices with 160 KB of memory and 16 or 32-bit RISC/CISC microprocessors


Configurations (KVM Archi.,)

>> Definition

Defines the minimum Java technology for a broad range of devices with similar capabilities

>>A configuration defines the minimum set of libraries and VM capabilities

>>Devices have similar processing and power and memory constraints

>> There are two type of configuration

-- CLDC -Connected limited device configuration

-- CDC – Connected device configuration

CLDC (Connected Limited Device Configuration)

>> Targeted at devices with:

160KB to 512KB total memory available for Java technology

Limited power (battery), connectivity (often intermittent), UI (small screen)

>>Addresses

Java language and virtual machine features

Core Java Libraries

Input/Output

Networking

Security

>> Targeted at devices with:

160KB to 512KB total memory available for Java technology

Limited power (battery), connectivity (often intermittent), UI (small screen)

>>Addresses

Java language and virtual machine features

Core Java Libraries

Input/Output

Networking

Security

>>Not Addresses (but in MIDP)

User Interface functionality

Event handling

High-Level application model

Application life-cycle management

>>CLDC API

--io

Input Stream, OutputStream, Reader, Writer

lang - No floating point support

util

Calendar, Date, Hashtable, Random, Stack, TimeZone, Vector, Enumeration

javax.microedition.io

Connection, Datagram, InputConnection, OutputConnection, Connector

>>Only CLDC is not enough for building applications

>>CLDC is the base for building the above profiles

>>It separates the machine dependent issues from the applications

>>There are two version of CLDC

CLDC 1.0

CLDC 1.1

>> Main differences between 1.0 and 1.1 are

Floating point is added in 1.1

More Date related classes is added in 1.1

The minimum memory budget has been raised from 160 to 192 kilobytes

>>Today, most mobile phones only support 1.0 version

Connected Device Configuration

>> Targeted for devices that have

2 MB or more total available memory

Memory dedicated to J2ME environment

More than 2MB ROM/Flash

More than 512 KB RAM

Network connectivity

>> Full Java 2 Virtual Machine specification

J2ME Arch., Profile

>> A profiles layer is a set of Java Based API that extend the J2ME definition

>> UI and presentation capabilities are generally defined at this layer

>> EX: CLDC => MIDP (Mobile Information Device Profile)

CDC => Personal Profile

CDC => Foundation Profile

J2ME Arch., Mobile Information Device Profile

>> Is a set of APIs that allow developers to control mobile device-specific problems

i.e. user interfaces, local storage and client application lifecycles etc.

>> MIDlets minimum requirements

96 x 54 pixels mono screen

two-way wireless network

input device (i.e. keypad)

128 KB ROM for CLDC/MIDP class and another 32 KB RAM for the KVM

>> Midlets are the most important and popular applications in the J2ME family.



MIDlet Programming

Any MIDP application must extends MIDlet

This is the MIDP equivalent of an applet, where starting/stopping is under the control of the environment

Like Java applets, MIDlets have an application life cycle while running on a mobile device.

MIDlet Transition States

Specifically, a MIDlet can be in one of three states as shown:


MIDP - API

javax.microedition.midlet

(application management)

javax.microedition.lcdui

High-level development

Form, TextBox, List, Alert

Low-level development

Canvas: Game applications will likely make heavy use of the

javax.microedition.rms

RecordStore

A record store consists of a collection of records which will remain persistent across multiple invocations of the MIDlet

MIDP API Tree