tcs0363 mobile programming using j2me chapter 1

25
TCS0363 Mobile Programming Using J2ME Introduction to J2ME Management and Science University Chapter 1 Week 2 1 Mobile Phone History In1843 Micheal Faraday a talented chemist begins researching the possibility that space can conduct electricity. His research starts the wheels turning for many other 19th century scientists. At the time, many of them were referred to as “crackpots”. In 1865 AVirginia Dentist/Scientist, Dr. Mahlon Loomis, develops a method of communicating through the earth’s atmosphere by using an electrical conductor. He does this by flying two kites, that are rigged with copper screens and wires, which are connected to the ground on two separate mountains about 18 miles apart. He later received a grant from the U.S. Congress for $50,000. (A fairly large chunk of change for 1865)

Upload: others

Post on 18-Dec-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

1

Mobile Phone History• In1843

– Micheal Faraday a talented chemist begins researching the possibility that space can conduct electricity. His research starts the wheels turning for many other 19th century scientists. At the time, many of them were referred to as “crackpots”.

• In 1865

– AVirginia Dentist/Scientist, Dr. Mahlon Loomis, develops a method of communicating through the earth’s atmosphere by using an electrical conductor. He does this by flying two kites, that are rigged with copper screens and wires, which are connected to the ground on two separate mountains about 18 miles apart. He later received a grant from the U.S. Congress for $50,000. (A fairly large chunk of change for 1865)

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

2

Mobile Phone History

• In 1866

– The first trans-Atlantic telegraph is built (not much to do with cell phones, but a major advancement in communication nonetheless)

• In 1921

– The Police Department in Detroit, Mich. begins installing mobile radios, operating around 2 MHz, in their squad cars. They encounter many problems such as overcrowding on the channels and terrible interference.

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

3

Mobile Phone History

• In 1934

– The U.S. Congress creates the Federal Communications Commission. They decide who gets to use certain radio frequencies. Most channels are reserved for emergency use and for the government. Radio is still a baby.

• In 1940’s

– the mobile radios are able to operate at 30 to 40 MHz and become much more common between police departments, and the wealthy. Several private companies and organizations begin using these same radios for personal gain.

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

4

Mobile Phone History

• In1945

– The first mobile-radio-telephone service is established in St. Louis, Miss. The system is comprised of six channels that add up to 150 MHz. The project is approved by the FCC, but due to massive interference, the equipment barely works.

• In 1947

– AT&T comes out with the first radio-car-phones that can be used only on the highway between New York and Boston; they are known as push-to-talk phones. The system operates at frequencies of about 35 to 44 MHz, but once again there is a massive amount of interference in the system. AT&T declares the project a failure.

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

5

Mobile Phone History

• In 1949

– The FCC authorizes the widespread use of many separate radio channels to other carriers. They are know as Radio Common Carriers (RCC) and are the first link between mobile phones and the telephone, rather than just radio to radio. The RCC's are the first step toward the cellular phone industry, which is were designed more for profit than for the general public.

• In 1956

– The first real car phones, not car radios, come into play accross the United States. Although, the system is still using push-to-talk phones, it is an improved version that acctually works. However, the units are big and bulky, and require a personal radio operator to switch the calls. A simular system appeared in Sweden a few years earlier.

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

6

Mobile Phone History

• In 1964

– A new operating system is developed that operates on a single channel at 150 MHz. In essence, this removes the need for push-to-talk operators. Now customers can dial phone numbers directly from their cars. RCC's are finally taken seriously by the FCC as ligitimate competitors to the land-line phone companies.

• In 1969

– The self-dialing capability is now upgraded to 450 MHz and becomes standard in the United States. This new service is known as (IMTS) Improved mobile telephone service.

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

7

Mobile Phone History

• In 1970

– Cell phone lobbyists finally win with the FCC and get a window of 75 MHz in the 800 MHz region, which allocated specifically for cell phones. The FCC realizes the potential of the industry and can’t ignore it any longer.

• In 1971

– AT&T is the first company to propose a modern-day mobile-phone system to the FCC. It involves dividing cities into “cells”. It is the first company to do so.

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

8

Mobile Phone History

• In 1973

– Dr. Martin Cooper invents the first personal handset while working for Motorola. He takes his new invention, the Motorola Dyna-Tac., to New York City and shows it to the public. His is credited with being the first person to make a call on a portable mobile-phone.

• In 1974

– The FCC actually starts to encourage cell phone companies to push forward the “cellular idea”. But unfortunately a law suit arises with Western Electric, who is the closest company to succeeding at the time, and it rules that they are not allowed to manufacture terminal and network phone systems under the same roof. This is an effort to prevent a monopoly. But it also prevents progress.

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

9

Mobile Phone History

• In 1975

– AT&T adapts its own cellular plan for the city of Chicago, but the FCC is still uneasy about putting the plan into action. They have concerns about its success.

• In 1977

– Finally cell phone testing is permitted by the FCC in Chicago. The Bell Telephone Company gets the license; they are in a partnership with AT&T which is a gerneral effort to battle the stubborn FCC.

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

10

Mobile Phone History

• In 1981

– The FCC makes firm rules about the growing cell phone industry in dealing with manufactures. It finally rules that Western Electric can manufacture products for both cellular and terminal use. (Basically they admit that they put the phone companies about 7 years behind)

• In 1988

– One of the most important years in cell phone evolution. The Cellular Technology Industry Association is created and helps to make the industry into an empire. One of its biggest contributions is when it helped create TDMA phone technology, the most evolved cell phone yet. It becomes available to the public in 1991.

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

11

Mobile Phone History

• In 2001

– BellSouth announces that it is leaving the pay

phone business because there is too much

competition from cell phones.

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

J2ME : Java 2 Micro Edition• Profiles

– J2ME complements configurations with profiles, software to match the

hardware.

– Each configuration supports several profiles.

– The most common profile in mobile phones is MIDP, the Mobile

Information Device Protocol, which adds networking, user interface, and

persistent storage support to the CLDC configuration.

• J2SE re-use– J2ME is designed to re-use J2SE code wherever possible, or at least to

pretend to.

– Within the scope of features supported by a given configuration and set of

profiles, wherever possible the J2ME implementation must not change

interfaces or behavior from the J2SE original.

12

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

J2ME : Java 2 Micro Edition• CLDC hardware requirements

– 128 Kb permanent storage for the J2ME engine and classes

– 32 Kb of RAM for applications to run in

• MIDP hardware requirements– A screen at least 96 pixels wide and 54 pixels tall

• Things the CLDC does not require:– Keyboard

– Mouse

– Floating-point support

– Persistent app data storage

(This is supported by the MIDP profile.)

– Multithreading or multiprocessing

(This is not required of the hardware; it’s left to the JVM.)

13

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

J2ME : Java 2 Micro Edition• J2SE features missing from the CLDC:

– Reflection (java.lang.reflect)

– Weak references (java.lang.ref)

– Object finalization (java.lang.Object has no finalize() method)

• J2SE features reduced in the CLDC:– Advanced thread handling

– Advanced error handling

– JNI (the Java Native Interface)

• J2SE behavior changed in the CLDC:– A number of security restrictions

– The class verification step

(J2SE verifies bytecode on load. J2ME shifts the bytecode verification

step to the vendor’s compiler.)

14

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

MIDP Software Development

• MIDP applications are called MIDlets. – (Because everything in Java is a somethinglet.)

– MIDlets are groups of classes, one of which is derrived from the abstract

class javax.microedition.midlet.MIDlet.

• MIDlets can be packaged in MIDlet suites

to group one or more MIDlets into the same

space.– MIDlets sharing a suite can access each other’s persistent data and are run

concurrently, giving an application-level interface to multithreading.

– MIDlets sharing a suite are installed and uninstalled together.

– Classes defined in a MIDlet suite are shared between all concurrent

midlets; only one instance of each class in the suite is loaded per suite.

15

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

MIDP Software Development• MIDlet packaging and installation

– Deploying a MIDlet requires several more steps than deploying a

conventional application.

• JAR files and JAD files– The MIDlet [suite] being deployed is packaged, along with all of its

supporting classes and data files, into a JAR file.

– The JAR also needs to include a manifest which will detail the contents of

the JAR.

– The JAR must be paired with a JAD (Java Application Descriptor) file for

installation.

– The .jad is almost identical to the JAR’s manifest.mf; where the manifest

is to allow installed software to be described to the user after loading, the

.jad is used to describe the application to the user before it’s downloaded

as part of the installation process.16

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

MIDP Software Development

• Sample .jad or manifest.mf :

MIDlet-1: Tetris,, TetrisMIDlet

MIDlet-Description: Tetris MIDlet demo

MIDlet-Name: Tetris

MIDlet-Vendor: Me

MIDlet-Version: 1.0.0

MicroEdition-Configuration: CLDC-1.0

MicroEdition-Profile: MIDP-1.0

17

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

MIDP Software Development

• Software you’ll need to install in order to

develop MIDP applications:– The Java 2 SDK

• I use J2SDK version 1.4.1.01

– The J2ME CLDC

– Sun’s Wireless Toolkit 1.04

– At least one cell phone emulator

• I use the Nokia 7210 MIDP SDK 1.0 emulator

– Software to deploy to your phone

• I use the Nokia Developer Suite

18

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

MIDP Software Development

• Compiling and deploying a MIDlet1) Java compiler

– javac.exe

-target 1.1

-bootclasspath "[Wireless toolkit path]\lib\midpapi.zip"

-d preverify

*.java

2) Preverify

– preverify.exe

-classpath "[Wireless toolkit path]\lib\midpapi.zip"

-cldc

-d postverify .\preverify

3) JAR builder

– jar.exe cvfm Project.jar Project.jad -C postverify .

4) Deploy and test

19

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

MIDP Software Deployment• Deploying MIDlets over the WWW

– After you’ve tested your MIDlet on your local emulator and on a locally-

connected cell phone (perhaps connected over an IR port) you’ll want to

ship it to the world at large.

– You’ll need to configure your web server to support the JAD MIME type.

The JAD MIME type is

text/vnd.sun.j2me.app-descriptor

– The user can now click on an HTML link such as

Click <a href=“sample.jad”>here</a> to...

– This will download the JAD file. An attribute in the JAD file is the

MIDlet-Jar-URL; if the phone user chooses to continue, the phone

requests this URL from the server.

– The JAR file is then transmitted with MIME type

application/java-archive

20

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

Anatomy of a MIDlet

A MIDlet consists of [at least] one class extending

javax.microedition.midlet.MIDlet, plus supporting

classes.

You must implement three abstract methods:

– startApp()

– pauseApp()

– destroyApp(boolean unconditional)

In startApp() you’ll create a user interface object--

a Canvas or Screen.

21

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

Anatomy of a MIDlet• J2ME provides two user interface

approaches:– High-level UI: Screen

The Screen class and those derived from it provide support for an

assisted layout of high-level objects like buttons and text fields. This

means that while it’s easier to control what goes where and how

events are passed and so on, it’s harder to control precisely the

contents of the screen.

Derived classes: Alert, Form, List and TextBox.

– Low-level UI: Canvas

The Canvas class gives the developer complete control over the contents

of the screen. While this has the upshot of giving you advanced

graphical abilities and precise screen control, it has the downside that

you have to do everything yourself. Tetris was written on a Canvas.

22

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

Anatomy of a MIDlet• “Hello World”, the MIDlet:

import javax.microedition.midlet.*;

import javax.microedition.lcdui.*;

public class HelloWorldMIDlet extends MIDlet

{

public HelloWorldMIDlet() { }

public void pauseApp() { }

public void destroyApp(boolean unconditional) { }

public void startApp()

{

if (Display.getDisplay(this).getCurrent() == null)

{

HelloScreen helloScreen = new HelloScreen(this, "Hello World.");

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

}

}

void exitRequested()

{

destroyApp(false);

notifyDestroyed();

}

}

23

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

Anatomy of a MIDlet• “Hello World” screen class:

import javax.microedition.lcdui.*;

class HelloScreen

extends TextBox

implements CommandListener

{

private final HelloWorldMIDlet m_midlet;

private final Command m_exitCommand;

HelloScreen(HelloWorldMIDlet midlet, String string)

{

super("HelloWorldMIDlet", string, 256, 0);

m_midlet = midlet;

m_exitCommand = new Command("Exit", Command.EXIT, 1);

addCommand(m_exitCommand);

setCommandListener(this);

}

public void commandAction(Command c, Displayable d)

{

if (c == m_exitCommand)

m_midlet.exitRequested();

}

}

24

TCS0363 Mobile Programming Using J2ME

Introduction to J2ME

Management and Science University

Chapter 1

Week 2

Recommended Reading

• J2ME In A Nutshell, by Kim Topley,

O’Reilly & Associates Inc., 2002– Dense yet informative; details the guts of J2ME from below CLDC on up

to forms and timers. Also has a handy reference to the new J2ME Java

classes.

• http://java.sun.com– The resource of all things Java.

– This is where you can download the J2SDK and Wireless Toolkit.

• http://forum.nokia.com– Good site to download phone emulators and SDKs.

– Non-intrusive signup process required

25