Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Java 2 Micro Edition Mano Chen Senior Technical Consultant Sun Microsystems [email protected] 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 2 A Game What am I? I have the following: CPU some memory screen keyboard networked runs applications 3 Meet Your New Computers 4 Agenda Overview of J2ME Developing J2ME Application 5 Agenda Overview of J2ME Developing J2ME Application 6 Problems No software market !!! Everything is proprietary Hardware, software and tools Handsets are useless without a network No compelling content 7 J2ME is the Solution Designed for small devices Online and offline activities Rich user and network interaction models Fully programmable Portable 8 Where Does J2ME Fit In? 9 J2ME Configurations and Profiles 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 2 Micro Edition Core APIs Java Card APIs Java Programming Language 10 Java HotSpot ™ Java Virtual Machine (JVM) KVM Card VM 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 11 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 12 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 13 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 14 CLDC and MIDP Architecture MIDP Profile Applications OEM Applications MID Profile CLDC (KVM) Operating System 15 OEM APIs MIDP Application Lifecycle 16 Destroyed destroyApp startApp Active destroyApp Start – acquire resources and start executing Pause – release resources and become quiescent (wait) Destroy – release all resources, destroy threads, and end all activity Pause pauseApp MIDP applications are known as “MIDlets” MIDlets move from state to state in the lifecycle, as indicated. Typical J2ME Technology 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 17 KVM DSP chip (e.g., ARM) Threads, no Floats… 32-bit RISC, 256K ROM, 256K Flash, 64K RAM 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 18 Application Loading Process Advertise App on Web Page User Selects App JAM Downloads App Web Page (Name, Version, Size, …) Descriptor File Jar File 19 Network Transfer Java Application Manager J2ME Application Screenshots 20 Agenda Overview of J2ME Developing J2ME Application 21 J2EE Architecture Client Tier 22 Web Tier Business Tier Integration Tier EIS Tier 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 23 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 24 J2ME To J2EE Communication J2EE Application Server Web Container EJB Container J2ME Servlet forward HTTP 25 HTML Servlet Book EJB 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 26 Design Issues Networking Application messages Working offline Security 27 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 28 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 … 29 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 30 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 31 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( ); 32 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!!! 33 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 34 Security – Authentication Build HTTP basic authentication into MIDP application GET /get_list.html HTTP/1.1 WWW-Authenticate: Basic realm=“fred” Servlet Container Authorization: Basic QWxhZGpbjpvcG… 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 35 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); 36 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 37 Summary Designed for small handheld devices Easy to program Works with J2EE It’s real and its available now!!!! 38 Getting Started on J2ME Java2 Standard Edition http://java.sun.com/j2se Java2 Micro Edition Wireless Toolkit http://java.sun.com/products/j2mewtoolki t/ 39 Thank You 40