Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java for Mobile Devices

Similar presentations


Presentation on theme: "Java for Mobile Devices"— Presentation transcript:

1 Java for Mobile Devices
Objectives To present some elements on J2ME. To give the basic steps on how to work with J2ME. To develop some examples. 2/17/2019 Mobile Applications - Lecture 1

2 What is J2ME (JAVA MICRO EDITION)
J2ME = Java solution for small electronic commodities. - mobile phones, pagers, PDA, set-top boxes, etc J2ME architecture Small Java virtual machines: KVM and CVM Configurations and Profiles – Java Libraries and APIs Various tools for deployment and device configuration Why J2ME? It is device independent. It reuses some of the Java classes. 2/17/2019 Mobile Applications - Lecture 1

3 Mobile Applications - Lecture 1
Some Terminology J2ME = Java Micro Edition CLDC = Connected Limited Device Configuration CDC = Connected Device Configuration KVM = Kilobyte virtual machine. CVM = Consumer and embedded virtual machine. MIDP = Mobile information device profile. PDAP = Personal digital assistant device. MIDlet = Java program for mobile devices. 2/17/2019 Mobile Applications - Lecture 1

4 J2ME General Architecture
Of Interest of us 2/17/2019 Mobile Applications - Lecture 1

5 Mobile Applications - Lecture 1
CLDC CLDC defines some common features / Java classes for small devices. CLDC considers: - Limited memory: 160 KB to 512 KB of total memory - Limited computation: 16-bit or 32-bit processor with at least 25 Mhz speed - Connectivity to some kind of networking Low power consumption CLDC is a collection of Java packages for A subset of Java language and virtual machine features A subset of core Java libraries (java.lang and java.util) Basic input/output (java.io) Basic networking support (javax.microedition.io) Some of those might not be scaled down (see the documentation for changes) 2/17/2019 Mobile Applications - Lecture 1

6 Mobile Applications - Lecture 1
MIDProfile The MIDP standard defines a MID as a device with the following minimum characteristics: Small Display: A screen size of at least 96 x 54 pixels with at least a 1-bit display depth. Input: A one-handed keyboard, two-handed keyboard, or touch screen. Memory: 32 KB of volatile memory for the Java runtime (heap); 128 KB of non-volatile memory for the MIDP components; 8 KB of non-volatile memory for persistent data . Networking: Two-way intermittent connection, usually wireless, with limited bandwidth 2/17/2019 Mobile Applications - Lecture 1

7 Mobile Applications - Lecture 1
MIDProfile (1) The main functions of MIDProfile are: Application Life Cycle Management The MIDP includes the javax.microedition.midlet package, which contains classes and methods for starting, pausing, and destroying applications in the host environment. User Interface and Events The MIDP also provides the javax.microedition.lcdui packages, which include classes and interfaces for creating GUI components for applications. Network Connectivity The MIDP extends the ContentConnection interface of the Generic Connection Framework by providing the HttpConnection interface, as well as a subset implementation of the HTTP protocol. Storing Data on Device The MIDP also provides the javax.microedition.rms package, which implements a record-based database management system. This provides applications with the capability to store data on the device. 2/17/2019 Mobile Applications - Lecture 1

8 Mobile Applications - Lecture 1
MIDlet Life Cycle javax.microedition.midlet.MIDlet is an abstract class defines three life cycle methods: pauseApp(), startApp(), and destroyApp(). MIDlet cycles: Paused, Active, Destroyed. public void startApp( ) This method indicates that the MIDlet is moving from a paused state to an active state. Here, the MIDlet will typically initialize any objects that are required while the MIDlet is active, and set the current display. public void pauseApp( ) This method is called when the MIDlet is moving from an active state to a paused state. This means that it will pause any threads that are currently active, as well as optionally setting the next display to be shown when the MIDlet is re-activated. Data can be persisted, if necessary, and retrieved later when the MIDlet is activated again. public void destroyApp(boolean unconditional) This method indicates that the MIDlet is moving to the destroyed state. It should free or close all resources that have been acquired during the life of the MIDlet. In addition, the method should persist any data that it wishes to save for future use. 2/17/2019 Mobile Applications - Lecture 1

9 Mobile Applications - Lecture 1
MIDlet Skeleton import javax.microedition.midlet.*; public class MyMIDlet extends MIDlet { public MyMIDlet( ) { // constructor } public void startApp( ) { // entering active state } public void pauseApp( ) { // entering paused state } public void destroyApp( boolean unconditional) { // entering destroyed state } } 2/17/2019 Mobile Applications - Lecture 1

10 Mobile Applications - Lecture 1
Example import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class HelloWorld extends MIDlet{ private Display display; TextBox textbox; public HelloWorld(){ display = Display.getDisplay(this); textbox = new TextBox("HelloWorld","HelloWorld.",500,0); } public void startApp(){ display.setCurrent(textbox);} public void pauseApp(){} public void destroyApp(boolean unconditional){} 2/17/2019 Mobile Applications - Lecture 1

11 Mobile Applications - Lecture 1
Run a MIDlet Hard but Safer Way: Write the MIDlet (Java program) Compile the MIDlet's source code (javac) javac –bootclasspath c:\j2me\midp2.0fcs\classes HelloWorld.java Preverify the MIDlet's class file () preverify –classpath c:\j2me\midp2.0fcs\classes –d HelloWorld Package the application in a JAR file  It is optional jar cvf payment.jar PaymentMidlet.class Run the MIDlet midp HelloWorld 2/17/2019 Mobile Applications - Lecture 1

12 Mobile Applications - Lecture 1
Run a MIDlet (1) Simple Way by Using a J2ME Toolkit (several emulators). Write the MIDlet (Java program). Create a new J2ME project. Add the java file in the src folder of the project. Build the project. Run the project using the emulator you want. 2/17/2019 Mobile Applications - Lecture 1

13 Mobile Applications - Lecture 1
Run a MIDlet (2) 2/17/2019 Mobile Applications - Lecture 1

14 Mobile Applications - Lecture 1
import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class Welcome extends MIDlet implements CommandListener {private Display display; // Reference to Display object for this MIDlet private TextBox tbMain; // A Textbox to display a message private Command cmExit; // A Command to exit the MIDlet public Welcome() { display = Display.getDisplay(this); cmExit = new Command("Exit", Command.SCREEN, 1); tbMain = new TextBox ("Welcome", "Hello to J2ME", 50, 0); tbMain.addCommand(cmExit); tbMain.setCommandListener(this); } public void startApp() { display.setCurrent(tbMain);} // Called by application manager to start the MIDlet. public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable s) if (c == cmExit) { destroyApp(false); notifyDestroyed(); } 2/17/2019 Mobile Applications - Lecture 1

15 Mobile Applications - Lecture 1
2/17/2019 Mobile Applications - Lecture 1

16 Mobile Applications - Lecture 1
Deploy a MIDlet Deploy = Transfer the jar + jad files to your mobile. jar – archive of the MIDlet. jad – (java application description) MIDlet-1: Hello,,HelloMidlet MIDlet-Name: HelloMidlet MIDlet-Version: 1.0 MIDlet-Vendor: ORA MIDlet-Jar-URL: HelloMidlet.jar MIDlet-Jar-Size: 863 The jad file can also provide other elements e.g. parameters. Several ways to deploy depending on network, phone etc. 2/17/2019 Mobile Applications - Lecture 1

17 Mobile Applications - Lecture 1
Almost the Same Java CLDC – contains some classes from java.lang.*: Boolean, Byte, Character, Class, Integer, Long, Math, Object, Runnable, Runtime, Short, String, StringBuffer, System, Thread, Throwable java.io.*: ByteArrayInputStream, ByteArrayOutputStream, DataInput, DataOutput, DataInputStream, DataOutputStream, InputStream, OutputStream, InputStreamReader, OutputStreamWriter, PrintStream, Reader, Writer java.util.*: Calendar, Date, Enumeration, Hashtable, Random, Stack, TimeZone, Vector Plus 20+ classes to work with Exceptions Some of the classes are scaled down quite a lot. 2/17/2019 Mobile Applications - Lecture 1

18 Certainly the Same New Java
MIDP – contains the following new packages: javax.microedition.midlet.*; MIDlet and MIDletStateChangeException; javax.microedition.lcdui.*; several classes for UI – Command, Display, TextBox, TextField, Graphics, Canvas, etc. javax.microedition.rms.*; RecordStore + etc. Old Packages java.util.*: Timer and TimerTask. 2/17/2019 Mobile Applications - Lecture 1

19 Mobile Applications - Lecture 1
MIDlet-Name: Show Properties MIDlet MIDlet-Version: 1.0.1 MIDlet-Vendor: Core J2ME MIDlet-1: ShowProps, , ShowProperties MicroEdition-Profile: MIDP-1.0 MicroEdition-Configuration: CLDC-1.0 MIDlet-Data-Size: 1500 getAppProperty() import javax.microedition.midlet.*; public class ShowProperties extends MIDlet { public void startApp() { System.out.println("Vendor: " + getAppProperty("MIDlet-Vendor")); System.out.println("Description: " + getAppProperty("MIDlet-Description")); System.out.println("JadFile Version: " + getAppProperty("JadFile-Version")); System.out.println("MIDlet-Data-Size: " + getAppProperty("MIDlet-Data-Size")); Runtime rtime = Runtime.getRuntime(); System.out.println("Total memory: " + rtime.totalMemory()); System.out.println("Free memory: " + rtime.freeMemory()); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } 2/17/2019 Mobile Applications - Lecture 1

20 Mobile Applications - Lecture 1
Problems to Solve: Read about the CLDC and MIDP References: 1.Jonathan Knudsen, Wireless Java, APress, 2003 2. Quasay Madmud, Learning Wireless Java, eBook from 2/17/2019 Mobile Applications - Lecture 1


Download ppt "Java for Mobile Devices"

Similar presentations


Ads by Google