J 2 Me
J 2 Me
J 2 Me
J2ME
Contents
Whats J2ME? J2ME core concepts
Introduction
Personalized and intelligent information appliances are necessities in our life today. Such appliances can be:
J2ME
Environment requirements
We need an environment which is adapted for constrained devices - devices that have limitations on what they can do when compared to standard desktop or server computers. The constraints are:
extremely limited memory small screen sizes alternative input methods slow processors
J2ME
Because of the vast need, Sun has decided to develop a special edition of Java - J2ME (Java 2 Micro Edition).
J2ME
J2ME
Java Editions
Different devices have different requirements and different expectations of Java. One platform (solution) cannot address all the market segments (web server, video games etc.) Users/developers want flexibility. They want to choose what they want to use and what they do not.
J2ME 7
Java Editions
The Java 2 Platform is split into three editions. Each edition provides a complete environment for running Java-based applications, including the Java virtual machine (VM) and runtime classes. The three editions target different kinds of applications running on different kinds of devices.
J2ME 8
Java Editions
Java 2 Platform
J2ME
Java Editions
Each edition defines different sets of class libraries. There are thousands of core J2SE runtime classes, taking up to 10-20 megabytes of space. J2EE J2ME-based devices have J2SE fewer classes.
J2ME
J2ME
10
Uses the basic Java 1.1 runtime classes with a few features from Java 2. Implementation still requires a couple of megabytes of memory and a fast processor to run.
J2ME
11
EmbeddedJava
Makes every behavior of the JVM and the runtime classes optional - the implementor can choose exactly which classes and methods are required. The limitation: "write once, run anywhere".
J2ME
12
Configuration
J2ME Profile
Profile
Optional Packages
Host Operating System
J2ME 13
J2ME
14
Configurations
Configurations
The set of core classes is normally quite small and must be enhanced with additional classes supplied by J2ME profiles or by configuration implementor. Configurations do not define any user interface classes.
J2ME
16
Configurations
Configuration
CLDC
Connected Limited Device Configuration
CDC
Connected Device Configuration
J2ME
17
CLDC For very constrained devices 160 - 512 KB of total memory 16-bit or 32-bit processor Low power consumption and often operating with battery power Connectivity with limited bandwidth
CDC 2 MB or more memory for Java platform 32-bit processor High bandwidth network connection, most often using TCP/IP
J2ME
18
Floating point types Object finalization JNI or reflection Thread groups or daemon threads User Class loaders
KVM - Java virtual machines for the CLDC CVM - Java virtual machines for the CDC Written specifically to work in the constrained environment of a handheld or embedded device and to be easily ported to different platforms. CLDC and CDC specifications do not require the use of the KVM or the CVM.
J2ME
20
The CDC includes 17 packages Includes more classes even in the shared packages
J2ME
J2SE
CDC
CLDC
J2ME
22
Handling I/O
J2SE includes many classes for performing input and output. There are a large number of I/O classes and they tend to encapsulate I/O models that are not necessarily found on all devices. For example, some handheld devices do not have file systems. Socket support is not universal, either.
J2ME 23
The CLDC has define a new set of APIs for I/O called the Generic Connection Framework. The GCF, part of the new javax.microedition.io package, defines interfaces for the different kinds of I/O that are possible. The CLDC does not actually define any I/O implementations these are left to the profiles and/or the device vendor to define.
J2ME
24
GCF - example
import java.io.*; import javax.microedition.io.*;
StreamConnection conn = null; InputStream is = null; String url = "socket://somewhere.com:8909";
try {
conn = (StreamConnection) Connector.open( url ); is = conn.openInputStream(); .... // etc. etc.
}
J2ME 25
J2ME 26
J2ME
27
Profiles
Most profiles define user interface classes for building interactive applications. To use a profile, the device must meet the minimum requirements of the underlying configuration and of the profile.
J2ME 28
Profiles
Profile MIDP
Mobile Information Device Profile
PDAP
Personal Digital Assistant Profile
FP
Foundation Profile
PBP
Personal Basis Profile
PP
Personal Profile
J2ME
29
Enough memory to run MIDP applications Display of at least 96 X 56 pixels, either monochrome or color A keypad, keyboard, or touch screen Two-way wireless networking capability
J2ME 30
MIDP - Specification
There
MIDP
1.0 - released in September 2000. Many devices currently on the market support it. MIDP 2.0 - currently in proposed final draft form. No devices yet support it.
J2ME
31
MIDP - Specification
The MIDP adds APIs to the basic APIs defined by the CLDC. The new features include:
Support for application lifecycle management similar to the way applets are defined in J2SE. Persistent storage of data. HTTP-based network connectivity based on the CLDC's GCF. Simple user interface support, with enough flexibility to build games or business applications.
J2ME
32
MIDP - Specification
J2ME
33
The early Motorola J2ME-enabled phones limited the size of an application to 50K. Some Nokia phones limit them to even less, about 30K.
MIDP 1.0 applications cannot share classes. Placing part of the application in a web or application server (as a servlet, typically) that the MIDP application calls is almost a requirement for anything serious.
J2ME
34
J2ME
35
Optional Packages
Set of APIs in support of additional, common behaviors. Have specific dependencies on a particular configuration and/or one or more profiles. Examples of optional packages :
J2ME 36
"J2ME application" is an ambiguous term. Configuration, profile and optional packages should be chosen. CDC-based profiles make development simpler due to J2SE-like APIs, but dont suit the low-end devices. CLDC-based profiles makes the development task harder, especially when trying to shrink the size of the application to run on many of the small devices.
J2ME 37
J2ME
38
J2ME
39
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
J2ME
40
J2ME
41
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.
J2ME 42
MIDlet Suite
The JAR file must also include a manifest that describe the MIDlets in the suite. The application descriptor (JAD) contains similar information, and is used by devices to obtain information about a MIDlet suite without having to download and install the MIDlet suite first.
J2ME 43
Creating a MIDlet
J2ME
44
Creating a MIDlet
J2ME
45
Creating a MIDlet
Extends MIDlet Implements CommandListener
J2ME
46
Creating a MIDlet
Creating the form, adding the Commands
public HelloMIDlet() { mMainForm = new Form("HelloMIDlet"); mMainForm.append(new StringItem(null, "Hello, Seminar Software Design!")); mMainForm.addCommand(new Command("Exit", Command.EXIT, 0)); mMainForm.setCommandListener(this); }
J2ME
47
CommandListener ItemCommandListener
Item
J2ME
48
Base class
Form Command
CommandListener ItemCommandListener
Item
J2ME
49
protected abstract void startApp() protected abstract void pauseApp() protected abstract void destroyApp(boolean unconditional) public final String getAppProperty(String key) public final void notifyDestroyed()
J2ME
50
MIDlet
Form
Command
CommandListener ItemCommandListener
Item
J2ME
51
Form class
A Form is a Screen that contains an arbitrary mixture of items: images, read-only text fields, editable text fields, editable date fields, gauges, choice groups, and custom items. In general, any subclass of the Item class may be contained within a form. The implementation handles layout, traversal, and scrolling.
J2ME
52
management
public
Item
J2ME
54
Command class
The Command class represents the semantic meaning of an action. Command objects are presented in the user interface. The action itself is implemented in a CommandListener object. The CommandListener is associated with a Displayable or an Item. Once the Command is called the CommandListener is invoked, and the action is performed.
J2ME 55
Command class
Command type public int getCommandType() Command priority public int getPriority()
J2ME
56
J2ME
57
J2ME 58
CommandListener ItemCommandListener
Item
J2ME
59
Item class
A superclass for components that can be added to a Form. All Item objects have a label field Choose the Items layout, size, and appearance Attach Commands
J2ME
60
J2ME 61
Getting Started
1st
2nd
step: Make sure you have J2SE SDK installed 3rd step: Install the J2ME Toolkit.
J2ME
62
J2ME
63
Using KToolbar
J2ME
64
J2ME
65
J2ME/apps/{proj}/res
J2ME/apps/{proj}/src J2ME/apps/lib
resource files
source files
Choose the target platform Write your code Save Build (Compile + Preverify) Run
JTWI - conforms to Java Technology for the Wireless Industry (JSR-185). MIDP1.0 - includes MIDP 1.0 and CLDC 1.0 Custom - user defined settings, you can select project profile, configurations and various APIs.
J2ME 67
J2ME
68
J2ME
69
The END!
You can download all the demos JARs from: www.cs.huji.ac.il/~kerengaz/j2me/ Have Fun!!!
J2ME
70