Session 10 J2ME Prof. Sridhar Iyer IIT Bombay

Slides:



Advertisements
Similar presentations
MIDP Mobile Information Device Profile Johnny Yau CIS 642 Prof. Insup Lee.
Advertisements

Pengantar Teknologi Mobile 12
J2ME 25 July Overview  What is J2ME?  The CLDC and CDC configurations  MIDP and MIDlets  Development Tools  Demonstrations.
Writing Your First MIDlet Running JAVA on a Cell Phone Jon A. Batcheller January 27, 2004.
UNDERSTANDING JAVA APIS FOR MOBILE DEVICES v0.01.
Introduction to Java 2 Micro Edition Mark Balbes, Ph.D. Senior Software Engineer Jeff Brown Senior Software Engineer.
Developing an Application with J2ME Technology Scott Palmer, Nat Panchee, Judy Sullivan, Karen Thabet, Sten Westgard.
J2ME RMI 1 Java 2 Platform, Micro Edition Implementation of J2ME RMI Application Farooq Sheikh.
Java Integrated Development Environments: ECLIPSE Part1 Installation.
Introduction to Mobility Java Technology Mobile and Wireless Networks.
Developing Software for Wireless Devices
PDA Programming Using J2ME Presenter :涂俊凱 Date : 2003/4/8.
Making Cell Phone Games An Overview Ray Ratelis Guild Software, Inc.
Developing J2ME Applications Mobile and Wireless Networks.
The 21th century Repairman Agenda Introduction J2EE J2ME Demonstration.
Cosc 4730 Phone Programming in Java An Introduction.
Lab 1 Instructor: Jolanta Soltis.
Java 2 Platform, Micro Edition (J2ME) By Xiaorong Wang.
Chapter 4 Servlets Concept of Servlets (What, Why, and How) Servlet API Third-party tools to run servlets Examples of Using Servlets HTML tag with GET.
J2ME Programming. 2 Recommended Books Programming Wireless Devices with the Java2 Platform, Micro Second Edition (Paperback) by Roger Riggs (Editor),
Java Servlets and JSP.
LESSON 1 INTRODUCTION Compiled By: Edwin O. Okech [Tutor, Amoud University] JAVA PROGRAMMING.
SERVLETS.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
An Introduction to the Java ME Project Jens A Andersson.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
1 Servlet How can a HTML page, displayed using a browser, cause a program on a server to be executed?
Getting Started with JXTA for J2ME Advisor : Dr. Ching-Long Yeh Report : DI.2, 洪泰昌 ( ) Course: XML 文件管理.
Michael Brockway Advanced Applications Development in Java J2ME -- Introduction l Introduction / Overview l Java 2 Micro Edition n CLDC n MIDP l Examples.
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 11 J2ME and MIDlets Rob Pooley
AN OVERVIEW OF SERVLET TECHNOLOGY SERVER SETUP AND CONFIGURATION WEB APPLICATION STRUCTURE BASIC SERVLET EXAMPLE Java Servlets - Compiled By Nitin Pai.
Computer Science Wi-Fi App using J2ME and MVC Architecture Advisor : Dr. Chung-E Wang Department of Computer Science Sacramento State University Date:
Chapter 7 Java Server Pages. Objectives Explain how the separation of concerns principle applies to JSP Describe the operation and life-cycle of a JSP.
J2ME Presented by May Sayed & Menna Hawash. Outline Introduction “Java Technology” Introduction “What is J2ME?” J2ME Architecture J2ME Core Concepts 
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems Web based Applications,
1Basics of J2ME. 2 Objectives –Understand the different java API’s and how the mobile edition API’s fit in –Understand what a mobile configuration and.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
Java Servlets & Java Server Pages Lecture July 2013.
Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.
8-January-2003cse ProjectOverview © 2003 University of Washington1 Project Overview CSE 403, Winter 2003 Software Engineering
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
S ERVLETS Hits Counter 21-Nov-15. S ERVLETS - H ITS C OUNTER Many times you would be interested in knowing total number of hits on a particular page of.
A seminar on j2ee by saritha. s. What is J2EE J2EE (Java 2 Platform, Enterprise Edition) is a Java platform designed for the mainframe-scale computing.
@2008 Huynh Ngoc Tin Chapter #2 JAVA SERVLET PRGRAMMING.
Java 2 Micro Edition The Connected, Limited Device Configuration.
Java Servlets and Java Server Pages
1 Introduction to J2ME Outline MIDP Building J2ME Apps- Tool J2ME Wireless Toolkit Demo MIDlet Programming -- MIDlet Transition States -- Midlet Skeleton.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Advance Computer Programming Market for Java ME The Java ME Platform – Java 2 Micro Edition (J2ME) combines a resource- constrained JVM and a set of Java.
The Java Platform Micro Edition Java ME
Java N Amanquah.
Part II Software When developing software there are several particularities to be aware of: Java is widespread used because of the platform independence.
Building Web Apps with Servlets
Server Side Programming
Java Servlets By: Tejashri Udavant..
Net-centric Computing
Writing simple Java Web Services using Eclipse
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Introduction to Java Servlets on Jakarta Tomcat
MOBILE DEVICE OPERATING SYSTEM
Wireless Instant Messaging Using J2ME
By Jeff Heaton An Overview of J2ME By Jeff Heaton
Objectives In this lesson you will learn about: Need for servlets
Java for Mobile Devices
Java Servlets and JSP.
Servlets.
Introduction to Java Servlets
Outcome of the Lecture Upon completion of this lecture you will be able to understand Fundamentals and Characteristics of Java Language Basic Terminology.
Java Chapter 7 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Session 10 J2ME Prof. Sridhar Iyer IIT Bombay IT 601: Mobile Computing Session 10 J2ME Prof. Sridhar Iyer IIT Bombay

Why Java™ Technology for Small Devices? The nature of wireless devices is changing Old devices: All the software hard-coded by the device manufacturer New devices: Can be customized by dynamically loading software over the air New opportunities for manufacturers, operators, and developers!

JAVA Architecture

Overview of the Java 2 Platform J2EE A comprehensive platform for multi-user, enterprise-wide applications. based on J2SE and adds APIs for server-side computing. J2SE designed for desktop computers. Mostly runs on top of OS X, Linux, Solaris, or Microsoft Windows. J2ME subset of J2SE components set of technologies and specifications developed for small devices like pagers, mobile phones, and set-top boxes. J2ME uses smaller virtual machines and leaner APIs.

Elements of J2ME Architecture Profile: Defines the Environment API exposing the functionality of a specific class of target devices, and necessary to support a particular set of services Optional Package: Augments the Environment APIs exposing specific functionality Deployment determined by the Platform Vendor Configuration: Defines the VM API exposing the minimal sized, preexisting profile defined for the specific VM it is deployed against. VM is either a full JVM or some subset of it (KiloByte VM).

Elements of J2ME Architecture

Configurations Connected, Limited Device Configuration(JSR-30,139) Smallest mobile devices Phones, Pagers, PDAs (small) 128K to 2MB with Profile and Optional Packages Network connectivity usually limited Connected Device Configuration (JSR-36) Larger devices, some mobile, some not TVs, PDAs (larger), Communicators, Cars, Gateways 2MB and up with Profile and Optional Packages Connectivity includes TCP/IP

J2ME Connected Limited Device Configuration (CLDC)

Profiles for CLDC Mobile Information Device Profile (JSR-37, 118) Will work with CLDC Volume Wireless Handsets LCDUI based GUI PDA Profile (JSR-75) References MIDP Smaller memory PDAs AWT based GUI

J2ME Mobile Information Device Profile (MIDP)

J2ME-CLDC Stack

MIDlet Life Cycle MIDP applications, or “MIDlets”, move from state to state in their lifecycle according to a state diagram MIDlet states include: Paused—initialized and quiescent (waiting) Active—has resources and is executing Destroyed—has released all resources, destroyed threads, and ended all activity

J2ME APIs not suitable for small devices with limited resources. J2SE APIs require several megabytes of memory not suitable for small devices with limited resources. APIs for the CLDC, provide a minimum set of libraries useful for application development and profile definition for a variety of small devices. The CLDC library APIs can be divided into the following two categories: Classes that are a subset of the J2SE APIs: java.lang, java.io, and java.util packages Classes specific to the CLDC: These classes are located in the javax.microedition package

CLDC classes inherited from J2SE ByteArrayInputStream, ByteArrayOutputStream, DataInput, DataOutput, DataInputStream, DataOutputStream, InputStream, OutputStream, InputStreamReader, OutputStreamWriter, PrintStream, Reader, Writer java.io Calendar, Date, Enumeration, Hashtable, Random, Stack, TimeZone, Vector java.util Boolean, Byte, Character, Class, Integer, Long, Math, Object, Runnable, Runtime, Short, String, StringBuffer, System, Thread, Throwable java.lang Classes Package

CLDC Specific Classes Classes Packages Connection, ConnectionNotFoundException, Connector, ContentConnector, Datagram, DatagramConnection, InputConnection, OutputConnection, StreamConnection, StreamConnectionNotifier javax.microedition.io Classes Packages

MIDP Specific Classes MIDP-specific classes include the javax.microedition.rms, javax.microedition.midlet, javax.microedition.lcdui packages Some additional classes, interfaces, and exception classes available: IllegalStateException class in the java.lang package Timer and TimerTask classes in the java.util package HttpConnection interface for HTTP protocol access over the network in the javax.microedition.io package

J2ME vs J2SE Reduced number support float, double primitives Double, Float classes Extendable UI components Final High-level components New components subclass Canvas Lacks: JNI Sound API Serialization Reflection User defined class loaders

Some Links to Start with J2ME http://developers.sun.com/techtopics/mobility/learn/ midp/getstart http://developers.sun.com/techtopics/mobility/midp/ articles/wtoolkit/ http://developers.sun.com/techtopics/mobility/midp/ articles/tutorial2/ http://developers.sun.com/techtopics/mobility/midp/ articles/api/

Sun J2ME Wireless Toolkit Install J2SE SDK Available at http://java.sun.com/j2se/. Add bin subdirectory to the path. Install J2ME Wireless Toolkit Available at http://java.sun.com/products/j2mewtoolkit/ . Run KToolbar. Use Any IDE for coding java Eclipse, netbeans etc.

MIDP Development with J2MEWTK Write your Java™ application (midlets) using any text editor or IDE Use J2ME Wireless Toolkit, Create a Project Follow the instructions and copy the source file to the location specified in the Wireless Toolkit Click on Build Run against any emulator

Sun J2ME Wireless Toolkit

Creating a new Project

Server Side Implementation MIDlet: The application, a MIDlet, was designed for the Mobile Information Device Profile, one of the J2ME specifications. Servlet: Servlets are Java programs which run on the server. The MIDlets connect to servlets, which implement server side functionality. Next slides show how to write and deploy a servlet, and then how to hook up a MIDlet with the servlet

Installing Tomcat Download Tomcat server Available at http://jakarta.apache.org/builds/jakarta-tomcat- 4.0/nightly Unpack the distribution in to a directory and set the environment variable CATALINA_HOME to the path of the directory Upon starting the server, Tomcat 4.0 will be available by browsing: http://localhost:8080/ Further details of Installation refer to http://jakarta.apache.org/tomcat/tomcat-4.1-doc/RUNNING.txt

Writing a Simple Servlet HitServlet simply counts the number of times it's been invoked and writes back to the client a message containing the count. 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); } Save the source code in a file under the Tomcat root directory named webapps/midp/WEB-INF/classes/HitServlet.java

Compiling and deploying the servlet Execute the following shell commands: #export CLASSPATH=\jakarta-tomcat-4.1.27\common\lib\servlet.jar #javac HitServlet.java Deploying: you'll need to edit one of Tomcat's configuration files to tell Tomcat about the new web application. Open the conf/server.xml file with a text editor. In this file, web applications are called contexts. Scroll down to find the Context entry for the examples web application, which begins like this: <!-- Tomcat Examples Context --> <Context path="/examples" docBase="examples" debug="0" reloadable="true" crossContext="true"> Above or below this lengthy context entry (it's closed by </Context>, many lines down), create a new context entry for your new web application. It will look similar to the opening tag for the examples context, but you'll change the names to midp as appopriate and close the tag inline. <!-- MIDP Context --> <Context path="/midp" docBase="midp" reloadable="true"/> Once you're finished adding the context entry, save the file.

Create a web-application config Copy the following text and save it as webapps/midp/WEB-INF/web.xml under the Tomcat root directory: <?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>myServlet</servlet-name> <servlet-class>HitServlet</servlet-class> </servlet> <servlet-mapping> <url-pattern>/hits</url-pattern> </servlet-mapping> </web-app>

Hooking Up a MIDlet to the Servlet Create a command action method in your MIDlet: public void commandAction(Command c, Displayable s) { if (c == mExitCommand) notifyDestroyed(); else if (c == mConnectCommand) { Form waitForm = new Form("Waiting..."); mDisplay.setCurrent(waitForm); Thread t = new Thread() { public void run() { connect(); } }; t.start();

Hooking Up a MIDlet to the Servlet The Connect method 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 = new byte[contentLength]; int length = in.read(raw); in.close(); hc.close(); // Show the response to the user. String s = new String(raw, 0, length); mMessageItem.setText(s); } catch (IOException ioe) { mMessageItem.setText(ioe.toString()); mDisplay.setCurrent(mMainForm); Source code available here for download: http://developers.sun.com/techtopics/mobility/midp/articles/tutorial2/src/HitMIDlet.java

Build and run your MIDlet Save it as HitMIDlet.java inside the apps/HelloSuite/src directory underneath the J2ME Wireless Toolkit root directory. Click on Settings..., then select the MIDlets tab. Click on Add and fill in "HitMIDlet" for both the MIDlet name and class name. You can leave Icon blank. Click on OK and you should see both HelloMIDlet and HitMIDlet listed. Define a system property that HitMIDlet uses as the URL for its network connection. (This property is retrieved in the third line of the connect() method.) In the toolkit, click on Settings..., then select the User Defined tab. Click on the Add button. Fill in the property name as HitMIDlet.URL; the value should be the URL that invokes HitServlet, the same URL you used in a browser to test the servlet. When you're finished, click on OK to dismiss the project settings window. Click on Build to build the project. Make sure your server is running first. Then click on Run and select HitMIDlet. Select the Connect command.

MIDP Programming General MIDP Tutorials http://developers.sun.com/techtopics/mobility/midp/reference/techart/ Useful Links Event Handling (http://developers.sun.com/techtopics/mobility/ midp/articles/event/index.html) Client Server Communication( http://developers.sun.com/ techtopics/mobility/midp/ttips/clientserv/index.html) Session Handling ( http://developers.sun.com/techtopics/ mobility/midp/articles/sessions/index.html)

Recommended Programming Practices Keep in mind that there are strict memory constraints on most CLDC target devices Allocate memory resources just before use Free resources as soon as they are not needed Avoid allocating small temporary chunks of memory to avoid heap fragmentation Make local copies of global variables Avoid redundant method calls, and inline functions rather than creating a new class

References J2ME Java FAQ Online Java Tutorial JSP Tutorial http://java.sun.com/j2me/ http://www.billday.com/j2me/ Java FAQ http://java.sun.com/products/jdk/faq.html Online Java Tutorial http://java.sun.com/docs/books/tutorial/ JSP Tutorial http://www.jsptut.com/