1 / 43

Java ME Clients

Java ME Clients. Mobile Computing. Some materials from MobEdu.net. Constantly changing market means focus on learning basics. PDAs are gone and mobiles change. http://www.sheldoncomics.com/archive/050222.html. Mobile computing offers a new novel dimension.

Melvin
Download Presentation

Java ME Clients

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java ME Clients Mobile Computing Bruce Scharlau, University of Aberdeen, 2010 Some materials from MobEdu.net

  2. Constantly changing market means focus on learning basics PDAs are gone and mobiles change Bruce Scharlau, University of Aberdeen, 2010 http://www.sheldoncomics.com/archive/050222.html

  3. Mobile computing offers a new novel dimension This is still a new programming dimension compared to desktop and conventional distributed computing. Bruce Scharlau, University of Aberdeen, 2010

  4. Java Family Source: http://java.sun.com/developer/onlineTraining/webcasts/pdf/toronto/bday.pdf Bruce Scharlau, University of Aberdeen, 2010

  5. J2ME and J2EE connect easily Source: http://java.sun.com/blueprints/earlyaccess/wireless/designing/designing.pdf Bruce Scharlau, University of Aberdeen, 2010

  6. Java ME Components • Hosting OS • KVM – execution engine with simplified JVM • CLDC – base library • MIDP – additional libraries Phone PDA MIPD Profile CLDC Configuration KVM Bruce Scharlau, University of Aberdeen, 2010

  7. Configurations • CLDC – Connected, limited device configuration – assume disconnection • CDC = Connected device configuration – assume always connected Bruce Scharlau, University of Aberdeen, 2010

  8. Example Java ME Stack Source: http://java.sun.com/developer/onlineTraining/webcasts/pdf/toronto/bday.pdf Bruce Scharlau, University of Aberdeen, 2010

  9. CLDC 1.0 Overview • Targeted to small devices with • 160-512kb memory available for Java • Limited (battery) power and intermittent connectivity plus a small UI (screen) • Sun Java reference implementation using KVM Bruce Scharlau, University of Aberdeen, 2010

  10. CLDC Scope differs from core Java • Main differences: • No floating point support required • No finalisation of object instances • Limited error handling • No thread groups, reflection, JNI • Core java.* libraries • I/O and networking • Security and Internationalisation • New classes, javax.microedition.* Bruce Scharlau, University of Aberdeen, 2010

  11. ‘extra’ APIs can enhance applications Just remember that they are ‘optional’, so may not be available Bruce Scharlau, University of Aberdeen, 2010 http://java.sun.com/javame/overview/products.jsp

  12. CLDC Classes need pre-verification Source: http://java.sun.com/developer/onlineTraining/webcasts/pdf/toronto/bday.pdf Bruce Scharlau, University of Aberdeen, 2010

  13. CLDC Networking is based on GCF • CLDC uses GCF (Generic Connection Framework) • Everything is a URL Connector.open(“<protocol>://<address>:<parameters>”) • Protocols supported • Filesk, HTTP, Sockets, Communication ports • All specified in MIDP Profile HTTP and HTTPS must be supported, the others are optional Bruce Scharlau, University of Aberdeen, 2010

  14. Mobile Information Device Profile (MIDP) • Targets two-way devices implementing CLDC • Provides • Application model, ie lifecycle and packaging • Display toolkit, UI methods • Persistent data storage • HTTP 1.1 networking using CLDC GCF • MIDP 1.0 widely available • MIDP 2.0 released Nov. 2002 • MIDP 2.1 released summer 2006 • MIDP 3 out in beta spring 2009 Bruce Scharlau, University of Aberdeen, 2010

  15. MIDP applications (MIDlets) move from state to state implementing three methods Bruce Scharlau, University of Aberdeen, 2010

  16. Midlets are packaged in jars with required resources MyApp.jar Com/package/classes META-INF/MANIFEST.MF Mylogo.png MyApp.jad Bruce Scharlau, University of Aberdeen, 2010

  17. Jad and Manifest are similar required files for Java ME apps AuctionMidlet.jad MIDlet-1: AuctionMIDlet,,com.auction.j2me.AuctionMIDlet MIDlet-Jar-URL: AuctionMidlet.jar MIDlet-Name: AuctionMidlet Midlet Suite MIDlet-Vendor: Midlet Suite Vendor MIDlet-Version: 1.0.0 MicroEdition-Configuration: CLDC-1.1 MicroEdition-Profile: MIDP-2.1 MIDlet-Jar-Size: 4396 Bruce Scharlau, University of Aberdeen, 2010

  18. Manifest goes in the jar file MANIFEST.MF Manifest-Version: 1.0 MicroEdition-Configuration: CLDC-1.1 MIDlet-Name: AuctionMidlet Midlet Suite Ant-Version: Apache Ant 1.6.3 Created-By: 1.5.0_14-b03 (Sun Microsystems Inc.) MIDlet-Vendor: Midlet Suite Vendor MIDlet-1: AuctionMIDlet,,com.auction.j2me.AuctionMIDlet MIDlet-Version: 1.0.0 MicroEdition-Profile: MIDP-2.1 Bruce Scharlau, University of Aberdeen, 2010

  19. The JAD references the JAR Download of JAD means opening: • The AMS downloads the JAR by the information in the JAD • Mostly the JAR and the JAD are in similar folder AMS =Application Management System Bruce Scharlau, University of Aberdeen, 2010

  20. The JAD is validated by the AMS(Application Management System) • Is the CLDC version correct? • Is the MIDP version correct? • Is there enough memory to download the MIDlet? • Where is the JAR file? • Where is the execution unit inside the JAR? Bruce Scharlau, University of Aberdeen, 2010

  21. JAD used for over the air (OTA) installation JAD checks that the app will comply and fit on the mobile device when using OTA Otherwise, you can install the Jar file if side-loading from PC Bruce Scharlau, University of Aberdeen, 2010

  22. MIDlet Development • Write Java application • Compile • Preverify (and obfuscate) • Package into Jar file • Create deployment descriptor (jad) • Deploy and run in toolkit or other device Bruce Scharlau, University of Aberdeen, 2010

  23. Preverify to check that classes are correct • All classes automatically preverified after code is compiled • If it fails, then error message is passed back to the console • Automatically packages app using name of application directory Bruce Scharlau, University of Aberdeen, 2010

  24. Obfuscate to shrink the application Renames methods and variables with shorter names Optional and recommended Bruce Scharlau, University of Aberdeen, 2010

  25. Jar and run in emulator Create bundle with resources for deployment Use basic or complex emulator Bruce Scharlau, University of Aberdeen, 2010

  26. Run on device for final check Running on real devices is the final check Start with low end device Bruce Scharlau, University of Aberdeen, 2010

  27. MIDlet must implement three methods: import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class HelloMidlet extends MIDlet { public void startApp() { } public void pauseApp() { } public void destroyApp(boolean unconditional) { } } Bruce Scharlau, University of Aberdeen, 2010

  28. MIDlet needs other key parts • Import the packages import javax.microedition.midlet.*; import javax.microedition.lcdui.*; • All MIDlet extends from the MIDlet class public class HelloMidlet extends MIDlet implements CommandListener { • Furthermore it implements the CommandListener class Bruce Scharlau, University of Aberdeen, 2010

  29. MIDlet needs to initialise and create variables // Initializethe variables private Form form; private Display display; private Command exitCommand; Bruce Scharlau, University of Aberdeen, 2010

  30. MIDlet use startApp() to move to active state • The MIDlet starts at the call of the startApp() public void startApp() { form = new Form("Hello"); display = Display.getDisplay(this); exitCommand = new Command("Exit", Command.SCREEN, 1); form.addCommand(exitCommand); form.setCommandListener((CommandListener)this); form.append(new StringItem("Hello", "Hello World!")); display.setCurrent(form); } • Commands and the StringItem is added to the Form • Show the Form on the display Bruce Scharlau, University of Aberdeen, 2010

  31. The commandAction() method handles the incoming commands public void commandAction(Command command, Displayable screen) { if ( command == exitCommand ) { destroyApp(true); notifyDestroyed(); } } Bruce Scharlau, University of Aberdeen, 2010

  32. If it’s not used leave it empty The following methods are unused, so we leave them empty public void pauseApp() { } public void destroyApp(boolean unconditional) { } Bruce Scharlau, University of Aberdeen, 2010

  33. Before and after start Bruce Scharlau, University of Aberdeen, 2010

  34. Three levels of software for mobiles • Application level is about apps for end users using provided lower-level components • Middleware of communication and other libraries for protocols (bluetooth, etc) • Low-level software such as kernels and device drivers (platform) Bruce Scharlau, University of Aberdeen, 2010

  35. Class area Heap Stack App area Run-time data Understanding the virtual machine aids development loads Execution engine Class loader calls *.class Scheduler loads classes into Garbage collection Memory manager Bytecode interpreter use Bruce Scharlau, University of Aberdeen, 2010

  36. Allow garbage collection to do its job • Release early, allocate late: • Deallocate objects as soon as possible, and allocate new objects as late as possible Bruce Scharlau, University of Aberdeen, 2010

  37. Pay attention to your memory usage to improve performance Use what is required for the application. Use single-linked list, instead of double if you only need to traverse it in one direction. Bruce Scharlau, University of Aberdeen, 2010

  38. Use linear data structures to conserve memory Linear data structures use adjacent memory for their components, instead of separate memory for each item. Linear: linked lists, tables Non-linear: graphs, trees Bruce Scharlau, University of Aberdeen, 2010

  39. Avoid small classes in favour of larger ones There is a basic overhead for ANY class Inner classes cause the same problem, as does using lots of separate exceptions Bruce Scharlau, University of Aberdeen, 2010

  40. Avoid dependencies where possible Save items from joining the constant pool of the application’s memory load Look to reuse classes already loaded, or use indirection (abstraction) Bruce Scharlau, University of Aberdeen, 2010

  41. Use Arrays instead of Vectors where possible Method Allocated bytes Allocated objects arrayImplementation 8016 1 vectorImplementation 40,000 2002 vectorImplSimple 52,000 2010 Bruce Scharlau, University of Aberdeen, 2010

  42. Use StringBuffer instead of String Method Allocated bytes Allocated objects useString 39,000 450 useStringBuffer 304 5 Bruce Scharlau, University of Aberdeen, 2010

  43. Summary Use memory responsibly for best performance Create clients using appropriate CLDC and MIDP libraries Bruce Scharlau, University of Aberdeen, 2010

More Related