Скачать презентацию Wireless Application Programming with Java School of Technology Скачать презентацию Wireless Application Programming with Java School of Technology

7dc125aef8a09fcbee9591fd133e6456.ppt

  • Количество слайдов: 101

Wireless Application Programming with Java School of Technology of Setubal, Portugal April 9, 2002 Wireless Application Programming with Java School of Technology of Setubal, Portugal April 9, 2002 Qusay H. Mahmoud School of Computing Science Simon Fraser University, Burnaby, B. C. , Canada qmahmoud@cs. sfu. ca http: //www. javacourses. com Copyright © 2001 javacourses. com 1

You will learn: z. What is the J 2 ME platform? z. How does You will learn: z. What is the J 2 ME platform? z. How does it differ from J 2 SE? z. KVM (Kilo Virtual Machine) z. Configurations and Profiles y. CLDC and MIDP y. CDC, Foundation, Personal, RMI z. How to get started developing wireless applications using the J 2 ME platform http: //www. javacourses. com Copyright © 2001 javacourses. com 2

Outline z Web Content for Mobile Devices z WAP Programming Model z J 2 Outline z Web Content for Mobile Devices z WAP Programming Model z J 2 ME Platform z KVM (Kilo Virtual Machine) z Configurations and Profiles y. CLDC (Connected Limited Device Configuration) y. MIDP (Mobile Information Device Profile) z Examples z Availability and Resources http: //www. javacourses. com Copyright © 2001 javacourses. com 3

Web Content for Mobile Devices z. Markup languages to deliver Web content to device Web Content for Mobile Devices z. Markup languages to deliver Web content to device browsers: y. HDML x. Phone. com (now Openwave) y. Compact HTML (c. HTML) x. NTT Do. Co. Mo’s i-mode network y. WAP Forum’s WML x. An emerging standard for content delivered to mobile devices http: //www. javacourses. com Copyright © 2001 javacourses. com 4

WAP Network Structure z. The WAP Gateway plays an important role http: //www. javacourses. WAP Network Structure z. The WAP Gateway plays an important role http: //www. javacourses. com Copyright © 2001 javacourses. com 5

WAP Programming Model z. Similar to the Web programming model with extensions for the WAP Programming Model z. Similar to the Web programming model with extensions for the wireless environment http: //www. javacourses. com Copyright © 2001 javacourses. com 6

WML Example

My First WML Example

http: //www. javacourses. com Copyright © 2001 javacourses. com 7

Transcoding Proxies z. Transcoding proxies are becoming more capable and widely used z. HTML, Transcoding Proxies z. Transcoding proxies are becoming more capable and widely used z. HTML, c. HTML, and WML are converging towards XHTML z. XHTML is the re-writing of HTML as an XMLbased markup language http: //www. javacourses. com Copyright © 2001 javacourses. com 8

Java 2 Platform z. Virtual Machines and horizontal and vertical APIs specified in configurations Java 2 Platform z. Virtual Machines and horizontal and vertical APIs specified in configurations and Profiles Source: j 2 me white paper http: //www. javacourses. com Copyright © 2001 javacourses. com 9

Configurations z. A configuration defines the minimum APIs and VM capabilities for a family Configurations z. A configuration defines the minimum APIs and VM capabilities for a family of devices: y. Similar requirements of memory size and processing capabilities z. The minimum APIs that an application developer can expect to be available on implementing devices http: //www. javacourses. com Copyright © 2001 javacourses. com 10

Configurations z. May not contain any optional features z. Defined through the Java Community Configurations z. May not contain any optional features z. Defined through the Java Community Process (JCP) yhttp: //java. sun. com/jcp (www. jcp. org) z. Subject to compatibility tests http: //www. javacourses. com Copyright © 2001 javacourses. com 11

Profiles z. A profile is a collection of APIs that supplement a configuration to Profiles z. A profile is a collection of APIs that supplement a configuration to provide capabilities for a specific vertical market z. Defined through Java Community Process initiative (www. jcp. org) z. Subject to compatibility tests http: //www. javacourses. com Copyright © 2001 javacourses. com 12

How do they fit together? z. Profiles are built on top of configurations http: How do they fit together? z. Profiles are built on top of configurations http: //www. javacourses. com Copyright © 2001 javacourses. com 13

CLDC z. Targeted at devices with: y 160 to 512 KB of total memory CLDC z. Targeted at devices with: y 160 to 512 KB of total memory available for Java technology y. Limited power (e. g. battery) y. Limited connectivity to a network (wireless) y. Constrained User Interface (small screen) z. It is available for free download z. Reference implementation built using KVM http: //www. javacourses. com Copyright © 2001 javacourses. com 14

MIDP z. Targets mobile two-way communication devices implementing the CLDC z. It addresses: y. MIDP z. Targets mobile two-way communication devices implementing the CLDC z. It addresses: y. Display toolkit (user input) y. Persistent data storage y. HTTP based networking using CLDC generic connection framework z. Available for free download http: //www. javacourses. com Copyright © 2001 javacourses. com 15

KVM z. Stands for Kilo Virtual Machine z. Originated from a research project called KVM z. Stands for Kilo Virtual Machine z. Originated from a research project called Spotless at Sun Research Labs z. Implements the classes defined in the CLDC specification + some additional UI classes z. Note: the UI classes are not part of the CLDC and can be removed at any time http: //www. javacourses. com Copyright © 2001 javacourses. com 16

KVM… z. A complete runtime environment for small devices z. Built from the ground KVM… z. A complete runtime environment for small devices z. Built from the ground up in C z. Small footprint (40 – 80 KB) z. Class file verification takes place off-device z. Supports multi-threading z. Supports garbage collection http: //www. javacourses. com Copyright © 2001 javacourses. com 17

KVM Security z. VM level security y. Off-device pre-verification y. Small in-device verification z. KVM Security z. VM level security y. Off-device pre-verification y. Small in-device verification z. Application level security y. No Security Manager y. Sandbox security model: x. Applications run in a closed environment x. Applications can call classes supported by the device http: //www. javacourses. com Copyright © 2001 javacourses. com 18

KVM z. It runs on Solaris, Win 32, and Palm. OS y. MIDP 4 KVM z. It runs on Solaris, Win 32, and Palm. OS y. MIDP 4 Palm (java. sun. com/products/midp 4 palm) http: //www. javacourses. com Copyright © 2001 javacourses. com 19

Wireless Device Stack MIDlet Other Profiles MIDP Train Schedule UI HTTP CLDC APIs KVM Wireless Device Stack MIDlet Other Profiles MIDP Train Schedule UI HTTP CLDC APIs KVM No floats Host OS http: //www. javacourses. com Copyright © 2001 javacourses. com 20

CLDC Internals z. The CLDC specification specifies VM features required by a CLDC implementation CLDC Internals z. The CLDC specification specifies VM features required by a CLDC implementation z. Specifies requirements and APIs for y. Input/Output y. Networking http: //www. javacourses. com Copyright © 2001 javacourses. com 21

Beyond the CLDC scope z. Profiles implemented on top of CLDC specify APIs for: Beyond the CLDC scope z. Profiles implemented on top of CLDC specify APIs for: y. User Interface support y. Event handling y. Persistent support y. High-level application model z. An example profile is the Mobile Information Device Profile (MIDP) http: //www. javacourses. com Copyright © 2001 javacourses. com 22

Language & VM Compatibility z. Goal: y. Full java language and VM specification compatibility Language & VM Compatibility z. Goal: y. Full java language and VM specification compatibility z. Language-level exception: y. No floating point support in CLDC 1. 0 x. No hardware floating point support x. Manufacturers and developers can include their own floating point http: //www. javacourses. com Copyright © 2001 javacourses. com 23

CLDC vs. J 2 SE JVM z. Limitations in CLDC supporting JVM: y. No CLDC vs. J 2 SE JVM z. Limitations in CLDC supporting JVM: y. No floating point support y. No finalization y. Limited error handling y. No Java Native Interface (JNI) y. No support for reflection y. No thread groups or daemon threads y. No weak references http: //www. javacourses. com Copyright © 2001 javacourses. com 24

CLDC APIs z. Classes inherited from J 2 SE v 1. 3 are in CLDC APIs z. Classes inherited from J 2 SE v 1. 3 are in packages: yjava. lang yjava. io yjava. util z. New classes introduced by the CLDC are in package: yjavax. microedition http: //www. javacourses. com Copyright © 2001 javacourses. com 25

CLDC Libraries: java. lang. * z Boolean z Byte z Character z Class z CLDC Libraries: java. lang. * z Boolean z Byte z Character z Class z Integer z Long z Math z Object z Runnable http: //www. javacourses. com z Runtime z Short z String. Buffer z System z Thread z Throwable Copyright © 2001 javacourses. com 26

CLDC Libraries: java. io. * z Byte. Array. Input. Stream z Byte. Array. Output. CLDC Libraries: java. io. * z Byte. Array. Input. Stream z Byte. Array. Output. Stream z Data. Input z Data. Output z Data. Input. Stream z Data. Output. Stream z Input. Stream http: //www. javacourses. com z Output. Stream z Input. Stream. Reader z Output. Stream. Writer z Print. Stream z Reader z Writer Copyright © 2001 javacourses. com 27

CLDC Libraries: java. util. * z Calendar z Date z Enumeration z Hashtable z CLDC Libraries: java. util. * z Calendar z Date z Enumeration z Hashtable z Random z Stack z Time. Zone z Vector http: //www. javacourses. com Copyright © 2001 javacourses. com 28

MIDP internals z Goal: y. MIDP implementation must fit in small footprint (128 KB MIDP internals z Goal: y. MIDP implementation must fit in small footprint (128 KB ROM) y. Must run with limited heap size (32 -200 KB RAM) z. To be implemented by device manufacturers, operators, or developers http: //www. javacourses. com Copyright © 2001 javacourses. com 29

MIDlets z. A MIDlet consists of a class that extends the MIDlet class and MIDlets z. A MIDlet consists of a class that extends the MIDlet class and other classes as needed z. To handle events it must implement the Command. Listener interface public class My. MIDlet extends MIDlet implements Command. Listener{ } http: //www. javacourses. com Copyright © 2001 javacourses. com 30

MIDP Application Lifecycle z MIDlets move from state to state in the lifecycle: y. MIDP Application Lifecycle z MIDlets move from state to state in the lifecycle: y. Start: acquire resources and start executing y. Pause: release resources and wait y. Destroyed: release all resources and end all activities Paused start. App pause. App Active destroy. App Destroyed http: //www. javacourses. com Copyright © 2001 javacourses. com 31

MIDlet Packaging z. Two or mode MIDlets form a MIDlet suite z. One or MIDlet Packaging z. Two or mode MIDlets form a MIDlet suite z. One or more MIDlets may be packaged in a single JAR file that includes: y. A manifest describing the contents y. Java classes for the MIDlet(s) y. Resource file(s) used by the MIDlet(s) z. Each jar file is accompanied by a Java Application Descriptor (JAD) file http: //www. javacourses. com Copyright © 2001 javacourses. com 32

MIDlet Packaging z. Java Application Descriptor (JAD) file provides info: y. Configuration properties y. MIDlet Packaging z. Java Application Descriptor (JAD) file provides info: y. Configuration properties y. Pre-download properties x. Size, version, storage requirements http: //www. javacourses. com Copyright © 2001 javacourses. com 33

Example MIDlet import javax. microedition. midlet. MIDlet; import javax. microedition. lcdui. *; public class Example MIDlet import javax. microedition. midlet. MIDlet; import javax. microedition. lcdui. *; public class First. MIDlet extends MIDlet { Display display = null; Text. Box tb = null; public First. MIDlet() { display = Display. get. Display(this); } http: //www. javacourses. com Copyright © 2001 javacourses. com 34

Example MIDlet … public void start. App() { tb = new Text. Box( Example MIDlet … public void start. App() { tb = new Text. Box("First. MIDlet", "Welcome to MIDP Programming", 40, 0); display. set. Current(tb); } public void pause. App() { } public void destroy. App(boolean unconditional) { } } } http: //www. javacourses. com Copyright © 2001 javacourses. com 35

Example MIDlet… z z Compile (javac) Preverify (off device preverification) Create a JAR file: Example MIDlet… z z Compile (javac) Preverify (off device preverification) Create a JAR file: first. jar Create a JAD file: first. jad y MIDlet-Name: My. First y MIDlet-Version: 1. 0. 0 y MIDlet-Vendor: Sun Microsystems, Inc. y MIDlet-Description: My First MIDlet y MIDlet-Info-URL: http: //java. sun. com/j 2 me/ y MIDlet-Jar-URL: first. jar y MIDlet-Jar-Size: 1063 y Micro. Edition-Profile: MIDP-1. 0 y Micro. Edition-Configuration: CLDC-1. 0 y MIDlet-1: My. First, , First. MIDlet http: //www. javacourses. com Copyright © 2001 javacourses. com 36

Example MIDlet: Testing zmidp –descriptor first. jad http: //www. javacourses. com Copyright © 2001 Example MIDlet: Testing zmidp –descriptor first. jad http: //www. javacourses. com Copyright © 2001 javacourses. com 37

MIDlet Example: Deploy z. To deploy a MIDlet on a web server, you need MIDlet Example: Deploy z. To deploy a MIDlet on a web server, you need to add a new MIME type: text/vnd. sun. j 2 me. app-descriptor jad z. Use the following command to run: midp -transient http: //hostname/path/first. jad http: //www. javacourses. com Copyright © 2001 javacourses. com 38

Simplifying the Development Effort z. Sun’s Wireless Toolkit http: //www. javacourses. com Copyright © Simplifying the Development Effort z. Sun’s Wireless Toolkit http: //www. javacourses. com Copyright © 2001 javacourses. com 39

MIDP APIs z. The MIDP specifies APIs for: y. User Interface y. Networking (based MIDP APIs z. The MIDP specifies APIs for: y. User Interface y. Networking (based on CLDC) y. Persistent Storage y. Timers http: //www. javacourses. com Copyright © 2001 javacourses. com 40

MIDP User Interface z. Not a subset of AWT or Swing because: y. AWT MIDP User Interface z. Not a subset of AWT or Swing because: y. AWT is designed for desktop computers y. Assumes certain user interaction models (pointing device such as a mouse) y. Window management (resizing overlapping windows). This is impractical for cell phones z. Consists of high-level and low-level APIs http: //www. javacourses. com Copyright © 2001 javacourses. com 41

MIDP UI APIs z. High-level API y. Applications should be runnable and usable in MIDP UI APIs z. High-level API y. Applications should be runnable and usable in all MIDP devices y. No direct access to native device features z. Low-level API y. Provide access to native drawing primitives, device key events, native input devices y. Allows developers to choose to compromise portability for user experience http: //www. javacourses. com Copyright © 2001 javacourses. com 42

MIDP UI Programming Model z. The central abstraction is a screen z. Only one MIDP UI Programming Model z. The central abstraction is a screen z. Only one screen may be visible at a time z. Three types of screens: y. Predefined screens with complex UI components (List, Text. Box) y. Generic screens (Form where you can add text, images, etc) y. Screens used with low-level API (Canvas) http: //www. javacourses. com Copyright © 2001 javacourses. com 43

MIDP UI and Display z. The Display class is the display manager z. It MIDP UI and Display z. The Display class is the display manager z. It is instantiated for each active MIDlet z. Provides methods to retrieve information about the device’s display capabilities z. A screen is made visible by calling: Display’s set. Current(screen); http: //www. javacourses. com Copyright © 2001 javacourses. com 44

MIDP UI Classes zjavax. microedition. lcdui classes: Alert, Alert. Type, Canvas, Choice. Group, Command, MIDP UI Classes zjavax. microedition. lcdui classes: Alert, Alert. Type, Canvas, Choice. Group, Command, Date. Field, Displayable, Font, Form, Gauge, Graphics, Image. Item, List, Screen, String. Item, Text. Box, Text. Field, Ticker zjavax. microedition. lcdui interfaces: Choice, Command. Listener, Item. State. Listener http: //www. javacourses. com Copyright © 2001 javacourses. com 45

MIDP UI Class Diagram z. Major classes and interfaces: http: //www. javacourses. com Copyright MIDP UI Class Diagram z. Major classes and interfaces: http: //www. javacourses. com Copyright © 2001 javacourses. com 46

High-Level API Examples z. List: Display display = Display. get. Display(this); List menu = High-Level API Examples z. List: Display display = Display. get. Display(this); List menu = new List(“Method of payment”, Choice. EXCLUSIVE); menu. append(“Visa”); menu. append(“Master. Card”); menu. append(“Amex”); display. set. Current(menu); http: //www. javacourses. com Copyright © 2001 javacourses. com 47

High-Level API Examples… z. Form (Date/Time info): Date. Field date = new Date. Field(“Today’s High-Level API Examples… z. Form (Date/Time info): Date. Field date = new Date. Field(“Today’s date”, Date. Field. TIME); Form form = new Form(“Date Info”); form. append(date); display. set. Current(form); http: //www. javacourses. com Copyright © 2001 javacourses. com 48

High-Level Examples… z Form (Sign in screen): Display display = Display. get. Display(this); Text. High-Level Examples… z Form (Sign in screen): Display display = Display. get. Display(this); Text. Field user. Name = new Text. Field(“Login. ID: ”, “”, 10, Text. Field. ANY); Text. Field password = new Text. Field(“Password: ”, “”, 10, Text. Field. PASSWORD); Form form = new Form(“Sign in”); form. append(user. Name); form. append(password); display. set. Current(form); http: //www. javacourses. com Copyright © 2001 javacourses. com 49

Low-level Example z Canvas: public class My. Canvas extends Canvas { public void paint(Graphics Low-level Example z Canvas: public class My. Canvas extends Canvas { public void paint(Graphics g) { g. set. Color(255, 0, 0); g. fill. Rect(0, 0, get. Width(), get. Height()); g. set. Color(255, 255); g. draw. String("Hello World!", 0, 0, g. TOP | g. LEFT); } } http: //www. javacourses. com Copyright © 2001 javacourses. com 50

Low-level Example… z Instantiate and display My. Canvas public class My. Midlet extends MIDlet Low-level Example… z Instantiate and display My. Canvas public class My. Midlet extends MIDlet { public My. Midlet() { // constructor } public void start. App() { Canvas canvas = new My. Canvas(); Display display = Display. get. Display(this); display. set. Current(canvas); } // pause. App() and destroy. App() } http: //www. javacourses. com Copyright © 2001 javacourses. com 51

Input Handling z. High-Level API input is handled using abstract commands y. No direct Input Handling z. High-Level API input is handled using abstract commands y. No direct access to soft buttons y. Commands are mapped to appropriate soft buttons or menu items http: //www. javacourses. com Copyright © 2001 javacourses. com 52

Input Handling: Example z Text. Box screen with commands: Display display = Display. get. Input Handling: Example z Text. Box screen with commands: Display display = Display. get. Display(this); Text. Box tb = new Text. Box(“MIDP”, “Welcome to MIDP Programming”, 40, Text. Field. ANY); Command exit = new Command(“Exit”, Command. SCREEN, 1); Command info = new Command(“Info”, Command. SCREEN, 2); Command buy = new Command(“Buy”, Command. SCREEN, 2); tb. add. Command(exit); tb. add. Comment(info); tb. add. Command(buy); display. set. Current(tb); http: //www. javacourses. com Copyright © 2001 javacourses. com 53

Event Handling: High-level z. High-level Events: y. Based on a listener model y. Screen Event Handling: High-level z. High-level Events: y. Based on a listener model y. Screen objects can have listeners for commands y. For an object to be a listener, it must implement the Command. Listener interface y. This interface has one method: command. Action http: //www. javacourses. com Copyright © 2001 javacourses. com 54

Event Handling: Example z MIDlet implements Command. Listener public class My. MIDlet extends MIDlet Event Handling: Example z MIDlet implements Command. Listener public class My. MIDlet extends MIDlet implements Command. Listener { Command exit. Command = new Command(…); // other stmts public void command. Action(Command c, Displayable s) { if (c == exit. Command) { destroy. App(false); notify. Destroyed(); } } } http: //www. javacourses. com Copyright © 2001 javacourses. com 55

Event Handling: Example z Handling List events: public void command. Action(Command c, Displayable d) Event Handling: Example z Handling List events: public void command. Action(Command c, Displayable d) { if (c == exit. Command) {. . } else { List down = (List)display. get. Current(); switch(down. get. Selected. Index()) { case 0: test. Text. Box(); break; case 1: test. List(); break; case 2: test. Alert(); break; case 3: test. Date(); break; case 4: test. Form(); break; } http: //www. javacourses. com Copyright © 2001 javacourses. com 56

Event Handling: Low-level z. Low-level Events: y. Low-level API gives developers access to key Event Handling: Low-level z. Low-level Events: y. Low-level API gives developers access to key press events y. Key events are reported with respect to key codes y. MIDP defines key codes: KEY_NUM 0. . KEY_NUM 9, KEY_STAR, KEY_POUND http: //www. javacourses. com Copyright © 2001 javacourses. com 57

Handling Events: example z Low-level events protected void key. Pressed(int key. Code) { if Handling Events: example z Low-level events protected void key. Pressed(int key. Code) { if (key. Code > 0) { System. out. println("key. Pressed " +((char)key. Code)); } else { System. out. println("key. Pressed action “ +get. Game. Action(key. Code)); } } http: //www. javacourses. com Copyright © 2001 javacourses. com 58

MIDP UI Design Principles z. Make the UI simple and easy to use z. MIDP UI Design Principles z. Make the UI simple and easy to use z. Use the high-level API (portability) z. If you need to use low-level API, keep to the platform-independent part z. MIDlets should not depend on any specific screen size z. Entering data is tedious, so provide a list of choices to select from http: //www. javacourses. com Copyright © 2001 javacourses. com 59

Networking z. J 2 SE and J 2 EE networking APIs are not suitable Networking z. J 2 SE and J 2 EE networking APIs are not suitable for handheld devices y. Require several megabytes of memory to run y. Device manufacturers who work with circuitswitched networks require TCP support y. Device manufacturers who work with packetswitched networks require UDP support y. Other devices have specific mechanisms for communications http: //www. javacourses. com Copyright © 2001 javacourses. com 60

CLDC Generic Connections z. A set of related abstractions at the programming level z. CLDC Generic Connections z. A set of related abstractions at the programming level z. No abstractions for different forms of communications z. All connections are created using the Connector. open() z. If successful, it returns an object that implements one of the generic connection interfaces http: //www. javacourses. com Copyright © 2001 javacourses. com 61

Connection Interfaces http: //www. javacourses. com Copyright © 2001 javacourses. com 62 Connection Interfaces http: //www. javacourses. com Copyright © 2001 javacourses. com 62

Example Connections z. HTTP: Connector. open(“http: //www. host. com”); z. Socket: Connector. open(“socket: //host. Example Connections z. HTTP: Connector. open(“http: //www. host. com”); z. Socket: Connector. open(“socket: //host. com: 80”); z. Datagram: Connector. open(“datagram: //address: port”); z. File: Connector. open(“file: /myfile. txt”); http: //www. javacourses. com Copyright © 2001 javacourses. com 63

Advantages of CLDC Generic Connections z. Isolate the differences between the setup of one Advantages of CLDC Generic Connections z. Isolate the differences between the setup of one protocol and another z. Most of the application code remains the same regardless of the protocol you use z. Note: CLDC itself does not provide any protocol implementation http: //www. javacourses. com Copyright © 2001 javacourses. com 64

MIDP Connectivity z. It provides support for HTTP (Http. Connection) z. Why? HTTP can MIDP Connectivity z. It provides support for HTTP (Http. Connection) z. Why? HTTP can be implemented using IP protocols or non-IP protocols http: //www. javacourses. com Copyright © 2001 javacourses. com 65

Http. Connection z. Part of the javax. microedition. io z. Defines the necessary methods Http. Connection z. Part of the javax. microedition. io z. Defines the necessary methods and constants for an HTTP connection Http. Connection c = (Http. Connection) Connector. open(“http: //quotes. yahoo. com”); C. set. Request. Method(Http. Connection. POST); C. set. Request. Property(“Content-Language”, “en-CA”); http: //www. javacourses. com Copyright © 2001 javacourses. com 66

Invoking Remote Applications z. A MIDlet may invoke remote applications: y. Fetching a page Invoking Remote Applications z. A MIDlet may invoke remote applications: y. Fetching a page y. Invoking a CGI script (GET or POST method) y. Invoking a Servlet http: //www. javacourses. com Copyright © 2001 javacourses. com 67

Example: Invoke a CGI Script z GET Method: String url = “http: //host/cgi-bin/getgrade? idnum=182061”; Example: Invoke a CGI Script z GET Method: String url = “http: //host/cgi-bin/getgrade? idnum=182061”; c = (Http. Connection) Connector. open(url); c. set. Request. Method(Http. Connection. GET); // set some request properties: c. set. Request. Propert(“ “, “ “); is = c. open. Data. Input. Stream(); while((ch = is. read()) != -1) { b. append((char)ch); } http: //www. javacourses. com Copyright © 2001 javacourses. com 68

Example… z. If you want to send data to a remote application: String s Example… z. If you want to send data to a remote application: String s = “stuff. To. Send”; byte postmsg[] = s. get. Bytes(); for(int i=0; i

Servlet as a Mediator z Devices with no IP stack may access and use Servlet as a Mediator z Devices with no IP stack may access and use ‘net services through a servlet http: //www. javacourses. com Copyright © 2001 javacourses. com 70

Databases z. A persistent storage: a place to store the state of objects z. Databases z. A persistent storage: a place to store the state of objects z. Facilities provided in J 2 SE and J 2 EE are not suitable for handheld devices z. MIDP provides a record-oriented database mechanism to persistently store data and retrieve it later http: //www. javacourses. com Copyright © 2001 javacourses. com 71

MIDP’s RMS z. Lightweight record-oriented database y. Device independent API y. Unique record. ID MIDP’s RMS z. Lightweight record-oriented database y. Device independent API y. Unique record. ID for each record within the store y. A record is an array of bytes y. Shared within MIDlet suite y. Support for enumeration, sorting, and filtering zjavax. microedition. rms http: //www. javacourses. com Copyright © 2001 javacourses. com 72

MIDP RMS Methods z. Record Store open. Record. Store, close. Record. Store, list. Record. MIDP RMS Methods z. Record Store open. Record. Store, close. Record. Store, list. Record. Store, delete. Record. Store, get. Record. Size, get. Num. Records z. Record Data add. Record, delete. Record, get. Record, set. Record, get. Record. Size z. Record Selection Record. Enumeration, Record. Filter, Record. Comparator http: //www. javacourses. com Copyright © 2001 javacourses. com 73

RMS: Record Stores z. To open a record store: y. Record. Store db = RMS: Record Stores z. To open a record store: y. Record. Store db = Record. Store. open. Record. Store(“my. DB”, true); z. To close a record store: ydb. close. Record. Store(); http: //www. javacourses. com Copyright © 2001 javacourses. com 74

Create/Add a new record z To create a new record: Byte. Array. Output. Stream Create/Add a new record z To create a new record: Byte. Array. Output. Stream baos = new Byte. Array. Output. Stream() Data. Output. Stream dos = new Data. Output. Stream(baos); dos. write. UTF(record); Byte b[] = baos. to. Byte. Array(); db. add. Record(b, 0, b. length); http: //www. javacourses. com Copyright © 2001 javacourses. com 75

Building a Stock Database z. See appendix for source code: y. Stock. java y. Building a Stock Database z. See appendix for source code: y. Stock. java y. Stock. DB. java y. Quotes. MIDlet. java http: //www. javacourses. com Copyright © 2001 javacourses. com 76

Stock. Quotes MIDlet http: //www. javacourses. com Copyright © 2001 javacourses. com 77 Stock. Quotes MIDlet http: //www. javacourses. com Copyright © 2001 javacourses. com 77

MIDP Timers z. Handle queuing and delivery z. Timer task: y. Multiple tasks per MIDP Timers z. Handle queuing and delivery z. Timer task: y. Multiple tasks per timer y. Periodic y. Fixed interval y. One-time execution http: //www. javacourses. com Copyright © 2001 javacourses. com 78

Tasks z. To define a task, create a subclass of Timer. Task: import java. Tasks z. To define a task, create a subclass of Timer. Task: import java. util. *; public class My. Task extends Timer. Task { public void run() { System. out. println(“Run Task”); } } http: //www. javacourses. com Copyright © 2001 javacourses. com 79

Tasks… z. Schedule it for execution by creating a Timer object and invoking schedule() Tasks… z. Schedule it for execution by creating a Timer object and invoking schedule() Timer timer = new Timer(); Timer. Task task = new My. Task(); // wait five seconds before executing timer. schedule(task, 5000); // wait two seconds before executing then // execute every five seconds timer. schedule(task, 2000, 5000); http: //www. javacourses. com Copyright © 2001 javacourses. com 80

MIDP Next Generation z. MIDP NG will: y. Maintain backward compatibility with MIDP 1. MIDP Next Generation z. MIDP NG will: y. Maintain backward compatibility with MIDP 1. 0 y. Continue focus on wireless phones y. Maintain small footprint (limit API growth) y. Fine tune MIDP 1. 0 APIs y. Enable mobile commerce http: //www. javacourses. com Copyright © 2001 javacourses. com 81

MIDP Next Generation z. Areas to investigate: y. HTTPS and secure networking (SSL) y. MIDP Next Generation z. Areas to investigate: y. HTTPS and secure networking (SSL) y. Network connectivity via sockets and datagrams y. Formal inclusion of Over The Air Provisioning y. Inclusion of a small XML Parser y. Sound API http: //www. javacourses. com Copyright © 2001 javacourses. com 82

MIDP for Palm OS >= 3. 5 z. A J 2 ME application runtime MIDP for Palm OS >= 3. 5 z. A J 2 ME application runtime environment based on CLDC 1. 0 and MIDP 1. 0 z. It is targeted at handheld devices (such as Palm Pilot, Handspring Visor) running Palm OS 3. 5 or higher. z. Java Manager: MIDP. PRC http: //www. javacourses. com Copyright © 2001 javacourses. com 83

MIDP for Palm OS z. To install: y. Place palm device in the craddle MIDP for Palm OS z. To install: y. Place palm device in the craddle y. Use Palm Desktop Software to install MIDP. PRC http: //www. javacourses. com Copyright © 2001 javacourses. com 84

MIDP for Palm OS z. Comes with a PRC converter tool y. C: midp MIDP for Palm OS z. Comes with a PRC converter tool y. C: midp 4 palmjava –jar Converter. jar http: //www. javacourses. com Copyright © 2001 javacourses. com 85

MIDP for Palm OS z. Install GUI. PRC http: //www. javacourses. com Copyright © MIDP for Palm OS z. Install GUI. PRC http: //www. javacourses. com Copyright © 2001 javacourses. com 86

MIDP for Palm OS z. To have more control, use command line tool: z. MIDP for Palm OS z. To have more control, use command line tool: z. Converting a single MIDlet JAR to PRC file yjava –jar Make. MIDPApp. jar –nobeam –o Stocks. prc –JARto. PRC Stock. Quotes. jar Stock. MIDlet z. Converting a MIDlet suite to PRC file yjava –jar Make. MIDPApp. jar –jad My. Suite. jad –o My. Suite. prc –JARto. PRC My. Suite. jar My. Suite http: //www. javacourses. com Copyright © 2001 javacourses. com 87

MIDP for Palm OS z. Networking and Databases http: //www. javacourses. com Copyright © MIDP for Palm OS z. Networking and Databases http: //www. javacourses. com Copyright © 2001 javacourses. com 88

Other Configurations/Profiles z. PDA Profile (CLDC-based) z. Connected Device Configuration (CDC) y. CVM y. Other Configurations/Profiles z. PDA Profile (CLDC-based) z. Connected Device Configuration (CDC) y. CVM y. Supports full Java library z. Foundation Profile z. Personal Profile z. RMI Profile http: //www. javacourses. com Copyright © 2001 javacourses. com 89

PDA Profile zwww. jcp. org/jsr/detail/75. jsp z. Based on the CLDC 1. 0 z. PDA Profile zwww. jcp. org/jsr/detail/75. jsp z. Based on the CLDC 1. 0 z. Will provide user interface and data storage APIs for handheld devices z. The UI API is expected to be a subset of the AWT z. No reference implementation yet http: //www. javacourses. com Copyright © 2001 javacourses. com 90

CDC/Foundation z CDC targets the next generation of wireless, handheld consumer devices z The CDC/Foundation z CDC targets the next generation of wireless, handheld consumer devices z The Foundation Profile is meant to serve as a foundation for other profiles z It extends the CDC by adding most of the missing J 2 SE core libraries, except those related to UI z APIs for beans, rmi, sql are not part of CDC/Foundation z Reference Implementations are available for Linux and Vx. Works http: //www. javacourses. com Copyright © 2001 javacourses. com 91

CLDC vs. CDC z CLDC implements a subset of Java features and APIs z CLDC vs. CDC z CLDC implements a subset of Java features and APIs z KVM z For limited devices z 16 or 32 -bit processors z Targets devices with 160 -512 KB of memory http: //www. javacourses. com z CDC is a full Java implementation z CVM z For more powerful devices z 32 -bit processors z Targets devices with at least 2 MB of memory Copyright © 2001 javacourses. com 92

Personal Profile z. Personal. Java is being redefined as the Personal Profile z. It Personal Profile z. Personal. Java is being redefined as the Personal Profile z. It extends the Foundation Profile z. Provides GUI capable of running Java web applets z. Backward compatible with 1. 1 and 1. 2 Personal. Java applications z. No reference implementation yet http: //www. javacourses. com Copyright © 2001 javacourses. com 93

RMI Profile z. Extends the CDC and Foundation to provide Remote Method Invocation for RMI Profile z. Extends the CDC and Foundation to provide Remote Method Invocation for devices z. Therefore, it is meant to be used with the CDC/Foundation and not CLDC/MIDP z. Requires TCP/IP network connectivity z. Compatible with J 2 SE RMI API 1. 2. x or higher z. No reference implementation yet http: //www. javacourses. com Copyright © 2001 javacourses. com 94

Availability and Resources z Sun’s CLDC implementation supports development using Solaris, Win 32, Palm. Availability and Resources z Sun’s CLDC implementation supports development using Solaris, Win 32, Palm. OS z NTT Do. Co. Mo started Java-based cell phone service in January/01 z Motorola announced a Java-enabled GSM phone (Accompli A 008). z Motorola & Nextel (i 50 sx, i 85 s) z Nokia, Ericsson, and others support J 2 ME http: //www. javacourses. com Copyright © 2001 javacourses. com 95

J 2 ME SDKs z Sun’s Wireless Toolkit: java. sun. com/j 2 mewtoolkit z J 2 ME SDKs z Sun’s Wireless Toolkit: java. sun. com/j 2 mewtoolkit z Motorola’s J 2 ME implementation: www. motorola. com/java z RIM’s Black. Berry JDE: developers. rim. net/handhelds z Metrowerks Code. Warrior for Java: www. metrowerks. com/desktop/java z Zucotto’ WHITEborad SDK www. zucotto. com http: //www. javacourses. com Copyright © 2001 javacourses. com 96

J 2 ME Resources z J 2 ME: http: //java. sun. com/j 2 me J 2 ME Resources z J 2 ME: http: //java. sun. com/j 2 me z CLDC and KVM: http: //java. sun. com/products/cldc z MIDP: http: //java. sun. com/products/midp z Wireless Toolkit: http: //java. sun. com/products/j 2 mewtoolkit http: //www. javacourses. com Copyright © 2001 javacourses. com 97

Additional Resources z KVM Interest Archive: archives. java. sun. com/archives/kvm-interst. html z Device Programming Additional Resources z KVM Interest Archive: archives. java. sun. com/archives/kvm-interst. html z Device Programming Forum @ ITWorld. com forums. itworld. com z J 2 ME Archive: www. billday. com/j 2 me z Wireless. Dev. Net Developer Portal: www. wirelessdevnet. com http: //www. javacourses. com Copyright © 2001 javacourses. com 98

Thank you Q&A http: //www. javacourses. com Copyright © 2001 javacourses. com 99 Thank you Q&A http: //www. javacourses. com Copyright © 2001 javacourses. com 99

Copyright Info ©Copyright 2001 javacourses. com All rights reserved. Java™ and J 2 ME Copyright Info ©Copyright 2001 javacourses. com All rights reserved. Java™ and J 2 ME ™ are registered trademarks of Sun Microsystems, Inc. All trademarked product and company names are the property of their respective trademark holders. http: //www. javacourses. com Copyright © 2001 javacourses. com 100

Speaker Bio Qusay H. Mahmoud is a faculty member at the School of Computing Speaker Bio Qusay H. Mahmoud is a faculty member at the School of Computing Science at Simon Fraser University, Canada. Previously, he was a contractor for Sun Microsystems. He has published dozens of articles on the Java programming language, including the MIDP and Palm programming articles for Sun’s Java Developer Connection. Qusay is the author of Distributed Programming with Java (Manning Publications Co. , 1999) and the upcoming Wireless Java from O’Reilly. http: //www. cs. sfu. ca/~qmahmoud http: //www. javacourses. com Copyright © 2001 javacourses. com 101