You are on page 1of 17

A

PRACTICAL FILE
ON
MOBILE COMPUTING
SUBMITTED FOR
BACHELOR OF TECHNOLOGY
IN
COMPUTER SCIENCE AND ENGINEERING
AT

BMIET COLLEGE OF ENGINEERING


SONIPAT
2017-2021

SUBMITTED TO SUBMITTED BY
MS. NAMITA JAIN Shivani Bansal
Asst. Professor CSE CSE-IVth Year (8th SEM)
Roll NO.- Cse/17/232
INDEX

S.NO NAME OF DONE ON REMARKS


EXPERIMENT

INTRODUCTION OF 20/04/2021
1 J2ME
04/05/2021
2 Write a J2ME
program to
implement a
Calculator with add,
subtract, multiply and
division functions
(Use buttons).

Design a Calendar of 01/06/2021


3 any given month and
year using J2ME

4 Design a Login Form 08/06/2021


using J2ME
PROGRAM 1
INTRODUCTION OF J2ME
What is J2ME?

J2ME stands for Java 2, Micro Edition. It is a stripped-down version of Java targeted at devices which
have limited processing power and storage capabilities and intermittent or fairly low-bandwidth
network connections. These include mobile phones, pagers, wireless devices and set-top boxes
among others.

A Sample Wireless Stack would consist of:

Profiles

Configurations

Java Virtual Machines

Host Operating System

What is a J2ME Configuration?

A configuration defines the minimum Java technology that an application developer can expect on a
broad range of implementing devices.

J2ME Connected, Limited Device Configuration (CLDC)

specifies the Java environment for mobile phone, pager and wireless devices

CLDC devices are usually wireless

160 - 512k of memory available for Java

typically has limited power or battery operated

network connectivity, often wireless, intermittent, low-bandwidth (9600bps or less)

J2ME Connected Device Configuration (CDC)

describes the Java environment for digital television set-top boxes, high end wireless devices and
automotive telematics systems.

device is powered by a 32-bit processor

2MB or more of total memory available for Java

network connectivity, often wireless, intermittent, low-bandwidth (9600bps or less)

These two configurations differ only in their respective memory and display capabilities.
What is a J2ME Profile?

A specification layer above the configuration which describes the Java configuration for a specific
vertical market or device type.

J2ME Profiles

J2ME Mobile Information Device Profile (MIDP)

this is the application environment for wireless devices based on the CLDC

contains classes for user interface, storage and networking

J2ME Foundation Profile, Personal Basis, Personal and RMI profiles

these are profiles for devices based on the CDC, which are not addressed in this tutorial

Virtual Machines

The CLDC and the CDC each require their own virtual machine because of their different memory
and display capabilities. The CLDC virtual machine is far smaller than that required by the CDC and
supports less features. The virtual machine for the CLDC is called the Kilo Virtual Machine (KVM) and
the virtual machine for the CDC is called the CVM.

INSTALLIATION OF J2ME

1. Login to an Administrator account on your Windows machine.

2. Verify that you have an installation of Java Standard Edition Development Kit (JDK) 6 or later.

Now that you have a JDK installed, you are ready to install J2ME 2.5.2

3. Download the Sun Java Wireless Toolkit 2.5.2 for CLDC from here: http://www.rose-
hulman.edu/class/csse/binaries/csmobilegames/sun_java_wireless_toolkit-2.5.2_01-win.exe

4. Follow these instructions for installation

1. Find the Required File you downloaded in step 3 above and double click it to run it.

You may get a message that says "The publisher could not be verified. Are you sure
you want to run this software?"

Ignore the warning and run it by clicking the Run button. It will not harm your
system.

2. Click the Next button when the installSheild Wizard appears.

3. Accept the License Agreement by clicking the Accept button.

4. You will now be asked to choose your Java [TM] Virtual Machine Location. Accept
the default or browse to the location of your choice JVM.

5. Click the Next button.


6. The next screen will ask you to choose a destination location for installing Sun Java
Wireless Toolkit. Accept the default location or select one of your choice.

7. Click the Next button.

8. Select a Program (start menu) Folder the installation (or again, accept the default).

9. Click the Next button.

10. Make sure the box is selected to Check for Product Updates and click the Next
button.

11. When asked to Start Copying Files, click the Next button.

12. Wait a couple minutes while it installs the updates, then click the Finish
button. That completes your installation.

Verify that your installation works

Now that you have a Java Wireless Toolkit installed on your machine, you can open existing projects,
create new projects, and run them on a mobile device emulator or on an actual physical device.

Follow the instructions below for opening an existing project and running it in a mobile device
emulator.

1. Locate the Sun Java (TM) Wireless Toolkit 2.5.2_01 for CLDC Folder on your Windows
Machine. You can do this by clicking on Start Menu → All Programs, and scrolling to the
folder.

2. Expand the folder in step 1 and click on Wireless Toolkit 2.5.2.

3. Click Open Project and select from the list of available projects.

4. Double click on the project you selected (e.g., Audiodemo).

5. Click the Run button and voila! You are now ready to run the selected application on your
mobile device emulator.

6. Select from the games provided (e.g., Bouncing Ball). Select a background of your choice
and have fun with it.
PROGRAM 2

Write a J2ME program to implement a Calculator with add,


subtract, multiply and division functions (Use buttons).

import javax.microedition.lcdui.*;

import javax.microedition.midlet.MIDlet;

public final class CalcMIDlet extends MIDlet implements


CommandListener,ItemCommandListener

private static final int NUM_SIZE = 20;

private final Command exitCmd = new Command(“Exit”, Command.EXIT, 2);

private final Command add = new Command(“Add”, Command.ITEM, 1);

private final Command sub = new Command(“Sub”, Command.ITEM, 1);

private final Command mul = new Command(“Mul”, Command.ITEM, 1);

private final Command div = new Command(“Div”, Command.ITEM, 1);

private final TextField t1 = new TextField(“A”, “”, NUM_SIZE, TextField.DECIMAL);

private final TextField t2 = new TextField(“B”, “”, NUM_SIZE, TextField.DECIMAL);

private final TextField tr = new TextField(“Result”, “”, NUM_SIZE, TextField.UNEDITABLE);

private final Alert alert = new Alert(“Error”, “”, null, AlertType.ERROR);

private boolean isInitialized = false;

protected void startApp()

if (isInitialized)

return;
}

Form f = new Form(“Calculator”);

f.append(t1);

f.append(t2);

StringItem itema = new StringItem(“Add”, “”, Item.BUTTON);

itema.setDefaultCommand(add);

itema.setItemCommandListener(this);

f.append(itema);

StringItem items = new StringItem(“Sub”, “”, Item.BUTTON);

items.setDefaultCommand(sub);

items.setItemCommandListener(this);

f.append(items);

StringItem itemm = new StringItem(“Mul”, “”, Item.BUTTON);

itemm.setDefaultCommand(mul);

itemm.setItemCommandListener(this);

f.append(itemm);

StringItem itemd = new StringItem(“Div”, “”, Item.BUTTON);

itemd.setDefaultCommand(div);

itemd.setItemCommandListener(this);

f.append(itemd);

f.append(tr);

f.addCommand(exitCmd);

f.setCommandListener(this);

Display.getDisplay(this).setCurrent(f);
isInitialized = true;

protected void destroyApp(boolean unconditional)

protected void pauseApp()

public void commandAction(Command c, Item item)

//do not declare variables inside try…it will give you an error

double res = 0.0;

double n1 = getNumber(t1, “First”);

double n2 = getNumber(t2, “Second”);

try

if (c==add)

res=n1+n2;

if (c==sub)

res=n1-n2;

if (c==mul)

res=n1*n2;

if (c==div)

res=n1/n2;

}
catch (NumberFormatException e)

return;

catch (ArithmeticException e)

alert.setString(“Divide by zero.”);

Display.getDisplay(this).setCurrent(alert);

return;

String res_str = Double.toString(res);

if (res_str.length() > tr.getMaxSize())

tr.setMaxSize(res_str.length());

tr.setString(res_str);

public void commandAction(Command c, Displayable d)

if (c == exitCmd)

destroyApp(false);

notifyDestroyed();

return;

}
}

private double getNumber(TextField t, String type) throws NumberFormatException

String s = t.getString();

if (s.length() == 0)

alert.setString(“No ” + type + ” Argument”);

Display.getDisplay(this).setCurrent(alert);

throw new NumberFormatException();

double n;

try

n = Double.parseDouble(s);

catch (NumberFormatException e)

alert.setString(type + ” argument is out of range.”);

Display.getDisplay(this).setCurrent(alert);

throw e;

return n;

}
OUTPUT
PROGRAM 3
Design a Calender of any given month and year using J2ME

import javax.microedition.lcdui.*;

import javax.microedition.midlet.MIDlet;

import java.util.Date;

import java.util.TimeZone;

public class CalenderMIDlet extends MIDlet{

private Form form;

private Display display;

private DateField calender;

private static final int DATE = 0;

public CalenderMIDlet(){

calender = new DateField("Date In:", DateField.DATE, TimeZone.getTimeZone("GMT"));

public void startApp(){

display = Display.getDisplay(this);

Form form = new Form("Calender");

form.append(calender);

display.setCurrent(form);

public void pauseApp(){}

public void destroyApp(boolean destroy){

notifyDestroyed();

}}
OUTPUT
PROGRAM 4
Design a Login Form using J2ME

import javax.microedition.midlet.MIDlet;

import javax.microedition.lcdui.*;

public class LoginExample extends MIDlet implements CommandListener{

private Display display;

private TextField userName,password;

public Form form;

private Command login,cancel;

private Image img, imge, img2;

public LoginExample() {

form = new Form("Sign in");

userName = new TextField("LoginID:", "", 30, TextField.ANY);

password = new TextField("Password:", "", 30, TextField.PASSWORD);

cancel = new Command("Cancel", Command.CANCEL, 2);

login = new Command("Login", Command.OK, 2);

try{

img = Image.createImage("/logo.png");

imge = Image.createImage("/front_left1_bad.png");

img2 = Image.createImage("/Congratulations-1.png");

}catch(Exception e){

System.out.println(e.getMessage());

public void startApp() {

display = Display.getDisplay(this);
try{form.append(img);}catch(Exception e){}

form.append(userName);

form.append(password);

form.addCommand(cancel);

form.addCommand(login);

form.setCommandListener(this);

display.setCurrent(form);

public void pauseApp() {}

public void destroyApp(boolean unconditional) {

notifyDestroyed();

public void validateUser(String name, String password) {

if (name.equals("sandeep") && password.equals("sandeep")) {

showMsg();

} else {

tryAgain();

public void showMsg() {

Alert success = new Alert("Login Successfully", "Your Login Process is completed!", img2,
AlertType.INFO);

success.setImage(img2);

userName.setString("");

password.setString("");

display.setCurrent(success, form);

}
public void tryAgain() {

Alert error = new Alert("Login Incorrect", "Please try again", imge, AlertType.ERROR);

error.setTimeout(900);

error.setImage(imge);

userName.setString("");

password.setString("");

display.setCurrent(error, form);

public void commandAction(Command c, Displayable d) {

String label = c.getLabel();

if(label.equals("Cancel")) {destroyApp(true);

} else if(label.equals("Login")) {validateUser(userName.getString(), password.getString());

OUTPUT

You might also like