Вы находитесь на странице: 1из 21

Mobile Computing Lab

CSI College of Engineering

S.No
1 2

List of Experiment
Study of WML and J2ME Simulators Design of Simple Calculator +,* and / Using WML/J2ME Design of Calendar for any Given Month and Year Using

Page No

3 WML/J2ME 4 5 6 7 8 9 Design a Timer to System Time Using WML/J2ME Design a Simple Game using WML/J2ME Animate an Image Using WML/J2ME Design a Phone Book Containing Num, Name, Address, Mail Etc., Authentication and Encryption Technique Used in GSM Study of GLOMOSIM Simulator

Mr D. Stalin Alex

Page 1

Mobile Computing Lab

CSI College of Engineering

Exp No 1: Study of J2ME and WML Simulators


What is a WAP Server? WAP is published by the WAP Forum. This Forum was founded in 1997 by Ericsson, Motorola, Nokia, and Unwired Planet. These companies organized an industry group called the (Wireless Application Protocol) WAP Forum. This group produces the WAP specification, a (long and detailed) series of technical documents that define standards for implementing wireless network applications. Hundreds of industry firms have given strong backing to the WAP Forum, so the technology should become widely adopted, and it is already well-hyped. What is WAP (Wireless Application Protocol)? WAP stands for Wireless Application Protocol. It is an application communication protocol which is used to access services and information from handheld devices such as mobile phones. WAP protocol is designed for Micro Browsers (Similar to HTTP for Web Browsers). Similar to HTML used by HTTP protocol, WAP protocol uses WML (Web Markup Language). The syntax for WML follows the XML 1.0 rules. WAP is for handheld devices such as mobile phones. A WAP server is just a standard web server that hosts a WAP site's contents like WML and XHTML MP documents. Some companies have a "WAP server" product that is actually a web server plus a WAP gateway. This confuses the term. So, when you talk about WAP servers, make sure you and the one listening to you are not referring to different things. (Note that content providers do not need to care about the WAP gateway part typically since mobile network operators provide a WAP gateway to their service subscribers. However, if you are creating a secure WAP application like mobile banking, then you need to consider whether to use you own WAP gateway.) Two popular web servers are Apache and IIS. Tomcat is a Java Servlet / JSP container that can also be used as a standalone web server. Apache, IIS and Tomcat are the most commonly used software for hosting WAP / web sites. Apache - Open-source, Free WAP / Web Server Apache is a very professional open-source WAP / web server. It can be downloaded free of charge at the website http://httpd.apache.org/. Apache is available on many platforms including Microsoft Windows and Linux / UNIX. PHP is very often used with Apache for server-side scripting. Tomcat - Open-source, Free Java Servlet / JSP Container and Web / WAP Server

Mr D. Stalin Alex

Page 2

Mobile Computing Lab

CSI College of Engineering

Like Apache, Tomcat is open-source. It can be downloaded free of charge at the website http://jakarta.apache.org/tomcat/.Tomcat is mainly used to host dynamic WAP / web applications developed with the Java Servlet or JSP (Java Server Pages) server-side technologies. Tomcat can also be used to host static documents. It is available on many different platforms like Microsoft Windows and Linux / UNIX. Microsoft IIS - Built-in Web / WAP Server of Windows IIS (Internet Information Services) is a web server developed by Microsoft.IIS is only available on the MS Windows platform. It is bundled with some versions of MS Windows like Windows 2000, Windows XP Professional and Windows Server 2003.IIS is commonly used to host ASP applications.ASP (Active Server Pages) is a server-side technology developed by Microsoft for creating dynamic WAP / web sites. WML (Wireless Markup Language) Introduction Each and Every mobile devices which supports WAP have a small browser called Micro Browser. Micro Browser is a small software module or a software programe which requires minimum hardware, less memory consuption and CPU power.This is interprate with Web Markup Language WML syntax. This Wireless Markup Language is equivelent to the JavaScript for Web Browsers.This Micro Browser supports a reduced version of the JavaScript called WMLScript. Also for showing images on the mobile devices, Micro Browser supports WBMP (Wireless Bitmap) image files. The Wireless Application Protocol: WAP Protocol is layered in a way similar to OSI model protocol, in which each of the layers is accessible by the layers above, as well as other services and applications. There are four major layers in the WAP protocol: 1. Application layer 2. Session layer (WSP) 3. Transaction layer (WTP) 4. Security Layer (WTLS) 5. Transport layer or datagram layer (WDP)

1. Application Layer: WAP's application layer is the Wireless Application Environment (WAE). WAE directly supports WAP application development with Wireless Markup Language (WML) in place of HTML and WMLScript instead of JavaScript.WAE is to provide the operators and service providers an interoperable environment on which they can build applications and services which, in turn, can be used in a wide variety of hand-held client terminals such as Mobile phone. 2. Session layer (WSP)

Mr D. Stalin Alex

Page 3

Mobile Computing Lab

CSI College of Engineering

WAP's session layer is the Wireless Session Protocol (WSP). WSP is the equivalent to HTTP for WAP browsers but it is not similar to HTTP. WAP involves browsers and servers just like the internet technology, but HTTP was not a practical choice for WAP because of its relative inefficiency on the wire. WSP conserves precious bandwidth on wireless links; in particular, WSP works with relatively compact binary data where HTTP works mainly with text data.

These three protocols uses in WAP: Wireless Transaction Protocol (WTP) Wireless Transaction Layer Security (WTLS) Wireless Datagram Protocol (WDP) 3. Transaction layer (WTP) The Wireless Transaction Protocol(WTP) operates efficiently over either secure or non-secure wireless datagram networks. It provides three different kinds of wireless transaction services, these are: Unreliable one-way,Reliable one-way and Reliable two-way transactions. This layer also includes optional user-to-user reliability by triggering the confirmation of each received message or information. To reduce the number of messages which was sent, the feature of delaying acknowledgements can be used. 4. Security layer (WTP) Security protocol is based on Transport Layer Security (TLS) or formely known as Secure Sockets Layer (SSL). It is designed to be used with other WAP protocols and to support narrow-band networks. It uses data encryption with a method that is negotiated at the start of the session to provide privacy,protection,and data integrity, authentication and denialof-service protection. 5. Transport layer or datagram layer (WDP) Wireless Datagram Protocol (WDP) in WAP architecture covers the Transmission Layer Protocols (TLP) in an Internet model. As a general transport services, WDP offers to the upper layers an invisible interface independent of the underlying network technology used. In consequence of the interface common to transport protocols, the upper layer protocols of the WAP architecture can operate independent of the underlying wireless network. What is WML 1.x? WML (Wireless Markup Language) 1.x is the markup language defined in the WAP 1.x specification. WAP is the standard created by the WAP Forum (now the Open Mobile Alliance [OMA]) that brings the World Wide Web to wireless devices. It specifies the protocol stack and application environment of mobile Internet browsing applications. The role of WML in mobile Internet applications is the same as that of HTML in web applications. WAP sites are written in WML, while web sites are written in HTML.

Mr D. Stalin Alex

Page 4

Mobile Computing Lab

CSI College of Engineering

WML 1.x is very similar to HTML. Both of them use tags and are written in plain text format. Some tags in WML 1.x are directly borrowed from HTML. If you have experience in using the HTML markup language, you should be able to learn WML 1.x quickly. Some features of WML 1.x are specific to wireless devices. For example, WML 1.x provides a way for developers to program the soft keys of mobile phones. This feature is not supported in HTML since computers do not have any soft keys. The most up-to-date version of the WAP 1.x specification is WAP 1.2.1, which defines WML 1.3.WML files have the extension ".wml". The MIME type of WML is "text/vnd.wap.wml". WML supports client-side scripting. The scripting language supported is called WMLScript. Its syntax is based on JavaScript. WAP 2.0 WAP 1.x is an earlier version of the WAP standard. The most current version is WAP 2.0. The markup language defined in WAP 2.0 is XHTML MP (XHTML Mobile Profile). It is a subset of the XHTML used on the web. XHTML MP supports a mobile version of cascading style sheet called WCSS (WAP CSS). It is a subset of the CSS2 used on the web plus some WAP specific extensions. Most of the new mobile phone models released are WAP 2.0-enabled. As WAP 2.0 is backward compatible to WAP 1.x, WAP 2.0-enabled mobile devices can display both XHTML MP and WML documents. WML 1.x is an earlier technology. However, that does not mean it is of no use, since a lot of wireless devices that only supports WML 1.x are still being used. Besides, some useful features of WML are not available in XHTML MP. For example, XHTML MP does not support events, variables and client-side scripting. The major WML features lost in XHTML MP are discussed in the "WML Features Lost in XHTML MP" section of our XHTML MP tutorial. If you write the markup of your mobile Internet site in WML, both old and new WAP-enabled wireless devices can be used to view your mobile Internet site. The user base of your WAP application is maximized. WML 2.0 WAP site developers need not to care about WML 2.0. WML 2.0 is created for backward compatibility purposes and it is not for use by WAP site developers. To develop a WAP site with the WAP 2.0 standard, use XHTML Mobile Profile. WML Deck and Card A major difference between HTML and WML is that the basic unit of navigation in HTML is a page, while that in WML is a card. A WML file can contain multiple cards and they form a deck. When a user goes to a WAP site, the mobile browser loads a WML file that contains a deck of cards from the server. Only one card will be shown on the screen of the wireless device each time. If the user goes to another card of the same deck, the mobile browser does not have to send any requests to the server since the file that contains the deck is already stored in the wireless device.

Mr D. Stalin Alex

Page 5

Mobile Computing Lab

CSI College of Engineering

WML is designed in this way because wireless devices have a high latency for connecting to the server. Downloading a deck of cards at a time can lower the number of round trips to the server. You can put links, text, images, input fields, option boxes and many other elements in a card. WML Document Structure The following shows the structure of a typical WML document. (helloWorld.wml) <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD "http://www.wapforum.org/DTD/wml13.dtd"> <wml> <card id="card1" title="WML Tutorial"> <p>Hello World</p> </card> <card id="card2" title="WML Tutorial"> <p>Welcome to the world of WML</p> </card> </wml> The result of the "Hello World" WML example in mobile phone emulators is shown below: WML 1.3//EN"

Prolog Prolog refers to the first two lines of our "Hello World" WML example: <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd"> Every WML document starts with the prolog. The first line is the XML declaration and the second line is the DOCTYPE declaration. The prolog components are not WML elements and they should not be closed, i.e. you should not give them an end tag or finish them with />. XML Declaration and Character Encoding All WML documents are XML documents. So, there is an XML declaration at the start. The XML declaration specifies the XML version of the document. The character encoding of the document can also be specified here, like this:

Mr D. Stalin Alex

Page 6

Mobile Computing Lab

CSI College of Engineering

<?xml version="1.0" encoding="UTF-8"?> The above line states that the XML version of the WML document is 1.0 and the character encoding is UTF-8. If the character encoding of the WML document is UTF-8 or UTF-16, there is no need to declare the character encoding as it can be detected automatically. Note that there should have no whitespace before the XML declaration. If not, some WAP browsers or WAP gateways cannot process the WML file. DOCTYPE Declaration All WML documents must have the DOCTYPE declaration. It should be placed between the XML declaration and the <wml> element. Below is the DOCTYPE declaration for WML 1.3. You can simply copy and paste it into your WML files. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD "http://www.wapforum.org/DTD/wml13.dtd"> WML 1.3//EN"

The DOCTYPE declaration specifies the name of the DTD (Document Type Definition) and the URL to the DTD. The DTD contains information about the syntax of the mark-up language. It defines what elements and attributes can be used in the mark-up and the rules that they should be used. For example, the DTD of WML specifies that the <card> element should be enclosed in the <wml></wml> tag pair. If you do not follow this rule, your WML document is said to be invalid. WAP browsers will complain if you try to view an invalid WML document. This is the DTD declaration for WML 1.2: Validation tools can be used to check whether your WML document conforms to the WML language rules by comparing your WML document with the DTD specified in the DOCTYPE declaration. Such validation tools are integrated in some IDEs. The Deck <wml> ..... </wml> The deck is the WML document itself. It is embedded within <wml> tags The Cards <card> ..... </card> Cards are always displayed one at the time. This WML deck contains two cards - one for user input and one for displaying the result. The <do>element <do> ..... </do> The first card has a <do> element that defines an event to be triggered. The type="accept" attribute of the <do> element causes the label="Answer" to be displayed in the lower left corner of the display. The Event The <go> element triggers when the user clicks the <do> label. The href="#card2" attribute of the <go> element causes card2 to be displayed on the screen.

The Variable Card2 displays the $(name) variable from card1, because variables are valid across cards.

Mr D. Stalin Alex

Page 7

Mobile Computing Lab

CSI College of Engineering

When a WML page is accessed from a mobile phone (handset devices), all the cards in the page are downloaded from the WAP server. Navigation between the cards is done by the phone computer - inside the phone - without any extra access trips to the server:

For Example: <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card id="no1" title="Card 1"> <p>Hello World!</p> </card> <card id="no2" title="Card 2"> <p>Welcome to our WAP Academic Tutorials!</p> </card> </wml> Output Hello World! Result look like this in your mobile phone display (note that only one card is displayed at a time): Paragraphs and Line Breaks: A WML card can be set up to view the paragraph and line break functions of WML: <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card title="Paragraphs"> <p> This is a paragraph </p> <p> This is another<br/>with a line break </p>

Mr D. Stalin Alex

Page 8

Mobile Computing Lab

CSI College of Engineering

</card> </wml> Output display on your mobile set as: This is a paragraph This is another with a line break

Text Formatting: A WML card can be set up to display the text formatting functions of WML: <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card title="Formatting"> <p> normal<br/> <em>emphasized</em><br/> <strong>strong</strong><br/> <b>bold</b><br/> <i>italic</i><br/> <u>underline</u><br/> <big>big</big><br/> <small>small</small> </p> </card> </wml> The result display as... normal emphasized strong bold italic underline

big
small

Tables: A WML card can be set up to display the table functions of WML: <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

Mr D. Stalin Alex

Page 9

Mobile Computing Lab

CSI College of Engineering

<wml> <card title="Table"> <p> <table columns="3"> <tr> <td>Cell 1</td> <td>Cell 2</td> <td>Cell 3</td> </tr> </table> </p> </card> </wml> The result might be display as: Cell 1 Cell 2 Cell 3 Links: A WML card can be set up to display the anchor functions of WML. <anchor> The <anchor> tag always has a task ("go", "prev", or "refresh") specified. The task defines what to do when the user selects the link. In this example given bellow when the user selects the "Next page" link, the task says "go to the file test.wml": <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card title="Anchor Tag"> <p> <anchor>Next page <go href="academi.wml"/> </anchor> </p> </card> </wml> <a> The <a>tag always performs a "go" task, with no variables. The example given below does the same as the <anchor> tag example: <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

Mr D. Stalin Alex

Page 10

Mobile Computing Lab

CSI College of Engineering

<wml> <card title="A Tag"> <p> <a href="test.wml">Next page</a> </p> </card> </wml> Image A WML card can be set up to display an image: <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card title="Image"> <p> This is an image <img src="/images/heart.wbmp" alt="heart" /> in a paragraph </p> </card> </wml> The image display on the mobile looks like:

This is an image in a paragraph Note that .wbmp is the only image type that can be displayed in a WAP browser. Input Fields: A WML card can be set up to let a user enter information, as demonstrated in this example: <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card title="Input"> <p> Name: <input name="Name" size="25"/><br/> Age: <input name="Age" size="25" format="*N"/><br/> Sex: <input name="Sex" size="25"/> </p> </card> </wml>

Mr D. Stalin Alex

Page 11

Mobile Computing Lab

CSI College of Engineering

Output:

Name: Age: Sex:

Select and Option A WML card, can be set up to display the select and option functions of WML: <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card title="Selectable List 1"> <p> <select> <option value="htm">HTML Tutorial</option> <option value="xml">XML Tutorial</option> <option value="wap">WAP Tutorial</option> </select> </p> </card> </wml> Output: Here the result is a selectable list where the user can select more than one item:Example is given bellow. <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card title="Selectable List 2"> <p> <select multiple="true"> <option value="htm">HTML Tutorial</option> <option value="xml">XML Tutorial</option> <option value="wap">WAP Tutorial</option> </select>

Mr D. Stalin Alex

Page 12

Mobile Computing Lab

CSI College of Engineering

</p> </card> </wml> The result may looks like:

Fieldset A WML card, can be set up to display the fieldset function of WML: <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card title="Fieldset"> <p> <fieldset title="CD Info"> Title: <input name="title" type="text"/><br/> Prize: <input name="prize" type="text"/> </fieldset> </p> </card> </wml> The result might be display as:

The wml:Input component defines an input field (a text field where the user can enter some text).

Mr D. Stalin Alex

Page 13

Mobile Computing Lab

CSI College of Engineering

Go Task The <go> task represents the action of switching to a new card. <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card> <p> <anchor> Go To Test <go href="test.wml"/> </anchor> </p> </card> </wml> Prev Task The <prev> task represents the action of going back to the previous card. <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card> <p> <anchor> Previous Page
Mr D. Stalin Alex Page 14

Mobile Computing Lab

CSI College of Engineering

<prev/> </anchor> </p> </card> </wml> Refresh Task: The <refresh> task refreshes some specified card variables. If any of the variables are shown on the screen, this task also refreshes the screen. The example below uses an <anchor> tag to add a "Refresh this page" link to the card. When the user clicks on the link, he or she refreshes the page and the value of the variable x will be set to 30: <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card> <p> <anchor> Refresh this page <go href="thispage.wml"/> <refresh> <setvar name="x" value="30"/> </refresh> </anchor> </p> </card> </wml> Noop Task: The <noop> task says that nothing should be done (noop stands for "no operation"). This tag is used to override deck-level elements. The <do> tag can be used to activate the task when the user clicks on a word or phrase on the screen. The example given bellow below uses a <do> tag to add a "Back" link to the card. When the user clicks on the "Back" link, he or she should be taken back to the previous card. But the tag prevents this operation; when the user clicks on the "Back" link nothing will happen: <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card> <p> <do name="back" type="prev" label="Back"> <noop/>

Mr D. Stalin Alex

Page 15

Mobile Computing Lab

CSI College of Engineering

</do> </p> </card> </wml> Task Elements:

WML Timer The timer tag serves as a timer clock for a card. The timer is started when the card is entered and stops when you exit the card. You can have only one timer element per card. Timer is used as a timer of a card which starts at the card active and stops at the execution of a task inside the card. The timer will decrement from its initial value to 0. An ontimer intrinsic event is activated when the timer is conuted from integer value 1 to 0. The wml:Timer element declares a card timer, which provides a method for invoking a task automatically after some period of user inactivity. Any task or user action that activates the card starts the timer, and executing any task element stops it. You can only associate one task for each timer, and you can only define one timer for each card. timer( "name='variable' value='value'" ); "name" attribute specifies the name of the timer variables. When the timer is expired the variable has the value 0. 'value' attribute is the default value of the name variable. The name variable is set as the initial value if it has not been set. The timeout value is specified in the unit of 1/10 second. The example given below will display a message for 3 seconds, and then take you to the file "test.wml": <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card ontimer="test.wml"> <timer value="30"/> <p><i>Some Message</i></p>

Mr D. Stalin Alex

Page 16

Mobile Computing Lab

CSI College of Engineering

</card> </wml> Timer Parameters:

In WML variables are totaly different from another language. Variable names in WML are prefixed with a dollar($) sign.When any user switches from card to card in a deck, It is necessary to store data in variables. WML variables are case sensitive. WML supports variables that can hold transitional data between cards, provide custom output tailored to individual users, and more.Variables are special holding places for the values. They can hold numeric or alpha numeric values and their values can be changed by code at the requirement which needed. However, it is usually good practice to dedicate variables to particular purposes, and hence, to particular types of data. Variables in WML consist of words, enclosed in parentheses, prefixed with a dollar sign ($). For example: $(name) $(address) $(link) $(target_url) $(_method) The dollar sign ($) is used to signify a variable in WML, it is a reserved character in WML. If you want an actual dollar sign to appear anywhere in your card(s),you use a double dollar sign instead ("$$"). Variable names must start with a letter or underscore. Subsequent characters can be alpha, numeric, or underscores. Variables are case sensitive; "phone_number" is different from "Phone_Number." WML will substitute the value of the variable where the variable name appears. For Example: Hi! $(name)!! If the Adams is store in name variables than it display like Hi!Adams !!

Mr D. Stalin Alex

Page 17

Mobile Computing Lab

CSI College of Engineering

Specify a Variable through an Input Element Variables can also be set through an input element (like input, select, option, etc.). The following example given bellow that will create a variable named collegename: <card id="card1"> <select name="collegename"> <option value="HTML">HTML Tutorial</option> <option value="XML">XML Tutorial</option> </select> </card> To use the variable we created in the example above: <card id="card2"> <p>You selected: $(collegename)</p> </card>

J2ME
J2ME Introduction What is J2ME? Cut away the hype and the excess fat and you are left with yet another (set of) Java APIs. Since these APIs cannot run on a traditional Java Virtual Machine (JVM), due to the limited size of mobile devices in regards to memory and resource availability, J2ME defines a limited version of the JVM as well. In a nutshell: J2ME combines a resource constrained JVM and a set of Java APIs for developing applications for mobile devices. Do you, as a developer, have to install this JVM and the APIs on mobile devices? No. Device manufacturers install and prepackage their devices with this JVM (and associated APIs). As a developer, you only need to develop applications targeting these devices and install them. Easier said than done! J2ME can be divided into three parts, as shown in Figure 1: a configuration, a profile, and optional packages. A configuration contains the JVM (not the traditional JVM, but the cut-down version) and some class libraries; a profile builds on top of these base class libraries by providing a useful set of APIs; and optional packages, are well, an optional set of APIs that you may or may not use when creating your applications. Optional packages are traditionally not packaged by the device manufacturers, and you have to package and distribute them with your application. The configuration and profile are supplied by the device manufacturers and they embedded them in the devices.

Mr D. Stalin Alex

Page 18

Mobile Computing Lab

CSI College of Engineering

The most popular profile and configuration that Sun provides are the Mobile Information Device Profile (MIDP) and Connected Limited Device Configuration (CLDC), respectively. As the name suggests, CLDC is for devices with limited configurations; for example, devices that have only 128 to 512KB of memory available for Java applications. Consequently, the JVM that it provides is very limited and supports only a small number of traditional Java classes. (This limited JVM is actually called the KVM.) Its counterpart, the Connected Device Configuration (CDC) is for devices with at least 2MB of memory available and supports a more feature-rich JVM (but still not a standard JVM). The MID profile complements the CLDC configuration very well because it minimizes both the memory and power required for limited devices. It provides the basic API that is used for creating application for these devices. For example, it provides the javax.microedition.lcdui package that allows us to create the GUI elements that can be shown on a (limited) device running the MID profile on top of a CLDC configuration. Note that MIDP cannot be used with CDC devices. CDC devices get their own set of profiles, like the Foundation and Personal profiles. However, I will not cover these profiles or the CDC here, and will concentrate on using MIDP and CLDC only. The latest versions of MIDP and CLDC are 2.0 and 1.1, respectively. Not many devices currently support these versions, but the list is growing rapidly. Understanding the Process of MIDlet Creation There are seven steps in the creation of a MIDlet. These steps are: designing, coding, compiling, preverification, packaging, testing, and deployment. Some of these steps are not strictly MIDlet-centric (for example, every application needs to be designed, coded, and compiled), The Toolkit abstracts a lot of these steps so that it is easier for you in the overall scheme of things. This is fine and dandy once you know the process, but when you are only starting out, you really should be coding by hand, rather than using a sugar-coated abstraction. To ensure that we get a hands-on understanding of these steps, let us take the help of a simple example. We will create a MIDlet that, when executed, will print the current date and time on a mobile device for a short time. Along with this in mind, keep Figure 2 handy to understand the sequence of these steps. Also, note that I will explain the lifecycle of MIDlets later. For the moment, let's get a simple MIDlet up and running, which will illustrate these steps.

Mr D. Stalin Alex

Page 19

Mobile Computing Lab

CSI College of Engineering

Step 1: Design MIDlets are different from other applications that you may have created, simply because MIDlets run in an environment that is very different. There are several issues, not just those that are most visible (for example, the interactivity of your MIDlet with the user), but others that impact its usability. For the example application, our Date-Time MIDlet does not need user interactivity. It needs to display the current date and time for a few seconds when the user executes the MIDlet. For simple cases like this, it is perhaps sufficient to mimic the design of the MIDlet by drawing it on a piece of paper. For more complex designs with multiple screens, it is best to design the screens professionally before starting the actual coding process. Step 2: Code Each MIDlet must extend the abstract MIDlet class found in the javax.microedition.midlet package, much like creating an applet by extending the java.applet.Applet class. At the minimum, your MIDlet must override three methods of this abstract class, startApp(), pauseApp(), and destroyApp(boolean unconditional). Here is the DateTimeApp class: package com.j2me.part1; import java.util.Date; import javax.microedition.lcdui.Alert; import javax.microedition.lcdui.Display; import javax.microedition.midlet.MIDlet; public class DateTimeApp extends MIDlet { Alert timeAlert; public DateTimeApp() { timeAlert = new Alert("Alert!"); timeAlert.setString(new Date().toString()); } public void startApp() { Display.getDisplay(this).setCurrent(timeAlert); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } } In this example, DateTimeApp's constructor creates the element that is necessary to display the time on a device's screen and the startApp method does the actual task of displaying this element. Don't worry if you don't understand how the Alert element works, or when the constructor or the other methods are called. I will cover the former in the next part, when we look at the GUI elements of MIDP 2.0, and the latter later in this article in the

Mr D. Stalin Alex

Page 20

Mobile Computing Lab

CSI College of Engineering

MIDlet Lifecycle section. Copy this code into a file called DateTimeApp.java and save it in a folder that mimics its package structure (com\j2me\part1). You can save it anywhere you want on your machine; as far as this article is concerned, we will save it in the folder C:\WTK22\article\com\j2me\part1.

Mr D. Stalin Alex

Page 21