A Taste of Java ME


Published on

Published in: Business, Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

A Taste of Java ME

  1. 1. A Taste of JavaME Overview to Java’s approach to wireless mobile application development from a developer’s perspective Thomas Wiradikusuma [email_address] www.wiradikusuma.com Presentation to the 19 th Java User Group Meet Up (JaMU), March 4, 2006
  2. 2. Objective <ul><li>To introduce JavaME as a platform for developing wireless mobile applications. </li></ul>
  3. 3. Agenda <ul><li>Wireless mobile environment </li></ul><ul><li>JavaME architecture </li></ul><ul><li>JavaME versus JavaSE </li></ul><ul><li>First MIDlet </li></ul><ul><li>User interface and event handling </li></ul><ul><li>Persistence </li></ul><ul><li>Networking </li></ul><ul><li>Game API </li></ul><ul><li>Extensions (Messaging, Multimedia, Bluetooth, etc) </li></ul><ul><li>Performance </li></ul>
  4. 4. World of Wireless Mobile <ul><li>Wireless is in the air. </li></ul><ul><li>Wireless communication is one of the fastest growing technology. </li></ul><ul><li>Cell phones subscribers worldwide exceeded two billions in 2005. </li></ul><ul><li>More depended to the Internet, people want it accessible from mobile devices. </li></ul><ul><li>3+G is coming to town. </li></ul>
  5. 5. Meet JavaME <ul><li>JavaME defined </li></ul><ul><li>A little history </li></ul><ul><li>Why JavaME? </li></ul><ul><ul><li>Dynamic delivery of content </li></ul></ul><ul><ul><li>Offline access </li></ul></ul><ul><ul><li>Enhanced user experience and interactive content </li></ul></ul><ul><ul><li>Cross-platform compatibility </li></ul></ul><ul><ul><li>Security </li></ul></ul><ul><ul><li>The power of a modern object-oriented programming language </li></ul></ul><ul><ul><li>Large developer community </li></ul></ul>
  6. 6. JavaME Architecture
  7. 7. JavaME Architecture, cont’d <ul><li>Configurations: </li></ul><ul><ul><li>Connected Device Configuration </li></ul></ul><ul><ul><li>Connected, Limited Device Configuration </li></ul></ul><ul><li>Profiles: </li></ul><ul><ul><li>Mobile Information Device Profile </li></ul></ul><ul><ul><li>PDA Profile </li></ul></ul><ul><ul><li>Foundation Profile </li></ul></ul><ul><ul><li>etc </li></ul></ul><ul><li>Optional packages </li></ul><ul><li>Typically contains functionality independent of any particular vertical market segment or device family. The main goal is to allow the definition of APIs that can be added flexibly on top of a number of different profiles. One device can support multiple optional packages. </li></ul>
  8. 8. Miniaturized Standard Java APIs <ul><li>No floating-point in CLDC 1.0. </li></ul><ul><li>No user class loading, object finalization, reflection, native methods, demon threads, thread groups, Collections API, etc. </li></ul><ul><li>Simpler Runtime and System, java.io, date functions, exception handling, etc. </li></ul><ul><li>TIPS: </li></ul><ul><ul><li>Always refer to Javadoc. </li></ul></ul><ul><ul><li>When compiling, set Language Features and Target VM to lowest Java SDK available (IDEs can help this). </li></ul></ul>
  9. 9. Developing MIDlet <ul><li>Edit Source Code > Compile > Preverify > Package > Test or Deploy. </li></ul><ul><li>Free development tools: </li></ul><ul><ul><li>J2ME Wireless Toolkit </li></ul></ul><ul><ul><li>EclipseME (an Eclipse plug-in) </li></ul></ul><ul><ul><li>NetBeans Mobility Pack (a NetBeans module) </li></ul></ul><ul><li>Obfuscation: minimizing the size of MIDlet suite JARs. Originally designed to foil attempts to reverse engineer compiled bytecode, perform any combination of the following functions: </li></ul><ul><ul><li>Renaming things to make them compact </li></ul></ul><ul><ul><li>Removing unused things </li></ul></ul><ul><ul><li>Inserting illegal or questionable data to confuse decompilers </li></ul></ul><ul><li>Other useful tools: </li></ul><ul><ul><li>Antenna (specialized Ant tasks to help with MIDlet suite builds) </li></ul></ul><ul><ul><li>J2ME Polish </li></ul></ul><ul><li>Test your application in (varying) real devices as often as possible. </li></ul>
  10. 10. First MIDlet (“Hello World”)
  11. 11. User Interface
  12. 12. Event Handling <ul><li>A command is something the user can invoke—you can think of it as a button. Like a button, it has a title, like “OK” or “Cancel,” and your application can respond appropriately when the user invokes the command. The premise is that you want a command to be available to the user, but you don't really care how it is shown on the screen or exactly how the user invokes it—keypad button, soft button, touch screen, whatever. </li></ul>
  13. 13. Persisting Data <ul><li>“ Record stores”, small database containing pieces of data called records . Represented by instances of javax.microedition.rms.RecordStore. </li></ul>
  14. 14. Connecting to the World <ul><li>All contained in the javax.microedition.io package and based around the Connection interface. </li></ul><ul><li>HTTP (and HTTPS in MIDP 2.0) is mandatory, others are optional. </li></ul>
  15. 15. Connecting to the World, cont’d <ul><li>TIPS: </li></ul><ul><ul><li>Use GET rather than POST. </li></ul></ul><ul><ul><li>Don't hard-code URLs. </li></ul></ul><ul><ul><li>Put network access in a separate thread. </li></ul></ul><ul><ul><li>Handle exceptions gracefully. </li></ul></ul><ul><ul><li>Clean up after yourself. </li></ul></ul>
  16. 16. Game API <ul><li>Simplifies writing 2D games. </li></ul><ul><li>GameCanvas’ advantages over Canvas: </li></ul><ul><ul><li>Controls exactly when the display is updated </li></ul></ul><ul><ul><li>Controls region of the screen to update </li></ul></ul><ul><li>Typical game loop: </li></ul><ul><li>Graphics g = getGraphics(); </li></ul><ul><li>while(true) { </li></ul><ul><li> // Check for user input. </li></ul><ul><li> // Update game state. </li></ul><ul><li> // Draw stuff using g. </li></ul><ul><li> flushGraphics(); </li></ul><ul><li>} </li></ul><ul><li>Layer, Sprite, TiledLayer and LayerManager </li></ul><ul><li>Special effects: </li></ul><ul><ul><li>flashBacklight() </li></ul></ul><ul><ul><li>vibrate() </li></ul></ul>
  17. 17. Optional Packages <ul><li>JSR 120: Wireless Messaging API </li></ul><ul><li>JSR 135: Mobile Media API </li></ul><ul><li>JSR 172: Web Services Specification </li></ul><ul><li>JSR 177: Security and Trust Services </li></ul><ul><li>JSR 179: Location API </li></ul><ul><li>JSR 180: Session Initiation Protocol (SIP) </li></ul><ul><li>JSR 184: Mobile 3D Graphics </li></ul><ul><li>JSR 190: Event Tracking API </li></ul><ul><li>And a whole lot more… </li></ul>
  18. 18. Performance Issues <ul><li>Benchmarking </li></ul><ul><ul><li>Runtime.freeMemory() </li></ul></ul><ul><ul><li>Runtime.totalMemory() </li></ul></ul><ul><ul><li>System.currentTimeMilis() </li></ul></ul><ul><ul><li>Run multiple times and calculate the average </li></ul></ul><ul><li>TIPS: </li></ul><ul><ul><li>First make it run, the make it run right, then make it run fast </li></ul></ul><ul><ul><li>Create objects efficiently, reuse objects whenever possible </li></ul></ul><ul><ul><li>Use StringBuffer for string concatenation </li></ul></ul><ul><ul><li>Use arrays, not object collection </li></ul></ul><ul><ul><li>Use buffered I/O </li></ul></ul><ul><ul><li>Be clean </li></ul></ul><ul><ul><li>Make application responsive (“perceived performance”) </li></ul></ul><ul><ul><li>Use an obfuscator </li></ul></ul><ul><ul><li>Redesign / refactor </li></ul></ul><ul><ul><li>Run memory profiler </li></ul></ul><ul><ul><li>Manage resources efficiently </li></ul></ul><ul><ul><li>Don’t be too OO :-) </li></ul></ul>
  19. 19. Resources <ul><li>Websites: </li></ul><ul><ul><li>wireless.java.sun.com </li></ul></ul><ul><ul><li>www.microjava.com </li></ul></ul><ul><ul><li>www.onjava.com/onjava/wireless </li></ul></ul><ul><ul><li>www.javagaming.com </li></ul></ul><ul><ul><li>www.microdevnet.com </li></ul></ul><ul><li>Books: </li></ul><ul><ul><li>Knudsen, Jonathan. Wireless Java Developing with J2ME, Second Edition . Apress. 2003. </li></ul></ul><ul><ul><li>Riggs, Roger, et al . Programming Wireless Devices with the Java™ 2 Platform, Micro Edition, Second Edition . Addison Wesley. 2003. </li></ul></ul>