Developing Wireless Applications using Java Technology Bill Day bill.day@sun.com www.billday.com Technology Evangelist Sun Microsystems Computing Is Ubiquitous Mainframe era: one computer, many people PC era: one person, one computer As computing becomes ubiquitous: one person uses many computers, and these computers are networked 1
Agenda Java 2 Platform and J2ME Platform J2ME Platform and Mobile Service Technologies CLDC Internals and Details MIDP Details Availability and Resources Java 2 Platform and J2ME Platform 2
Java 2 Platform Optional Packages Java 2 Enterprise Edition (J2EE) Core APIs Optional Packages Java 2 Standard Edition (J2SE) Core APIs Java 2 Platform, Micro Edition (J2ME ) encompasses VMs and core APIs specified via Configurations as well as vertical or market-specific APIs specified in Profiles Personal Profile RMI Profile Foundation Profile Other CDC Profiles... Mobile Information Device Profile Java 2 Micro Edition Core APIs Java Card APIs Java Programming Language Java HotSpot Java Virtual Machine (JVM) KVM Card VM What Is a Configuration? 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 A J2ME platform configuration defines a minimum Java platform for a family of devices Broad range of devices in different areas Similar requirements of memory size and processing capabilities 3
Configurations May not contain any optional features Defined through the Java Community Process SM initiative (JCP) Subject to compatibility tests What Is a Profile? A collection of Java technology-based APIs that supplement a Configuration to provide capabilities for a specific vertical market or device type Defined through Java Community Process initiative Subject to compatibility tests 4
The J2ME Platform and Mobile Service Technologies J2ME Platform Connected, Limited Device Configuration (CLDC) Targeted at devices with 160KB to 512KB total memory available for Java technology Limited power (often battery) Limited, perhaps intermittent connectivity to a network (often wireless) Extremely constrained UIs, small screens CLDC 1.0 specification available for free download now Sun provides CLDC reference implementation built using the KVM 5
Mobile Information Device Profile (MIDP) Targets mobile two-way communication devices implementing J2ME CLDC Profile addresses Display toolkit, User input methods Persistent data storage using simple record-oriented database model HTTP-based networking using CLDC Generic Connection framework MIDP 1.0 spec and implementation available for download now Example J2ME Technology Wireless Device Stack CLDC = KVM + J2ME Core APIs in this example Mobile Information Device Profile KVM Your MIDlet J2ME core APIs DSP chip (e.g., ARM) Yellow Pages, train schedules and ticketing, games UI, HTTP networking... Threads, no Floats 32-bit RISC, 256K ROM, 256K Flash, 64K RAM 6
What About Web Content for Mobile Devices? Markup languages in use today to deliver Web content to device browsers: Compact HTML (C-HTML) is an HTML-based markup deployed to millions of users in NTT DoCoMo s i-mode network The WAP Forum s Wireless Markup Language (WML) is an emerging standard for content (data) delivered to mobile devices HTML dominates Web content worldwide WAP specifies its own protocols (Wireless Session Protocol, Wireless Transaction Protocol, etc.) Wireless Web Content Distribution Content Producers Carriers or Wireless Portals Client Devices Static Content Web Server or WAP Gateway Web or WML Browser Dynamic Content Java Applications Content Transcoding Applicati on Distribut ion Application Distribution Java Apps Java Application Manager MID Profile J2ME CLDC 7
Example Java Technology Application Loading Process Advertise App on Web Page User Selects App JAM Downloads App Web Page (Name, Version, Size, ) Descriptor File Network Transfer Java Application Manager Jar File The Future: Transcoding and XHTML Transcoders are becoming more capable and widely used WML, C-HTML, and HTML are converging towards XHTML XHTML is the re-writing of HTML as an XMLbased markup language XHTML Basic will be renderable everywhere WAP Forum and W3C collaborating on XHTML WML CHTML HTML XHTML The not too distant future... 8
CLDC Internals and Details Scope of the CLDC Specification Specifies VM features required of CLDC implementation in terms of additions to and deviations from The Java Virtual Machine Specification by Lindholm and Yellin Specifies requirements for interfaces and APIs for the following: Input/output, Networking Security model Internationalization features 9
Beyond the CLDC Scope Specified in Profiles to be implemented on top of the CLDC: User interface support Event handling High-level application model Persistence support One example specification of these remaining APIs: Mobile Information Device Profile (MIDP) CLDC Language and VM Compatibility General goal: Full Java programming language and Virtual Machine Specification compatibility Only language-level exception: Floating point not in CLDC 1.0 No hardware floating point support on most devices due to space limitations Manufacturers and/or developers may choose to include their own floating point, however 10
CLDC Language and VM Compatibility VM Implementation differences: No Java Native Interface (JNI) No reflection No thread groups No weak references No finalization New implementation of bytecode verification using preverifier and bytecode annotations CLDC Libraries Classes inherited from Java 2 Platform, Standard Edition (J2SE version 1.3) are in packages: java.lang.* java.util.* java.io.* New classes introduced by CLDC are in package: javax.microedition.* 11
CLDC Libraries: java.lang.* java.lang.object java.lang.class java.lang.runtime java.lang.system java.lang.thread java.lang.runnable java.lang.string java.lang.stringbuffer java.lang.math java.lang.throwable java.lang.byte java.lang. Long java.lang.integer java.lang.boolean java.lang.character java.lang.short CLDC Libraries: java.util.* java.util.vector java.util.stack java.util.hashtable java.util.enumeration java.util.random java.util.calendar 12
CLDC Libraries: java.io.* java.io.inputstream java.io.reader java.io.datainput java.io.inputstreamreader java.io.outputstreamreader java.io.bytearrayinputstream java.io.bytearrayoutputstream java.io.printstream java.io.outputstream java.io.writer java.io.dataoutput Comments on CLDC Libraries Internationalization Limited support for the translation of Unicode characters to and from a sequence of bytes Implemented using Readers and Writers By default, the only character encoding for which a converter is provided in ISO-LATIN1 Localization implemented by manufacturer Property support No java.util.properties class Properties read using System.getProperty(String key) Limited set of CLDC-specific properties supported 13
Networking, I/O and Storage Libraries Standard Java technology networking, I/O and storage libraries are too large for CLDC devices More than 100 classes Total static size of classfiles more than 200 KB Original classes were never designed for small devices Networking, I/O and Storage Libraries CLDC specifies an alternative Generic Connection framework More coherence in supporting different types of I/O Consistent way of supporting different protocols Improved portability of applications Smaller footprint 14
Generic Connection Possibilities General form: Connector.open("<protocol>://<address>:<parameters>"); 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 Primary goals: Size: MIDP implementation must fit in small footprint (128KB ROM) Efficiency: must run on low-end microprocessors must run in with limited heap size (32 200KB RAM) minimal creation of garbage Time to market is critical for manufacturers of Mobile Information Devices Beyond the MIDP Scope To be implemented by device manufacturers, operators, or third party developers: How an application actually gets on the device The end-to-end security model System- or OEM-specific technologies 16
MIDP Application Lifecycle MIDP applications are known as MIDlets MIDlets move from state to state in the lifecycle, as indicated. Start acquire resources and start executing Pause release resources and become quiescent (wait) Destroy release all resources, destroy threads, and end all activity MIDlet Packaging MIDlets are packaged in a JAR file including Class files of the MIDlet(s) Resource files Manifest with application properties Application Descriptors accompany MIDlet JARs and provide information including Configuration properties Pre-download properties Size, version, storage requirements 17
MIDP Libraries The MIDP specifies APIs for: Persistent Storage Networking Timers User Interface MIDP Persistent Storage Lightweight record oriented database Device independent API Unique record ID for each record within a store Records are arrays of bytes Shared within MIDlet suite Atomic update for single records Support for enumeration, sorting and filtering Device platform is responsible for: Integrity of data across reboots, battery changes Storage in flash or other device memory 18
MIDP Persistent Storage: RMS Methods Record Store openrecordstore, closerecordstore, listrecordstore, deleterecordstore, getrecordsize, getnumrecords Record Data addrecord, deleterecord, getrecord, setrecord, getrecordsize Record Selection RecordEnumeration, RecordFilter, RecordCompare MIDP Networking MIDP devices must implement HTTP protocol, though this may or may not use IP-based transport underneath 19
MIDP Networking Methods MIDP networking extends from CLDC Generic Connection Framework HttpConnection includes methods: get/setrequestproperty get/setrequestmethod getresponsecode, getresponsemessage getheaderfield geturl, gethost, getport, getfile, getquery, getref (Parsed URL components) MIDP Timer Methods Timer handles queuing and delivery Timer Task Multiple Tasks per Timer Periodic Fixed interval One shots 20
MIDP UI Design Principles MIDP must be usable in all devices Majority of wireless devices are one-hand operated Small screen (tens of pixels by tens of pixels) Not all devices have a pointing device Must constantly think of end users: Mobile Information Devices are consumer products, not desktop computers Unified user interface between MIDP applications and native apps on the device MIDP applications should behave consistently with resident functionality MIDP UI: A Tale of Two Layers MIDP UIs may be created using one of two layers of APIs Use the high-level APIs for portability Applications using these APIs should be runnable and usable in all MIDP devices No direct access to native device features Low-level APIs Provide access to native drawing primitives, device key events, native input devices, etc. Allow developers to choose to compromise portability for user experience, if needed 21
MIDP Screen-based Design Principles MIDlet UIs are built using simple screens Screens should contain minimum amount of information required Usually only one "thing" Screens should require only simple interactions from user No complex traversing, scrolling, or selection metaphors MIDP UI Class Hierarchy (major classes only) Canvas Displayable Screen 0-n Command Choice TextBox ChoiceGroup List Alert Form 1-n Item DateField TextField Gauge ImageItem TextItem 22
MIDP Input Handling High-level API input is handled using abstract commands instead of direct access to soft buttons Each MIDP implementation maps these commands to appropriate soft buttons or menu items for the particular device MIDlets can provide semantic hints (like back) Low-level API gives developers access to key press events MIDP Input Commands Example MIDP input commands: new Command("Buy", Command.SCREEN); new Command("Info", Command.SCREEN); new Command("Back", Command.BACK); Ford Opel BMW Options Back Pressing "options" opens a menu Buy Info Back 23
Availability and Resources Java Technology in Mobile Devices: Where Are We Today? Sun s CLDC implementation supports development using Solaris, Win32, PalmOS KVM ports to Linux, Motorola devices, Nokia phones, RIM handhelds, and more Symbian continues support for Java technology in current and upcoming releases of EPOC LG deployed J2ME technology in Korean mobile network beginning summer 2000 NTT DoCoMo deployed Java technology in i-mode service January 2001 Agreements and projects with Vodaphone AirTouch, One 2 One, Sprint PCS, Telefonica, and many others 24
The J2ME Platform and Mobile Phone Standards Special Mobile Group (SMG) Working group of European Telecommunications Standards Institute (ETSI) Specifies Mobile Station Application Execution Environment (MExE) for GSM mobile phone handsets SMG has adopted PersonalJava technologies as part of the MExE Release 98, classmark 2 spec for GSM handsets 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 Impl. Mailing list K Virtual Machine J2ME core Yes, part of CLDC Yes Yes, 1.0 Yes Connected, Limited Device Configuration Mobile Information Device Profile tech J2ME Config. J2ME Profile JSR-30, 1.0 JSR-37, 1.0 Yes Yes, 1.0 Yes via KVM list Yes Yes, 1.0 Yes via KVM list 25
J2ME Platform CLDC and MIDP Development Tools Sun J2ME Wireless Toolkit (optionally plugs into free Forte for Java IDE) MIDP reference, CLDC/KVM Software Development Kit (SDK), with support for Win32, Solaris platform, and PalmOS RIM BlackBerry IDE, Motorola J2ME SDK, KVM for Linux Any IDE or standard Java tool, including J2SE SDK (aka JDK 1.2.2 or 1.3) Tools from the J2ME Archive (Spotter utility, WBXML package, etc.) 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: PalmOS Emulator Example 4: Sun MIDP Reference Example 5: RIM BlackBerry Java Development Environment 27
J2ME Development Tools They are available NOW. They are FREE. They are all you need to start writing great Java applications for mobile devices TODAY. Discuss the J2ME Platform The kvm-interest mailing list is a free J2ME development list hosted by Sun To subscribe, send email to: listserv@java.sun.com In the body of the message, type: subscribe kvm-interest For digest mode, include the following line: set kvm-interest digest The kvm-interest archive is searchable online at: archives.java.sun.com/archives/kvm-interest.html 28
J2ME Platform CLDC and MIDP Resources J2ME: java.sun.com/j2me Connected, Limited Device Configuration specification and SDK: java.sun.com/products/cldc Mobile Information Device Profile specification and reference implementation: java.sun.com/products/midp Download the Sun J2ME Wireless Toolkit: java.sun.com/products/j2mewtoolkit J2ME Webcast: java.sun.com/jdc/onlinetraining/webcasts Additional Resources J2ME Archive: www.billday.com/j2me jguru J2ME FAQ: www.jguru.com/faq/j2me J2ME tutorial articles: java.sun.com/jdc/technicalarticles/wireless AnywhereYouGo developer portal: www.anywhereyougo.com WirelessDevNet developer portal: www.wirelessdevnet.com 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 Card, 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