Device programming with MIDP, Part
1 - JavaWorld
January
2001
Tutorial Details:
Device programming with MIDP, Part 1
Device programming with MIDP, Part 1
By: By Michael Cymerman
The concepts behind MIDP APIs and J2ME to build cross- wireless -platform apps
f you've been following the wireless industry, you've noticed the speed at which a technology runs through its life cycle. A brand new product can become obsolete within months due to an improved technology or platform. The result of that rapid change has been the lack of standardization between the deployment platforms in the wireless world. A development team currently needs its staff to understand numerous markup languages and processes in order to deploy a product onto multiple devices. A marketing department continually needs to modify product direction based on the changing marketplace.
Device programming with MIDP: Read the whole series!
Part 1. Build devices with MIDP APIs and J2ME across multiple wireless platforms.
Part 2. Use these user-interface and data-store components to create MIDP-based applications.
Part 3. Use MIDP's communication APIs to interact with external systems.
Devices that are compliant with Mobile Information Device Profile (MIDP) will enable vendors to develop applications that can run on multiple wireless platforms without spending intensive amounts of energy customizing or reworking each platform. That would, in turn, let developers focus their energies on the system's functionality.
This article is the first in a three-part series designed to introduce you to the concept of MIDP APIs and the Java 2 Micro Edition (J2ME) platform. I will expose you to the APIs used to generate graphical, form-based, storage-driven code that can connect with external resources.
Introduction to J2ME
The J2ME is Sun Microsystems's attempt to port the Java programming language to devices with resource limitations. A mobile phone, which lacks the computational power, memory, and workstation power, cannot perform the same functionality as high-end servers or client workstations.
The J2ME platform is built upon the Java programming language to provide the maximum functionality available on the resource-limited device. A subset of the base functionality is provided along with some specialized classes.
In this article, I will focus on the CLDC (Connected Limited Device Configuration) and MIDP classes. Those sets of classes make up a profile in the J2ME terminology. That profile is based on the extremely limited device memory, processor speed, battery, and network connectivity bandwidth.
Introduction to CLDC APIs
The CLDC is the base platform on which the MIDP APIs are stacked. The CLDC classes consist of a standardized set of functionality that all vendors who offer J2ME-certified phones will support. Generally, you won't have to interact directly with those classes, but certain devices require that you access those lower-level classes to perform certain functionality. Those low-level accesses will likely be deprecated as the devices and platform develop.
Introduction to the MIDP profile
The MIDP profile has been developed to support the vertical niche of cell phones or similar devices constrained by screen and keypad limitations, in addition to the obvious battery, processor, and bandwidth constraints.
That profile contains a series of APIs that let you create anything from video games using customized graphics to full-scale business applications using external and internal data sources.
Several device manufacturers have already announced that they will support the MIDP platform on their devices. At the time of this writing, Nextel has announced that its phones will support MIDP in the first quarter of 2001.
Quick example
Below is a simple HelloWorld type example that offers a quick overview of a midlet's life cycle. A midlet is the name given for the code that executes on your mobile device. It is similar to an applet in that it contains user interface, data, and control capabilities.
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HelloMidlet extends MIDlet implements CommandListener
{
// Initialize the Midlet Display variable
private Display midletDisplay;
// Initialize a variable for the doneCommand
private Command doneCommand;
public HelloMidlet()
{
// Retrieve the display from the static display object
midletDisplay = Display.getDisplay(this);
// Initialize the doneCommand
doneCommand = new Command("DONE", Command.SCREEN, 1);
}
/**
* Create the Hello Midlet World TextBox and associate
* the exit command and listener.
*/
public void startApp()
{
// Create the TextBox containing the "Hello Midlet World!!" message
TextBox textBox = new TextBox("Hello Midlet", "Hello Midlet World!!", 256, 0);
// Add the done Command to the TextBox
textBox.addCommand(doneCommand);
// Set the command listener for the textbox to the current midlet
textBox.setCommandListener( (CommandListener) this);
// Set the current display of the midlet to the textBox screen
midletDisplay.setCurrent(textBox);
}
/**
* PauseApp is used to suspend background activities and release
* resources on the device when the midlet is not active.
*/
public void pauseApp()
{
}
/**
* DestroyApp is used to stop background activities and release
* resources on the device when the midlet is at the end of its
* life cycle.
*/
public void destroyApp(boolean unconditional)
{
}
/*
* The commandAction method is implemented by this midlet to
* satisfy the CommandListener interface and handle the done action.
*/
public void commandAction(Command command, Displayable screen)
{
// If the command is the doneCommand
if (command == doneCommand)
{
// Call the destroyApp method
destroyApp(false);
// Notify the midlet platform that the midlet has completed
notifyDestroyed();
}
}
}
This midlet's output is shown in Figure 1, which is a screen capture of the J2ME Windows Toolkit DefaultGrayPhone emulator.
Figure 1. HelloMidlet output
The first two lines import midlet-specific classes to support the MIDlet class, the CommandAction interface, and the user interface (UI) classes. Those classes are present in the MIDP APIs along with a modified subset of the Java programming language. The classes included in the MIDP API will be discussed in more detail later in this article.
public class HelloMidlet extends MIDlet implements CommandListener
This line declares the HelloMidlet class to extend the MIDlet class and implement the CommandListener interface. Each midlet must extend the abstract MIDlet class, which contains three methods, described below, that each midlet must override to complete its life cycle.
Method Name
Method Purpose
startApp
To allocate desired system resources and initialize the application.
pauseApp
To temporarily suspend resource-intensive processes.
destroyApp
To release resources used by the midlet and dispose of the midlet.
In the previous example, the startApp contains the bulk of the functionality because the HelloMidlet does not use other system resources such as network connections or datastores. When the HelloMidlet is executed, the startApp will be called.
As you would expect, the constructor is executed prior to the startApp method. In this example, the constructor retrieves the display from the global Display object. In addition, the constructor initializes the doneCommand .
The startApp method above is used to create the screen to be displayed on the midlet. The following line shows the initialization of the TextBox screen.
TextBox textBox = new TextBox("Hello Midlet", "Hello Midlet World!!", 256, 0);
A midlet Screen may also contain Commands . A command is the mechanism the midlet uses to create menus as shown in the picture above with the "Done" button. Here's the code used to add the "Done" button to the TextBox screen:
// Add the done Command to the TextBox
textBox.addCommand(doneCommand);
The Command source will generate CommandActions when it is clicked. In this simple example, the HelloMidlet will implement the CommandListener interface and thereby handle all events itself. As the developed system becomes more complex, handling events in a more expanded manner may be beneficial.
// Set the command listener for the textbox to the current midlet
textBox.setCommandListener( (CommandListener) this);
Now that the TextBox has been created, it is ready to be displayed on the device screen. In the following line, I am setting the current display to the newly created TextBox :
// Set the current display of the midlet to the textBox screen
midletDisplay.setCurrent(textBox);
The HelloWorld midlet is a simple example that uses only a few of the classes contained in the MIDP platform. In the following section, I will explore a subset of the MIDP API.
Overview of the MIDP/CLDC APIs
Due to the limited nature of the devices upon which the MIDP/CLDC APIs will run, some Java functionality has been removed or modified from the specification. The MIDP/CLDC APIs include the following class libraries:
java.lang.*
java.io.*
java.util.*
javax.microedition.io.*
javax.microedition.ui.*
javax.microedition.rms.*
javax.microedition.midlet.*
The java.lang package
Included in the above library is a subset of the standard classes contained in the J2SE java.lang package. One notable exception is the Float class. The MIDP does not support floating-point calculations. Here are the included classes:
Object
Class
Runtime
System
Thread
Runnable
Throwable
Math
String
Boolean
Short
Long
Byte
Character
Integer
StringBuffer
The java.io package
The java.io package contains methods needed to retrieve information from remote systems. The following classes are included in the CLDC API:
InputStream
OutputStream
Reader
Writer
DataInput
DataOutput
DataInputStream
DataOutputStream
ByteArrayInputStream
ByteArrayOutputStream
InputStreamReader
OutputStreamReader
PrintStream
The java.util package
The java.util package contains
Read
Tutorial at: Click here to view the tutorial
Rate Tutorial: Device programming with MIDP, Part
1 - JavaWorld
January
2001
View Tutorial: Device programming with MIDP, Part
1 - JavaWorld
January
2001
Related
Tutorials:
|
Displaying 1 - 50 of about 2825 Related Tutorials.
|
J2ME Books
with the Mobile Information Device Profile (MIDP). With labs.
Published... Information Device Profile (MIDP), which this text centers on, plus the Connected... and about. The best part about J2ME is that programming a killer application |
JDO UNPLUGGED - PART 1
UNPLUGGED - PART I
JDO UNPLUGGED - PART I... , in the next
part of this tutorial.
==============================================================================
BOOKS FOR REFERENCE:
1. Java Data Objects (May |
Java Programming Idioms
Java: Java Programming Idioms
Java: Java Programming Idioms
Introduction
Every programming language has its ways of writing common programming
constructions. Sometimes |
Programming Style Guideline
Java Notes: Programming Style Guideline
Java Notes: Programming Style Guideline
Contents
I. Motivation for programming guidelines
II. Comments, indentation, spacing, braces, ...
III |
Programming: Initials 1
Java: Programming: Initials 1
Java: Programming: Initials 1
Name ________________________________________
Write a program that asks for names and displays the initials.
Ask the user |
Wi-Fi as a part of LBS
Wi-Fi as a part of LBS
Wi-Fi as a part of LBS
 ... the attached Wi-Fi device again converts it into binary code for the respective |
Bayanihan Linux 4 Beta 1 has been released
Bayanihan Linux 4 Beta 1 has been released
Bayanihan Linux 4 Beta 1
has been released
Bayanihan Linux 4 Beta 1 is now available... and Technology Institute last October 2001. This was the first initiative |
Java Programming Books
, and JavaBean architectures.
In Part 1 we describe the products used in our...
Java Programming Books
Java Programming Books... keep this brief: This Java programming stuff is a lot easier than it looks. I'm |
JDO UNPLUGGED - PART II
UNPLUGGED - PART II
JDO UNPLUGGED - PART II... find the following four jar files
1. jdo.jar : It contains the standard... needed for our application. They are,
1. jta.jar : The synchronization interface |
Java programming
Java Programming,Introduction to Java Programming,Online Java Programming Help
Java programming
 ...;
Java programming |
Definition of Bioinformatics
;
About Bioinformatics
In February 2001, the human genome was finally... for Biotechnology Information (NCBI
2001) defines bioinformatics as:
"... the Computer Programming Languages.
Experiment on your computer |
Common Interview Questions Page -1
Common Interview Questions Page -1
Common Interview Questions Page -1
 ...;
Question:1. Tell Me a Little |
Programming Style Guideline
Java Notes: Programming Style Guideline
Java Notes: Programming Style Guideline... programming, it's
M A I N T A I N A B I L I T Y
Cost or fun |
Programming: Hammurabi I - Solution
Java: Programming: Hammurabi I - Solution...
The following two source files are a solution to the
Hammurabi I programming... program
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 |
C# Programming Books
C# Programming Books
C# Programming Books... rights reserved. No part of this publication may be reproduced, stored...
With Microsoft's introduction of the .NET platform, a new, exciting programming language |
New to programming...
Java Programing, New to Java Programming, New in Java Programming...
to programming...
 ... & D's, the real life programming is here....having
no space for complexities |
SCADA Programming
SCADA Programming
SCADA Programming... technology was developed as part of Instrumentation Engineering. Monitoring systems... are recorded and displayed.
Where Programming Comes In
All of this requires |
Navigable Map Example
;String>();
navMap.put(1, "January");
 ...=June, 5=May, 4=April, 3=March, 2=February, 1=January}
First data: 1... key: 6=June
Removing First: 1=January
Removing Last: 12 |
WEBSERVICE USING APACHE AXIS - TUTORIAL-2 AXIS FOR EJB-WEBSERVICE (part-5)
had seen parts 1 to 4 of this tutorial on exposing an EJB as XML-Webservice using Axis. This is a 7 part
article.?
part-1 : Overview
part-2 : deploying... of Business and Programming
?(quoted ?from: Programming
web service with SOAP
?by? James |
C/C++ Programming Books
C/C++ Programming
Books
C/C++ Programming... topics for Visual C++ 6 programming. This book skips the beginning level material... Foundation Class Library. These enhancements include classes for Internet programming |
PHP Programming Books
PHP Programming Books
PHP Programming Books...;
PHP
5 Power Programming
This book...
PHP Programming
Welcome, reader, to the world of PHP. You're |
Perl Programming Books
Perl Programming Books
Perl Programming Books... programming projects that highlight some of the moderately advances features of Perl... partners. Extreme Programming (XP) is a software development methodology |
Programming
Java: Programming
Java NotesProgramming
Here are some tips on making programming student problems...
elements of Extreme Programming (a much hyped, but
good Software |
String Exercises 1 - Answers
Java: String Exercises 1 - Answers
Java: String Exercises 1 - Answers
Answers to the String Exercises 1.
3 -- s refers to exactly the same string as a.
ERROR -- t |
Capitalize - Solution
Java: Capitalize - Solution
See Exercise - Capitalize programming exercise... {
return s.substring(0,1).toUpperCase() + s.substring(1);
}
}
For the extra credit part, just an a null test to the if statement.
if (s == null |
JSP Session Counter Using SessionListener
;
Counter is a device which...
of the HttpSessionListener interface.This listener is a part of HttpSession
for the HttpSession object... is given below:
<html>
<head>
<title>Page 1< |
Eclipse Plunging/Team Development
. This integration has been available since January 2003,
and on April 9th... similar to CVS support, which is already part of the
standard Eclipse platform...;
XPairtise
- Pair Programming for Eclipse
The Eclipse plug |
Programming - World Peace
Java: Exercise - Programming - World Peace
Java: Programming - World Peace
Change all occurences... to extract the part
before "war" and after "war" and build a new string |
Programming - WordFrequency modifications
Java Notes: Programming - WordFrequency modifications
Java Notes: Programming - WordFrequency.....
After you have the previous part running, change the Comparator |
Programming: Weeks and Days
Java: Programming: Weeks and Days... and output values
Input: 9 Output: 1 week(s), 2 day(s)
Input: 20 Output: 2 week(s), 6 day(s)
Input: 1 Output: 0 week(s), 1 day(s |
Programming - Transform Name
Java: Exercise - Programming - Transform Name
Java: Programming - Transform Name
Write a program... must be rearranged.
Case 1 - Single name
If the user enters only one name, eg |
Programming: Initials 2
Java: Programming: Initials 2
Java: Programming: Initials 2
Name...
extra can cancel out points you may lose in the main part of the problem |
AN INTRODUCTION TO JSTL
.
Tutorial
Home |
Part
1 | Part 2 | Part
3 | Part 4....
Tutorial
Home |
Part
1 | Part 2 | Part
3 | Part 4
 ... on this article may be sent to:
ramrsr@rediffmail.com
)
In
this four-part |
Core Java Interview Question Page 1
Core Java Interview Question, Interview Question
Core Java Interview Question Page 1
 ... error device. By default, they both point at the system console. This how |
Programming: Prime Numbers - Dialog
Java: Programming: Prime Numbers - Dialog
Java NotesProgramming: Prime Numbers - Dialog
Name... by
any other integers except 1 and themselves. For example, some of the
first prime |
Programming: Count Words - Dialog
it the number of blanks+1.
Declare an int variable to count the number of blanks, initializing
to zero at the beginning, incrementing it by 1 for every blank in the input
string, and displaying it (plus 1) at the end.
Looking at every character |
Programming - Transform Name - Answer
Java: Exercise - Programming - Transform Name - Answer
Java: Programming - Transform Name - Answer..."), and the case where the names must be rearranged.
Iterative programming
Here |
Python Programming Books
Python Programming
Books
Python Programming.... The algorithms and data structures in the book are presented in the Python programming... on this website. Email me at <mertz@gnosis.cx> .A few caveats: (1) This stuff |
Simple Linked List Exercise 1
Java: Simple Linked List Exercise 1
Java Notes: Simple Linked List Exercise 1
Name... strings and puts
them in a doubly linked list.
1
2
3
4
5
6 |
JSP Programming Books
JSP Programming Books
JSP Programming Books... Pages? (JSP[1]) are examples of this. None of these normally requires a separate..., but the reader is assumed to be familiar with the Java programming language and the core |
Programming: Hammurabi I
Java: Programming: Hammurabi I... could have been put in a constructor.
1
2
3
4
5
6
7
8... the simulateOneYear method
to update the population.
1
2
3
4
5
6
7 |
Programming: Hammurabi I
Java: Programming: Hammurabi I... could have been put in a constructor.
1
2
3
4
5
6
7
8... the simulateOneYear method
to update the population.
1
2
3
4
5
6
7 |
Technology What is and FAQs
it
is the part of the MPEG-4 standard.
ASCIIASCII, the
abbreviation... programming package that can be access on a
single firm operating... is the standard unit of measuring frequency and
Giga is it?s multiplier of 1 billion times |
Java Virtual Machine(JVM)
class-file format.
1. Java Programming Language
Java Programming... of Java architecture and it is the part of the JRE (Java Runtime Enviroment... is an intermediary language between Java source and the host system. Most programming |
LG3D LiveCD 2.4 Test 1 has been relesed now
LG3D LiveCD 2.4 Test 1 has been relesed now
LG3D LiveCD 2.4 Test 1 has been relesed now
LG3D LiveCD 2.4-test1 available.... It is also possible to run it from a 256MB flash memory device.
Release 2.4-test1 |
Programming: Body Mass Index - Dialog
Java: Programming: Body Mass Index - Dialog
Java NotesProgramming: Body Mass Index - Dialog... conversions.
For example, 1 inch = 2.54 centimeters and one pound is 0.454 kilograms |
Programming: Hammurabi I - Project start
Java: Programming: Hammurabi I - Project start
Java: Programming: Hammurabi I - Project start
Copy... programming, here is a working version, but it doesn't implement
all of the features |
RR64 Linux 3.0 Beta 1 has been released
RR64 Linux 3.0 Beta 1 has been released
RR64 Linux 3.0 Beta 1 has been
released
RR64 Linux 3.0b1 (Xgl Beauty). RR64.... Welcome to a new dimension...
Features:
1. 2.6.15 Kernel (gentoo |
New to Java?
Information Device Profile (MIDP) together provides solid Java platform... Information Device Profile (MIDP) - This is another configuration
of Java Micro Edition... an overview of Java technology as programming language and
a platform. Java |
New to Java?
Information Device Profile (MIDP) together provides solid Java platform... Information Device Profile (MIDP) - This is another configuration
of Java Micro Edition... an overview of Java technology as programming language and
a platform. Java |
|
|
|