You are on page 1of 70

Developing Java 2 ME Applications

Abelski eLearning
www.abelski.com
Introduction
J2SE, J2EE & J2ME

 Sun Microsystems groups its Java technologies into groups.

 The three most important groups are the following platforms:


Java 2 SE (J2SE) Java 2 Standard Edition Platform
Java 2 EE (J2EE) Java 2 Enterprise Edition Platform
Java 2 ME (J2ME) Java 2 Micro Edition Platform

 The various platforms aren't fully separated from each other.

 Each platform includes a JVM, libraries of classes &


development tools.

04/02/08 © Abelski eLearning 3


J2SE, J2EE & J2ME

J2EE J2SE J2ME

04/02/08 © Abelski eLearning 4


J2ME Configurations

 The Java 2 Micro Edition platform has two possible


configurations:
CLDC Connected Limited Device Configuration
CDC Connected Device Configuration

 These two configurations target two different categories of


products:
Low End Devices
High End Devices

04/02/08 © Abelski eLearning 5


J2ME Configurations

J2SE CDC CLDC

04/02/08 © Abelski eLearning 6


J2ME Profiles

 On top of the configuration we can expect a profile (one or


more) to be deployed.

 A J2ME profile addresses a specific need, and it typically


includes class libraries that are more specific than the
classes libraries the configuration includes.

 Currently, MIDP (Mobile Information Device Profile) is the


most popular profile.

04/02/08 © Abelski eLearning 7


J2ME Profiles

Personal RMI Profile


Profile
MIDP PDAP
Profile Profile
Foundation Profile

CLDC CDC

J2ME

04/02/08 © Abelski eLearning 8


J2ME (CLDC/MIDP)

 This course focuses on developing J2ME application for


mobile telephones with J2ME running environment CLDC
configuration and MIDP profile.

 The mobile telephones mass market includes mobile


telephones that support the J2ME(CLDC/MIDP) running
environment.

04/02/08 © Abelski eLearning 9


The KVM

 The KVM is a compact portable small JVM designed for


resource constrained devices.

 The J2ME (CLDC/MIDP) devices use the KVM.

04/02/08 © Abelski eLearning 10


J2ME (CLDC/MIDP) & J2SE
 J2ME(CLDC\MIDP) java.lang package is a subset of the
J2SE java.lang package.

 J2ME(CLDC\MIDP) doesn’t allow controlling the class loader.

 J2ME(CLDC\MIDP) doesn’t support object finalization.

 J2ME(CLDC\MIDP) doesn’t support reflection.

04/02/08 © Abelski eLearning 11


J2ME (CLDC/MIDP) & J2SE
 J2ME(CLDC\MIDP) doesn’t support a mechanism (like the
JNI) that enables writing native methods.

 J2ME(CLDC\MIDP) multi threading mechanism is very


similar to the one that the J2SE has.

 J2ME(CLDC\MIDP) Math class is a subset.

 J2ME(CLDC\MIDP) has smaller version of the String and


the StringBuffer classes.

04/02/08 © Abelski eLearning 12


J2ME (CLDC/MIDP) & J2SE
 J2ME(CLDC\MIDP) has smaller version of the System and
the Runtime classes.

 J2ME(CLDC\MIDP) java.util package includes only few of


the classes and interface that exist in the J2SE version.

 J2ME(CLDC\MIDP) java.io package include only few of the


classes and the interfaces that exist in the J2SE version.

04/02/08 © Abelski eLearning 13


Developing The First Midlet
 The J2ME application model is very similar to the one used
by Java applets and Java servlets.

 You need to declare a class that extends the Midlet class.

 That class must be public and it must include a constructor


without parameters.

04/02/08 © Abelski eLearning 14


Developing The First Midlet
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class Hello extends MIDlet


{
private Display display;
private Form form;

public Hello()
{
form = new Form("Hello");
display = Display.getDisplay(this);
}

public void startApp()


{
display.setCurrent(form);
}

public void pauseApp() { }


public void destroyApp(boolean cond) { }
}

04/02/08 © Abelski eLearning 15


Developing The First Midlet
 Run the Wireless Toolkit.

04/02/08 © Abelski eLearning 16


04/02/08 © Abelski eLearning 17
04/02/08 © Abelski eLearning 18
Developing The First Midlet
 Create new project.
File -> New Project

 Fill in the details of the new project.


Project Name
The project name is the name of the project you choose for your new work.
MIDlet Class Name
The MIDlet class name is the name of the class you declared as one that
extends Midlet. When developing a J2ME application composed of several
classes, among those classes there must be a class that extends Midlet. That
would be the main class (similar to the Applet model).

04/02/08 © Abelski eLearning 19


04/02/08 © Abelski eLearning 20
04/02/08 © Abelski eLearning 21
Developing The First Midlet
 Press the “Create Project” button to create your project.

 The wizard pop up dialog window allows you to configure


the project you are about to develop.

04/02/08 © Abelski eLearning 22


04/02/08 © Abelski eLearning 23
Developing The First Midlet
 One of the outcomes for creating the new project is the
creation of folders hierarchy specifically for the new project.

 Each project has its own specific folder.

 All projects folders are kept within the “apps” folder.

 Each project folder includes the following sub folders:


bin ...this folder will include the JAR/JAD created files.
src ...this folder should include all project source code.
lib ...this folder should include all additional third party classes we add.
res ...this folder should include all additional resource files (images, sound etc.).

04/02/08 © Abelski eLearning 24


04/02/08 © Abelski eLearning 25
Developing The First Midlet
 Write your source code and save it within the “src” folder.

 Choose “Build” to compile & preverify your code.

04/02/08 © Abelski eLearning 26


04/02/08 © Abelski eLearning 27
Developing The First Midlet
 Choose “Project” -> “Package” -> Create Package” in order
to create the JAR/JAD files.

04/02/08 © Abelski eLearning 28


04/02/08 © Abelski eLearning 29
Developing The First Midlet
 You can now find the JAR/JAD files within the “bin” folder of
your project.

 You can install the JAR and the JAD files on your mobile
telephone.

 Alternatively, you can choose “Run” and run your code via
the wireless toolkit on one of its emulators.

04/02/08 © Abelski eLearning 30


04/02/08 © Abelski eLearning 31
04/02/08 © Abelski eLearning 32
04/02/08 © Abelski eLearning 33
The Java Application Manager (JAM)
 The MIDlet life cycle is controlled by the Java Application
Manager (JAM).
The JAM is a MIDlet management software that controls the process of
installing, running and removing the MIDlets.

 When the user chooses to run a MIDlet, it is the JAM that


creates an instance of the MIDlet class and runs methods
on it.
The sequence of method that will be invoked on the MIDlet subclass instance is
defined by the MIDlet life cycle. Like the servlets and the applets, the midlets
also have a well-defined set of states.

04/02/08 © Abelski eLearning 34


The Java Application Manager (JAM)
 The JAM calls various methods on the midlet to signify
changes from one state to another.
These methods include the following: startApp(), pauseApp(), destroyApp() and
the MIDlet subclass constructors as well.

04/02/08 © Abelski eLearning 35


© Zindell Technologies, Ltd. 04/02/08

Developing Java 2 ME Applications

Abelski eLearning
www.abelski.com

04/02/08 © Abelski eLearning 1

© Abelski eLearning 1
© Zindell Technologies, Ltd. 04/02/08

Introduction

04/02/08 © Abelski eLearning 2

© Abelski eLearning 2
© Zindell Technologies, Ltd. 04/02/08

J2SE, J2EE & J2ME

 Sun Microsystems groups its Java technologies into groups.

 The three most important groups are the following platforms:


Java 2 SE (J2SE) Java 2 Standard Edition Platform
Java 2 EE (J2EE) Java 2 Enterprise Edition Platform
Java 2 ME (J2ME) Java 2 Micro Edition Platform

 The various platforms aren't fully separated from each other.

 Each platform includes a JVM, libraries of classes &


development tools.

04/02/08 © Abelski eLearning 3

Browsing at http://java.sun.com/ you can find on the right a list


of all available Java technologies.

© Abelski eLearning 3
© Zindell Technologies, Ltd. 04/02/08

J2SE, J2EE & J2ME

J2EE J2SE J2ME

04/02/08 © Abelski eLearning 4

© Abelski eLearning 4
© Zindell Technologies, Ltd. 04/02/08

J2ME Configurations

 The Java 2 Micro Edition platform has two possible


configurations:
CLDC Connected Limited Device Configuration
CDC Connected Device Configuration

 These two configurations target two different categories of


products:
Low End Devices
High End Devices

04/02/08 © Abelski eLearning 5

These two configurations target two categories of products:


High-end devices (TV set-top boxes, Internet TVs, automobile
navigation systems etc�) which have large range of user
interface capabilities, high-bandwidth network connections
(usually TCP/IP) and more memory and CPU power.
and
Low-end devices (Cell phones, pagers, PDA�s etc�) which
have very simple user interface and small screen size, less
memory, less CPU power, lower bandwidth and most of them
are usually operated using batteries.

© Abelski eLearning 5
© Zindell Technologies, Ltd. 04/02/08

J2ME Configurations

J2SE CDC CLDC

04/02/08 © Abelski eLearning 6

© Abelski eLearning 6
© Zindell Technologies, Ltd. 04/02/08

J2ME Profiles

 On top of the configuration we can expect a profile (one or


more) to be deployed.

 A J2ME profile addresses a specific need, and it typically


includes class libraries that are more specific than the
classes libraries the configuration includes.

 Currently, MIDP (Mobile Information Device Profile) is the


most popular profile.

04/02/08 © Abelski eLearning 7

A J2ME configuration defines the Java language, the virtual


machine features and the minimum class libraries for a
category\group of devices (�horizontal� market).
A J2ME profile is layered on top of configuration and address
the specific demands of a specific vertical market (or device
category). The profile typically includes class libraries that are
far more specific than the class libraries provided in a
configuration.

© Abelski eLearning 7
© Zindell Technologies, Ltd. 04/02/08

J2ME Profiles

Personal RMI Profile


Profile
MIDP PDAP
Profile Profile
Foundation Profile

CLDC CDC

J2ME

04/02/08 © Abelski eLearning 8

© Abelski eLearning 8
© Zindell Technologies, Ltd. 04/02/08

J2ME (CLDC/MIDP)

 This course focuses on developing J2ME application for


mobile telephones with J2ME running environment CLDC
configuration and MIDP profile.

 The mobile telephones mass market includes mobile


telephones that support the J2ME(CLDC/MIDP) running
environment.

04/02/08 © Abelski eLearning 9

According to the specification, the MID profile has the following


characteristics:
At least 128KB of non-volatile memory (non-volatile memory is
memory that is capable of keeping its contents intact as the
device is turned on and off. The ROM is one example for non-
volatile memory) for the MIDP implementation.
At least 32KB of volatile memory for the heap.
At least 8KB of non-volatile memory for persistent data.
A screen of at least 96x54 pixels.
Pixel ratio approximately 1:1.
An Input mechanism � one of the following: keypad, keyboard
or touch screen.
Two-way network connection.
The classes a MIDP application can use come from packages
in both the CLDC and the MIDP. The packages the CLDC has
are: java.lang, java.io, java.util, javax.microedition.io. The
packages the MID profile adds are: javax.microedition.lcdui,
javax.microedition.midlet and javax.microedition.rms.

© Abelski eLearning 9
© Zindell Technologies, Ltd. 04/02/08

The KVM

 The KVM is a compact portable small JVM designed for


resource constrained devices.

 The J2ME (CLDC/MIDP) devices use the KVM.

04/02/08 © Abelski eLearning 10

According to the specification, the MID profile has the following


characteristics:
At least 128KB of non-volatile memory (non-volatile memory is
memory that is capable of keeping its contents intact as the
device is turned on and off. The ROM is one example for non-
volatile memory) for the MIDP implementation.
At least 32KB of volatile memory for the heap.
At least 8KB of non-volatile memory for persistent data.
A screen of at least 96x54 pixels.
Pixel ratio approximately 1:1.
An Input mechanism � one of the following: keypad, keyboard
or touch screen.
Two-way network connection.
The classes a MIDP application can use come from packages
in both the CLDC and the MIDP. The packages the CLDC has
are: java.lang, java.io, java.util, javax.microedition.io. The
packages the MID profile adds are: javax.microedition.lcdui,
javax.microedition.midlet and javax.microedition.rms.

© Abelski eLearning 10
© Zindell Technologies, Ltd. 04/02/08

J2ME (CLDC/MIDP) & J2SE


 J2ME(CLDC\MIDP) java.lang package is a subset of the
J2SE java.lang package.

 J2ME(CLDC\MIDP) doesn’t allow controlling the class loader.

 J2ME(CLDC\MIDP) doesn’t support object finalization.

 J2ME(CLDC\MIDP) doesn’t support reflection.

04/02/08 © Abelski eLearning 11

© Abelski eLearning 11
© Zindell Technologies, Ltd. 04/02/08

J2ME (CLDC/MIDP) & J2SE


 J2ME(CLDC\MIDP) doesn’t support a mechanism (like the
JNI) that enables writing native methods.

 J2ME(CLDC\MIDP) multi threading mechanism is very


similar to the one that the J2SE has.

 J2ME(CLDC\MIDP) Math class is a subset.

 J2ME(CLDC\MIDP) has smaller version of the String and


the StringBuffer classes.

04/02/08 © Abelski eLearning 12

© Abelski eLearning 12
© Zindell Technologies, Ltd. 04/02/08

J2ME (CLDC/MIDP) & J2SE


 J2ME(CLDC\MIDP) has smaller version of the System and
the Runtime classes.

 J2ME(CLDC\MIDP) java.util package includes only few of


the classes and interface that exist in the J2SE version.

 J2ME(CLDC\MIDP) java.io package include only few of the


classes and the interfaces that exist in the J2SE version.

04/02/08 © Abelski eLearning 13

© Abelski eLearning 13
© Zindell Technologies, Ltd. 04/02/08

Developing The First Midlet


 The J2ME application model is very similar to the one used
by Java applets and Java servlets.

 You need to declare a class that extends the Midlet class.

 That class must be public and it must include a constructor


without parameters.

04/02/08 © Abelski eLearning 14

© Abelski eLearning 14
© Zindell Technologies, Ltd. 04/02/08

Developing The First Midlet


import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class Hello extends MIDlet


{
private Display display;
private Form form;

public Hello()
{
form = new Form("Hello");
display = Display.getDisplay(this);
}

public void startApp()


{
display.setCurrent(form);
}

public void pauseApp() { }


public void destroyApp(boolean cond) { }
}

04/02/08 © Abelski eLearning 15

© Abelski eLearning 15
© Zindell Technologies, Ltd. 04/02/08

Developing The First Midlet


 Run the Wireless Toolkit.

04/02/08 © Abelski eLearning 16

© Abelski eLearning 16
© Zindell Technologies, Ltd. 04/02/08

04/02/08 © Abelski eLearning 17

© Abelski eLearning 17
© Zindell Technologies, Ltd. 04/02/08

04/02/08 © Abelski eLearning 18

© Abelski eLearning 18
© Zindell Technologies, Ltd. 04/02/08

Developing The First Midlet


 Create new project.
File -> New Project

 Fill in the details of the new project.


Project Name
The project name is the name of the project you choose for your new work.
MIDlet Class Name
The MIDlet class name is the name of the class you declared as one that
extends Midlet. When developing a J2ME application composed of several
classes, among those classes there must be a class that extends Midlet. That
would be the main class (similar to the Applet model).

04/02/08 © Abelski eLearning 19

© Abelski eLearning 19
© Zindell Technologies, Ltd. 04/02/08

04/02/08 © Abelski eLearning 20

© Abelski eLearning 20
© Zindell Technologies, Ltd. 04/02/08

04/02/08 © Abelski eLearning 21

© Abelski eLearning 21
© Zindell Technologies, Ltd. 04/02/08

Developing The First Midlet


 Press the “Create Project” button to create your project.

 The wizard pop up dialog window allows you to configure


the project you are about to develop.

04/02/08 © Abelski eLearning 22

Press OK when the project configuration pop up window dialog


is shown. For now we will accept all default setting.

© Abelski eLearning 22
© Zindell Technologies, Ltd. 04/02/08

04/02/08 © Abelski eLearning 23

© Abelski eLearning 23
© Zindell Technologies, Ltd. 04/02/08

Developing The First Midlet


 One of the outcomes for creating the new project is the
creation of folders hierarchy specifically for the new project.

 Each project has its own specific folder.

 All projects folders are kept within the “apps” folder.

 Each project folder includes the following sub folders:


bin ...this folder will include the JAR/JAD created files.
src ...this folder should include all project source code.
lib ...this folder should include all additional third party classes we add.
res ...this folder should include all additional resource files (images, sound etc.).

04/02/08 © Abelski eLearning 24

© Abelski eLearning 24
© Zindell Technologies, Ltd. 04/02/08

04/02/08 © Abelski eLearning 25

© Abelski eLearning 25
© Zindell Technologies, Ltd. 04/02/08

Developing The First Midlet


 Write your source code and save it within the “src” folder.

 Choose “Build” to compile & preverify your code.

04/02/08 © Abelski eLearning 26

When developing a J2ME application there is a need to


preverify the source code (in addition to the compilation). The
KVM – unlike the JVM – is not capable of doing all code checks
before it runs it. Therefore, these checks are carried out via the
preverification stage.

© Abelski eLearning 26
© Zindell Technologies, Ltd. 04/02/08

04/02/08 © Abelski eLearning 27

© Abelski eLearning 27
© Zindell Technologies, Ltd. 04/02/08

Developing The First Midlet


 Choose “Project” -> “Package” -> Create Package” in order
to create the JAR/JAD files.

04/02/08 © Abelski eLearning 28

© Abelski eLearning 28
© Zindell Technologies, Ltd. 04/02/08

04/02/08 © Abelski eLearning 29

© Abelski eLearning 29
© Zindell Technologies, Ltd. 04/02/08

Developing The First Midlet


 You can now find the JAR/JAD files within the “bin” folder of
your project.

 You can install the JAR and the JAD files on your mobile
telephone.

 Alternatively, you can choose “Run” and run your code via
the wireless toolkit on one of its emulators.

04/02/08 © Abelski eLearning 30

© Abelski eLearning 30
© Zindell Technologies, Ltd. 04/02/08

Click to add title


● Click to add an outline

04/02/08 © Abelski eLearning 31

© Abelski eLearning 31
© Zindell Technologies, Ltd. 04/02/08

Click to add title


● Click to add an outline

04/02/08 © Abelski eLearning 32

© Abelski eLearning 32
© Zindell Technologies, Ltd. 04/02/08

Click to add title


● Click to add an outline

04/02/08 © Abelski eLearning 33

© Abelski eLearning 33
© Zindell Technologies, Ltd. 04/02/08

The Java Application Manager (JAM)


 The MIDlet life cycle is controlled by the Java Application
Manager (JAM).
The JAM is a MIDlet management software that controls the process of
installing, running and removing the MIDlets.

 When the user chooses to run a MIDlet, it is the JAM that


creates an instance of the MIDlet class and runs methods
on it.
The sequence of method that will be invoked on the MIDlet subclass instance is
defined by the MIDlet life cycle. Like the servlets and the applets, the midlets
also have a well-defined set of states.

04/02/08 © Abelski eLearning 34

© Abelski eLearning 34
© Zindell Technologies, Ltd. 04/02/08

The Java Application Manager (JAM)


 The JAM calls various methods on the midlet to signify
changes from one state to another.
These methods include the following: startApp(), pauseApp(), destroyApp() and
the MIDlet subclass constructors as well.

04/02/08 © Abelski eLearning 35

© Abelski eLearning 35

You might also like