Hierarchy of management that covers different levels of management
Mobile Application Development MAD J2ME UNIT 2
1. Unit-II
J2ME Architecture
Small Computing Device Requirements
Run-Time Environment
MIDlet Programming
Java Language for J2ME
J2ME Software Development Kits
Hello World J2ME Style
Multiple MIDlets in a MIDlet Suite
J2ME Wireless Toolkit
3. 1. J2ME architecture
The design of j2me architecture provides the scalability to an application based on
the constraints of the small computing devices.
J2me architecture does not replace the operating system of small computing devices
J2me architecture consists of layers located above the native operating system.
4. J2ME architecture
Three layers
1. Configuration layer- includes the jvm, which interacts the operating
system. and also interacts the profiles and jvm.
2. Profile layer- it provides the java API used to implement the
applications for the small computing devices.
3. MIDP- provides classes for the network connections, user interface and
persistent storage.
small computing devices has two components provided by the original
equipment manufacturers.
1. OEM classes- these are used by the MIDP to access the features of the
specific device such as sending and receiving messages and access
persistent storage.
2. OEM applications- these can be accessed by the MIDP such as address
book.
Note:- these components are not portable since all the small computing
devices does not use the same OEM classes and OEM applications.
5. 2. Small computing device requirements
• Hardware requirements
- display 96 X 54 pixel should supports the bitmapped pixels.
- key pad, keyboard, or touch screen for input
- ROM - 128KB to run the Mobile information Device (MID)
- 8KB for permanent storage like applications data.
- RAM - 32KB to run JVM
- device must provide the two way network connectivity (SIM)
• software requirements
- native operating system ( which is supported by specific system)
- it must includes the exception handling, scheduling, process interrrupts,
ability to run the JVM
- file system does not required to run the JVM
- able to read and write permanent data on to the nonvolatile memory.
6. 3. Run time environment
• MIDlet( MIDP applications ) - is a J2ME program specific for the J2ME
virtual machine to run applications on small computing devices like
cellphones.
MIDlet has atleast one class that is derived from the
javax.microedition.midlet.MIDlet abstract class.
MIDlet required the device which implements with the J2ME, MIDP to
run.
MIDlet are compiled once and run anywhere
a group of MIDlet are packed into MIDlet suit.
MIDlet suite uses the same instance of java class and run within the same
JVM.
7. Advantage of MIDlet suite is that all the MIDlets which are belong to same
MIDlet suite share the same data so it reduces the data errors during the
concurrent read and write access to a data.
MIDlet suit installed, executed and removed by the application manager which is
provided by the manufactures and run on the device.
Once this is installed on the device each member of the MIDlet suit can have
access to the classes and methods of the JVM and CLDC ( configuration layer)
bye the application manager.
MIDlet suite consists of two files
1. .JAR file
2. .JAD file
.JAR file- it contains compiled classes in a compressed and preverified manner.
- several MIDlets are included in the MIDlet suite all its classes are
includes in the .JAR file.
- and also includes the graphics images and the manifest file.
8. JAR
All the files necessary to implement a MIDlet suite must
be contained within a production package called a Java
archive (JAR) file.
These files include MIDlet classes, graphic images (if
required by a MIDlet), and the manifest file.
The manifest file contains a list of attributes and related
definitions that are used by the application manager to
install the files contained in the JAR file onto the small
computing device.
Nine attributes are defined in the manifest file; all but six
of these attributes are optional.
9. Manifest file- list of attributes and definitions used by the application.
- nine attributes define in Manifest file, six are mandatory
Attributes of the manifest file
10. • Go to project folder, see bin folder and open
manifest file.
MIDlet-2: HelloWorld, , hello.
HelloWorldMIDlet-1: HelloMIDlet, , hello.
HelloMIDletMIDlet-Vendor: Vendor
MIDlet-Name: MobileApplication5
MIDlet-Version: 1.0
MicroEdition-Configuration: CLDC-1.1
MicroEdition-Profile: MIDP-2.0
11. JAD file
• A JAD file is also used to provide the application
manager with additional content information about the
JAR file to determine whether the MIDlet suite can be
implemented on the device.
• All JAD files must have the .jad extension
• A JAD file is similar to a manifest in that both contain
attributes that are name:value pairs. Name:value pairs
can appear in any order within the JAD file. There are
five required system attributes for a JAD file:
12. JAD file
• MIDlet-Name
• MIDlet-Version
• MIDlet-Vendor
• MIDlet-n
• MIDlet-Jar-URL
• The first three attributes in the JAD file are identical to
attributes in the manifest file.
15. • C:Documents and
settingsAdministratorj2mewtk2.5.2appssnistbin
• in bin folder you can find manifest file and jad file
• to create jar file – goto sun java wirelss tool kit 2.5.2->
project-> create package
• then jar would created in the bin folder, extract file it
includes manifest file, .class file and images with .png
extension.
16. MIDlet Programming
• Programming a MIDlet is similar to creating a J2SE
application in that define a class and related methods
• Less Robust
• A MIDlet is a class that extends the MIDlet class and is
the interface between application statements and the
run-time environment, which is controlled by the
application manager.
17. MIDP Applications (MIDlets) and MIDlet Lifecycle
• When j2me application (MIDlet) is created it must extended
from the MIDlet class in javax.microedition.midlet.MIDlet
• MIDlet class as three abstract methods that are called by the
Application manager software (AMS).
• When MIDlet starts to run, it goes into three phases which are
controlled by the AMS.
1.pasueApp()
2. startApp()
3. destroyApp();
18. Stages of MIDlet's lifecycle
1. When the MIDlet is about to be run, an instance
of javax.microedition.midlet.MIDlet class is created. The MIDlet's class
constructor with 0 arguments is run, and the MIDlet is in the Paused
state.
2. Next, MIDlet move into Active state after application manager
calling startApp() method which implement with extend MIDlet class.
3. While the MIDlet is Active state, the application manager can suspend
its execution by calling pauseApp() method
4. After application manager execute startApp() method, can terminate the
execution by calling destroyApp() method.
5. A MIDlet can destroy itself by calling notifyDestroyed() method.
19. • public class HelloWorld extends MIDlet
{
public void startApp()
{ }
public void pauseApp()
{ }
public void destroyApp( boolean unconditional ) { }
}
20. • Both the startApp() and pauseApp() methods are public
and have no return value nor parameter list.
• The destroyApp() method is also a public method without
a return value.
• However, the destroyApp() method has a boolean
parameter that is set to true if the termination of the
MIDlet is unconditional and false if the MIDlet can throw a
MIDletStateChangeException telling the application
manager that the MIDlet does not want to be destroyed
just yet.
21. • At the center of every MIDlet are the MIDP API classes
used by the MIDlet to interact with the user and handle
data management.
• User interactions are managed by user interface MIDP
API classes.
• These APIs enable a developer to display screens of data
and prompt the user to respond with an appropriate
command. The command causes the MIDlet to execute
oneof three routines: perform a computation, make a
network request, or display another screen.
22. • The data-handling MIDP API classes enable the
developer to perform four kinds of data routines:
• write and read persistent data, store data in data types,
receive data from and send data to a network, and
interact with the small computing device’s input/output
features.
23. Event Handling
• A MIDlet is an event-based application.
• All routines executed in the MIDlet are invoked in
response to an event reported to the MIDlet by the
application manager.
• The initial event that occurs is when the MIDlet is started
and the application manager invokes the startApp()
method.
• The startApp() method in a typical MIDlet contains a
statement that displays a screen of data and prompts the
user to enter a selection from among one or more
options. The nature and number of options is MIDlet and
screen dependent.
24. Event Handling
• A Command object is used to present a user with a
selection of options to choose from when a screen is
displayed.
• Each screen must have a CommandListener.
• A CommandListener monitors user events with a screen
and causes the appropriate code to execute based on
the current event.
25. User interfaces
• Some small computing devices contain resources that
provide a rich user interface, while other more resource-
constrained devices offer a modest user interface.
• A rich user interface contains the following elements,
and a device with a minimal user interface has some
subset of these elements as determined by the profile
used for the device.
• A Form is the most commonly invoked user interface
element found in a MIDlet and is used to contain other
user interface elements. Text is placed on a form as a
StringItem, a List, a ChoiceGroup, and a Ticker
26. • A StringItem contains text that appears on a form that
cannot be changed by the user.
• A List is an itemized options list from which the user can
choose an option.
• A ChoiceGroup is a related itemized options list.
• And a Ticker is text that is scrollable.
• A user enters information into a form by using the Choice
element, TextBox, TextField, or DateField elements.
• The Choice element returns an option that the user
selected.
User interfaces
27. User interfaces
• TextBox and TextField elements collect textual
information from a user and enable the user to edit
information that appears in these user interface
elements.
• The DateField is similar to a TextBox and TextField
except its contents are a date and time
• An Alert is a special Form that is used to alert the user
that an error has occurred. An Alert is usually limited to a
StringItem user interface element that defines the nature
of the error to the user
28. Device Data
• A MIDlet can use an MIDP class—RecordStore—and
two MIDP interfaces— RecordComparator and
RecordFilter—to write and read persistent data.
• A RecordStore class contains methods used to write
and read persistent data in the form of a record.
• Persistent data is read from a RecordStore by using
either the RecordComparator interface or the
RecordFilter interface
29. Java Language for J2ME
• CDC implements the full J2SE available, but CLDC implements a
stripped-down J2SE
• Floating-point math is probably the most notable missing feature of
J2ME. MIDlet cannot use any floating-point data types or
calculations.
• Absence of support for the finalize() method
• Reduced number of error-handling exceptions
• Changes were also made in the Java Virtual Machine that runs on a
small computing device because of resource constraints. One such
change occurs with the class loader. JVM for small computing
devices requires a custom class loader that is supplied by the
device manufacturer and cannot be replaced or modified.
• Another feature lacking in the JVM is the ThreadGroup class. You
cannot group threads.
30. • Two other features of J2SE that are missing from J2ME are weak
references and the Reflection classes
• The standard JVM uses class file verification to protect applications
from malicious code through the use of a security manager.
However, this process is replaced with a two-step process because
of the limited resources available on small computing devices
31.
32. J2ME Software Development Kits
• A MIDlet is built using free software packages that are
downloadable from the java.sun .com
• Although we can purchase third-party development products such
as Borland JBuilder Mobile Set, Sun One Studio 4 (formerly Forte
for Java), and WebGain VisualCafe Enterprise Suite.
• Three software packages need to be downloaded from
java.sun.com.
• Java Development Kit (1.3 or greater) (java.sun.com/
j2se/downloads.html),
• Connected Limited Device Configuration (CLDC) (java.sun.
com/products/cldc/),
• Mobile Information Device Profile (MIDP) (java.sun.com/
products/midp/).
• And also need the J2ME Wireless Toolkit to develop MIDlets for
handheld devices
(java.sun.com/products/j2mewtoolkit/download.html).
33. • Install the CLDC once the Java development kit is installed.
• Unzip the downloaded CLDC files fromthe java.sun.com web site
onto the d:j2me directory(J2ME_HOME) on your computer.
• You’ll need to create the j2me directory if one doesn’t exist.
Unzipping the CLDC package creates the j2me_cldc subdirectory
below the j2me directory
• Each platform is in its own subdirectory under j2me_cldc. Add the
j2mej2me_cldcbinwin32 subdirectory to the PATH environment
variable
• Next, download and unzip the MIDP file. Be sure to use j2me as the
directory for the MIDP file. Unzipping the MIDP file creates a midp
directory.
• you’ll need to include the j2memidp1.0.3fcsbin subdirectory in the
PATH environment variable.
Installation and setting paths
34. • Next, create two environment variables. These are CLASSPATH
and MIDP_HOME.
• The CLASSPATH environment variable identifies the path to be
searched whenever a class is invoked.
• Set the CLASSPATH to d:j2memidp1.0.3fcsclasses;
• The MIDP_HOME environment variable identifies the location of
the lib directory that contains the internal.config file and the
system.config file.
• Set the MIDP_HOME environment variable to d:j2memidp1.0.3fcs
35. creating a directory structure within which
you can create and run MIDlets
• J2me
• j2mesrc
• j2mesrcgreeting
• j2metmp_classes
• j2memidlets
36.
37. HelloWorld Example
• The HelloWorld MIDlet performs three basic functions that are found
in nearly all MIDlets. These are to display a text box and a
command on the screen, then listen to events that occur while the
MIDlet is running
• The HelloWorld MIDlet is created by defining a class called
HelloWorld that extends the MIDlet class and implements a
CommandListener.
• The HelloWorld class contains three private data members and four
methods. The data members are a Display object, a text box, and a
command. The methods are startApp(), pauseApp(), and
destroyApp(). The fourth method is called commandAction() and is
invoked by the application manager whenever an event occurs
• Twopackages must be imported at the beginning of the MIDlet to
access MIDlet classes and lcdui classes.
• MIDlet classes are screen oriented and create a Display object and
then place components of the screen into the Display object
38. • The startApp() method contains the necessary statements to invoke
previously defined objects
• Calling getDisplay multiple times always returns the same Display
reference for the specified MIDlet.
• An instance of a command object is created.
Command- a label, a type, and a priority
Label- string
Type- specifies type of the command
- BACK,EXIT,CANCEL,OK,SCREEN,ITEM,HELP,STOP.
Priority- importance of the command with the other commands on the screen.
it may be integer.
The last instance is TextBox object. Four values are necessary to create an
instance of a TextBox object. The first is the caption for the TextBox
object followed by the text that will appear in the TextBox object. The
other two values are coordinates used by the application manager to
position the TextBox object on the screen
39. Compiling Hello World
• Make j2mesrcgreeting the current directory
• javac -d d:j2metmp_classes -target 1.1 -bootclasspath
d:j2memidp1.0.3fcsclasses HelloWorld.java
• The bootclasspath option points to the startup class files commonly
referred to as the Java bootstrap files.
• Next, you’ll need to preverify the HelloWorld.class that was
generated by the compiler. Make sure that j2mesrcgreeting is the
current directory and enter the following command:
• preverify -d d:j2meclasses -classpath d:j2memidp1.0.3fcsclasses
d:j2metmp_classes
• The -d option places the class file within the tmp_classes directory.
The second option is -classpath, which points to the location of the
library classes that come with the MIDP.
40. Running HelloWorld
• There are two ways to run a MIDlet. These are either by invoking
the MIDlet class or by creating a JAR file, then running the MIDlet
from the JAR file.
• Make sure that j2mesrc greeting is the current directory, and then
enter the following command
• midp -classpath d:j2meclasses greeting.HelloWorld
41. Deploying HelloWorld
• The MIDlet suite is then packaged into a JAR file along with other
related files for downloading to a small computing device. This
process is commonly referred to as packaging
• create the manifest file
• MIDlet-1: HelloWorld, , greeting.HelloWorld
• MIDlet-Name: Hello World
• MIDlet-Version: 1.0
• MIDlet-Vendor: Jim
• MIDlet-1: HelloWorld, /greeting/myLogo.png, greeting.HelloWorld
MicroEdition-Configuration: CLDC-1.0
• MicroEdition-Profile: MIDP-1.0
• create the JAR file once the manifest.txt file is saved in the j2mesrc
greeting directory.
42. • create the JAR file by entering the following command:
• jar -cfvm d:j2memidletsHelloWorld.jar manifest.txt -C
d:j2meclasses greeting
• Create the JAD file
• MIDlet-Name: Hello World
• MIDlet-Version: 1.0
• MIDlet-Vendor: Jim
• MIDlet-Description: My First MIDlet suite
• MIDlet-1: HelloWorld, /greeting/myLogo.png, greeting.HelloWorld
MIDlet-Jar-URL: HelloWorld.jar
• MIDlet-Jar-Size: 1428
• Copy the HelloWorld.jad file into the j2me/midlets directory
• Then make j2me/midlets the current directory.
• Invoke the MIDlet by entering the following command.
• midp -classpath HelloWorld.jar -Xdescriptor HelloWorld.jad
43. Packages available in J2ME
• Java.lang
• Java.io
• Java.util
• Javax.microedition.io
• Javax.microedition.lcdui
• Javax.microedition.midlet.
• Javax.microedition.rms.
44. Javax.microedition.lcdui- provides a set of features for
implementation of user interfaces for MIDP applications.
• Interfaces
1. Choice
2. CommandListener
3. ItemStateListener
classes
1. Alert
2. Command
3. Display
4. Displayable
5. Form
6. Font
7. Image
8. TextBox etc
45. Javax.microedition.midlet.
MIDlet package defines Mobile Information Device Profile applications and
the interactions between the application and the environment in which the
application runs.
Classes
1. MIDlet
Exception
MIDletStateChangeException
46. Display- manger of the display and input device of the system.
MIDlet classes are screen oriented
- 1st
create the Display object on which we can place all the
components of the screen into the Display object
- this display object calling the method getDisplay().to display
the screen on the small computing devices.
- setCurrent()- The Display class has a setCurrent() method for setting the
current Displayable ( Form)
Displayable- objects that are capable of being placed on the
display
ex- Form, Command all are Displayable objects.
Form- A Form is a Screen that contains an arbitrary mixture of items:
images, read-only text fields, editable text fields
notifyDestroyed(); - Used by an MIDlet to notify the
application management software that it has entered
into the Destroyed state.
47. Command- a label, a type, and a priority
Label- string
Type- specifies type of the command
- BACK,EXIT,CANCEL,OK,SCREEN,ITEM,HELP,STOP.
Priority- importance of the command with the other commands on
the screen.
it may be integer.
- commandAction( Command c, Displayable d)
* this method in interface CommandListener
* Indicates that a command event has occurred on Displayable d.
48. Multiple MIDlets in a MIDlet Suite
add multiple MIDlets to the MIDlet Suite
AMS displays the MIDlets in menu option and enables the user to
run one MIDlet at a time.
How to create MIDlet Suite
step-1 : open sun_java_wireless toolkit and click on settings
50. Java Language for J2ME
Floating- point math not available on J2ME.
- special processor hardware required for the float point calculations but small computing
devices lack in hardware
- MIDlet cannot support floating point calculations
Absence of Finalize() method
Fewer error handling exceptions
- error handling exceptions grabs the system resources which are very less in small
computing devices.
- run time exceptions are handled by the underlying native operating system.
Weak references and no reflection classes.
Some changes made in the JVM which runs on small computing devices
1. class loader: JVM of small computing devices have custom class loader that is
supplied by the manufactures only those cannot be modified or replaced
2. Thread group class: threads cannot be grouped. All the threads handled by the object
level.
J2SE uses the file verification to protect from malicious code through the use of a
security manager. whereas, in J2ME this took place in two steps
1. preverification- done outside of the small computing devices before loading MIDlet
2. MIDlet class loaded on to the device and verifier in small computing devices validates
each instruction in the MIDlet class.
51. Alert- it is screen that shows the data to the user and wait for some time to
process the next displayable.
- it contains text and images.
AlertType.INFO- provides non threatening
information to the user.
52. J2ME Wireless Toolkit
• J2ME Wireless Toolkit that is downloadable from
java.sun.com/products/j2mewtoolkit/download.html.
• It is used to develop and test J2ME applications by selecting a few
buttons from a toolbar
• J2ME Wireless Toolkit is a stripped-down integrated development
environment in that it does not include an editor, a full debugger,
and other amenities found in a third-party integrated development
environment.
• Building and Running a Project
• Ktoolbar is the executable within the directory that launches the
Toolkit. The main window is displayed when you run ktoolbar
53.
54.
55.
56.
57.
58. Step- 3 : click ok button on Enter MIDlet Details
60. Step- 5: go to project (MIDlet suite) to which you added
MIDlets and open manifest file in bin folder.
MIDlet-1: ExampleTb, ExampleTb.png, ExampleTb
MIDlet-2: MidletLifecycle, MidletLifecycle.png,
MidletLifecycle
MIDlet-Name: TextBoxEx
MIDlet-Vendor: Unknown
MIDlet-Version: 1.0
MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-2.0
61. Step- 6 : place MIDlets in the src folder of the
MIDlet Suite
62. Step – 7 : build the project
step- 8 : run project
63. JAVA ME SDK
• The Oracle Java, Micro Edition (Java ME) Software Development
Kit (SDK) provides device emulation, a standalone development
environment and a set of utilities for rapid development of Java ME
applications.
• It integrates the Connected Limited Device Configuration (CLDC)
and the Connected Device Configuration (CDC) technology into one
simple development environment.
• The Java ME SDK is a successor to the Sun Java Wireless Toolkit
and the Java Toolkit for CDC and offers improved device emulation,
a standalone lightweight development environment, and powerful
tools to speed application development.
64. Key Features:
• A single SDK for application development for the full range of Java
ME device targets
• Built-in emulators for application prototyping
• Customizable device skins for your development environment
• NetBeans and Eclipse plugins for better IDE integration
• On-device tooling for remote application management and
debugging
• Application profiling, network monitoring, and memory monitoring
•