Developing Wireless Applications Using Java(TM)

Transcription

Developing Wireless Applications Using Java(TM)
Developing Wireless
Applications using
Java™ Technology
Bill Day
[email protected]
www.billday.com
Technology Evangelist
Sun Microsystems
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
l
l
l
l
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
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
Optional
Packages
Optional
Packages
Java 2
Enterprise
Edition
(J2EE)
Core APIs
Java 2
Standard
Edition
(J2SE)
Core APIs
Personal
Profile
RMI
Profile
Other
CDC
Profiles
...
Foundation
Profile
Mobile Information
Device Profile
Java
Card
APIs
Java 2 Micro Edition Core APIs
Java Programming Language
Java HotSpot ™
Java Virtual Machine (JVM)
KVM
Card VM
What Is a Configuration?
l
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
A J2ME platform configuration defines
a minimum Java platform for a family
of devices
Broad range of devices in different areas
u Similar requirements of memory size and
processing capabilities
u
3
Configurations
l
l
l
May not contain any optional features
Defined through the Java Community
ProcessSM initiative (JCP)
Subject to compatibility tests
What Is a Profile?
l
l
l
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)
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
l
CLDC 1.0 specification available for
free download now
Sun provides CLDC reference
implementation built using the KVM
5
Mobile Information
Device Profile (MIDP)
l
l
Targets mobile two-way
communication devices implementing
J2ME CLDC
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
MIDlet
Mobile
Information
Device
Profile
Yellow Pages, train
schedules and ticketing,
games…
UI, HTTP
networking...
J2ME core APIs
CLDC =
KVM +
J2ME
Core
APIs
in this
example
KVM
DSP chip
(e.g., ARM)
Threads, no Floats…
32-bit RISC, 256K ROM,
256K Flash, 64K RAM
6
What About Web Content
for Mobile Devices?
l
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
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
u
l
WAP specifies its own protocols
(Wireless Session Protocol, Wireless
Transaction Protocol, etc.)
Wireless Web
Content Distribution
Content
Producers
Static
Content
Carriers
or Wireless
Portals
Web Server
or WAP
Gateway
Client
Devices
Web or WML
Browser
Java Apps
Dynamic
Content
Java
Applications
Content
Transcoding
Applicati
Application
on
Distribution
Distribut
ion
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
l
l
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
u XHTML Basic will be renderable everywhere
u WAP Forum and W3C collaborating on XHTML
u
WML
CHTML
XHTML
The not
too distant
future...
HTML
8
CLDC Internals and Details
Scope of the
CLDC Specification
l
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
Specifies requirements for interfaces and
APIs for the following:
Input/output, Networking
u Security model
u Internationalization features
u
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
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
n
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
l
l
l
l
l
l
l
java.lang.Object
java.lang.Runtime
java.lang.Thread
java.lang.String
java.lang.Math
java.lang.Byte
java.lang.Integer
java.lang.Character
java.lang.Class
java.lang.System
java.lang.Runnable
java.lang.StringBuffer
java.lang.Throwable
java.lang. Long
java.lang.Boolean
java.lang.Short
CLDC Libraries: java.util.*
l
l
l
java.util.Vector
java.util.Hashtable
java.util.Random
java.util.Stack
java.util.Enumeration
java.util.Calendar
12
CLDC Libraries: java.io.*
l
l
l
l
l
l
l
l
java.io.InputStream java.io.OutputStream
java.io.Reader
java.io.Writer
java.io.DataInput
java.io.DataOutput
java.io.InputStreamReader
java.io.OutputStreamReader
java.io.ByteArrayInputStream
java.io.ByteArrayOutputStream
java.io.PrintStream
Comments on CLDC Libraries
l
Internationalization
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
u
l
Property support
No java.util.Properties class
u Properties read using
System.getProperty(String key)
u Limited set of CLDC-specific properties
supported
u
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("<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
l
Primary goals:
u Size:
MIDP implementation must fit in
small footprint (128KB ROM)
u Efficiency:
must run on low-end microprocessors
must run in with limited heap size (32–200KB
RAM)
n minimal creation of garbage
n
n
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
l
MIDP applications are
known as “MIDlets”
MIDlets move from state to
state in the lifecycle, as
indicated.
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
u
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
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
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,
RecordCompare
RecordFilter,
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
l
Timer handles queuing and delivery
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
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
u
l
Must constantly think of end users:
Mobile Information Devices are consumer
products, not desktop computers
u Unified user interface between MIDP
applications and native apps on the device
u
n
MIDP applications should behave
consistently with resident functionality
MIDP UI: A Tale of Two Layers
l
l
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
u No direct access to native device features
u
l
Low-level APIs
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
u
21
MIDP Screen-based Design
Principles
l
l
MIDlet UIs are built using simple
screens
Screens should contain minimum
amount of information required
u Usually
l
only one "thing"
Screens should require only simple
interactions from user
u No
complex traversing, scrolling, or
selection metaphors
MIDP UI Class Hierarchy
(major classes only)
Displayable
Canvas
0-n
Command
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
Options Back
Pressing "options"
opens a menu
Back
23
Availability and Resources
Java™ Technology in Mobile
Devices: Where Are We Today?
l
l
l
l
l
l
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
l
Special Mobile Group (SMG)
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
u
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
K Virtual
Machine
J2ME
core
tech
J2ME
Config.
Yes, part
of CLDC
J2ME
Profile
Connected,
Limited Device
Configuration
Mobile
Information
Device Profile
FAQ Reference
Impl.
Yes Yes, 1.0
Mailing
list
Yes
JSR-30,
1.0
Yes
Yes, 1.0
JSR-37,
1.0
Yes
Yes, 1.0
Yes via
KVM
list
Yes via
KVM
list
25
J2ME™ Platform CLDC and
MIDP Development Tools
l
l
l
l
l
l
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
l
l
l
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
l
The kvm-interest mailing list is a free J2ME
development list hosted by Sun
u
u
u
l
To subscribe, send email to:
[email protected]
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
l
l
l
l
l
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
l
l
l
l
l
l
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