Java 2 Platform Micro Edition J 2 ME

  • Slides: 70
Download presentation
Java 2 Platform, Micro Edition (J 2 ME) Masha Gutkhen Keren Gazit J 2

Java 2 Platform, Micro Edition (J 2 ME) Masha Gutkhen Keren Gazit J 2 ME 1

Contents What’s J 2 ME? l J 2 ME core concepts l l l

Contents What’s J 2 ME? l J 2 ME core concepts l l l Configurations (CLDC, CDC) Profiles (MIDP) l MIDlet, MIDlet Suite l Basic classes API l Installation and using the Toolkit l Demos!!! J 2 ME 2

Introduction Personalized and intelligent information appliances are necessities in our life today. l Such

Introduction Personalized and intelligent information appliances are necessities in our life today. l Such appliances can be: l l l l cell phones two-way pagers smart cards personal organizers palmtops These appliances tend to be special-purpose, limited -resource, network-connected devices. J 2 ME 3

Environment requirements We need an environment which is adapted for constrained devices - devices

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. l The constraints are: l l l extremely limited memory small screen sizes alternative input methods slow processors J 2 ME 4

So – what’s the solution? l Because of the vast need, Sun has decided

So – what’s the solution? l Because of the vast need, Sun has decided to develop a special edition of Java - J 2 ME (Java 2 Micro Edition). J 2 ME 5

J 2 ME 6

J 2 ME 6

Java Editions l Different devices have different requirements and different expectations of Java. l

Java Editions l Different devices have different requirements and different expectations of Java. l One platform (solution) cannot address all the market segments (web server, video games etc. ) l Users/developers want flexibility. They want to choose what they want to use and what they do not. J 2 ME 7

Java Editions l The Java 2 Platform is split into three editions. l Each

Java Editions l The Java 2 Platform is split into three editions. l Each edition provides a complete environment for running Java-based applications, including the Java virtual machine (VM) and runtime classes. l The three editions target different kinds of applications running on different kinds of devices. J 2 ME 8

Java Editions Java 2 Platform Java 2 Standard Edition (J 2 SE™) Java 2

Java Editions Java 2 Platform Java 2 Standard Edition (J 2 SE™) Java 2 Enterprise Edition (J 2 EE™) Java 2 Micro Edition (J 2 ME™) Standard desktop & workstation applications Heavy duty server systems Small & memory constrained devices J 2 ME 9

Java Editions Each edition defines different sets of class libraries. l There are thousands

Java Editions Each edition defines different sets of class libraries. l There are thousands of core J 2 SE runtime classes, taking up to 10 -20 megabytes of space. J 2 EE l J 2 ME-based devices have J 2 SE fewer classes. l J 2 ME 10

Personal. Java and Embedded. Java l J 2 ME is not the first attempt

Personal. Java and Embedded. Java l J 2 ME is not the first attempt at adapting Java for constrained environments. l Personal. Java Uses the basic Java 1. 1 runtime classes with a few features from Java 2. l Implementation still requires a couple of megabytes of memory and a fast processor to run. l J 2 ME 11

Personal. Java and Embedded. Java l Embedded. Java Makes every behavior of the JVM

Personal. Java and Embedded. Java l Embedded. Java Makes every behavior of the JVM and the runtime classes optional - the implementor can choose exactly which classes and methods are required. l The limitation: "write once, run anywhere". l J 2 ME 12

Configuration l l Minimum platform required for a group of devices J 2 ME

Configuration l l Minimum platform required for a group of devices J 2 ME Libraries Profile l l J 2 ME Profile Addresses specific needs of a certain device family Java Language Java Virtual Machine Configuration l Profiles J 2 ME Core Concepts Optional Packages Host Operating System J 2 ME 13

J 2 ME Core Concepts J 2 ME is based on 3 core concepts:

J 2 ME Core Concepts J 2 ME is based on 3 core concepts: l Configurations l Profiles l Optional packages J 2 ME 14

Configurations l. A configuration is a complete Java runtime environment, consisting of: Java virtual

Configurations l. A configuration is a complete Java runtime environment, consisting of: Java virtual machine (VM) to execute Java bytecode l Native code to interface to the underlying system l Set of core Java runtime classes l l To use a configuration, a device must meet certain minimum requirements. J 2 ME 15

Configurations l The set of core classes is normally quite small and must be

Configurations l The set of core classes is normally quite small and must be enhanced with additional classes supplied by J 2 ME profiles or by configuration implementor. l Configurations do not define any user interface classes. J 2 ME 16

Configurations Configuration CLDC Connected Limited Device Configuration Connected Device Configuration J 2 ME 17

Configurations Configuration CLDC Connected Limited Device Configuration Connected Device Configuration J 2 ME 17

CLDC vs. CDC l CLDC l For very constrained devices l 160 - 512

CLDC vs. CDC l CLDC l For very constrained devices l 160 - 512 KB of total memory l 16 -bit or 32 -bit processor l Low power consumption and often operating with battery power l Connectivity with limited bandwidth l J 2 ME CDC l 2 MB or more memory for Java platform l 32 -bit processor l High bandwidth network connection, most often using TCP/IP 18

CLDC vs. CDC - VM l Features missing in the CLDC VM: l l

CLDC vs. CDC - VM l Features missing in the CLDC VM: l l l l Floating point types Object finalization JNI or reflection Thread groups or daemon threads User Class loaders The CDC supports a complete, fullfeatured Java 2 virtual machine Change in classfile verification preverification J 2 ME 19

The KVM and CVM KVM - Java virtual machines for the CLDC l CVM

The KVM and CVM KVM - Java virtual machines for the CLDC l CVM - Java virtual machines for the CDC l Written specifically to work in the constrained environment of a handheld or embedded device and to be easily ported to different platforms. l CLDC and CDC specifications do not require the use of the KVM or the CVM. l J 2 ME 20

CLDC vs. CDC – J 2 SE Subset l The CLDC includes classes from:

CLDC vs. CDC – J 2 SE Subset l The CLDC includes classes from: l l java. lang java. io java. util The CDC includes 17 packages l Includes more classes even in the shared packages l Only selected classes from each package are included J 2 ME 21

CLDC vs. CDC – J 2 SE Subset J 2 SE CDC J 2

CLDC vs. CDC – J 2 SE Subset J 2 SE CDC J 2 ME CLDC 22

Handling I/O l J 2 SE includes many classes for performing input and output.

Handling I/O l J 2 SE includes many classes for performing input and output. l There a large number of I/O classes and they tend to encapsulate I/O models that are not necessarily found on all devices. l For example, some handheld devices do not have file systems. Socket support is not universal, either. J 2 ME 23

Handling I/O in CLDC The CLDC has define a new set of APIs for

Handling I/O in CLDC The CLDC has define a new set of APIs for I/O called the Generic Connection Framework. l The GCF, part of the new javax. microedition. io package, defines interfaces for the different kinds of I/O that are possible. l The CLDC does not actually define any I/O implementations these are left to the profiles and/or the device vendor to define. l J 2 ME 24

GCF - example import java. io. *; import javax. microedition. io. *; Stream. Connection

GCF - example import java. io. *; import javax. microedition. io. *; Stream. Connection conn = null; Input. Stream is = null; String url = "socket: //somewhere. com: 8909"; try { conn = (Stream. Connection) Connector. open( url ); is = conn. open. Input. Stream(); . . // etc. }… J 2 ME 25

Handling I/O in CDC l Since the CDC is a superset of the CLDC,

Handling I/O in CDC l Since the CDC is a superset of the CLDC, it includes the GCF. l CDC also requires GCF support for two specific connection types: files and datagrams. l The reason: CDC includes the relevant classes from java. io and java. net packages. J 2 ME 26

J 2 ME Core Concepts J 2 ME is based on 3 core concepts:

J 2 ME Core Concepts J 2 ME is based on 3 core concepts: l Configurations l Profiles l Optional packages J 2 ME 27

Profiles l Adds domain-specific classes to a configuration: l l To fill in missing

Profiles l Adds domain-specific classes to a configuration: l l To fill in missing functionality To support specific uses of a device Most profiles define user interface classes for building interactive applications. l To use a profile, the device must meet the minimum requirements of the underlying configuration and of the profile. l J 2 ME 28

Profiles Profile MIDP Mobile Information Device Profile PDAP Personal Digital Assistant Profile FP Foundation

Profiles Profile MIDP Mobile Information Device Profile PDAP Personal Digital Assistant Profile FP Foundation Profile J 2 ME PBP PP Personal Basis Profile Personal Profile 29

MIDP – MID Profile l MIDP is targeted at a class of devices known

MIDP – MID Profile l MIDP is targeted at a class of devices known as mobile information devices (MIDs). l Minimal characteristics of MIDs: Enough memory to run MIDP applications l Display of at least 96 X 56 pixels, either monochrome or color l A keypad, keyboard, or touch screen l Two-way wireless networking capability l J 2 ME 30

MIDP - Specification l There are two versions of the MIDP: l MIDP 1.

MIDP - Specification l There are two versions of the MIDP: l MIDP 1. 0 - released in September 2000. Many devices currently on the market support it. l MIDP 2. 0 - currently in proposed final draft form. No devices yet support it. J 2 ME 31

MIDP - Specification l The MIDP adds APIs to the basic APIs defined by

MIDP - Specification l The MIDP adds APIs to the basic APIs defined by the CLDC. The new features include: l l Support for application lifecycle management similar to the way applets are defined in J 2 SE. 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. J 2 ME 32

MIDP - Specification l The MIDP specification is silent about a number of things:

MIDP - Specification l The MIDP specification is silent about a number of things: No standard way to interface to the device's phonebook, in order to initiate voice calls. l How MIDP applications are loaded onto a device and how they are activated or deactivated. l J 2 ME 33

MIDP Applications restrictions l Memory is a particularly scarce resource. l The early Motorola

MIDP Applications restrictions l Memory is a particularly scarce resource. l The early Motorola J 2 ME-enabled phones limited the size of an application to 50 K. Some Nokia phones limit them to even less, about 30 K. MIDP 1. 0 applications cannot share classes. l 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. l J 2 ME 34

J 2 ME Core Concepts J 2 ME is based on 3 core concepts:

J 2 ME Core Concepts J 2 ME is based on 3 core concepts: l Configurations l Profiles l Optional packages J 2 ME 35

Optional Packages l Set of APIs in support of additional, common behaviors. l Have

Optional Packages l Set of APIs in support of additional, common behaviors. l Have specific dependencies on a particular configuration and/or one or more profiles. l Examples of optional packages : RMI Optional Package l Bluetooth Optional Package l JDBC Optional Package l J 2 ME 36

What it all means "J 2 ME application" is an ambiguous term. l Configuration,

What it all means "J 2 ME application" is an ambiguous term. l Configuration, profile and optional packages should be chosen. l CDC-based profiles make development simpler due to J 2 SE-like APIs, but don’t suit the low-end devices. l 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. l J 2 ME 37

J 2 ME 38

J 2 ME 38

MIDlets – The heart of J 2 ME… l MIDP does not support the

MIDlets – The heart of J 2 ME… l 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. l Instead, we use a MIDlet, which is a MID Profile application. J 2 ME 39

MIDlets – The heart of J 2 ME… l Every application must extend javax.

MIDlets – The heart of J 2 ME… l Every application must extend javax. microedition. midlet. MIDlet class to allow the application management software to: control the MIDlet l be able to retrieve properties from the application descriptor l notify and request state changes l J 2 ME 40

MIDlets – The heart of J 2 ME… l The extending class is the

MIDlets – The heart of J 2 ME… l The extending class is the main class of the application. l The MIDlet class defines abstract methods that the main class implements (for example: start. App(), destroy. App(), notify. Destroyed()). J 2 ME 41

MIDlet Suite l One or more MIDlets are packaged together into a MIDlet suite,

MIDlet Suite l One or more MIDlets are packaged together into a MIDlet suite, composed of: JAR (Java archive) file l JAD (Java Application Descriptor) file l l All the user-defined classes and resources required by the suite's MIDlets must be in the JAR file. J 2 ME 42

MIDlet Suite l The JAR file must also include a manifest that describe the

MIDlet Suite l The JAR file must also include a manifest that describe the MIDlets in the suite. l 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. J 2 ME 43

Creating a MIDlet J 2 ME 44

Creating a MIDlet J 2 ME 44

Creating a MIDlet Importing MIDP specific packages import javax. microedition. lcdui. *; import javax.

Creating a MIDlet Importing MIDP specific packages import javax. microedition. lcdui. *; import javax. microedition. midlet. *; J 2 ME 45

Creating a MIDlet Extends MIDlet Implements Command. Listener public class Hello. MIDlet extends MIDlet

Creating a MIDlet Extends MIDlet Implements Command. Listener public class Hello. MIDlet extends MIDlet implements Command. Listener { J 2 ME 46

Creating a MIDlet Creating the form, adding the Commands public Hello. MIDlet() { m.

Creating a MIDlet Creating the form, adding the Commands public Hello. MIDlet() { m. Main. Form = new Form("Hello. MIDlet"); m. Main. Form. append(new String. Item(null, "Hello, Seminar Software Design!")); m. Main. Form. add. Command(new Command("Exit", Command. EXIT, 0)); m. Main. Form. set. Command. Listener(this); } J 2 ME 47

Sample MIDP classes API l MIDlet l Form l Command. Listener l Item. Command.

Sample MIDP classes API l MIDlet l Form l Command. Listener l Item. Command. Listener l l Item J 2 ME 48

Sample classes API l MIDlet – Base class l Form l Command. Listener l

Sample classes API l MIDlet – Base class l Form l Command. Listener l Item. Command. Listener l l Item J 2 ME 49

MIDlet class API l l l protected abstract void start. App() protected abstract void

MIDlet class API l l l protected abstract void start. App() protected abstract void pause. App() protected abstract void destroy. App(boolean unconditional) public final String get. App. Property(String key) public final void notify. Destroyed() J 2 ME 50

Sample classes API l MIDlet l Form l Command. Listener l Item. Command. Listener

Sample classes API l MIDlet l Form l Command. Listener l Item. Command. Listener l l Item J 2 ME 51

Form class A Form is a Screen that contains an arbitrary mixture of items:

Form class A Form is a Screen that contains an arbitrary mixture of items: images, read-only text fields, editable date fields, gauges, choice groups, and custom items. l In general, any subclass of the Item class may be contained within a form. l The implementation handles layout, traversal, and scrolling. l J 2 ME 52

Form class API l Item management l public int append(Item item) l public Item

Form class API l Item management l public int append(Item item) l public Item get(int item. Num) l Layout l public void set. Item. State. Listener(Item. State Listener i. Listener) J 2 ME 53

Sample classes API l MIDlet l Form l Command. Listener l Item. Commad. Listener

Sample classes API l MIDlet l Form l Command. Listener l Item. Commad. Listener l Item J 2 ME 54

Command class The Command class represents the semantic meaning of an action. Command objects

Command class The Command class represents the semantic meaning of an action. Command objects are presented in the user interface. l The action itself is implemented in a Command. Listener object. l The Command. Listener is associated with a Displayable or an Item. l Once the Command is called – the Command. Listener is invoked, and the action is performed. l J 2 ME 55

Command class l Command label l public String get. Label() l Command type l

Command class l Command label l public String get. Label() l Command type l public int get. Command. Type() l Command priority l public int get. Priority() J 2 ME 56

Command. Listener class API l This object is a listener for Commands that are

Command. Listener class API l This object is a listener for Commands that are attached to a Displayable. l public void command. Action(Command c, Displayable d) J 2 ME 57

Item. Command. Listener class API l When a command (attached to an Item) is

Item. Command. Listener class API l When a command (attached to an Item) is invoked, the application is notified by having the command. Action() method called on the Item. Command. Listener that had been set on the Item. l public void command. Action(Command c, Item item) J 2 ME 58

Sample classes API l MIDlet l Form l Command. Listener l Item. Command. Listener

Sample classes API l MIDlet l Form l Command. Listener l Item. Command. Listener l l Item J 2 ME 59

Item class l. A superclass for components that can be added to a Form.

Item class l. A superclass for components that can be added to a Form. l All Item objects have a label field l Choose the Item’s layout, size, and appearance l Attach Commands J 2 ME 60

Item class API l public void set. Default. Command(Command cmd) l public void set.

Item class API l public void set. Default. Command(Command cmd) l public void set. Item. Command. Listener(Item. Com mand. Listener listener) l public void notify. State. Changed() l public int get. Preferred. Width() J 2 ME 61

Getting Started… l 1 st step: Download sun’s J 2 ME Wireless Toolkit from:

Getting Started… l 1 st step: Download sun’s J 2 ME Wireless Toolkit from: http: //java. sun. com/products/j 2 mewtoolkit/d ownload-2_1. html l 2 nd step: Make sure you have J 2 SE SDK installed l 3 rd step: Install the J 2 ME Toolkit. J 2 ME 62

After the installation…. l Shortcuts are available from the start menu. l New directories

After the installation…. l Shortcuts are available from the start menu. l New directories created J 2 ME 63

Using KToolbar J 2 ME 64

Using KToolbar J 2 ME 64

Creating a new Application Press “New Project”. l Enter the project’s name and the

Creating a new Application Press “New Project”. l Enter the project’s name and the MIDlet’s class name. l New directories will automatically be created. l J 2 ME 65

Where to place your files? J 2 ME/apps/{proj}/bin J 2 ME/apps/{proj}/lib source, resource, and

Where to place your files? J 2 ME/apps/{proj}/bin J 2 ME/apps/{proj}/lib source, resource, and binary files JAR, JAD, unpacked manifest files. J 2 ME/apps/{proj}/res external class libraries, (JAR or ZIP) for a specific project resource files J 2 ME/apps/{proj}/src source files J 2 ME/apps/lib external class libraries, (JAR or ZIP) for all KToolbar projects. J 2 ME 66

And then what? l l l Choose the target platform JTWI - conforms to

And then what? l l l Choose the target platform JTWI - conforms to Java Technology for the Wireless Write your code Industry (JSR-185). Save MIDP 1. 0 - includes MIDP 1. 0 and CLDC 1. 0 Custom - user defined settings, you can select project Build profile, configurations and various APIs. (Compile + Preverify) Run J 2 ME 67

Distribution to actual devices l Create a package l Place your code somewhere on

Distribution to actual devices l Create a package l Place your code somewhere on the net. l Update. jad file l Download the application to your mobile l Start playing… J 2 ME 68

Some other issues l OTA provisioning l Using Servlets l Working with Eclipse. ME

Some other issues l OTA provisioning l Using Servlets l Working with Eclipse. ME l Web services J 2 ME 69

The END! l You can download all the demos JARs from: www. cs. huji.

The END! l You can download all the demos JARs from: www. cs. huji. ac. il/~kerengaz/j 2 me/ l Have Fun!!! J 2 ME 70