introduction to java me mobile development

22
JAVA Mobile Apps Introduction to JAVA ME Mobile Application Development Prof. Erwin M. Globio, MSIT Resource Speaker http://eglobiotraining.com/ h t t p : / / e g l o b i o t r a i n i n g . c o m /

Upload: prof-erwin-globio

Post on 24-Dec-2014

2.563 views

Category:

Education


4 download

DESCRIPTION

Introduction to Java ME Mobile Development discussed by Prof. Erwin Globio from http://eglobiotraining.com/

TRANSCRIPT

Page 1: Introduction to Java ME Mobile Development

JAVA Mobile Apps

Introduction to JAVA ME Mobile Application Development

Prof. Erwin M. Globio, MSITResource Speaker

http://eglobiotraining.com/

http

://eglo

bio

train

ing.co

m/

Page 2: Introduction to Java ME Mobile Development

Mobile Devices

Mobile devices may vary in size, design and layout, but they have some characteristics in common that are totally different from desktop systems.

Small in sizeMobile devices are small in size. Consumers want smaller devices for mobility and convenience.

Limited memoryMobile devices also have small memory, both primary (RAM) and secondary (disk). This limitation is one of the factors that affects writing programs for these types of devices. With limited amount of memory, special considerations must be taken to conserve the use of this precious resource.

JAVA Mobile Apps

http

://eglo

bio

train

ing.co

m/

Page 3: Introduction to Java ME Mobile Development

JAVA Mobile Apps

Continuation(Mobile Devices)Limited processing power Mobile systems are not as powerful as their desktop counterparts. Size, technology and budget are some of the factors that affect the state of this resource. Like the disk storage and RAM, you can only fit so much of these resources in such a small package. Low power consumptionMobile devices consume less power than desktop machines. These devices must conserve the use of power because they run on a limited supply from batteries. Robust and reliableBecause mobile devices are always carried along, they must be robust enough to stand the force of bumps, motion and occasional drops.

http

://eglo

bio

train

ing.co

m/

Page 4: Introduction to Java ME Mobile Development

JAVA Mobile Apps

Continuation(Mobile Devices)

Limited connectivityMobile devices have low bandwidth, some of them not connected at all. Most of them use wireless connections.

Short wakeup timeThese consumer devices startup in seconds and most of them are always on. Take the case of mobile phones: they boot up within seconds and most people do not turn them off even at night. PDAs wakeup the second you press their power button.

http

://eglo

bio

train

ing.co

m/

Page 5: Introduction to Java ME Mobile Development

JAVA Mobile Apps

Java was created in 1991 by James Gosling of Sun Microsystems. Initially called Oak, in honor of the tree outside Gosling's window, its name was changed to Java because there was already a language called Oak. The original motivation for Java was the need for platform independent language that could be embedded in various consumer electronic products like toasters and refrigerators. One of the first projects developed using Java was a personal hand-held remote control named Star 7. At about the same time, the World Wide Web and the Internet were gaining popularity. Gosling realized that Java could be used for Internet programming.

Java Platformhttp

://eglo

bio

train

ing.co

m/

Page 6: Introduction to Java ME Mobile Development

JAVA Mobile Apps

With the release of version 1.2, the Java platform was classified into several editions: Now we have 1.7 version JAVA SE – Java 2 Platform, Standard Editiondesktop applications

JAVA EE – Java 2 Platform, Enterprise Editionenterprise applications w/ focus on web server-side development including servlets, JSP, EJB and XML

JAVA ME – Java 2 Platform, Micro Editionmobile and handheld devices

JavaCardSmart Cards

Continuation(Java Platform)http

://eglo

bio

train

ing.co

m/

Page 7: Introduction to Java ME Mobile Development

JAVA Mobile Apps

Continuation(Java Platform)

ServersServers

J ava 2 Micro Edition (J 2ME)

Desktopmachines

High-endconsumerdevices Low-end

consumer devices

SmartCards

J2EEJ2SE

CDC

Foundation Profile

Personal Profile

CLDC

MIDP

OptionalPackages

OptionalPackages

J avaCard

J ava Virtual Machine KVM Card VM

http

://eglo

bio

train

ing.co

m/

Page 8: Introduction to Java ME Mobile Development

JAVA Mobile Apps

The Java Platform, Mobile Edition (JAVA ME) is a set of specifications and technologies that focus on consumer devices. These devices have limited amount of memory, less processing power, small screens and low network bandwidth.

With the proliferation of mobile consumer devices from phones, PDAs, gaming boxes to home appliances, Java provides a single portable environment for developing and running applications on these devices.

JAVA ME programs, like all Java programs, are interpreted. Programs are compiled into byte codes and interpreted by the Java Virtual Machine (VM). JAVA ME provides a consistent interface with the devices. Applications do not have to be recompiled to be able to run on different machines.

JAVA ME Overviewhttp

://eglo

bio

train

ing.co

m/

Page 9: Introduction to Java ME Mobile Development

JAVA Mobile Apps

The Connected Limited Device Configuration (CLDC) defines and addresses the following areas:

Java language and Virtual Machine (VM) features

Core libraries (java.lang.*, java.util.*)

Input/Output (java.io.*)

Security

Networking

Internationalization

CLDChttp

://eglo

bio

train

ing.co

m/

Page 10: Introduction to Java ME Mobile Development

JAVA Mobile Apps

The Mobile Information Device Profile (MIDP) builds on top of the CLDC. The MIDP specification, much like the CLDC and other APIs, has been defined through the Java Community Process (JCP). It involved an expert group, from more that 50 companies, composed of mobile device manufacturers, carriers and software developers.MIDP defines the application model, user interface API, persistent storage and networking, gaming and media API, security policies, application deployment and over-the-air provisioning.

MIDP

MI Dlets

MI DP 2.0OptionalPackages

OEMAPI s

CLDC 1.0 or 1.1

WMA1.1

MMAPI1.1

Device Operating System

http

://eglo

bio

train

ing.co

m/

Page 11: Introduction to Java ME Mobile Development

JAVA Mobile Apps

An MIDP application is called a MIDlet. The device's application management software (AMS) interacts directly with the MIDlet with the MIDlet's create, start, pause, and destroy methods.

The MIDlet is part of the javax.microedition.midlet package. A MIDlet must extend the MIDlet class. It can request parameters from the AMS as defined in the application descriptor (JAD).

A MIDlet does not have (and MUST NOT have) a public static void main(String[] argv) method. It will not be recognized by the AMS as the program's starting point.

MIDlethttp

://eglo

bio

train

ing.co

m/

Page 12: Introduction to Java ME Mobile Development

JAVA Mobile Apps

A MIDlet's life begins when it is instantiated by the AMS. It initially enters the "Paused" state after being created with the new command. The AMS calls the public no argument constructor of the MIDlet. If an exception occurs at the constructor, the MIDlet is put into a Destroyed state and discarded immediately.The MIDlet enters the Active state upon calling the startUp() method by the AMS.

The MIDlet enters the Destroyed state when the AMS calls the destroyApp() method. This state is also entered when the notifyDestroyed() method returns succesfully to the application. Take note that the MIDlet enters the Destroyed state only once in its lifetime.

MIDlet Life Cyclehttp

://eglo

bio

train

ing.co

m/

Page 13: Introduction to Java ME Mobile Development

JAVA Mobile Apps

MIDlet Life Cycle

Active

Paused

Destroyed

destroyApp()

destroyApp()

startApp()

pauseApp()

new

To be able to create a MIDlet, we must create a subclass of the MIDlet class from javax.microedition.midlet package. We must also override or implement the methods: startApp(), destroyApp() and pauseApp(). These are the methods expected by the AMS for running and controlling our MIDlet.

http

://eglo

bio

train

ing.co

m/

Page 14: Introduction to Java ME Mobile Development

JAVA Mobile Apps

Using the Sun Wireless ToolkitWe'll now use the Sun Wireless Toolkit to compile and package our MIDlet suite (containing a single MIDlet).Open ktoolbar (from the Wireless Toolkit distribution)

Create a new projectProject Name: HelloMidletMIDlet Class Name: HelloMidlet

On this Settings window, you can customize the a very comprehensive selection of settings for your project. You can select what configuration to use, what packages/APIs to include, Push Registry settings and more. For our purposes, we will use the default project settings. Click "OK" to finish creating the project.

Copy HelloMidlet.java into the project's "src directory: In Window, this is under the directory: C:\WTK23\apps\HelloMidlet\src (where C:\WTK23 is where you installed the wireless toolkit). Click "Build" and "Run":

http

://eglo

bio

train

ing.co

m/

Page 15: Introduction to Java ME Mobile Development

JAVA Mobile Apps

Sample Code HelloMidletimport javax.microedition.midlet.*;import javax.microedition.lcdui.*;public class HelloMidlet extends MIDlet implements CommandListener {Display display;Command exitCommand = new Command("Exit", Command.EXIT, 1);Alert helloAlert;

public HelloMidlet(){helloAlert = new Alert("Hello MIDlet", "Hello,

world!",null, AlertType.INFO);helloAlert.setTimeout(Alert.FOREVER);helloAlert.addCommand(exitCommand);helloAlert.setCommandListener(this);

}public void startApp() {

if (display == null){display = Display.getDisplay(this);

}display.setCurrent(helloAlert);

}

http

://eglo

bio

train

ing.co

m/

Page 16: Introduction to Java ME Mobile Development

JAVA Mobile Apps

Sample Code HelloMidletpublic void pauseApp() { }

public void destroyApp(boolean unconditional) { }

public void commandAction(Command c, Displayable d){if (c == exitCommand){

destroyApp(true);notifyDestroyed(); // Exit

}}

}

http

://eglo

bio

train

ing.co

m/

Page 17: Introduction to Java ME Mobile Development

JAVA Mobile Apps

Sample Code ExplanationPackage javax.microedition.midlet The MIDlet package defines Mobile Information Device Profile applications and the interactions between the application and the environment in which the application runs.

Package javax.microedition.lcdui The UI API provides a set of features for implementation of user interfaces for MIDP applications.

public interface CommandListener This interface is used by applications which need to receive high-level events from the implementation. An application will provide an implementation of a CommandListener (typically by using a nested class or an inner class) and will then provide the instance to the addCommand method on a Displayable in order to receive high-level events on that screen.

http

://eglo

bio

train

ing.co

m/

Page 18: Introduction to Java ME Mobile Development

JAVA Mobile Apps

Sample Code ExplanationClass SummaryAlertAn alert is a screen that shows data to the user and waits for a certain period of time before proceeding to the next Displayable.AlertTypeThe AlertType provides an indication of the nature of alerts.ChoiceGroupA ChoiceGroup is a group of selectable elements intended to be placed within a Form.CommandThe Command class is a construct that encapsulates the semantic information of an action.DateFieldA DateField is an editable component for presenting date and time (calendar) information that may be placed into a Form.DisplayDisplay represents the manager of the display and input devices of the system.

http

://eglo

bio

train

ing.co

m/

Page 19: Introduction to Java ME Mobile Development

JAVA Mobile Apps

Sample Code ExplanationClass SummaryDisplayableAn object that has the capability of being placed on the display.Implements a graphical display, such as a bar graph, of an integer value.ListA Screen containing list of choices.StringItemAn item that can contain a string.TextBoxThe TextBox class is a Screen that allows the user to enter and edit text.TextFieldA TextField is an editable text component that may be placed into a Form.TickerImplements a "ticker-tape", a piece of text that runs continuously across the display.

http

://eglo

bio

train

ing.co

m/

Page 20: Introduction to Java ME Mobile Development

SAMPLE PROGRAMS

http

://eglo

bio

train

ing.co

m/

Page 21: Introduction to Java ME Mobile Development

PROFESSOR’S INFORMATION

http

://eglo

bio

train

ing.co

m/

Prof. Erwin M. Globio, MSITSenior IT Lecturer of Far Eastern UniversityOwner and Senior Technical Trainer at http://eglobiotraining.com/Email Address: [email protected] Id: erwinglobio

Page 22: Introduction to Java ME Mobile Development

http

://eglo

bio

train

ing.co

m/