8/8/2019 Introduction to J2ME, Albeski
1/70
Developing Java 2 ME Applications
AbelskieLearning
www.abelski.com
http://www.abelski.com/http://www.abelski.com/8/8/2019 Introduction to J2ME, Albeski
2/70
Introduction
8/8/2019 Introduction to J2ME, Albeski
3/70
04/02/08 Abelski eLearning
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.
8/8/2019 Introduction to J2ME, Albeski
4/70
04/02/08 Abelski eLearning
J2SE, J2EE & J2ME
J2EE J2SE J2ME
8/8/2019 Introduction to J2ME, Albeski
5/70
8/8/2019 Introduction to J2ME, Albeski
6/70
04/02/08 Abelski eLearning
J2ME Configurations
J2SE CDC CLDC
8/8/2019 Introduction to J2ME, Albeski
7/70
04/02/08 Abelski eLearning
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.
8/8/2019 Introduction to J2ME, Albeski
8/70
04/02/08 Abelski eLearning
J2ME Profiles
J2ME
CLDC CDC
Foundation Profile
RMI ProfilePersonalProfile
PDAPProfile
MIDPProfile
8/8/2019 Introduction to J2ME, Albeski
9/70
04/02/08 Abelski eLearning
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.
8/8/2019 Introduction to J2ME, Albeski
10/70
04/02/08 Abelski eLearning 1
The KVM
The KVM is a compact portable small JVM designed for
resource constrained devices.
The J2ME (CLDC/MIDP) devices use the KVM.
8/8/2019 Introduction to J2ME, Albeski
11/70
04/02/08 Abelski eLearning 1
J2ME (CLDC/MIDP) & J2SE
J2ME(CLDC\MIDP) java.lang package is a subset of the
J2SE java.lang package.
J2ME(CLDC\MIDP) doesnt allow controlling the class loader.
J2ME(CLDC\MIDP) doesnt support object finalization.
J2ME(CLDC\MIDP) doesnt support reflection.
8/8/2019 Introduction to J2ME, Albeski
12/70
04/02/08 Abelski eLearning 1
J2ME (CLDC/MIDP) & J2SE
J2ME(CLDC\MIDP) doesnt 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.
8/8/2019 Introduction to J2ME, Albeski
13/70
04/02/08 Abelski eLearning 1
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.
8/8/2019 Introduction to J2ME, Albeski
14/70
04/02/08 Abelski eLearning 1
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.
8/8/2019 Introduction to J2ME, Albeski
15/70
04/02/08 Abelski eLearning 1
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) { }
}
8/8/2019 Introduction to J2ME, Albeski
16/70
04/02/08 Abelski eLearning 1
Developing The First Midlet
Run the Wireless Toolkit.
8/8/2019 Introduction to J2ME, Albeski
17/70
04/02/08 Abelski eLearning 1
8/8/2019 Introduction to J2ME, Albeski
18/70
04/02/08 Abelski eLearning 1
8/8/2019 Introduction to J2ME, Albeski
19/70
04/02/08 Abelski eLearning 1
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).
8/8/2019 Introduction to J2ME, Albeski
20/70
04/02/08 Abelski eLearning 2
8/8/2019 Introduction to J2ME, Albeski
21/70
04/02/08 Abelski eLearning 2
8/8/2019 Introduction to J2ME, Albeski
22/70
04/02/08 Abelski eLearning 2
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.
8/8/2019 Introduction to J2ME, Albeski
23/70
04/02/08 Abelski eLearning 2
8/8/2019 Introduction to J2ME, Albeski
24/70
04/02/08 Abelski eLearning 2
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.).
8/8/2019 Introduction to J2ME, Albeski
25/70
04/02/08 Abelski eLearning 2
8/8/2019 Introduction to J2ME, Albeski
26/70
04/02/08 Abelski eLearning 2
Developing The First Midlet
Write your source code and save it within the src folder.
Choose Build to compile & preverify your code.
8/8/2019 Introduction to J2ME, Albeski
27/70
04/02/08 Abelski eLearning 2
8/8/2019 Introduction to J2ME, Albeski
28/70
04/02/08 Abelski eLearning 2
Developing The First Midlet
Choose Project -> Package -> Create Package in order
to create the JAR/JAD files.
8/8/2019 Introduction to J2ME, Albeski
29/70
04/02/08 Abelski eLearning 2
8/8/2019 Introduction to J2ME, Albeski
30/70
04/02/08 Abelski eLearning 3
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.
8/8/2019 Introduction to J2ME, Albeski
31/70
04/02/08 Abelski eLearning 3
8/8/2019 Introduction to J2ME, Albeski
32/70
04/02/08 Abelski eLearning 3
8/8/2019 Introduction to J2ME, Albeski
33/70
04/02/08 Abelski eLearning 3
8/8/2019 Introduction to J2ME, Albeski
34/70
04/02/08 Abelski eLearning 3
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.
8/8/2019 Introduction to J2ME, Albeski
35/70
04/02/08 Abelski eLearning 3
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.
8/8/2019 Introduction to J2ME, Albeski
36/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 1
Developing Java 2 ME Applications
AbelskieLearning
www.abelski.com
8/8/2019 Introduction to J2ME, Albeski
37/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 2
Introduction
8/8/2019 Introduction to J2ME, Albeski
38/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 3
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.
Browsing at http://java.sun.com/ you can find on the right a listof all available Java technologies.
8/8/2019 Introduction to J2ME, Albeski
39/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 4
J2SE, J2EE & J2ME
J2EE J2SE J2ME
8/8/2019 Introduction to J2ME, Albeski
40/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 5
J2ME Configurations
The Java 2 Micro Edition platform has two possibleconfigurations:
CLDC Connected Limited Device Configuration
CDC Connected Device Configuration
These two configurations target two different categories of
products:
Low End Devices
High End Devices
These two configurations target two categories of products:High-end devices (TV set-top boxes, Internet TVs, automobilenavigation systems etc) which have large range of userinterface capabilities, high-bandwidth network connections(usually TCP/IP) and more memory and CPU power.
andLow-end devices (Cell phones, pagers, PDAs etc) whichhave very simple user interface and small screen size, lessmemory, less CPU power, lower bandwidth and most of themare usually operated using batteries.
8/8/2019 Introduction to J2ME, Albeski
41/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 6
J2ME Configurations
J2SE CDC CLDC
8/8/2019 Introduction to J2ME, Albeski
42/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 7
J2ME Profiles
On top of the configuration we can expect a profile (one ormore) 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.
A J2ME configuration defines the Java language, the virtualmachine features and the minimum class libraries for acategory\group of devices (horizontal market).A J2ME profile is layered on top of configuration and addressthe specific demands of a specific vertical market (or device
category). The profile typically includes class libraries that arefar more specific than the class libraries provided in aconfiguration.
8/8/2019 Introduction to J2ME, Albeski
43/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 8
J2ME Profiles
J2ME
CLDC CDC
Foundation Profile
RMI ProfilePersonalProfile
PDAPProfile
MIDPProfile
8/8/2019 Introduction to J2ME, Albeski
44/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 9
J2ME (CLDC/MIDP)
This course focuses on developing J2ME application formobile 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.
According to the specification, the MID profile has the followingcharacteristics:At least 128KB of non-volatile memory (non-volatile memory ismemory that is capable of keeping its contents intact as thedevice 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, keyboardor 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 hasare: java.lang, java.io, java.util, javax.microedition.io. Thepackages the MID profile adds are: javax.microedition.lcdui,
javax.microedition.midlet and javax.microedition.rms.
8/8/2019 Introduction to J2ME, Albeski
45/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 10
The KVM
The KVM is a compact portable small JVM designed forresource constrained devices.
The J2ME (CLDC/MIDP) devices use the KVM.
According to the specification, the MID profile has the followingcharacteristics:At least 128KB of non-volatile memory (non-volatile memory ismemory that is capable of keeping its contents intact as thedevice 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, keyboardor 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 hasare: java.lang, java.io, java.util, javax.microedition.io. Thepackages the MID profile adds are: javax.microedition.lcdui,
javax.microedition.midlet and javax.microedition.rms.
8/8/2019 Introduction to J2ME, Albeski
46/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 11
J2ME (CLDC/MIDP) & J2SE
J2ME(CLDC\MIDP) java.lang package is a subset of the
J2SE java.lang package.
J2ME(CLDC\MIDP) doesnt allow controlling the class loader.
J2ME(CLDC\MIDP) doesnt support object finalization.
J2ME(CLDC\MIDP) doesnt support reflection.
8/8/2019 Introduction to J2ME, Albeski
47/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 12
J2ME (CLDC/MIDP) & J2SE
J2ME(CLDC\MIDP) doesnt 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.
8/8/2019 Introduction to J2ME, Albeski
48/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 13
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.
8/8/2019 Introduction to J2ME, Albeski
49/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 14
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.
8/8/2019 Introduction to J2ME, Albeski
50/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 15
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) { }}
8/8/2019 Introduction to J2ME, Albeski
51/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 16
Developing The First Midlet
Run the Wireless Toolkit.
8/8/2019 Introduction to J2ME, Albeski
52/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 17
8/8/2019 Introduction to J2ME, Albeski
53/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 18
8/8/2019 Introduction to J2ME, Albeski
54/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 19
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).
8/8/2019 Introduction to J2ME, Albeski
55/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 20
8/8/2019 Introduction to J2ME, Albeski
56/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 21
8/8/2019 Introduction to J2ME, Albeski
57/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 22
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.
Press OK when the project configuration pop up window dialogis shown. For now we will accept all default setting.
8/8/2019 Introduction to J2ME, Albeski
58/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 23
8/8/2019 Introduction to J2ME, Albeski
59/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 24
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.).
8/8/2019 Introduction to J2ME, Albeski
60/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 25
8/8/2019 Introduction to J2ME, Albeski
61/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 26
Developing The First Midlet
Write your source code and save it within the src folder.
Choose Build to compile & preverify your code.
When developing a J2ME application there is a need topreverify the source code (in addition to the compilation). TheKVM unlike the JVM is not capable of doing all code checksbefore it runs it. Therefore, these checks are carried out via thepreverification stage.
8/8/2019 Introduction to J2ME, Albeski
62/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 27
8/8/2019 Introduction to J2ME, Albeski
63/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 28
Developing The First Midlet
Choose Project -> Package -> Create Package in order
to create the JAR/JAD files.
8/8/2019 Introduction to J2ME, Albeski
64/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 29
8/8/2019 Introduction to J2ME, Albeski
65/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 30
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.
8/8/2019 Introduction to J2ME, Albeski
66/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 31
Click to add title
Click to add an outline
8/8/2019 Introduction to J2ME, Albeski
67/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 32
Click to add title
Click to add an outline
8/8/2019 Introduction to J2ME, Albeski
68/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 33
Click to add title
Click to add an outline
8/8/2019 Introduction to J2ME, Albeski
69/70
indell Technologies, Ltd. 04
belski eLearning
04/02/08 Abelski eLearning 34
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.
8/8/2019 Introduction to J2ME, Albeski
70/70
indell Technologies, Ltd. 04
04/02/08 Abelski eLearning 35
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.