You are on page 1of 27

Java ME

Introduction
Java Editions
Differences J2SE / Java ME (MIDP)

• Java ME is mainly a subset of J2SE


– But different UI-and event handling functionality
– Less utility classes (only Vector and Hashtable, no
LinkedLists, …)
• Code runs on both platforms?
– general algorithms: yes
– But the whole application needs porting
Java ME Core Concepts
Configuration
• Defines Java Platform for different device
classes:
• A configuration specifies the minimum set of
features and Java class libraries that the
associated Java virtual machine (JVM) should
support.
• J2ME offers two configurations
– Connected Limited Device Configuration (CLDC)
– Connected Device Configuration (CDC).
Configuration
• CLDC
– Limited user interface
– Low computing power (usually with a battery)
– Network with low bandwidth
• CDC
– Network connection with high bandwidth,
possibly persistent
– Larger memory requirements
CLDC
• CLDC is the J2ME configuration for
devices with less than 512 KB memory
footprint.
• CLDC is for the kilo VM (KVM), which is
a highly optimized JVM meant for lower-
end, network-connected, battery-operated
devices based on 16-bit or 32-bit
microprocessors.
CDC
• This configuration targets larger devices with
more capacity and with a network-connection, like
high-end personal digital assistants, and set-top
boxes.
• On the CDC configuration there are three different defined
profiles:
– The Foundation Profile (JSR 219)
– The Personal Basis Profile (JSR 217) and
– The Personal Profile (JSR 216)
J2SE-CDC-CLDC
Profiles
• Extension and more detailed specification
for a configuration
• Contains APIsfor UI, event handling, data
storage, networks, timers, …
• Minimum requirements for devices (screen
size, input possibilities, ...)
• For mobile phones:Mobile Information
Device Profile (MIDP)
Profiles
Sample Architecture of a Phone
Java ME –Examples

• Motorola/MOTORAZR V3
– CLDC 1.0
– MIDP 2.0
• Nokia N70
– CLDC 1.1
– MIDP 2.0
• SonyEricssonP990i
– CLDC 1.1
– MIDP 2.0
– CDC 1.0
– Personal Profile
Java ME –Examples

• Nokia N86 8MP


– CLDC 1.1
– MIDP 2.1
– MSA (Subset)
• Amazon Kindle 2
– CDC
MIDlet
• 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.
• Instead, we use a MIDlet, which is a MID
Profile application.
MIDlet
• Every application must extend
javax.microedition.midlet.MIDlet class to
allow the application management software
to:
– control the MIDlet
– be able to retrieve properties from the
application descriptor
– notify and request state changes
MIDlet
• The extending class is the main class of the
application.
• The MIDlet class defines abstract methods
that the main class implements (for
example: startApp(), destroyApp(),
notifyDestroyed()).
MIDlet Suite
• One or more MIDlets are packaged together
into a MIDlet suite, composed of:
– JAR (Java archive) file
– JAD (Java Application Descriptor) file
• All the user-defined classes and resources
required by the suite's MIDlets must be in
the JAR file.
Creating a MIDlet
• import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class HelloMidlet extends MIDlet {
    private Display display;
     TextBox box = null;
    public HelloMidlet() {
    }
    public void startApp() {
        display = Display.getDisplay(this);
        box = new TextBox("Simple Example", "Hello World", 20, 0);
        display.setCurrent(box);
    }

      public void pauseApp() {
    }
     public void destroyApp(boolean unconditional) {
    }
}

           
Event Handling
Listener
• Implement the Listener-Interface to get
informed:
– CommandListener: commandAction()Notification
when e.g. a menu item has been selected
– ItemCommandListener: commandAction()Used for
events for individual items
– ItemStateListener: itemStateChanged()When an UI
element has been changed
Command-Types
Command-Exit
• Class HelloWorldMIDlet:
… implements CommandListener
• Define new command (member variable):
– private Command cmdExit;
• Create it in the constructor:
cmdExit= new Command(“Exit”, Command.EXIT, 1);
frmMain.addCommand(cmdExit);
frmMain.setCommandListener(this);
Command Handling
• Method defined in the base class CommandListener:

• public void commandAction(Command c,


Displayable d){
if (c == cmdExit)
{destroyApp(true);
notifyDestroyed();
}
}
Discussion

You might also like