Introduction to Java 2 Micro Edition
description
Transcript of Introduction to Java 2 Micro Edition
![Page 1: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/1.jpg)
Introduction to Java 2 Micro Edition
Mark Balbes, Ph.D. Senior Software Engineer
Jeff Brown Senior Software Engineer
![Page 2: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/2.jpg)
J2ME
(2)
What is J2ME
• Java platform for small devices
• A subset of Java 2 Standard Edition
• Complementary technology to WAP/WML
• For programming the Palm
• For programming wireless devices (e.g mobile phones)
![Page 3: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/3.jpg)
J2ME
(3)
J2ME-Enabled Devices• Motorola
– i85s and i50sx iDen phones
– Applications are downloaded and installed via a special cable http://commerce.motorola.com/iupdatephone/main/j2me_softcat.cfm
• NTT DoCoMo– Japanese phone company
• ~80% of wireless internet users are in Japan
– iMode and iAppli support
• Research In Motion– CLDC and MIDP compliant
– http://www.rim.net/
• Palm and compatibles
• WinCE devices
i85s
P503i RIM BlackBerry
![Page 4: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/4.jpg)
J2ME
(4)
Configurations and Profiles• CDC - Connected Device Configuration• CLDC - Connected Limited Device Configuration• MIDP - Mobile Information Device Profile• PDAP - Personal Digital Assistant Profile• Personal Profile
Host Operating System
JVM KVM
CDC
Personal MIDP PDAP
CLDC
kJava
![Page 5: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/5.jpg)
J2ME
(5)
CLDCConnected Limited Device Configuration
• Specification Version 1.0
• Hardware Requirements– 160 - 512 kB of memory– 16 or 32 bit processor– network connectivity (possibly wireless)
• No floating point support
• Deliver applications dynamically
![Page 6: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/6.jpg)
J2ME
(6)
CLDC (Cont’d) Connected Limited Device Configuration
• CLDC addresses– Java languages and virtual machine features– Core Java libraries– Input/output– Networking– Security– Internationalization
![Page 7: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/7.jpg)
J2ME
(7)
CLDC (Cont’d) Connected Limited Device Configuration
• CLDC does not address– Application life-cycle management– User interface functionality– Event handling– High-level application model
• These can be addressed in profiles
![Page 8: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/8.jpg)
J2ME
(8)
CLDCWhat’s been removed
• Floating point
• Java Native Interface
• User-defined class loaders
• Reflection
• Thread groups and daemon threads
• Finalization
• Weak references
![Page 9: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/9.jpg)
J2ME
(9)
CLDC Security
• Less memory-consuming than J2SE model
• Sandbox– No user-defined class loaders– Classes loaded at native level
• No native method calls except from JVM
• System classes cannot be overridden by programmer
![Page 10: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/10.jpg)
J2ME(10)
Programming the Palm
• Development Environment– J2ME CLDC API
• Contains a subset of the standard J2SE classes
– J2ME KJava API• GUI components
• Access to Palm database
• Access to IR port
– JBuilder Handheld Express– POSE Palm Emulator
Already superceded.Not supported!
![Page 11: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/11.jpg)
J2ME(11)
Programming the Palm CLDC Packages
• io– InputStream, OutputStream, Reader, Writer
• lang - No floating point support
• util– Enumeration, Calendar, Date, Hashtable,
Random, Stack, TimeZone, Vector
• javax.microedition.io– Connection, Datagram, InputConnection,
OutputConnection, Connector
![Page 12: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/12.jpg)
J2ME(12)
Programming the Palm KJava GUI Components
• Spotlet– Container for other components– Handles events
• All events go to the spotlet.
• Spotlet must send events to the contained components.
– Only one spotlet can be registered• The registered spotlet is displayed.
• The registered spotlet receives all events from keys and screen.
![Page 13: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/13.jpg)
J2ME(13)
Programming the Palm HelloSpotlet
public class HelloSpotlet extends Spotlet {
private Graphics g;
private Button quitButton; private String message = "Hello Spotlet!";
public HelloSpotlet() { g = Graphics.getGraphics(); g.clearScreen(); quitButton = new Button("Quit", 5, 125); quitButton.paint(); g.drawString(message, 5, 5, Graphics.PLAIN); }
Graphics must be managed manually!
Cannot specify the size of the button.
![Page 14: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/14.jpg)
J2ME(14)
Programming the Palm HelloSpotlet (Cont’d)
public void penDown(int x, int y){ if (quitButton.pressed(x, y)) { System.exit(0); } }
public static void main(String[] args) { new HelloSpotlet().register(Spotlet.NO_EVENT_OPTIONS); }}
Register for screen events only. No key events
Pass screen events to the button
![Page 15: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/15.jpg)
J2ME(15)
Programming the Palm Deploy & Test HelloSpotlet
• Use JBuilder Wizard to create .prc file
• Command line java palm.database.MakePalmApp
• Install into POSE
• No debugger
![Page 16: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/16.jpg)
J2ME(16)
Programming the Palm KAWT Project
• Implementation of the AWT classes
• Can make GUIs that work in J2ME & J2SE
• Open source
• Not part of J2ME
• Lightweight
• Clean-room implementation
![Page 17: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/17.jpg)
J2ME(17)
Building the Conduit
• Synchronizes data with desktop
• Java Conduit Development Kit– Claims to require Visual Café– MS Windows– Supports generic conduits
![Page 18: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/18.jpg)
J2ME(18)
What is MIDP?• Provides APIs for building software on mobile
devices with limited resources.
• Works on top of the Connected Limited Device Configuration (CLDC)
![Page 19: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/19.jpg)
J2ME(19)
Where does MIDP fit in the Java platforms?
– Works with CLDC– Runs in the KVM– Examples of devices:
mobile phones
pagers
BlackBerry devices
personal digital assistants From http://java.sun.com/products/midp/
![Page 20: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/20.jpg)
J2ME(20)
HelloMIDLetimport javax.microedition.midlet.*;import javax.microedition.lcdui.*;public class HelloMIDlet extends MIDlet implements CommandListener { private Command exitCommand; private Display display;
public HelloMIDlet() { display = Display.getDisplay(this); exitCommand = new Command("Exit", Command.SCREEN, 2);
}
public void startApp() { TextBox t = new TextBox("Hello MIDlet", "Hello World!", 256, 0); t.addCommand(exitCommand); t.setCommandListener(this); display.setCurrent(t);
}
public void pauseApp() {} public void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable s) { if (c == exitCommand) { destroyApp(false); notifyDestroyed(); }
}}
Signals the MIDlet to terminate and enter the Destroyed state.
Notify the application manager thatthe MIDlet has entered the Destroyed state
Make TextBox the current screen
![Page 21: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/21.jpg)
J2ME(21)
J2ME Wireless Toolkit• J2ME Wireless Toolkit 1.01
– http://java.sun.com/products/j2mewtoolkit/– Integrates with Sun Forte IDE
• J2ME Wireless Toolkit 1.02– adds debugging capabilities– adds new emulators – early access version available (as of 6/3/01)
![Page 22: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/22.jpg)
J2ME(22)
J2ME Wireless Toolkit Emulators
![Page 23: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/23.jpg)
J2ME(23)
Final thoughts
• What happened to write-once, run anywhere. Now there are different configurations and profiles to write to.
• How many developers can actually write for phones? Access may be controlled by the phone companies.
• CLDC & KJava provides a more familiar development paradigm.
It’s back withJ2ME for Palm!
Wireless SIG
![Page 24: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/24.jpg)
J2ME(24)
Wireless SIG
• A joint special interest group of the St. Louis Web Developers Organization and the St. Louis Java User’s Group
• http://www.stlwebdev.org
• First meeting is on Tuesday, July 24 at 6:30 p.m. in this auditorium.
• I will be talking about J2ME MIDP
• Contact Mark Balbes (me) to be a speaker at [email protected]
![Page 25: Introduction to Java 2 Micro Edition](https://reader036.fdocuments.in/reader036/viewer/2022062409/568146a9550346895db3c5b2/html5/thumbnails/25.jpg)
J2ME(25)
References
• CLDC Specification http://java.sun.com/aboutJava/communityprocess/final/jsr030/index.html
• MIDP Specification http://java.sun.com/aboutJava/communityprocess/final/jsr037/index.html
• J2ME Archive http://www.billday.com/j2me/index.html
• http://www.kvmworld.com/
• Palm Emulator (POSE) http://www.palmos.com/dev/tech/tools/emulator/
• J2ME Wireless Toolkit http://java.sun.com/products/j2mewtoolkit/
• Conduit Development Kit - Windows Java Edition http://www.palmos.com/dev/tech/tools/cdk/java