Java ME (J2ME) is a Java platform for mobile devices and embedded systems. It has two configurations: Connected Limited Device Configuration (CLDC) and Connected Device Configuration (CDC). CLDC contains minimal libraries for basic functionality on memory-limited devices. Profiles like MIDP add user interface and storage capabilities. MIDP, layered on CLDC, is widely used and provides APIs for user interfaces, networking, and local storage. Java ME applications built using profiles like MIDP are called midlets. Midlets can be run on emulators and go through start, pause, and destroy life cycle states.
2. Introduction J2ME or Java ME is a java platform designed for mobile phones and embedded systems Java ME is a replacement for a similar technology known as Personal Java Java ME is basically divided into two configurations Connected Limited Device Configuration Connected Device Configuration
3. Connected Limited Device Configuration The CLDC or Connected Limited Device Configuration contains a strict subset of the Java-class libraries, and is the minimum amount needed for a JVM to operate. A configuration provides the most basic set of libraries and virtual-machine features that must be present in each implementation of a J2ME environment. When coupled with one or more profiles, the Connected Limited Device Configuration gives developers a solid Java platform for creating applications for consumers and embedded devices. CLDC has got many profiles of which MIDP is the most widely used one CLDC is used with devices having limited memory and processor
4. Connected Device Configuration CDC or Connected Device Configuration is a subset of Java SE, containing almost all the libraries that are not GUI related It is richer than CLDC It has got 3 profiles namely Foundation profile , Personal basis profile and Personal profile CDC profile is used for devices with more memory and processor speed CDC is used in high-end PDA’s, smart phones and set-top boxes
5. Profiles A profile complements a configuration by adding additional classes that provide features appropriate to a particular type of device or to a specific vertical market segment Profiles are layered on top of the configuration Both Java ME configurations have one or more associated profiles MIDP or Mobile Information Device Profile is the most widely used profile under CLDC
6. MIDP MIDP or Mobile Information Device Profile complements the CLDC by adding networking, user interface components, and local storage This profile is primarily aimed at the limited display and storage facilities of mobile phones, and it therefore provides a relatively simple user interface and basic networking based on HTTP 1.1. MIDP is the best known of the J2ME profiles because it is the basis for Wireless Java MIDP provides some important API’s under CLDC such as javax.microedition.midlet, javax.microedition.lcdui, javax.microedition.rms
7. Midlets and emulator Java ME is a platform designed for small devices with low memory and processor speed An application made using MID profile is called a midlet Midlets can be run on any platform which has a JVM installed Midlets needs an emulator to run them An emulator is an application that run a midlet on the desktop Sun’s Wireless Toolkit and EclipseME provides an emulator that are used for running a midlet A group of midlets is called a midlet suite
8. Midlet life cycle There are three possible states in a midlet’s life cycle paused – The midlet instance is created and is inactive active – The midlet is active destroyed – The midlet is terminated and is ready for reclamation by the garbage collector When the midlet is created in response to a user request, it is in paused state. At some point later, the midlet is activated and again later can go back to the paused state and finally terminates due to the user request
9. A simple midlet import javax.microedition.midlet.*; class simple entendsMIDLet { public simple() { // constructor } public void startApp() { // some code } public void pauseApp() { } public void destroyApp(boolean destroy) { } }
10. A tour of CLDC/MIDP Packages: javax.microedition.midlet.*; javax.microedition.io.*; javax.microedition.lcdui.*; javax.microedition.rms.*; User Interface widgets: Form, TextField, List, TextBox, DateField, Image, Gauge, Alert, Canvas, Graphics, Display Event Handling classes: Command and Command Listener High level UI : Form, TextBox, etc. Low level UI : Canvas, Graphics
11. User Interface with MIDP The javax,microedition,lcdui.*; includes several classes for displaying the interface to the screen
12. Sample code using UI import javax.microedition.midlet.*; import javax.microedition.lcdui.*; // for using user interface widgets class UIdemo extends MIDlet implements CommandListener { Form form; Display display; // helps in displaying the form Command back,save; // commands public UIdemo() { form = new Form(“Sample code”); display = Display.getDisplay(this); back = new Command(“Back”,Command.BACK,1); save = new Command(“Save”,Command.OK,1); form.addCommand(back); form.addCommand(save); display.setCurrent(form); form.setCommandListener(this); } public void startApp() {} public void pauseApp() {} public void destroyApp(boolean destroy) {} public void commandAction(Command c, Displayable d) { // handler for the user actions if(c==back) destroyApp(true); else form.append(“Hello”); } }
13. Persistent storage Record Management System or rms helps in storing records locally on the device It stores records in binary format It stores data persistently and data can be retrieved later even after the device has been switched off Records are stored in the Record Stores Several methods in record store are: openRecordStore() closeRecordStore() deleteRecordStore() getRecord() Enumeraterecord() and so on
14. Connection types All the important classes and methods for connecting the to the wireless network are included in the javax.microedition.io.* package The connections types are provided by the InputStream and the OutputStream interfaces These interfaces adds the ability to input and output data over the network There are three important level of connections available Socket Datagram HTTP connection