400 likes | 537 Views
Java 2 Micro Edition. Mano Chen Senior Technical Consultant Sun Microsystems Mano@sun.com. Computing Is Becoming Ubiquitous. Mainframe era One computer, many users PC era One computer, one user Consumer era One user, many computers, and these computers are networked. A Game.
E N D
Java 2 Micro Edition Mano Chen Senior Technical Consultant Sun Microsystems Mano@sun.com
Computing Is Becoming Ubiquitous • Mainframe era • One computer, many users • PC era • One computer, one user • Consumer era • One user, many computers, and these computers are networked
A Game • What am I? • I have the following: • CPU • some memory • screen • keyboard • networked • runs applications
Agenda • Overview of J2ME • Developing J2ME Application
Agenda • Overview of J2ME • Developing J2ME Application
Problems • No software market !!! • Everything is proprietary • Hardware, software and tools • Handsets are useless without a network • No compelling content
J2ME is the Solution • Designed for small devices • Online and offline activities • Rich user and network interaction models • Fully programmable • Portable
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 Other CDC Profiles ... Personal Profile RMI Profile 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 J2ME Configurations and Profiles
What Is a Configuration? • Defines the minimum capabilities and libraries for a JVM that will be available on all devices belonging to the same “horizontal” family of devices • Similar requirements in memory size and processing capabilities • Subject to compatibility test • Two configuration defined • Connected, Limited Device Configuration • Connected Device Configuration
Connected Limited Device Configuration • Targeted at devices with • 160KB to 512KB total memory available for Java™ technology • Slow processor • 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
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 • Adds features that are specific to a certain device category such as cell phones or PDAs • One profile defined • Mobile Information Device Profile
Mobile Information Device Profile • 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
MIDP Profile Applications OEM Applications MID Profile OEM APIs CLDC (KVM) Operating System CLDC and MIDP Architecture
Pause pauseApp startApp Active destroyApp destroyApp Destroyed 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
Your MIDlet Yellow Pages, train schedules and ticketing, games… Mobile Information Device Profile UI, HTTP networking... J2ME core APIs CLDC = KVM + J2ME Core APIs in this example Threads, no Floats… KVM 32-bit RISC, 256K ROM, 256K Flash, 64K RAM DSP chip(e.g., ARM) Typical J2ME Technology Stack
MIDlet Suite • MIDlets are package as a JAR • MIDlets that are in the same suite can access each others database • A descriptor file contains information pertaining to the suite • Vendor name, version, size • Name of each MIDlet • Icons
Advertise App on Web Page User Selects App JAM Downloads App Web Page (Name, Version, Size, …) Java Application Manager Descriptor File Network Transfer Jar File Application Loading Process
Agenda • Overview of J2ME • Developing J2ME Application
Integration Tier Client Tier Web Tier Business Tier EIS Tier J2EE Architecture
Key J2EE Components • Enterprise Java Bean • Business logic packaging, distribution and access • Servlet • Java classes that extends the function of a web server • Java Server Pages • Templates used to generate content dynamically • J2EE Connectors • Generic access to back end EIS
Example of A J2EE Application • EJB is used to encapsulate business logic and apply them to EIS back office systems • Servlets are used to co-ordinate the interactions between users and EJBs • JSPs are used to present forms, information and results back to the user
J2EE Application Server Web Container EJB Container HTTP J2ME Servlet Book EJB forward lookup HTML Servlet HTTP J2ME To J2EE Communication
Handling J2ME Client • A request is made to the servlet • Process the request • Servlet determines if the type of client • Redirect to J2ME servlet for all J2ME client communications
Design Issues • Networking • Application messages • Working offline • Security
Networking • J2ME side • Use HTTP 1.1 – requirement for all MIDP devices • Use GET and POST communicating with web tier • Client is responsible for HTTP headers and data • J2EE side • Use servlet to handle client request
MIDP Networking – Request 01 String url = “http://www.books.com/web/list?isdn=12345”; 02 03 HttpConnection con = (HttpConnection)Connection.open(url); 04 con.setRequestMethod(HttpConnection.POST); 05 06 con.setRequestProperty(“user-agent”, “CLDC-MIDP”); 07 con.setRequestProperty(“content-language”, “en”); 08 con.setRequestProperty(“content-type” 09 , “application/x-www-form-encoded”); 10 11 switch (con.getResponseCode( )) { 12 …
MIDP Networking – Response 01 InputStream is = con.openInputStream(); 02 03 if (is.getType( ) != “application/mybook-encoding”) 04 // Reject data stream 05 06 byte buffer = new byte[256]; 07 int size; 08 while ((size = is.read(buffer)) != -1) { 09 // Do something with data 10 11 is.close( ); 12 // Display the data
Servlet – Existing 01 public void doPost(HttpServletRequest req, 02 HttpServletResponse res) … { 03 04 // Looks up book 05 String isdn = req.getParameter(“isdn”); 06 07 if (req.getHeader(“user-agent”).equals(“CLDC-MIDP”) { 08 RequestDispatcher rd = req.getRequestDispatcher( 09 “MIDPcommunications”); 10 rd.forward(req, res); 11 return; 12 } 13 14 // Normal processing
Servlet – MIDP Servlet 01 public void doPost(HttpServletRequest req, 02 HttpServletResponse res) … { 03 04 res.setContentType(“application/mybook-encoding”); 05 06 ServletOutputStream os = res.getOutputStream( ); 07 // Write data out 08 09 os.flush( );
Application Messages Since 3G is NOT with us yet… • Conserve bandwidth • Send only the necessary data • Accommodate high latency • Send all required data in a single message • Use Gauge to provide progress indication • Message encodings • Use binary messages • Don’t use XML!!!
Working Offline • MIDP supports record oriented database • Data can be stored locally on the CLDC device • Information stored in local databases can be manipulated • Need to implement data synchronization
WWW-Authenticate: Basic realm=“fred” Servlet Container Authorization: Basic QWxhZGpbjpvcG… GET /get_list.html HTTP/1.1 Security – Authentication • Build HTTP basic authentication into MIDP application 01 if (con.getHeaderField(“www-authenticate”) != null) { 02 String authString = Base64.encode(login + “:” + password); 03 con.setRequestProperty(“authorization”, “basic “ + authString); 04 if (con.getResponseCode() != HttpConnection.HTTP_OK) { 05 // Do something … 06 else
Security – Authentication • Use JSP/Servlet form login • Use j_security_check method for authentication • Required parameters are j_username and j_password 01 String url = “http://www.books.com/web/j_security_check”; 02 url += “?j_username=“ + username; 03 url += “&j_password=“ + password; 04 HttpConnection con = (HttpConnection)Connection.open(url); 05 06 con.setRequestMethod(HttpConnection.POST);
Security – Secure Transport • HTTPS is not a requirement for MIDP 1.0 • However… • Vendors are implementing them • J2ME for Palm supports HTTPS • HTTPS support targeted for MIDP-NG
Summary • Designed for small handheld devices • Easy to program • Works with J2EE • It’s real and its available now!!!!
Getting Started on J2ME • Java2 Standard Edition • http://java.sun.com/j2se • Java2 Micro Edition Wireless Toolkit • http://java.sun.com/products/j2mewtoolkit/