Wireless Java Technology

Similar documents
Java 2 Micro Edition

Mobile Services 2 - Java 2 Micro Edition. F. Ricci

Internet and Mobile Services 2 - Java 2 Micro Edition. F. Ricci 2009/2010

Mobile Services 2 - Java 2 Micro Edition. F. Ricci 2008/2009

Who am I? Wireless Online Game Development for Mobile Device. What games can you make after this course? Are you take the right course?

DAY 3 J2ME Aalborg University, Mobile Device Group. Mobile. Mobile Phone Programming

Mobile Application Development. Introduction. Dr. Christelle Scharff Pace University, USA

DAY 3 J2ME March 2007 Aalborg University, Mobile Device Group Mobile Phone Programming

Mobile Information Device Profile (MIDP) Alessandro Cogliati. Helsinki University of Technology Telecommunications Software and Multimedia Laboratory

J2ME With Database Connection Program

Chapter 13 Add Multimedia to Your MIDlets

Accessing DB2 Everyplace using J2ME devices, part 1

Developing Mobile Applications

J2ME crash course. Harald Holone

Nutiteq Maps SDK tutorial for Java ME (J2ME)

Minne menet, Mobiili-Java?

Lab Exercise 4. Please follow the instruction in Workshop Note 4 to complete this exercise.

Java 2 Micro Edition Server socket and SMS

Java Card 3 Platform. Peter Allenbach Sun Microsystems, Inc.

Portability and Design Issues in Developing a Mobile Phone Quiz Application Quiz Pro 2006

Mobile Station Execution Environment (MExE( MExE) Developing web applications for PDAs and Cellphones. WAP (Wireless Application Protocol)

phoneme: High-performance, product-quality GPLv2 CDC + CLDC stacks Terrence Barr

Mobile Devices in Software Engineering. Lab 2

Project Overview. CSE 403, Spring 2003 Software Engineering.

Project Overview. Readings and References. Opportunity. Initial project motivation. References. CSE 403, Spring 2003 Software Engineering

sessionx Desarrollo de Aplicaciones en Red A few more words about CGI CGI Servlet & JSP José Rafael Rojano Cáceres

JAVA. Java Micro Edition

CM0256 Pervasive Computing

Advanced Internet Technology Lab # 4 Servlets

SUN. Sun Certified Mobile Application Developer for the Java 2 Platform, Micro Edition, Version 1.0

Project Overview. Readings and References. Initial project motivation. Opportunity. References. CSE 403, Winter 2003 Software Engineering

Implementation and Analysis of Electronic Medical Records in Mobile Devices

Introduction to JAVA Programming Language

JAVA SERVLET. Server-side Programming INTRODUCTION

Servlet and JSP Review

Java Servlets. Preparing your System

Université Antonine - Baabda

J2ME ARCHITECTURE AND RELATED EMBEDDED TECHNOLOGIES

This tutorial will teach you how to use Java Servlets to develop your web based applications in simple and easy steps.

Servlet Fudamentals. Celsina Bignoli

Supplement IV.E: Tutorial for Tomcat For Introduction to Java Programming By Y. Daniel Liang

Acknowledgments Introduction p. 1 The Wireless Internet Revolution p. 1 Why Java Technology for Wireless Devices? p. 2 A Bit of History p.

Java 2 Micro Edition Server socket and SMS. F. Ricci

Lab session Google Application Engine - GAE. Navid Nikaein

Web based Applications, Tomcat and Servlets - Lab 3 -

Introduction to Servlets. After which you will doget it

Overview of Java 2 Platform, Micro Edition (J2ME )

Setting Up the Development Environment

Database Applications Recitation 6. Project 3: CMUQFlix CMUQ s Movies Recommendation System

JUGAT meeting. Roman Waitz Development. MATERNA Information & Communications

Developing mobile UI

Chapter 17. Web-Application Development

Outline. Introduction to Java. What Is Java? History. Java 2 Platform. Java 2 Platform Standard Edition. Introduction Java 2 Platform

Bluetooth Scatternet Application. Sun Code for Freedom

CS434/534: Topics in Networked (Networking) Systems

Servlet Basics. Agenda

CHAMELEON Project. Developer Guide. - Mobile Client - Server - UDDIe Registry. CHAMELEON Client and Server side

Certified Core Java Developer VS-1036

Alma Mater Studiorum University of Bologna CdS Laurea Magistrale (MSc) in Computer Science Engineering

Mobile Devices in Software Engineering. Lab 3

Servlets1. What are Servlets? Where are they? Their job. Servlet container. Only Http?

Alma Mater Studiorum University of Bologna CdS Laurea Magistrale (MSc) in Computer Science Engineering

The network connection

Mensch-Maschine-Interaktion 2

Building a Java ME Test Suite in 15 Minutes

Software Development & Education Center. Java Platform, Micro Edition. (Mobile Java)

3.3.4 Connection Framework

The Basic Web Server CGI. CGI: Illustration. Web based Applications, Tomcat and Servlets - Lab 3 - CMPUT 391 Database Management Systems 4

II. Compiling and launching from Command-Line, IDE A simple JAVA program

JSR 248: Taking Java Platform, Micro Edition (Java ME) to the Next Level

Database Systems Lab. 11. JSP I 충남대학교컴퓨터공학과 데이타베이스시스템연구실

BVRIT HYDERABAD College of Engineering for Women Department of Information Technology. Hand Out

CS506 Web Design & Development Final Term Solved MCQs with Reference

INTRODUCTION TO SERVLETS AND WEB CONTAINERS. Actions in Accord with All the Laws of Nature

Stateless -Session Bean

Servlets. An extension of a web server runs inside a servlet container

How to Build, Run, and Develop Code With the phoneme Open Source Project Stuart Marks Hinkmond Wong Sun Microsystems, Inc.

UNIT-V. Web Servers: Tomcat Server Installation:

CS5015 Object-oriented Software Development. Lecture: Overview of Java Platform. A. O Riordan, 2010 Most recent revision, 2014 updated for Java 8

Introduction. This course Software Architecture with Java will discuss the following topics:

Servlets and JSP (Java Server Pages)

Programming Wireless Devices with the Java 2 Platform, Micro Edition

ServletConfig Interface

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

Introduction. Literature: Steelman & Murach, Murach s Java Servlets and JSP. Mike Murach & Associates Inc, 2003

Tutorial: Developing a Simple Hello World Portlet

CHAPTER 6. Java Project Configuration

&' () - #-& -#-!& 2 - % (3" 3 !!! + #%!%,)& ! "# * +,

TAMZ. JavaME. MIDlets. Department of Computer Science VŠB-Technical University of Ostrava

Learning objectives. The Java Environment. Java timeline (cont d) Java timeline. Understand the basic features of Java

servlets and Java JSP murach s (Chapter 2) TRAINING & REFERENCE Mike Murach & Associates Andrea Steelman Joel Murach

AJP. CHAPTER 5: SERVLET -20 marks

NOKIA 12 GSM MODULE JAVA TM IMLET PROGRAMMING GUIDE. Copyright Nokia. All rights reserved. Issue

CS433 Technology Overview

AN ISO 9001:2008 CERTIFIED COMPANY ADVANCED. Java TRAINING.

7. Concurrency. Motivation Infrastructure Faking concurrency Mobile Java implementation Symbian OS implementation. Maemo implementation Summary

Accessing EJB in Web applications

2. Follow the installation directions and install the server on ccc. 3. We will call the root of your installation as $TOMCAT_DIR

JXTA for J2ME Extending the Reach of Wireless With JXTA Technology

Agenda. Summary of Previous Session. Extreme Java G Session 3 - Main Theme Java Core Technologies (Part I)

Transcription:

Wireless Java Technology Pao-Ann Hsiung National Chung Cheng University Ref: http://developers.sun.com/techtopics/mobility/learning/tutorial/ 1

Contents Overview of Java 2 Platform Overview of J2ME Scope of Wireless Java Technology Wireless Development Tutorial Part I Wireless Development Tutorial Part II 2

Overview of Java 2 Platform Java Programming Language Type safe object references (instead of pointers) Automatic garbage collection Interfaces (instead of multiple inheritance) Virtual Machine Runs on various OS and HW Safe execution of untrusted code APIs From UI to cryptography, from CORBA to internalization 3

Overview of Java 2 Platform Java 2, Standard Edition (J2SE) Desktop computers, OS X, Linux, Solaris, Windows Java 2, Enterprise Edition (J2EE) Multiuser, enterprise-wide applications J2SE + Server-side computing Java 2, Micro Edition (J2ME) Small devices: mobile phones, set-top boxes Smaller VM, leaner APIs than J2SE 4

Overview of J2ME J2ME is a platform of: Configurations Profiles Optional packages 5

Configurations Virtual Machine Specifications Full JVM or a subset Base set of API for a certain class of device Subset of J2SE APIs Example for devices with <512 KB memory, intermittent network connection Implementations CLDC, CDC 6

Profiles Profile consists of Configuration Application-specific APIs User Interface Persistent Storage Examples Mobile Information Device Profile (MIDP) Foundation Profile (FP) Personal Basis Profile (PBP) Personal Profile (PP) 7

Optional Packages Functionality not associated with a specific configuration or profile Example Bluetooth API (BTAPI, JSR 82) Web Services, Mobile Media API (MMAPI), Wireless Messaging API (WMA), Security and Trust Services API (SATSA), Location API, Content Handling API (CHAPI), Event Tracking, Mobile 3D Graphics API, Scalable 2D Vector Graphics API, Payment API, Data Sync API, 8

The J2ME Universe Today Optional Packages Profiles Configurations 9

The J2ME Universe Today Two Main Branches Connected, Limited Device Configuration (CLDC) Small wireless devices with intermittent network Examples: Pagers, mobile phones, PDAs Connected Device Configuration (CDC) Larger devices (in terms of memory and processing power) Examples: set-top boxes, internet appliances, high-end PDAs (Sharp Zaurus) 10

Software Stacks A configuration A profile Some optional APIs Example 1: 1st Generation J2ME mobile phones J2ME Stack 11

Software Stacks Example 2: JSR 185 mandates CLDC 1.0 or 1.1 MIDP 2.0 WMA OPTIONAL JSR 185 Stack 12

Scope of Wireless Java Technology Intersection of two vast worlds Wireless data communication The Java Platform Misconceptions Wireless Java Technology and J2ME are not same CDC devices may have wired connections Laptop running J2SE applications, connected by 802.11 MIDP is not all of J2ME First finished profile MIDP is not all of wireless technology PP, J2SE on wireless devices, PDA profiles 13

Why Java for Wireless Development? Java platform is safe. In JVM Java encourages robust programming. Garbage collection, exception mechanism Portability When you write a MIDlet (a MIDP application), it will run on any device that implements the MIDP specification Over-the-air provisioning of applications 14

Wireless Development Tutorial Part I To create a Java Wireless Application called a MIDlet, that runs on implementations of the Mobile Information Device Profile (MIDP) MIDlets will connect to some type of network service Part II will describe how to setup a servlet development environment, how to write, compile, and test a servlet 15

Software Required OS Windows, Linux, OS X, Solaris Java 2 Standard Edition SDK 1.4.2 or higher Currently 1.5.0 update 6 http://java.sun.com/j2se/ Java Wireless Toolkit 2.2 or higher Currently 2.3 Beta http://java.sun.com/products/j2mewtoolkit/ Text Editor Notepad on Windows, jedit, etc. 16

Development Environment Install J2SE SDK Provides Java platform for Java Wireless Toolkit to run Provides Java compiler and other tools to build your projects To test installation, open cmd and type: java version Microsoft Windows XP [ 版本 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\>java -version java version "1.5.0_06" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05) Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing) 17

Development Environment Install Java Wireless Toolkit To build and test MIDP applications Will be installed in C:\WTK22 Run KToolbar Works with projects Result: MIDlet suite 18

Development Environment Create a new project Select OK for the default options Some helpful messages Creating project "HelloSuite" Place Java source files in "C:\WTK22\apps\HelloSuite\src" Place Application resource files in "C:\WTK22\apps\HelloSuite\res" Place Application library files in "C:\WTK22\apps\HelloSuite\lib 19

Development Environment Project is stored in C:\WTK22\apps\HelloSuite. Project Directory Structure: After building a project: 20

Creating a MIDlet Save the following code in the src directory with filename HelloMIDlet.java import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class HelloMIDlet extends MIDlet implements CommandListener { private Form mmainform; public HelloMIDlet() { mmainform = new Form("HelloMIDlet"); mmainform.append(new StringItem(null, "Hello, MIDP!")); mmainform.addcommand(new Command("Exit", Command.EXIT, 0)); mmainform.setcommandlistener(this); } public void startapp() { Display.getDisplay(this).setCurrent(mMainForm); } public void pauseapp() {} public void destroyapp(boolean unconditional) {} public void commandaction(command c, Displayable s) { notifydestroyed(); } } You can also download from http://developers.sun.com/techtopics/mobility/midp/articles/wtoolkit/src/hellomidlet.java 21

Creating a MIDlet Click Build button on the KToolbar Debug if there are any errors Click Run button on the KToolbar The MIDlet is always run on a device emulator such as a Mobile Phone Emulator (see next slide) 22

Mobile Phone Emulator Click on the soft button under Launch 23

Mobile Phone Emulator The HelloSuite MIDlet runs in the emulator 24

Mobile Phone Emulator This is the DefaultColorPhone You can try other phone emulators in the combo box in the KToolbar DefaultGrayPhone MediaControlSkin QwertyDevice 25

Looking under the hood What does Build do? Compilation of.java files in src directory Uses the MIDP API instead of the J2SE API Preverification Toolkit performs verification during build time Device performs verification during load time Bundling JARing the MIDlet suite class files and the resource files Project Package.jad and.jar files for MIDlet suite will be created in bin 26

Wireless Development Tutorial Part II To write and deploy a servlet Then, hook the MIDlet (from Part I) with the servlet Two versions of development platforms Tomcat (currently 5.5.16 Beta) Reference implementation for Java servlet and JSP J2EE RI Full implementation of J2EE specification 27

Installing and Running Tomcat Download from http://jakarta.apache.org/tomcat/ Installs in C:\Program Files\Apache Software Foundation\Tomcat 5.5 Start Tomcat (from the Start Menu) To check if Tomcat is running http://localhost:8080/ A default page shows up: TOMCAT_HOM /webapps/root/index.jsp 28

Writing Servlet Source Code Use text editor to create HitServlet.java in webapps/midp/web- INF/classes/ (you need to create midp and all subdirectories) import javax.servlet.http.*; import javax.servlet.*; import java.io.*; public class HitServlet extends HttpServlet { private int mcount; public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException { String message = "Hits: " +++mcount; response.setcontenttype("text/plain"); response.setcontentlength(message.length()); PrintWriter out = response.getwriter(); out.println(message); } } You can copy the code from http://developers.sun.com/techtopics/mobility/midp/articles/tutorial2/ 29

Compiling the Servlet You need to set an environment variable C:\>set CLASSPATH=\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\servlet-api.jar Compile the Servlet in a command window: C:\Program Files\Java\jdk1.5.0_06\bin>javac "\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\midp\WEB- INF\classes\HitServlet.java It will generate a HitServlet.class file. 30

Deploying the Servlet Web Application HTML, image files, servlets, other resources Accessible via a web interface Tomcat has several web applications installed in webapps directory examples, webdav Let s create a web application and place our servlet inside 31

Deploying the Servlet To tell Tomcat about our new web application Select Tomcat Manager from the Start menu Enter the admin username and password, which you entered when installing Tomcat The Tomcat Manager starts up Create a configuration xml file <Context path="/midp" docbase="midp" reloadable="true"/> Deploy the web application using the above XML file 32

Deploying the Servlet Create webapps/midp/web-inf/web.xml <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <servlet> <servlet-name>bob</servlet-name> <servlet-class>hitservlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>bob</servlet-name> <url-pattern>/hits</url-pattern> </servlet-mapping> </web-app> Tells Tomcat to map the servlet HitServlet to the path /hits 33

Testing the Servlet Connect to http://localhost:8080/midp/hits You should see the output of HitServlet, i.e., a count that is increased when you reload the page Hits: 9 Hits: 10 Hits: 11 34

Hooking up a MIDlet to the Servlet Hooking up A MIDlet can connect to the world via HTTP A Servlet is available to the world via HTTP So, it is easy to connect a MIDlet to a Servlet Start KToolbar, open the MIDlet project (from Part I), i.e, HelloSuite Create a new MIDlet that connects to the servlet, retrieves its output, and displays it. Source codes of HitMIDlet (next 2 slides) 35

import java.io.*; import javax.microedition.io.*; import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class HitMIDlet extends MIDlet implements CommandListener { private Display mdisplay; private Form mmainform; private StringItem mmessageitem; private Command mexitcommand, mconnectcommand; public HitMIDlet() { mmainform =newform("hitmidlet"); mmessageitem =newstringitem(null, ""); mexitcommand =newcommand("exit", Command.EXIT, 0); mconnectcommand =newcommand("connect", Command.SCREEN, 0); mmainform.append(mmessageitem); mmainform.addcommand(mexitcommand); mmainform.addcommand(mconnectcommand); mmainform.setcommandlistener(this); } public void startapp() { mdisplay = Display.getDisplay(this); mdisplay.setcurrent(mmainform); } public void pauseapp() {} public void destroyapp(boolean unconditional) {} public void commandaction(command c, Displayable s) { if (c == mexitcommand) notifydestroyed(); else if (c == mconnectcommand) { Form waitform =newform("waiting..."); mdisplay.setcurrent(waitform); Thread t = newthread() { public void run() { connect(); } }; t.start(); } 36 }

private void connect() { HttpConnection hc = null; InputStream in = null; String url = getappproperty("hitmidlet.url"); try { hc = (HttpConnection)Connector.open(url); in = hc.openinputstream(); int contentlength = (int)hc.getlength(); byte[] raw = newbyte[contentlength]; int length = in.read(raw); in.close(); hc.close(); // Show the response to the user. String s = newstring(raw, 0, length); mmessageitem.settext(s); } catch (IOException ioe) { mmessageitem.settext(ioe.tostring()); } mdisplay.setcurrent(mmainform); } } 37

To make HitMIDlet start working Click on Settings in KToolbar Select the MIDlets tab Click on Add and fill in HitMIDlet for both MIDlet name and class name You can leave ICON blank Click OK Both HelloMIDlet and HitMIDlet must be listed 38

To make HitMIDlet start working Need to define a system property that HitMIDlet uses as URL for network connection Click on Settings User Defined Add Fill in HitMIDlet.URL as the property name Value: http://localhost:8080/midp/hits Click OK 39

To make HitMIDlet start working In Java Wireless Toolkit Click Build Click Run Select Connect HitMIDlet invokes HitServlet The hit counter value is displayed in the mobile phone emulator 40

Success!!! The result of HitServlet is display by HitMIDlet in the device emulator 41

Conclusion This tutorial shows how to develop an end-toend Java wireless application Part I setup and use a MIDlet development environment create a MIDlet and run and test it Part II configure and use a servlet development environment Write and deploy a servlet Hook up MIDlet with Servlet (end-to-end application) 42