J2ME and MIDlets

Download Report

Transcript J2ME and MIDlets

Programming of Handheld and Mobile
Devices
Lecture 11 J2ME and MIDlets
Rob Pooley [email protected]
Programming Handheld and
Mobile devices
1
The Java world
Also our focus
Programming Handheld and
Mobile devices
2
Connected, Limited Device
Configuration
• The goal of this work is to define a standard, minimum-footprint Java
platform for small, resource-constrained, connected devices
characterized as follows:
– 160 kB to 512 kB of total memory budget available for the Java
platform
– a 16-bit or 32-bit processor
– low power consumption, often operating with battery power
– connectivity to some kind of network, often with a wireless,
intermittent connection and with limited (often 9600 bps or less)
bandwidth
• Cell phones, two-way pagers, personal digital assistants (PDAs),
organizers, home appliances, and point of sale terminals are some,
but not all, of the devices that might be supported by this
specification.
Programming Handheld and
Mobile devices
3
Host environment
• the system software in CLDC devices varies considerably.
– some of the devices may have a full-featured operating system
that supports multiple, concurrent operating system processes
and a hierarchical file system.
– other devices may have extremely limited system software with
no notion of a file system.
• CLDC makes minimal assumptions about the system software
available in CLDC devices.
• assumes that a minimal host operating system or kernel is available
to manage the underlying hardware.
• host operating system must provide at least one schedulable entity
to run the Java virtual machine.
• The host operating system does not need to support separate
address spaces or processes, or make any guarantees about realtime scheduling or latency behaviour.
Programming Handheld and
Mobile devices
4
Role of CLDC spec
• CLDC Specification addresses the following areas:
•
•
•
•
•
•
Java language and virtual machine features
Core Java libraries (java.lang.*, java.util.*)
Input/output
Networking
Security
Internationalization
Programming Handheld and
Mobile devices
5
Virtual machine
•
At the heart of a CLDC
implementation is the Java Virtual
Machine, which, apart from
• specific differences, is compliant
with the Java Virtual Machine
Specification and Java Language
Specification.
• The virtual machine typically runs
on top of a host operating system
that is outside the scope of CLDC.
• On top of the virtual machine are
the Java libraries. These libraries
are divided into two categories:
1. those defined by the Connected,
Limited, Device Configuration,
2. those defined by profiles
Programming Handheld and
Mobile devices
6
J2ME on Palm OS
MIDlet (Data to Java KVM)
CLDC (JavaHQ)
Palm OS
Hardware (68k or ARM)
Programming Handheld and
Mobile devices
7
Differences from Java standard
•
•
•
•
No floating point support
The main language-level difference
between the full Java Language
Specification and CLDC is that a JVM
supporting CLDC does not have
floating point support.
Floating point support was removed
because
– the majority of CLDC target
devices do not have hardware
floating point support,
– the cost of supporting floating
point in software was too high.
•
•
No finalization
CLDC libraries do not include the
method Object.finalize(), and therefore
a JVM supporting CLDC shall not
support finalization of class instances
•
•
Error handling limitations
A JVM supporting CLDC shall
generally support exception handling
as defined in JLS.
However, the set of error classes
included in CLDC libraries islimited,
and consequently the error handling
capabilities of CLDC are restricted.
•
This means that a JVM supporting
CLDC shall not allow the use of
– floating point literals,
– floating point types and values
– floating point operations
Programming Handheld and
Mobile devices
8
MIDlet Lifecycle - Launching
• The user selects and launches
the MIDlet. At this point, the
MIDlet enters the KVM and the
lifecycle methods of the MIDlet
are invoked.
Programming Handheld and
Mobile devices
9
Simple MIDlet
/*
* HelloMIDlet.java
* Copyright (c) 2000 Sun Microsystems, Inc. All
Rights Reserved.
*
* Author: Srikanth Raju
*
* This software is the confidential and
proprietary information of Sun
* Microsystems, Inc. ("Confidential
Information"). You shall not
* disclose such Confidential Information and
shall use it only in
* accordance with the terms of the license
agreement you entered into
* with Sun.
*
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES
ABOUT THE SUITABILITY OF THE
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE
LIABLE FOR ANY DAMAGES
* SUFFERED BY LICENSEE AS A RESULT OF USING,
MODIFYING OR DISTRIBUTING
* THIS SOFTWARE OR ITS DERIVATIVES.
*/
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
* An example MIDlet with simple "Hello" text.
* Refer to the startApp, pauseApp, and destroyApp
* methods so see how each handles the requested
transition.
*/
public class HelloMIDlet extends MIDlet
{
/**
* Start up the Hello MIDlet. Just write some info
*/
public void startApp() {
System.out.println( "\nHello Camp" );
pauseApp();
}
/**
* Pause is a no-op since there are no background
activities or
* record stores that need to be closed.
*/
public void pauseApp() {
System.out.println( "In pauseApp... " );
destroyApp( true );
}
/**
* Destroy must cleanup everything not handled by
the garbage collector.
* In this case there is nothing to cleanup.
*/
public void destroyApp(boolean unconditional) {
System.out.println( "In destroyApp... " );
}
}
Programming Handheld and
Mobile devices
10
How MIDlets fit in
Programming Handheld and
Mobile devices
11
J2ME Wireless Toolkit
• Current Version 1.0.3
• Supports application development from Java source to
MIDlet suite containing .jar and .jad files, ready for
deployment
• Provides a GUI-based development environment
• Provides several emulators that allows you to run the
application on different emulated target devices
Programming Handheld and
Mobile devices
12
KtoolBar IDE in J2ME Wireless Toolkit
• Use kToolBar to compile, build, and execute a MIDlet
with the Emulator
• Need a Third-party tool for editing source file
• Enables source level debugging when integrated with
Forte for Java
• Available on Windows, Solaris, and Linux
Programming Handheld and
Mobile devices
13
KtoolBar (in J2MEWTK1.0.3)
Programming Handheld and
Mobile devices
14
MIDlet Lifecycle - Installation
• The application management software installs the MIDlet
on the MID
• The MIDP implementation may verify that the MIDlet
does not violate the MID’s security policies.
• A transformation of the MIDlet may take place to convert
the MIDlet from its public format to a device specific
format.
Programming Handheld and
Mobile devices
15
Emulators in J2ME Wireless Toolkit
Programming Handheld and
Mobile devices
16
OTA in J2ME Wireless
Toolkit
• Can Deploy MIDlets Over The
Air (OTA) on the Toolkit
Programming Handheld and
Mobile devices
17