Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.



Published on


  1. 1. Java 2 Platform, Micro Edition (J2ME) Masha Gutkhen Keren Gazit
  2. 2. Contents <ul><li>What’s J2ME? </li></ul><ul><li>J2ME core concepts </li></ul><ul><ul><li>Configurations (CLDC, CDC) </li></ul></ul><ul><ul><li>Profiles (MIDP) </li></ul></ul><ul><li>MIDlet, MIDlet Suite </li></ul><ul><li>Basic classes API </li></ul><ul><li>Installation and using the Toolkit </li></ul><ul><li>Demos!!! </li></ul>
  3. 3. Introduction <ul><li>Personalized and intelligent information appliances are necessities in our life today. </li></ul><ul><li>Such appliances can be: </li></ul><ul><ul><li>cell phones </li></ul></ul><ul><ul><li>two-way pagers </li></ul></ul><ul><ul><li>smart cards </li></ul></ul><ul><ul><li>personal organizers </li></ul></ul><ul><ul><li>palmtops </li></ul></ul><ul><li>These appliances tend to be special-purpose, limited-resource, network-connected devices. </li></ul>
  4. 4. Environment requirements <ul><li>We need an environment which is adapted for constrained devices - devices that have limitations on what they can do when compared to standard desktop or server computers. </li></ul><ul><li>The constraints are: </li></ul><ul><ul><li>extremely limited memory </li></ul></ul><ul><ul><li>small screen sizes </li></ul></ul><ul><ul><li>alternative input methods </li></ul></ul><ul><ul><li>slow processors </li></ul></ul>
  5. 5. So – what’s the solution? <ul><li>Because of the vast need, Sun has decided to develop a special edition of Java - J2ME (Java 2 Micro Edition). </li></ul>
  6. 7. Java Editions <ul><li>Different devices have different requirements and different expectations of Java. </li></ul><ul><li>One platform (solution) cannot address all the market segments (web server, video games etc.) </li></ul><ul><li>Users/developers want flexibility. They want to choose what they want to use and what they do not. </li></ul>
  7. 8. Java Editions <ul><li>The Java 2 Platform is split into three editions. </li></ul><ul><li>Each edition provides a complete environment for running Java-based applications, including the Java virtual machine (VM) and runtime classes. </li></ul><ul><li>The three editions target different kinds of applications running on different kinds of devices. </li></ul>
  8. 9. Java Editions Java2 Standard Edition (J2SE™) Java2 Enterprise Edition (J2EE™) Java2 Micro Edition (J2ME™) Java 2 Platform Standard desktop & workstation applications Heavy duty server systems Small & memory constrained devices
  9. 10. Java Editions <ul><li>Each edition defines different sets of class libraries. </li></ul><ul><li>There are thousands of core J2SE runtime classes, taking up to 10-20 megabytes of space. </li></ul><ul><li>J2ME-based devices have fewer classes. </li></ul>J2ME J2SE J2EE
  10. 11. PersonalJava and EmbeddedJava <ul><li>J2ME is not the first attempt at adapting Java for constrained environments. </li></ul><ul><li>PersonalJava </li></ul><ul><ul><li>Uses the basic Java 1.1 runtime classes with a few features from Java 2. </li></ul></ul><ul><ul><li>Implementation still requires a couple of megabytes of memory and a fast processor to run. </li></ul></ul>
  11. 12. PersonalJava and EmbeddedJava <ul><li>EmbeddedJava </li></ul><ul><ul><li>Makes every behavior of the JVM and the runtime classes optional - the implementor can choose exactly which classes and methods are required. </li></ul></ul><ul><ul><li>The limitation: &quot;write once, run anywhere&quot;. </li></ul></ul>
  12. 13. J2ME Core Concepts <ul><li>Configuration </li></ul><ul><ul><li>Minimum platform required for a group of devices </li></ul></ul><ul><li>Profile </li></ul><ul><ul><li>Addresses specific needs of a certain device family </li></ul></ul><ul><li>Optional Packages </li></ul>J2ME Profile J2ME Libraries Java Virtual Machine Profiles Configuration Host Operating System Java Language
  13. 14. J2ME Core Concepts <ul><li>J2ME is based on 3 core concepts: </li></ul><ul><li>Configurations </li></ul><ul><li>Profiles </li></ul><ul><li>Optional packages </li></ul>
  14. 15. Configurations <ul><li>A configuration is a complete Java runtime environment, consisting of: </li></ul><ul><ul><li>Java virtual machine (VM) to execute Java bytecode </li></ul></ul><ul><ul><li>Native code to interface to the underlying system </li></ul></ul><ul><ul><li>Set of core Java runtime classes </li></ul></ul><ul><li>To use a configuration, a device must meet certain minimum requirements. </li></ul>
  15. 16. Configurations <ul><li>The set of core classes is normally quite small and must be enhanced with additional classes supplied by J2ME profiles or by configuration implementor. </li></ul><ul><li>Configurations do not define any user interface classes. </li></ul>
  16. 17. Configurations Connected Limited Device Configuration Connected Device Configuration Configuration CLDC CDC
  17. 18. CLDC vs. CDC <ul><li>CLDC </li></ul><ul><ul><li>For very constrained devices </li></ul></ul><ul><ul><li>160 - 512 KB of total memory </li></ul></ul><ul><ul><li>16-bit or 32-bit processor </li></ul></ul><ul><ul><li>Low power consumption and often operating with battery power </li></ul></ul><ul><ul><li>Connectivity with limited bandwidth </li></ul></ul><ul><li>CDC </li></ul><ul><ul><li>2 MB or more memory for Java platform </li></ul></ul><ul><ul><li>32-bit processor </li></ul></ul><ul><ul><li>High bandwidth network connection, most often using TCP/IP </li></ul></ul>
  18. 19. CLDC vs. CDC - VM <ul><li>Features missing in the CLDC VM: </li></ul><ul><ul><li>Floating point types </li></ul></ul><ul><ul><li>Object finalization </li></ul></ul><ul><ul><li>JNI or reflection </li></ul></ul><ul><ul><li>Thread groups or daemon threads </li></ul></ul><ul><ul><li>User Class loaders </li></ul></ul><ul><li>Change in classfile verification  preverification </li></ul><ul><li>The CDC supports a complete, full-featured Java 2 virtual machine </li></ul>
  19. 20. The KVM and CVM <ul><li>KVM - Java virtual machines for the CLDC </li></ul><ul><li>CVM - Java virtual machines for the CDC </li></ul><ul><li>Written specifically to work in the constrained environment of a handheld or embedded device and to be easily ported to different platforms. </li></ul><ul><li>CLDC and CDC specifications do not require the use of the KVM or the CVM. </li></ul>
  20. 21. CLDC vs. CDC – J2SE Subset <ul><li>The CLDC includes classes from: </li></ul><ul><ul><li>java.lang </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li>java.util </li></ul></ul><ul><li>Only selected classes from each package are included </li></ul><ul><li>The CDC includes 17 packages </li></ul><ul><li>Includes more classes even in the shared packages </li></ul>
  21. 22. CLDC vs. CDC – J2SE Subset CDC CLDC J2SE
  22. 23. Handling I/O <ul><li>J2SE includes many classes for performing input and output. </li></ul><ul><li>There are a large number of I/O classes and they tend to encapsulate I/O models that are not necessarily found on all devices. </li></ul><ul><li>For example, some handheld devices do not have file systems. Socket support is not universal, either. </li></ul>
  23. 24. Handling I/O in CLDC <ul><li>The CLDC has define a new set of APIs for I/O called the Generic Connection Framework. </li></ul><ul><li>The GCF, part of the new package, defines interfaces for the different kinds of I/O that are possible. </li></ul><ul><li>The CLDC does not actually define any I/O implementations these are left to the profiles and/or the device vendor to define. </li></ul>
  24. 25. GCF - example <ul><li>import*; </li></ul><ul><li>import*; </li></ul><ul><li>StreamConnection conn = null; </li></ul><ul><li>InputStream is = null; </li></ul><ul><li>String url = &quot;socket://;; </li></ul><ul><li>try { </li></ul><ul><li>conn = (StreamConnection) url ); </li></ul><ul><li>is = conn.openInputStream(); </li></ul><ul><li>.... // etc. etc. </li></ul><ul><li>} … </li></ul>
  25. 26. Handling I/O in CDC <ul><li>Since the CDC is a superset of the CLDC, it includes the GCF. </li></ul><ul><li>CDC also requires GCF support for two specific connection types: files and datagrams. </li></ul><ul><li>The reason: CDC includes the relevant classes from and packages. </li></ul>
  26. 27. J2ME Core Concepts <ul><li>J2ME is based on 3 core concepts: </li></ul><ul><li>Configurations </li></ul><ul><li>Profiles </li></ul><ul><li>Optional packages </li></ul>
  27. 28. Profiles <ul><li>Adds domain-specific classes to a configuration: </li></ul><ul><ul><li>To fill in missing functionality </li></ul></ul><ul><ul><li>To support specific uses of a device </li></ul></ul><ul><li>Most profiles define user interface classes for building interactive applications. </li></ul><ul><li>To use a profile, the device must meet the minimum requirements of the underlying configuration and of the profile. </li></ul>
  28. 29. Profiles Mobile Information Device Profile Personal Digital Assistant Profile Foundation Profile Personal Basis Profile Personal Profile Profile MIDP PDAP PP PBP FP
  29. 30. MIDP – MID Profile <ul><li>MIDP is targeted at a class of devices known as mobile information devices (MIDs). </li></ul><ul><li>Minimal characteristics of MIDs: </li></ul><ul><ul><li>Enough memory to run MIDP applications </li></ul></ul><ul><ul><li>Display of at least 96 X 56 pixels, either monochrome or color </li></ul></ul><ul><ul><li>A keypad, keyboard, or touch screen </li></ul></ul><ul><ul><li>Two-way wireless networking capability </li></ul></ul>
  30. 31. MIDP - Specification <ul><li>There are two versions of the MIDP: </li></ul><ul><ul><li>MIDP 1.0 - released in September 2000. Many devices currently on the market support it. </li></ul></ul><ul><ul><li>MIDP 2.0 - currently in proposed final draft form. No devices yet support it. </li></ul></ul>
  31. 32. MIDP - Specification <ul><li>The MIDP adds APIs to the basic APIs defined by the CLDC. The new features include: </li></ul><ul><ul><li>Support for application lifecycle management similar to the way applets are defined in J2SE. </li></ul></ul><ul><ul><li>Persistent storage of data. </li></ul></ul><ul><ul><li>HTTP-based network connectivity based on the CLDC's GCF. </li></ul></ul><ul><ul><li>Simple user interface support, with enough flexibility to build games or business applications. </li></ul></ul>
  32. 33. MIDP - Specification <ul><li>The MIDP specification is silent about a number of things: </li></ul><ul><ul><li>No standard way to interface to the device's phonebook, in order to initiate voice calls. </li></ul></ul><ul><ul><li>How MIDP applications are loaded onto a device and how they are activated or deactivated. </li></ul></ul>
  33. 34. MIDP Applications restrictions <ul><li>Memory is a particularly scarce resource. </li></ul><ul><ul><li>The early Motorola J2ME-enabled phones limited the size of an application to 50K. Some Nokia phones limit them to even less, about 30K. </li></ul></ul><ul><li>MIDP 1.0 applications cannot share classes. </li></ul><ul><li>Placing part of the application in a web or application server (as a servlet, typically) that the MIDP application calls is almost a requirement for anything serious. </li></ul>
  34. 35. J2ME Core Concepts <ul><li>J2ME is based on 3 core concepts: </li></ul><ul><li>Configurations </li></ul><ul><li>Profiles </li></ul><ul><li>Optional packages </li></ul>
  35. 36. Optional Packages <ul><li>Set of APIs in support of additional, common behaviors. </li></ul><ul><li>Have specific dependencies on a particular configuration and/or one or more profiles. </li></ul><ul><li>Examples of optional packages : </li></ul><ul><ul><li>RMI Optional Package </li></ul></ul><ul><ul><li>Bluetooth Optional Package </li></ul></ul><ul><ul><li>JDBC Optional Package </li></ul></ul>
  36. 37. What it all means <ul><li>&quot;J2ME application&quot; is an ambiguous term. </li></ul><ul><li>Configuration, profile and optional packages should be chosen. </li></ul><ul><li>CDC-based profiles make development simpler due to J2SE-like APIs, but don’t suit the low-end devices. </li></ul><ul><li>CLDC-based profiles makes the development task harder, especially when trying to shrink the size of the application to run on many of the small devices . </li></ul>
  37. 38. Start working...
  38. 39. MIDlets – The heart of J2ME… <ul><li>MIDP does not support the running of applications that use a static main method as their entry point, nor calling the System.exit method in order to terminate. </li></ul><ul><li>Instead, we use a MIDlet , which is a MID Profile application. </li></ul>
  39. 40. MIDlets – The heart of J2ME… <ul><li>Every application must extend javax.microedition.midlet.MIDlet class to allow the application management software to: </li></ul><ul><ul><li>control the MIDlet </li></ul></ul><ul><ul><li>be able to retrieve properties from the application descriptor </li></ul></ul><ul><ul><li>notify and request state changes </li></ul></ul>
  40. 41. MIDlets – The heart of J2ME… <ul><li>The extending class is the main class of the application. </li></ul><ul><li>The MIDlet class defines abstract methods that the main class implements (for example: startApp(), destroyApp(), notifyDestroyed()). </li></ul>
  41. 42. MIDlet Suite <ul><li>One or more MIDlets are packaged together into a MIDlet suite, composed of: </li></ul><ul><ul><li>JAR (Java archive) file </li></ul></ul><ul><ul><li>JAD (Java Application Descriptor) file </li></ul></ul><ul><li>All the user-defined classes and resources required by the suite's MIDlets must be in the JAR file. </li></ul>
  42. 43. MIDlet Suite <ul><li>The JAR file must also include a manifest that describe the MIDlets in the suite. </li></ul><ul><li>The application descriptor (JAD) contains similar information, and is used by devices to obtain information about a MIDlet suite without having to download and install the MIDlet suite first. </li></ul>
  43. 44. Creating a MIDlet
  44. 45. Creating a MIDlet Importing MIDP specific packages import javax.microedition.lcdui.*; import javax.microedition.midlet.*;
  45. 46. Creating a MIDlet Extends MIDlet Implements CommandListener public class HelloMIDlet extends MIDlet implements CommandListener {
  46. 47. Creating a MIDlet Creating the form, adding the Commands public HelloMIDlet() { mMainForm = new Form(&quot;HelloMIDlet&quot;); mMainForm.append(new StringItem(null, &quot;Hello, Seminar Software Design!&quot;)); mMainForm.addCommand(new Command(&quot;Exit&quot;, Command.EXIT, 0)); mMainForm.setCommandListener(this); }
  47. 48. Sample MIDP classes API <ul><li>MIDlet </li></ul><ul><li>Form </li></ul><ul><li>Command </li></ul><ul><ul><li>CommandListener </li></ul></ul><ul><ul><li>ItemCommandListener </li></ul></ul><ul><li>Item </li></ul>
  48. 49. Sample classes API <ul><li>MIDlet – Base class </li></ul><ul><li>Form </li></ul><ul><li>Command </li></ul><ul><ul><li>CommandListener </li></ul></ul><ul><ul><li>ItemCommandListener </li></ul></ul><ul><li>Item </li></ul>
  49. 50. MIDlet class API <ul><li>protected abstract void startApp () </li></ul><ul><li>protected abstract void pauseApp () </li></ul><ul><li>protected abstract void destroyApp (boolean unconditional) </li></ul><ul><li>public final String getAppProperty (String key) </li></ul><ul><li>public final void notifyDestroyed () </li></ul>
  50. 51. Sample classes API <ul><li>MIDlet </li></ul><ul><li>Form </li></ul><ul><li>Command </li></ul><ul><ul><li>CommandListener </li></ul></ul><ul><ul><li>ItemCommandListener </li></ul></ul><ul><li>Item </li></ul>
  51. 52. Form class <ul><li>A Form is a Screen that contains an arbitrary mixture of items: images, read-only text fields, editable text fields, editable date fields, gauges, choice groups, and custom items. </li></ul><ul><li>In general, any subclass of the Item class may be contained within a form. </li></ul><ul><li>The implementation handles layout, traversal, and scrolling. </li></ul>
  52. 53. Form class API <ul><li>Item management </li></ul><ul><ul><li>public int append (Item item) </li></ul></ul><ul><ul><li>public Item get (int itemNum) </li></ul></ul><ul><li>Layout </li></ul><ul><li>public void setItemStateListener (ItemStateListener iListener) </li></ul>
  53. 54. Sample classes API <ul><li>MIDlet </li></ul><ul><li>Form </li></ul><ul><li>Command </li></ul><ul><ul><li>CommandListener </li></ul></ul><ul><ul><li>ItemCommadListener </li></ul></ul><ul><li>Item </li></ul>
  54. 55. Command class <ul><li>The Command class represents the semantic meaning of an action. Command objects are presented in the user interface. </li></ul><ul><li>The action itself is implemented in a CommandListener object. </li></ul><ul><li>The CommandListener is associated with a Displayable or an Item. </li></ul><ul><li>Once the Command is called – the CommandListener is invoked, and the action is performed. </li></ul>
  55. 56. Command class <ul><li>Command label </li></ul><ul><ul><li>public String getLabel () </li></ul></ul><ul><li>Command type </li></ul><ul><ul><li>public int getCommandType () </li></ul></ul><ul><li>Command priority </li></ul><ul><ul><li>public int getPriority () </li></ul></ul>
  56. 57. CommandListener class API <ul><li>This object is a listener for Commands that are attached to a Displayable. </li></ul><ul><li>public void commandAction (Command c, Displayable d) </li></ul>
  57. 58. ItemCommandListener class API <ul><li>When a command (attached to an Item) is invoked, the application is notified by having the commandAction() method called on the ItemCommandListener that had been set on the Item. </li></ul><ul><li>public void commandAction (Command c, Item item) </li></ul>
  58. 59. Sample classes API <ul><li>MIDlet </li></ul><ul><li>Form </li></ul><ul><li>Command </li></ul><ul><ul><li>CommandListener </li></ul></ul><ul><ul><li>ItemCommandListener </li></ul></ul><ul><li>Item </li></ul>
  59. 60. Item class <ul><li>A superclass for components that can be added to a Form. </li></ul><ul><li>All Item objects have a label field </li></ul><ul><li>Choose the Item’s layout, size, and appearance </li></ul><ul><li>Attach Commands </li></ul>
  60. 61. Item class API <ul><li>public void setDefaultCommand (Command cmd) </li></ul><ul><li>public void setItemCommandListener (ItemCommandListener listener) </li></ul><ul><li>public void notifyStateChanged () </li></ul><ul><li>public int getPreferredWidth () </li></ul>
  61. 62. Getting Started… <ul><ul><li>1 st step : Download sun’s J2ME Wireless Toolkit from: </li></ul></ul><ul><ul><li>2 nd step : Make sure you have J2SE SDK installed </li></ul></ul><ul><ul><li>3 rd step : Install the J2ME Toolkit. </li></ul></ul>
  62. 63. After the installation…. <ul><li>Shortcuts are available from the start menu. </li></ul><ul><li>New directories created </li></ul>
  63. 64. Using KToolbar
  64. 65. Creating a new Application <ul><li>Press “New Project”. </li></ul><ul><li>Enter the project’s name and the MIDlet’s class name. </li></ul><ul><li>New directories will automatically be created. </li></ul>
  65. 66. Where to place your files? external class libraries, (JAR or ZIP) for all KToolbar projects. J2ME/apps/lib source files J2ME/apps/{proj}/src resource files J2ME/apps/{proj}/res external class libraries, (JAR or ZIP) for a specific project J2ME/apps/{proj}/lib JAR, JAD, unpacked manifest files. J2ME/apps/{proj}/bin source, resource, and binary files J2ME/apps/{proj}
  66. 67. And then what? <ul><li>Choose the target platform </li></ul><ul><li>Write your code </li></ul><ul><li>Save </li></ul><ul><li>Build (Compile + Preverify) </li></ul><ul><li>Run </li></ul><ul><ul><li>JTWI - conforms to Java Technology for the Wireless Industry (JSR-185). </li></ul></ul><ul><ul><li>MIDP1.0 - includes MIDP 1.0 and CLDC 1.0 </li></ul></ul><ul><ul><li>Custom - user defined settings, you can select project profile, configurations and various APIs. </li></ul></ul>
  67. 68. Distribution to actual devices <ul><li>Create a package </li></ul><ul><li>Place your code somewhere on the net. </li></ul><ul><li>Update .jad file </li></ul><ul><li>Download the application to your mobile </li></ul><ul><li>Start playing…  </li></ul>
  68. 69. Some other issues <ul><li>OTA provisioning </li></ul><ul><li>Using Servlets </li></ul><ul><li>Working with EclipseME </li></ul><ul><li>Web services </li></ul>
  69. 70. The END! <ul><li>You can download all the demos JARs from: </li></ul><ul><li>Have Fun!!! </li></ul>