Careful study J2ME

xiaoxiao2021-03-06  61

Reprinted from DeveloperWorks

Author Senior Application Developer, Entigo

November 2001

Java 2 Platform Pool (Java 2 Platform, Micro Edition (J2ME)) provides developers with great tools, which transplays the Java platform to the network-centered and platform unknown features to finite memory and limited processors . Soma Ghosh explains the basics of J2ME fields to show you the components of the platform and demonstrate a sample application.

In our lives today, personalized intelligent information items are already a necessity. These supplies include mobile phones, two-way pager, smart cards, Personal Organizer and Palmtop. Their trend is a specific, resource limited network connection device, rather than our universal desktop known to date. To meet this huge consumption space, Java 2 Platform Pocket Edition (J2ME) provides a lot of innovative Java technology.

Changes of Java VM: from desktop to miniature equipment

A micro device as a J2ME target has a 16-bit or 32-bit processor and a total of not less than about 128 kb. These devices are in line with

Connection Limited Device Configuration (CLDC), also retains the traditional characteristics of Java, namely, any time, any location of code portability, deployment flexibility, secure network transmission, and code stability. J2ME CLDC prerequisite is a tightening JVM, called

K Virtual Machine (KVM)). KVM is designed for small memory, resource-limited network connection devices.

Another J2ME configuration is

Connecting device configuration (CDC)). Its goals are high-grade consumer electronics and embedded devices, such as intelligent communications, advanced "intelligent" pagers, smart personal digital assistants (PDAs), and interactive digital TV set top boxes. Typically, these devices operate a 32-bit microprocessor / controller, and there is a memory that is more than 2 MB for a virtual machine and library stored. The CDC contains a C virtual machine (C Virtual Machine (CVM)). In this article, we will focus on the CLDC and KVM architecture. For more information on CDC and CVM, please refer to

Reference section.

In order to adapt to the characteristics of a small-footprint device, KVM has been modified as follows:

The size of the VM and the class library have reducing the standard memory of 50 to 80 kB target code, which has reduced to several tens of kilobytes on devices with 16-bit and 32-bit processors, and the performance valid architecture is high. Multi-multi-threaded and garbage recovery is independent of the system's components that can be configured for specific devices, which enhances flexibility to configure components of the virtual machine to suit specific devices.

The J2ME architecture and configuration J2ME architecture is based on the device's series and category. A category defines a particular type of device: mobile phones, simple pagers and computer notepads are separate categories. A series of devices that have a few categories of devices that have similar requirements for memory and processing capabilities. Mobile phones, simple pagers, and simple personal computer notepads are a series of devices that occupy small resources.

Figure 1 defines the relationship between the series and categories of the device in the J2ME context environment.

Figure 1. Family and category (Category) designs the J2ME architecture into modular and scalable. J2ME technology defines this module and scalability in a complete application runtime model, and four software layers in the model are constructed on the host operating system of the device.

Figure 2 shows the J2ME architecture.

Figure 2. J2ME architecture

Java Virtual Machine Layer: This layer is an implementation of the Java virtual machine, which is customized for host operating systems for specific devices, and supports a specific J2ME configuration. Configuration Layer: The configuration layer defines the minimum set of Java class libraries available on the Java virtual machine feature and specific categories. To a certain extent, a configuration defines the commonality of the Java platform feature and libraries, which can assume that these features and libraries are available on all devices belonging to a particular class. Users don't see this layer, but it is very important to the PROFILE implementator. PROFILE LAYER: The frame layer defines the minimum set of application programming interfaces (APIs) available on a particular series of devices. The frame is implemented above a specific configuration. The application is written for a particular framework, so it can be ported to any device that supports the framework. A device can support multiple frames. User and application vendors see the most of this layer. MIDP layer: Mobile Information Device Profile (MIDP)) is a Java API collection that handles problems such as user interfaces, persistent storage, and networking.

Java Virtual Machine Layer, a configuration layer (PROFILTION LAYER), together with the Connected Limited Device Configuration (CLDC)). MID Framework (MID PROFILE) and CLDC provide a standard runtime environment that allows new applications and services to dynamically deploy on end user devices.

J2ME programming with the MIDP API: Components CLDC and MIDP combine provide a complete environment for creating applications on mobile phones and simple bidirectional paging.

The core of the MID frame is a MIDlet application. This application inherits the MIDlet class to allow application management software to control the MIDlet, retrieve properties from the application descriptor, and notify status changes.

All MIDlets inherit the interface between the MIDlet class - Runtime Environment (Application Manager) and MIDlet application code. The MIDLET class provides an API for calling, pause, restarting, and terminating the MIDlet application.

Application Management Software can manage multiple MIDlet activities in the runtime environment. In addition, MIDlet can initiate some status changes and notify these changes to the application management software.

A complete collection of the MIDP API class can be divided into two categories:

MIDP API for user interfaces: Designing these APIs to interact with users in a series of screens, each screen displays the right amount of data to the user. The command is provided to the user based on each screen. These APIs allow applications to determine what requests for the next screen display, what requests to perform and use network services. MIDP APIs for processing databases: These APIs are responsible for organizing and operating device databases, which consists of persistent information from multiple calls in MIDlets. The underlying CLDC API is used to process strings, objects, and integers. A subset of Java 2 API is also provided for processing I / O and network communication.

Figure 3 shows a member of J2ME.

Figure 3. Members of J2ME

The relationship between the standard (STANDARD) version and the MICRO version Java API is shown in Figure 4.

Figure 4. Relationship between J2ME and J2SE API

Event processing in J2ME is based on a series of screens, which is very different from the event processing of the desktop version of the Java platform. Each screen displays a particular small amount of data.

The command is provided to the user based on each screen. The Command object encapsulates the semantic name and information related to the action. This object is mainly used to provide user selection. The resulting command behavior is defined in the CommandListener associated with the screen display.

Each Command contains three pieces of information: a label, a Type (type) and a priority (priority). Label is used for the visual representation of the command; Type and Priority are used by the system, and the system uses them to determine how Command is mapped to the specific user interface.

Figure 5 shows the event processing mechanism in J2ME.

Figure 5. Handling user events in J2ME

Designing User Interface MIDP API Although maintaining a limited framework, it also provides a complete collection of UI elements. The following is some of the most important UI elements:

Alert is used to display information about exceptions or errors on the screen. Choice is used to achieve selection from a set of options. Choicegroup provides a set of related options. FORM is a container of other UI elements. List provides a list of options. StringItem acts as a DISPLAY-ONLY string. Textbox is a screen display that allows users to enter and edit text. TextField allows users to enter and edit text. Multiple TextField can be placed in an Form. DateField is an editable component for representing date and time information. Datefield can be placed in Form. Ticker can scroll-on the text for text.

A complete list of UI elements can be found in the MID PROFILE API document that provides more information with J2ME Wireless Toolkit (see the references below).

The management device database MIDP provides a set of classes and interfaces for organizational and operating device databases: RecordStore, RecordComparator, and Recordfilter. RecordStore consists of a large number of records, which remains lasting when multiple calls of MIDlets. Compare the records in the RecordStore, or draw a number of group records from the RecordStore, which is the function provided by the RecordComparator and Recordfilter interface.

The part of the development J2ME application has made an overview of J2ME. In this section, we will be familiar with the practice details of this platform by developing a real-world phone interface app.

A sample application: One of the famous features of the phone calendar J2ME is its date processing in the restricted environment. The Datefield UI element provided by J2ME is an editable component, which is used to represent calendar information (ie, the date and time). In this section, we will use the DateField and Date functions to develop a J2ME application, which is used to display a scroll calendar on the mobile phone UI. A telephone calendar application

// Import of API Classes

Import javax.microedition.midlet. *;

Import javax.microedition.lcdui. *;

Import java.util. *;

// a First Midlet with Simple Text and A Few Commands.

Public Class Phonecalendar Extends MIDLET

Implements commandListener, ItemStatelistener {

// THE Commands

Private Command EXITCOMMAND;

// the display for this MIDLET

Private display display;

// Display Items E.G Form and Datefield

Form Displayform;

Datefield Date;

Public phonecalendar () {

Display = display.getdisplay (this);

EXITCOMMAND = New Command ("EXIT", Command.Screen, 1);

Date = New Datefield ("Select to Date", Datefield.date;

}

// start the midlet by create the form and

// Associating The EXIT Command and Listener.

Public void startapp () {

Displayform = New Form ("Quick Calendar");

Displayform.Append (date);

DisplayForm.Addcommand (exitcommand);

Displayform.SetCommandListener (this);

Displayform.SetItemStateListener (this);

Display.SetCurrent (DisplayForm);

}

Public Void ItemStateChanged (item item)

{

// Get the value from change ITEM

}

// Pause is a no-op when it is no background

// Activities or Record Stores to be closed.

Public void pauseapp () {}

// Destroy Must Cleanup Everything Not Handled

// by The Garbage Collector.

Public void destroyApp (boolean unconditional) {}

// Respond to commands. Here We are Only IMPLEMENTING

// the exit command. in the exit command, Cleanup and

// Notify That The Midlet Has Been Destroyed.

Public void CommandAction (Command C, Displayable S) {

IF (c == EXITCOMMAND) {

DESTROYAPP (FALSE);

NotifyDestroyed ();

}

}

}

The PhoneCalendar MIDET as defined above inherits ItemListener and CommandListener. It enables MIDlets with the ability to track entries on the screen and the functionality to respond to user commands. The user interface created by this application is defined for a phone screen and attaches the last Form start. The Form acts as a container to maintain some user interface items. The CommandAction () function performs a command handler in J2ME and defines the action that should be performed.

Deploy J2ME You can download an emulator from Sun, which allows you to test the J2ME application on your desktop system. If you prefer to avoid all graphic overhead, you can also deploy J2ME on the command line.

Deploying and running a J2ME application in the simulation environment, to involve the installation and configuration of the emulator. J2ME Wireless Toolkit provides an simulation environment for development and deployment of Java applications on the resource resource-limited device. Here you teach you how to run it yourself:

Install J2ME Wireless Toolkit (see Resources). You will use the necessary instructions to guide you to install. To run these examples, select Standalone mode. If you want to integrate it into the IDE, select an Integrated mode. Create a new project through KToolbar user interface. Specify a class name. Place the class name specified in step 2 in the C: / [J2ME Installation Directory] / Apps / [Project Name] / src directory. Compile this project. From J2ME Wireless Toolkit -> Default Device Selection Select DefaultGrayphone as the default device. Run this project.

The toolbox also provides an option to pack the engineering into a JAR file and a JAD file. Double-click the JAD file will deploy the application specified by the JAR file.

There are also some available command line options on the command line.

1. Create a class file:

C: / j2me / apps / phonecalendar>

Javac_TmpClasses_ootclasspath

C: /j2me/lib/midpapi.zip -classpath TMPCLASES;

Classes src / *. Java

2. Create a list of manifest.mf:

MIDLET-1: PhoneCalendar,

Phonecalendar.png,

Phonecalendar

MIDlet-name: Phone Calendar

MIDlet-vendor: Sun Microsystems

MIDlet-Version: 1.0

MicroEdition-Configuration: CLDC-1.0

MicroEdition-Profile: MIDP-1.0

3. Create a JAR file:

C: / j2me / apps / phonecalendar> JAR CFM ./bin/

Phonecalendar.jar

Manifest.mf -c classes._ rs.

4. Create a JAD file:

MIDLET-1: PhoneCalendar,

Phonecalendar.png,

Phonecalendar

MIDlet-jar-size: 4490

MIDlet-Jar-URL:

F: /j2me/apps/phonecalendar/bin/phonecalendar.jar

MIDlet-name: PhoneCalendar

MIDlet-vendor: Sun Microsystems

MIDlet-Version: 1.0

5. Run the JAD file:

C: / j2me / bin> Emulator -xdescriptor:

C: / j2me / apps / phonecalendar

/bin/phoneclendar.jad

Conclusion J2ME is an important Java platform for wireless aspects, which is converted from portable and network-centered Java virtual machines. The development and deployment of the J2ME application will effectively meet the growing demand in the area of ​​wireless. Please continue to pay attention!

Reference

Participate in the discussion forums in this article. Access the developerWorks Wireless area to keep concern in the WiReless area. The developerWorks Java technology area allows you to follow the events that occurred in the Java area. This article discusses the relationship peer-to-peer and the mechanism that integrates all wireless supplies. Review the latest developments to IBM's Pervasive Computing site. Compile the Java application with IBM Visualage for Java.

Some documents provided by Sun:

Visit the J2ME home page to learn about J2ME. Read the J2ME architecture and configuration details (PDF format). See About J2ME more documentation. Read the J2ME platform Connected Limited Device Configuration and Connected Device Configuration. Access the MIDP home page to learn about the MIDP API. Download J2ME Wireless Toolkit to run and test your J2ME application. You can also browse the MIDP API documentation with this toolkit. Check out a wide range of articles about "Java Wireless Initiative".

About the author soma ghosh is a bachelor of computer science and engineering. In the past six years, she has developed a wide range of e-commerce and network Java applications. She believes that the wireless business is the future of the industry in recent years, and she has recently transferred from the existing desktop model to the wireless initiative. At present, she is an adiGo's senior application developer and an advocacy of B2B sales and server e-commerce products and solutions. Please contact Soma via sghosh@ntigo.com.

转载请注明原文地址:https://www.9cbs.com/read-112465.html

New Post(0)