Developing Wireless Applications using ™ Technology

Bill Day [email protected] www.billday.com

Technology Evangelist

Computing Is Ubiquitous

l Mainframe era: one computer, many people

l PC era: one person, one computer

l As computing becomes ubiquitous: one person uses many computers, and these computers are networked

1 Agenda

l Java™ 2 Platform and J2ME™ Platform l J2ME Platform and Mobile Service Technologies l CLDC Internals and Details l MIDP Details l Availability and Resources

Java™ 2 Platform and J2ME™ Platform

2 Java™ 2 Platform

Java™ 2 Platform, Micro Optional Edition (J2ME™) encompasses Packages VMs and core APIs specified via Optional Configurations as well as vertical— Packages or market-specific—APIs specified in Profiles Java 2

Enterprise Other Java 2 Personal RMI CDC Edition Profile Profile Profiles Standard ... (J2EE) Edition Core APIs (J2SE) Foundation Mobile Information Profile Device Profile Core APIs Java Java 2 Micro Edition Core APIs Card APIs

Java Programming Language

Java HotSpot ™ (JVM) KVM Card VM

What Is a Configuration?

l A configuration defines the minimum Java™ technology libraries and virtual machine capabilities that an application developer/content provider can expect to be available on implementing devices l A J2ME platform configuration defines a minimum Java platform for a family of devices u Broad range of devices in different areas u Similar requirements of memory size and processing capabilities

3 Configurations

l May not contain any optional features l Defined through the Java Community ProcessSM initiative (JCP) l Subject to compatibility tests

What Is a Profile?

l A collection of Java™ technology-based APIs that supplement a Configuration to provide capabilities for a specific vertical market or device type l Defined through initiative l Subject to compatibility tests

4 The J2ME™ Platform and Mobile Service Technologies

J2ME Platform Connected, Limited Device Configuration (CLDC)

l Targeted at devices with u 160KB to 512KB total memory available for Java™ technology u Limited power (often battery) u Limited, perhaps intermittent connectivity to a network (often wireless) u Extremely constrained UIs, small screens l CLDC 1.0 specification available for free download now l Sun provides CLDC reference implementation built using the KVM

5 Mobile Information Device Profile (MIDP) l Targets mobile two-way communication devices implementing J2ME CLDC l Profile addresses u Display toolkit, User input methods u Persistent data storage using simple record-oriented database model u HTTP-based networking using CLDC Generic Connection framework l MIDP 1.0 spec and implementation available for download now

Example J2ME™ Technology Wireless Device Stack

Your Yellow Pages, train MIDlet schedules and ticketing, games… Mobile Information UI, HTTP Device networking... Profile J2ME core APIs

CLDC = Threads, no Floats… KVM + KVM J2ME Core 32-bit RISC, 256K ROM, APIs 256K Flash, 64K RAM in this DSP chip example (e.g., ARM)

6 What About Web Content for Mobile Devices?

l Markup languages in use today to deliver Web content to device browsers: u Compact HTML (C-HTML) is an HTML-based markup deployed to millions of users in NTT DoCoMo’s i-mode network u The WAP Forum’s Wireless Markup Language (WML) is an emerging standard for content (data) delivered to mobile devices u HTML dominates Web content worldwide l WAP specifies its own protocols (Wireless Session Protocol, Wireless Transaction Protocol, etc.)

Wireless Web Content Distribution

Carriers Client Content or Wireless Devices Producers Portals

Static Web Server Web or WML Content or WAP Browser Gateway

Java Apps Dynamic Content Content Transcoding Java Application Manager Applicati MID Profile Java Applicationon Applications DistributDistribution J2ME CLDC ion

7 Example Java™ Technology Application Loading Process

Advertise User JAM App on Selects Downloads Web Page App App

Web Page

(Name, Descriptor Network Transfer Java Application Version, File Manager Size, …)

Jar File

The Future: Transcoding and XHTML

l Transcoders are becoming more capable and widely used l WML, C-HTML, and HTML are converging towards XHTML u XHTML is the re-writing of HTML as an XML- based markup language u XHTML Basic will be renderable everywhere u WAP Forum and W3C collaborating on XHTML

WML The not too distant XHTML CHTML future... HTML

8 CLDC Internals and Details

Scope of the CLDC Specification

l Specifies VM features required of CLDC implementation in terms of additions to and deviations from “The Java™ Virtual Machine Specification” by Lindholm and Yellin l Specifies requirements for interfaces and APIs for the following: u Input/output, Networking u Security model u Internationalization features

9 Beyond the CLDC Scope

l Specified in Profiles to be implemented on top of the CLDC: u User interface support u Event handling u High-level application model u Persistence support l One example specification of these remaining APIs: Mobile Information Device Profile (MIDP)

CLDC Language and VM Compatibility

l General goal: u Full Java programming language and Virtual Machine Specification compatibility l Only language-level exception: u Floating point not in CLDC 1.0 n No hardware floating point support on most devices due to space limitations n Manufacturers and/or developers may choose to include their own floating point, however

10 CLDC Language and VM Compatibility

l VM Implementation differences: u No Java™ Native Interface (JNI) u No reflection u No thread groups u No weak references u No finalization u New implementation of bytecode verification using preverifier and bytecode annotations

CLDC Libraries

l Classes inherited from Java 2 Platform, Standard Edition (J2SE version 1.3) are in packages: u java.lang.* u java.util.* u java.io.* l New classes introduced by CLDC are in package: u javax.microedition.*

11 CLDC Libraries: java.lang.*

l java.lang.Object java.lang.Class l java.lang.Runtime java.lang.System l java.lang.Thread java.lang.Runnable l java.lang.String java.lang.StringBuffer l java.lang.Math java.lang.Throwable l java.lang.Byte java.lang. Long l java.lang.Integer java.lang.Boolean l java.lang.Character java.lang.Short

CLDC Libraries: java.util.*

l java.util.Vector java.util.Stack l java.util.Hashtable java.util.Enumeration l java.util.Random java.util.Calendar

12 CLDC Libraries: java.io.* l java.io.InputStream java.io.OutputStream l java.io.Reader java.io.Writer l java.io.DataInput java.io.DataOutput l java.io.InputStreamReader l java.io.OutputStreamReader l java.io.ByteArrayInputStream l java.io.ByteArrayOutputStream l java.io.PrintStream

Comments on CLDC Libraries

l Internationalization u Limited support for the translation of Unicode characters to and from a sequence of bytes u Implemented using Readers and Writers u By default, the only character encoding for which a converter is provided in ISO-LATIN1 u Localization implemented by manufacturer l Property support u No java.util.Properties class u Properties read using System.getProperty(String key) u Limited set of CLDC-specific properties supported

13 Networking, I/O and Storage Libraries

l Standard Java technology networking, I/O and storage libraries are too large for CLDC devices u More than 100 classes u Total static size of classfiles more than 200 KB u Original classes were never designed for small devices

Networking, I/O and Storage Libraries

l CLDC specifies an alternative Generic Connection framework u More coherence in supporting different types of I/O u Consistent way of supporting different protocols u Improved portability of applications u Smaller footprint

14 Generic Connection Possibilities

General form: Connector.open("://

:");

Files: Connector.open("file://billday.txt");

HTTP: Connector.open("http://www.billday.com");

Sockets: Connector.open("socket://129.144.111.222:9000");

Communication ports: Connector.open("comm://9600:18N");

MIDP Details

15 Scope of the MIDP Specification

l Primary goals: u Size: MIDP implementation must fit in small footprint (128KB ROM) u Efficiency: n must run on low-end microprocessors n must run in with limited heap size (32–200KB RAM) n minimal creation of garbage u Time to market is critical for manufacturers of Mobile Information Devices

Beyond the MIDP Scope

l To be implemented by device manufacturers, operators, or third party developers: u How an application actually gets on the device u The end-to-end security model u System- or OEM-specific technologies

16 MIDP Application Lifecycle

l MIDP applications are known as “” l MIDlets move from state to state in the lifecycle, as indicated. u Start – acquire resources and start executing u Pause – release resources and become quiescent (wait) u Destroy – release all resources, destroy threads, and end all activity

MIDlet Packaging

l MIDlets are packaged in a JAR file including u Class files of the MIDlet(s) u Resource files u Manifest with application properties l Application Descriptors accompany MIDlet JARs and provide information including u Configuration properties u Pre-download properties n Size, version, storage requirements

17 MIDP Libraries

l The MIDP specifies APIs for: u Persistent Storage u Networking u Timers u User Interface

MIDP Persistent Storage

l Lightweight record oriented database

u Device independent API

u Unique record ID for each record within a store

u Records are arrays of bytes

u Shared within MIDlet suite

u Atomic update for single records

u Support for enumeration, sorting and filtering l Device platform is responsible for:

u Integrity of data across reboots, battery changes

u Storage in flash or other device memory

18 MIDP Persistent Storage: RMS Methods

l Record Store u openRecordStore, closeRecordStore, listRecordStore, deleteRecordStore, getRecordSize, getNumRecords l Record Data u addRecord, deleteRecord, getRecord, setRecord, getRecordSize l Record Selection u RecordEnumeration, RecordFilter, RecordCompare

MIDP Networking

l MIDP devices must implement HTTP protocol, though this may or may not use IP-based transport underneath

19 MIDP Networking Methods

l MIDP networking extends from CLDC Generic Connection Framework

l HttpConnection includes methods:

u get/setRequestProperty u get/setRequestMethod u getResponseCode, getResponseMessage u getHeaderField u getURL, getHost, getPort, getFile, getQuery, getRef (Parsed URL components)

MIDP Timer Methods

l Timer handles queuing and delivery l Timer Task u Multiple Tasks per Timer u Periodic u Fixed interval u One shots

20 MIDP UI Design Principles

l MIDP must be usable in all devices u Majority of wireless devices are one-hand operated u Small screen (tens of pixels by tens of pixels) u Not all devices have a pointing device l Must constantly think of end users: u Mobile Information Devices are consumer products, not desktop computers u Unified user interface between MIDP applications and native apps on the device n MIDP applications should behave consistently with resident functionality

MIDP UI: A Tale of Two Layers

l MIDP UIs may be created using one of two “layers” of APIs l Use the high-level APIs for portability u Applications using these APIs should be runnable and usable in all MIDP devices u No direct access to native device features l Low-level APIs u Provide access to native drawing primitives, device key events, native input devices, etc. u Allow developers to choose to compromise portability for user experience, if needed

21 MIDP Screen-based Design Principles

l MIDlet UIs are built using simple screens l Screens should contain minimum amount of information required u Usually only one "thing" l Screens should require only simple interactions from user u No complex traversing, scrolling, or selection metaphors

MIDP UI Class Hierarchy (major classes only)

0-n Displayable Command

Canvas Screen Choice

TextBox ChoiceGroup

List DateField 1-n Alert Item TextField Gauge Form ImageItem TextItem

22 MIDP Input Handling

l High-level API input is handled using abstract commands instead of direct access to soft buttons u Each MIDP implementation maps these commands to appropriate soft buttons or menu items for the particular device u MIDlets can provide semantic hints (like back) l Low-level API gives developers access to key press events

MIDP Input Commands

l Example MIDP input commands: new Command("Buy", Command.SCREEN); new Command("Info", Command.SCREEN); new Command("Back", Command.BACK);

Ford Buy Opel Info BMW Pressing "options" Options Back opens a menu Back

23 Availability and Resources

Java™ Technology in Mobile Devices: Where Are We Today? l Sun’s CLDC implementation supports development using Solaris, Win32, PalmOS l KVM ports to Linux, Motorola devices, Nokia phones, RIM handhelds, and more l Symbian continues support for Java technology in current and upcoming releases of EPOC l LG deployed J2ME technology in Korean mobile network beginning summer 2000 l NTT DoCoMo deployed Java technology in i-mode service January 2001 l Agreements and projects with Vodaphone AirTouch, One 2 One, Sprint PCS, Telefonica, and many others

24 The J2ME Platform and Mobile Phone Standards

l Special Mobile Group (SMG) u Working group of European Telecommunications Standards Institute (ETSI) u Specifies Mobile Station Application Execution Environment (MExE) for GSM mobile phone handsets u SMG has adopted PersonalJava™ technologies as part of the MExE Release 98, classmark 2 spec for GSM handsets l 3GPP has announced adoption of J2ME CLDC and MIDP technologies for worldwide third generation (3G) mobile standards

J2ME Platform Mobile Tech Availability (as of 6 February 2001)

Technology Type Spec FAQ Reference Mailing Impl. list K Virtual J2ME Yes, part Yes Yes, 1.0 Yes Machine core of CLDC tech Connected, J2ME JSR-30, Yes Yes, 1.0 Yes via Limited Device Config. 1.0 KVM Configuration list Mobile J2ME JSR-37, Yes Yes, 1.0 Yes via Information Profile 1.0 KVM Device Profile list

25 J2ME™ Platform CLDC and MIDP Development Tools l Sun J2ME Wireless Toolkit (optionally plugs into free Forte for Java IDE) l MIDP reference, CLDC/KVM Software Development Kit (SDK), with support for Win32, Solaris™ platform, and PalmOS l RIM BlackBerry™ IDE, Motorola J2ME SDK, KVM for Linux l Any IDE or standard Java tool, including J2SE™ SDK (aka JDK™ 1.2.2 or 1.3) l Tools from the J2ME Archive (Spotter utility, WBXML package, etc.) l Other PalmOS tools (Beam Box, RsrcEdit, etc.)

Sun J2ME™ Wireless Toolkit

26 Other J2ME Tools

Example 1: Zentek i-JADE as P503i

Example 2: Zucotto WHITEboard Emulator

Other J2ME Tools

Example 3: Example 5: PalmOS RIM BlackBerry™ Emulator Example 4: Java Development Sun MIDP Environment Reference

27 J2ME Development Tools

l They are available NOW. l They are FREE. l They are all you need to start writing great Java applications for mobile devices TODAY.

Discuss the J2ME™ Platform

l The kvm-interest mailing list is a free J2ME development list hosted by Sun u To subscribe, send email to: [email protected] u In the body of the message, type: subscribe kvm-interest u For digest mode, include the following line: set kvm-interest digest l The kvm-interest archive is searchable online at: archives.java.sun.com/archives/kvm-interest.html

28 J2ME™ Platform CLDC and MIDP Resources

l J2ME: java.sun.com/j2me l Connected, Limited Device Configuration specification and SDK: java.sun.com/products/cldc l Mobile Information Device Profile specification and reference implementation: java.sun.com/products/midp l Download the Sun J2ME Wireless Toolkit: java.sun.com/products/j2mewtoolkit l J2ME Webcast: java.sun.com/jdc/onlineTraining/webcasts

Additional Resources

l J2ME™ Archive: www.billday.com/j2me l jGuru J2ME FAQ: www.jguru.com/faq/J2ME l J2ME tutorial articles: java.sun.com/jdc/technicalArticles/wireless l AnywhereYouGo developer portal: www.anywhereyougo.com l WirelessDevNet developer portal: www.wirelessdevnet.com l J2ME tools CD, available now as part of Java Jumpstart™ from Sun Developer Connection (SDC)

29 For more, please visit SDC at: www.sun.com/developers

© Copyright 2001 Sun Microsystems, Inc., All rights reserved.

Sun, Sun Microsystems, the Sun logo, Solaris, Java, PersonalJava, Java TV, EmbeddedJava, , Java Hotspot, JavaOne, JavaScript, iPlanet, JDBC, JDK, JavaCheck, Enterprise JavaBeans, Java Embedded Server, Java Community Process, The Java Coffee Cup Logo, Java Virtual Machine, Java Native Interface, JVM, J2ME, J2SE, and The Network Is The Computer are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.

Speaker Bio

Bill Day is a Technology Evangelist at Sun Microsystems.

Bill writes about software development for JavaWorld™ magazine, Dr. Dobb’s Journal Software Careers, and numerous other publications. He manages jGuru’s J2ME FAQ. Bill also speaks frequently on consumer device programming and teaches Java and Wireless development as an extension instructor for the University of California Berkeley.

More information is available from Bill’s web site: www.billday.com

30 31