SlideShare a Scribd company logo
Java ME CLDC MIDP
Agenda History Java Universe Understanding Java ME Configuration Profile Java ME : CLDC Java ME : MIDP
History 1990: Java started as an internal project at Sun Microsystems 1995: Initial release of JDK 1.0 (applets   servlets) 1999: JavaOne conference Subdivision of Java in Java 2 Enterprise Edition (J2EE) Java 2 Standard Edition (J2SE) Java 2 Micro Edition (Java ME) (successor of Personal Java and  Embedded Java) 2000/01 First mobile phones with support for J2ME
Java Universe
What is Java ME? Java ME : Java 2 Platform, Micro Edition “ Java for small devices” Java ME is downsized version on J2SE It is currently restricted to JRE 1.3  features Divided in configurations, profiles  and optional  APIs/JSRs
Existence of Java ME In the early 1990s, Sun Microsystems created a new programming  language called Oak with cross-platform support  Primary focus on small handheld device with an LCD touch-screen  and built-in wireless networking and infrared communications Market was not ready Internet market was booming now oak rename java  It was now divided into two group J2SE & J2EE After a long time demand began to grow for Java on smaller devices  and even on smart cards, thus returning Java to its roots. J2ME born later rename it as Java ME
Advantage  of Java ME “ Write Once, Run Anywhere” Portability across the widest range of devices Provide best solution for an extremely wide range of small device Secure  Incorporation of high usability and value features Easy to master
Java ME Specification
Configuration At the heart of the Java ME platform is the configuration. A configuration defines a minimal Java runtime environment suitable for a certain class or family of devices. In particular, a configuration defines: The capabilities of the Java virtual machine (VM)  The native code that interfaces with the underlying system  A set of Java runtime classes for running applications  Minimal device requirements for memory and input/output  mechanisms. Configuration CLDC CDC
How CLDC, CDC Configurations came into existence Mobile phone , TV set-Top Boxes, Home appliances etc. having Limited processing power Limited graphical capability Limited battery power  Lower power consumption  Limited memory  Working on intermittent connection and limited bandwidth  CLDC targeted for? KVM based devices CDC targeted for? JVM based devices
Connected Device Configuration A subset of Java Standard Edition. Contains almost all the libraries of Java SE except GUI related. Optimized for multi-threaded low memory conditions. 2 MB or more memory for Java platform Four profiles are based on CDC: Foundation Profile Personal Basis Profile Personal Profile Gaming Profile Designed for Mobile & Embedded Devices with higher Processing Power, Memory and Display. Current Release: CDC 1.1.2 (JSR 218)
Connected Limited Device Configuration  160 – 512K of memory available for Java. Typically has limited power or battery operated.  Network connectivity, often wireless, intermittent, low - bandwidth.  Core Java class libraries available on a particular category of  devices.  32 kilobytes memory for runtime memory allocation. Two profiles are based on CLDC: Mobile Information Device Profile Information Module Profile
CLDC API Structure CLDC defines a core of APIs, mostly taken from the J2SE world. These include fundamental language classes in java.lang, stream classes from java.io, and simple collections from java.util. CLDC also specifies a generalized network API in javax.microedition.io.*;
CLDC Core API
Profile A profile is layered on top of a configuration It is a collection of Java based APIs that supplement a  Configuration to provide capabilities for a specific vertical market or  device type (for example, wireless: mobile devices, set-top box etc.). The main goal for a profile is to provide flexibility to the Java  Community while still maintaining portability across device types. Profiles are defined by open industry working groups (Samsung,Nokia,  Sony ericsson,LG etc.)utilizing the Java Community Process Program.  In this way industries can decide for themselves what elements are  necessary to provide a complete solution targeted at their industry.
Profile Profiles define the application life cycle model, the user interface,  and access to device specific properties. Java ME Profiles: Mobile Information Device Profile (MIDP) PDA Profile (PDAP) Foundation Profile (FP), Personal Profile (PP) and Personal Basic Profile (PBP). RMI Profile Game Profile
Java ME Family
KVM Sun's Kilobyte virtual machine  ~ 50K With libraries + KVM ~130K Designed from ground up to meet needs to mobile devices Highly configurable but limits us because of size restrictions
KVM Limitations Doesn’t support float or double data types (CLDC 1.1 does) java.util greatly reduced Limited string, and I/O functionality No JNI or custom class loaders Change in classfile verification    preverification
KVM Limitations java.lang subset and in some cases modified interface and  implementation signatures Runtime - Reduced signature to memory operations - freeMemory(), gc(), totalMemory()) and exit()  System (reduced signature) Threading – Thread groups or daemon threads Provide ~8 K of data storing facility {RMS} Unicode is supported, but far fewer encodings are supported
One More Glance
MIDP MIDP stands for Mobile Information Device Profile. MIDP combined with the Connected Limited Device  Configuration (CLDC), is the Java runtime environment for  today's mobile information devices (MIDs) such as phones and  set top box.  Provide Graphical User Interface  Currently MIDP 2.0/2.1 device in market A keypad, keyboard, or touch screen Two-way wireless networking capability Media Support  Database support
MIDP features Externally triggered Java ME activation is supported { SMS ,  MMS, CBS etc} Access native services {dial tel number, open system browser  etc} User Interface  Multimedia access { playing tone, songs etc} Gaming API Network Connectivity
MIDP Packages
MIDP UI Library
MIDlet   What is MIDlet ? A MIDlet is a MID Profile application javax.microedition.midlet.MIDlet;   The application must extend this class to allow the application  management software (AMS)to control the MIDlet It Allows AMS to create, start, pause, and destroy a MIDlet javax.microedition.midlet.MIDlet;   MyApp
Application Management System AMS software must work in conjunction with the device's native  system software Control app lifecycle Starting, Stopping & Pausing KVM Control by AMS Java ME app run under the control of KVM AMS list all the installed MIDlet on the system Task done by AMS Installation, Upgrade & Version management to  removal of application software
AMS Action & MIDlet State
MIDlet lifecycle
MIDlet lifecycle MIDlet belong to javax.microedition.midlet.*; package. Every Java ME MIDlet based on three method startApp pauseApp destroyApp startApp method The startApp method is called when the MIDlet is started. After startApp has completed, the MIDlet is in Active state. It check whether any elements have been set as the current  screen (Display).
MIDlet lifecycle pauseApp MIDlet application start with pause state.  pauseApp call by external event like SMS, phone call etc. destroyApp When application wants to terminate MIDlet it calls destroyApp MIDlet goes into the Destroyed state    destroyApp method provides unconditional parameter  false MIDlet refuse to terminate true AMS terminate the MIDlet notifyDestroyed notifies the AMS that the MIDlet has entered  Destroyed state
MIDlet lifecycle MIDlet  import javax.microedition.midlet.MIDlet; public class FirstMidlet extends MIDlet {  public void startApp() {   // MIDlet in Active State } public void pauseApp() {   //MIDlet in Pause state }  public void destroyApp(boolean unconditional) {   //MIDlet in Destroyed state  } }
Hands On Hands On try it your self
Writing the code Using  the text editor, enter source code, save the  code as <name>.java  Compiling the code <name>.class Pre-verification <name>.class { increase size upto 5%} Get JAD & JAR Run MIDlet on device Java ME Development Cycle
Java ME Development Cycle
MIDlet Suite The MIDlet suite is JAR & JAD file’s that contain one or more MIDlet JAR=Java Archive File JAD=Java Application Descriptor The JAD makes information available to the application manager. With this information, the manager can determine if the  device can accommodate the MIDlet
Inside JAR JSR is a production, packaged application generally consist of  many files. In addition to Java classes, other files such as images  and application data, known as resources, may be part of the  package. You bundle all this information together into a single entity,  a JAR file.
Inside JAD The JAD file provides information about the JAR, there are six  attributes that must be included into the JAD file. Required six must JAD attributes: MIDlet-Name  -- Name of the MIDlet suite MIDlet-Version  -- Version number of the MIDlet MIDlet-Vendor  -- Who created the MIDlet MIDlet-<n>  -- Information about the MIDlet(s) in the suite MIDlet-Jar-URL  --  The URL of the JAR file MIDlet-Jar-Size  -- The size, in bytes, of the JAR  Optional attributes: MIDlet-Description: MIDlet-Delete-Confirm: MIDlet-Install-Notify:
Inside manifest Reside inside the JAR file to provide the additional  information about the JAR, there are  six attributes that must be in the manifest file Mandatory Attributes: MIDlet-Name  -- Name of the MIDlet suite MIDlet-Version  -- Version number of the MIDlet MIDlet-Vendor  -- Who created the MIDlet MIDlet-<n>  -- Information about MIDlet(s) in the suite MicroEdition-Profile  -- What profile is required by the MIDlet MicroEdition-Configuration  -- Configuration is required by the MIDlet Optional attributes:  MIDlet-Icon: MIDlet-Description: MIDlet-Info-URL: Location
Over the Air
Over the Air OTA  is Over the Air provisioning, users acquire the jad/jar  as required via their browser MIDP OTA Specification –  Device Functionality Support for HTTP 1.0 or 1.1 Discovery Application (to locate application and to download) AMS to manage OTA Application Provisioning life cycle.
J2ME MIDP packages Application Lifecycle package javax.microedition.midlet User Interface package javax.microedition.lcdui Networking package javax.microedition.io Core packages java.lang, java.io, java.util Record Management Store javax.microedition.rms
MIDP UI is divided into two levels: the High-level and the  Low-level lcdui  package
lcdui  package
lcdui  package User-interface classes in javax.microedition.lcdui (and  lcdui.games) Device’s display is represented by an instance of Display. Accessed from factory method getDisplay() Display keeps track of what is currently visible, which is an  instance of Displayable Current state of the screen is changed by passing  Displayable instances to Display’s setCurrent() method
High Level UI High-level API’s for high portability (Screen) High – level MIDlet look and feel is same on all devices No direct access to device features Color, device inputs, screen size Implementation provides interaction (scrolling, navigation, drawing) Input key event handling is not available in high-level APIs by default . The high-level APIs are: Alert  - A popup screen to notify the user about an event. Form  - A screen to which Form Items can be added. The Items are also considered high-level APIs. List  - A screen containing a scrollable list of choices. TextBox  - A screen in which the user can enter or edit text.
Example import javax.microedition.midlet.MIDlet; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Form; public class HelloMidlet extends MIDlet implements CommandListener{ private Form form = null; private final Command cmdExit = new Command(&quot;Exit&quot;,Command.EXIT,1); private final String name=“Hello World”; public void startApp() { form = new Form(name); form.addCommand(cmdExit); form.setCommandListener(this); Display.getDisplay(this).setCurrent(form); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable d) { destroyApp(true); notifyDestroyed(); } }
Event Handling High Level Event Handling Low Level Event Handling
Handling events in the high-level API is based on a listener model.  CommandListener Interface  ItemStateListener Interface Command - The javax.microedition.lcdui.*; package provides the  Command  class Command(String label, int commandType, int priority) High Level Event Handling
High Level Event Handling Command Type - The type specifies the command's intent. The defined  types  are: BACK, CANCEL, EXIT, HELP, ITEM, OK, SCREEN, and STOP. ...  Command exitCommand = new Command(&quot;Exit&quot;, Command. EXIT, 1); Command backCommand = new Command(&quot;Back&quot;, Command. BACK, 1); Command moreCommand = new Command(&quot;More&quot;, Command.SCREEN, 2);  ...
Canvas allows capturing of key-press events for most of the keys  available on the device. The only way to respond keyboard input is  by overriding the following methods  protected void keyPressed(int keyCode) protected void keyReleased(int keyCode) protected void keyRepeated(int keyCode) Code snippet  protected void keyPressed(int keyCode){ //handle key code  } Low Level Event Handling
Low Level Event Handling The minimal set of keys required by the MIDP specification to be  captured is: The digits 0 through 9 The star or asterisk character (*) The pound or hash character (#) Standard key codes KEY_NUM0  To  KEY_NUM9 UP ,DOWN ,LEFT ,RIGHT ,FIRE  GAME_A ,GAME_B ,GAME_C ,GAME_D
Full control over the pixel   Low Level UI
Low Level UI In contrast to the high-level API, the low-level API allows full  control of the MID display at pixel level The low-level API is composed of the Canvas, Graphics  The Canvas and Graphics classes work together to provide low-level  control over a device. To create your own canvas  must extends your class with Canvas  class.  To writing/drawing on Canvas must implement paint method public void paint(Graphics g) { … }
Graphics object is used by the Canvas to do all 2D geometric rendering capability. Rendering of Graphics can be done directly to the display or to an off-screen image buffer.  Graphics
It provides method to handle the low level events{ key press,  pointer events} Issue graphics object for drawing to display It provides methods to identify the device's capabilities and mapping  of keys to game actions It can register Command Listener Canvas define following keys: KEY_NUM0,KEY_NUM1,KEY_NUM2,KEY_NUM3,KEY_NUM4,  KEY_NUM5,KEY_NUM6,KEY_NUM7,KEY_NUM8,KEY_NUM9, KEY_STAR,KEY_POUND. Canvas
Game action Key: UP,DOWN,LEFT,RIGHT,FIRE,GAME_A,GAME_B,GAME_C,and  GAME_D. Code snippet  public class MyCanvas extends Canvas{ public void paint(Graphics g){   g.drawString(...); } } Canvas
Key Handling …  protected void keyPressed(int keyCode) {  switch (keyCode){  …  case Canvas.KEY_NUM3:    System.out.println(getKeyName(keyCode));  break; ... } } …  Canvas
Game Action Key Handling protected void keyPressed(int keyCode){  int action = 0;  try {  action = getGameAction(keyCode); switch(action){ case Canvas.DOWN:      System.out.println(getKeyName(keyCode));  break; } } Canvas
Canvas Pointer Event Handling …  protected void pointerPressed(x, int y){  if(x>0 && y<50){ … . } } …
Low Level External Interrupts Interruptions such as incoming calls to a Java ME application in a device invokes hideNotify() and showNotify() on any displaying canvas. The showNotify() method is called prior to the Canvas actually being made visible on the display, and the hideNotify() method is called after the Canvas has been removed from the display. /*called when an interrupt such as incoming call is received*/ protected void hideNotify() { } /*called when an interrupt such as incoming call is ended*/  protected void showNotify() { }
Example import javax.microedition.lcdui.Canvas; import javax.microedition.lcdui.Graphics; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Image; public class MIDPCanvas extends Canvas implements CommandListener, Runnable { … public MIDPCanvas(DemoMidlet mid) { … } public void paint(Graphics g) { g.drawImage(offScreen, 0, 0, Graphics.LEFT | Graphics.TOP); g.drawImage(ball, ix_co, iy_co, Graphics.LEFT | Graphics.TOP); } protected void keyPressed(int keyCode) { int key = 0; try { key = getGameAction(keyCode); } catch (Exception ex) { key = keyCode;  } switch (key) { case Canvas.LEFT: ix_co--; if(ix_co<0){ ix_co=0; }  break; } } case Canvas.RIGHT: ix_co++; if ((ix_co + (iballWidth)) >= iScreenWidth) { ix_co = ix_co - 1; } break; case Canvas.UP:  iy_co--; if(iy_co<0){ iy_co=0; } break; case Canvas.DOWN: iy_co++; if((iy_co + iballHeight)>=iScreenHight){ iy_co=iy_co-1; } break; } } }
Class Hierarchy of the GCF
Generic Connection Framework The CLDC has define a set of APIs for I/O called  the Generic Connection Framework.  The GCF, part of the javax.microedition.io package,  defines interfaces & Classes for the different kinds of I/O  that are possible(such as  HTTP, socket, or streams ). The CLDC does not actually define any I/O  implementations these are left to the profiles and/or the  OEM to define.
GCF – Protocol Support Its support for different connection protocols Connector class is used to request to open a Connection Connector.Open(&quot;protocol:address;parameters&quot;); Opening various connection types   Connector.Open(&quot;socket://…&quot;);  Connector.Open(&quot;http://...&quot;);  Connector.Open(&quot;datagram://…&quot;);  Connector.Open(&quot;file://...&quot;);
GCF - example import java.io.*;  import javax.microedition.io.*; …  public void run() { try { HttpConnection httpConn = (HttpConnection) Connector.open(textField.getString(),  Connector.READ_WRITE); InputStream inputStrem  = httpConn.openDataInputStream(); int i=0; ... while((i=inputStrem.read())!=-1){ … } … inputStrem.close(); httpConn.close();  } catch (Exception ex) { ex.printStackTrace(); } } …
javax.microedition.lcdui.game.*;
Game package API javax.microedition.lcdui.game.*; is compact and consists of only five classes. They are: Game Canvas Layer Layer Manager Sprite TiledLayer javax.microedition.lcdui.game.*;
Canvas  Known as low-level user interface, it provides a rich variety of possibilities to draw onto the display. A class which extends Canvas has to implement the method “paint ()” with instructions that draw elements in the screen. GameCanvas  is a Canvas extension to simplify game development and to fix weak points from Canvas. Using GameCanvas is easier to control key events and update the screen. To control key events you just have to use the method getKeyStates() instead of using 3 methods (keyPressed, keyReleased keyRepeated) used in Canvas and to update the screen you just use flushGraphics() method.  Canvas Vs Game Canvas
Canvas Vs Game Canvas Using Canvas protected   void  keyPressed( int  keyCode) { switch  (getGameAction(keyCode)) { case  UP: … break ;   }  protected   void  keyRepeated( int  keyCode) { switch  (getGameAction(keyCode)) { case  UP: break; } Using GameCanvas Public void getEventStatus(){ int  key = getKeyStates(); if  ((key & LEFT_PRESSED) != 0) { …  } }
Simple record-oriented database (RMS) stored in Flash  memory Device-independent API Records are arrays of bytes that live in record stores Record stores are shared within MIDlet suite MIDP allows for optional sharing of record stores  between MIDlet suites  Support for enumeration, sorting, and filtering Atomic update for single records RMS
Sharing of record stores RMS
Create record Store To create a recordstore you can use  RecordStore.openRecordStore() with the second parameter set to  true. //open record if present else create a record ...  RecordStore rs = null; try {  rs = RecordStore.openRecordStore(&quot;RecordName&quot;, true);  } catch (Exception exe) {  //unable to open record or create record  } finally {  try{ //to close the record store  rs. closeRecordStore();  }catch(Exception ex){  } } ...  RMS
Close Record Store To close the record store you can call closeRecordStore() it will  close specific Record Store ... try{  rs. closeRecordStore(); } catch (Exception ex){ } ...  RMS
Add Record to RecordStore  To add record get bytes of record and call addRecord() to add the  record to the record store ...  String str= &quot;firstRecord&quot;;  //get bytes of record    byte[] rec = str.getBytes();   try {  // added record to recordstore  rs.addRecord(rec, 0, rec.length);    } catch (Exception e) { } ...  RMS
Read Record from RecordStore Set the array of bytes using the record size and call getRecord()  method to retrieve the Record Data. ...  byte[] getData;  try {  for (int i = 1; i <= rs.getNumRecords(); i++) { getData = new byte[rs.getRecordSize(i)];  rs.getRecord(i, getData, 0); } } catch (Exception exe) { }  ...  RMS
Delete Records form Record Store    To delete the record of specific id call the deleteRecord(int recordID) ... try{  for(int i=rs. getNumRecords(); i>0;i--) {  rs.deleteRecord(i); } } catch(Exception ex){ } ...  RMS
RMS Deleting the Record Store        ...  private final String S_LOGIN = “loginRS”;  try{ RecordStore.deleteRecordStore(S_LOGIN);  }catch(Exception ex){ } ...

More Related Content

PDF
J2ME GUI Programming
PPT
PPT
Introduction to j2me
PPTX
PPTX
PPTX
PPTX
Introduction to Mobile programming(J2ME)
J2ME GUI Programming
Introduction to j2me
Introduction to Mobile programming(J2ME)

What's hot (20)

PPTX
J2ME mobile app development
PDF
Java2 MicroEdition-J2ME
PPT
Mobile Application Development MAD J2ME
PPS
J2ME Unit_01
PPTX
Presenting Cloud Computing
PPT
MOBILE APPs DEVELOPMENT PLATFORMS
PPT
Scmad Chapter 01
PPT
Session1 j2me introduction
PDF
PDF
Android internals
PDF
AMD Unified Video Decoder
 
PPTX
Java ME - 01 - Overview
PPTX
PDF
Introduction to Java ME
PPSX
information highway
PDF
Ajava final(sachin sir9822506209)_vision_academy_21
PDF
Dell Latitude E6430 Laptops Trần Phát
PDF
Aspire 4520 4220 4520g 4220g
PPTX
Manish Chasta - Securing Android Applications
DOCX
Parallelogram by using j2 me j2me.shahid
J2ME mobile app development
Java2 MicroEdition-J2ME
Mobile Application Development MAD J2ME
J2ME Unit_01
Presenting Cloud Computing
MOBILE APPs DEVELOPMENT PLATFORMS
Scmad Chapter 01
Session1 j2me introduction
Android internals
AMD Unified Video Decoder
 
Java ME - 01 - Overview
Introduction to Java ME
information highway
Ajava final(sachin sir9822506209)_vision_academy_21
Dell Latitude E6430 Laptops Trần Phát
Aspire 4520 4220 4520g 4220g
Manish Chasta - Securing Android Applications
Parallelogram by using j2 me j2me.shahid
Ad

Viewers also liked (8)

PPT
Session2-J2ME development-environment
PPTX
Introduction To J2ME(FT - Prasanjit Dey)
PDF
MIDP GUI Development: Alert, List, Form, TextBox
PPT
Session 3 J2ME Mobile Information Device Profile(MIDP) API
PDF
Where 2.0 2009 - Location on the Web
PDF
"JavaME + Android in action" CCT-CEJUG Dezembro 2008
DOC
It6611 mobile application development laboratory l t p c0 0 3 2
DOCX
Cs 6611 mad lab manual
Session2-J2ME development-environment
Introduction To J2ME(FT - Prasanjit Dey)
MIDP GUI Development: Alert, List, Form, TextBox
Session 3 J2ME Mobile Information Device Profile(MIDP) API
Where 2.0 2009 - Location on the Web
"JavaME + Android in action" CCT-CEJUG Dezembro 2008
It6611 mobile application development laboratory l t p c0 0 3 2
Cs 6611 mad lab manual
Ad

Similar to Java ME CLDC MIDP (20)

PDF
010118565.pdf
PPTX
Introduction to mobile programing (J2ME)
PPTX
Java J2ME
PPT
PPT
Mobile Java
PPT
Introduction to Mobile Application Development
PPTX
J2me Platform
PPT
J2ME-java-training-document-internal.ppt
PPT
A Taste of Java ME
PDF
J2me Crash Course
PPT
CIS 642 - Mobile Information Device profie
PPT
Introduction to JAVA ME Mobile Application.ppt
PPT
Java ME An Introduction. www.javameblog.com
PPT
J2 me 1
PPTX
Lab 1 new
PDF
06 Eclipse ME
PPTX
Blackberry Development Environment
PPT
Mobile Application Development MAD J2ME UNIT 2
PDF
03 midp
PPT
Scmad Chapter02
010118565.pdf
Introduction to mobile programing (J2ME)
Java J2ME
Mobile Java
Introduction to Mobile Application Development
J2me Platform
J2ME-java-training-document-internal.ppt
A Taste of Java ME
J2me Crash Course
CIS 642 - Mobile Information Device profie
Introduction to JAVA ME Mobile Application.ppt
Java ME An Introduction. www.javameblog.com
J2 me 1
Lab 1 new
06 Eclipse ME
Blackberry Development Environment
Mobile Application Development MAD J2ME UNIT 2
03 midp
Scmad Chapter02

More from SMIJava (9)

PPT
SMI - Introduction to JSR 75 PIM
PPT
SMI - Introduction to PushRegistry
PPT
SMI - Introduction to JSR 75 PIM
PPT
SMI - Introduction to Java
PPT
JSR 82 (bluetooth obex)
PPT
Jsr135 sup
PPT
Jsr120 sup
PPT
Jsr75 sup
PPT
Push registrysup
SMI - Introduction to JSR 75 PIM
SMI - Introduction to PushRegistry
SMI - Introduction to JSR 75 PIM
SMI - Introduction to Java
JSR 82 (bluetooth obex)
Jsr135 sup
Jsr120 sup
Jsr75 sup
Push registrysup

Recently uploaded (20)

PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
PDF
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
PDF
LDMMIA Reiki Yoga S2 L3 Vod Sample Preview
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PDF
Cell Biology Basics: Cell Theory, Structure, Types, and Organelles | BS Level...
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
How to Manage Starshipit in Odoo 18 - Odoo Slides
PDF
Types of Literary Text: Poetry and Prose
PDF
Module 3: Health Systems Tutorial Slides S2 2025
PPTX
Software Engineering BSC DS UNIT 1 .pptx
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
How to Manage Bill Control Policy in Odoo 18
PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Introduction and Scope of Bichemistry.pptx
PDF
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
PDF
English Language Teaching from Post-.pdf
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
LDMMIA Reiki Yoga S2 L3 Vod Sample Preview
The Final Stretch: How to Release a Game and Not Die in the Process.
Open Quiz Monsoon Mind Game Final Set.pptx
Cell Biology Basics: Cell Theory, Structure, Types, and Organelles | BS Level...
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
How to Manage Starshipit in Odoo 18 - Odoo Slides
Types of Literary Text: Poetry and Prose
Module 3: Health Systems Tutorial Slides S2 2025
Software Engineering BSC DS UNIT 1 .pptx
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
How to Manage Bill Control Policy in Odoo 18
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
O7-L3 Supply Chain Operations - ICLT Program
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Introduction and Scope of Bichemistry.pptx
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
English Language Teaching from Post-.pdf

Java ME CLDC MIDP

  • 2. Agenda History Java Universe Understanding Java ME Configuration Profile Java ME : CLDC Java ME : MIDP
  • 3. History 1990: Java started as an internal project at Sun Microsystems 1995: Initial release of JDK 1.0 (applets  servlets) 1999: JavaOne conference Subdivision of Java in Java 2 Enterprise Edition (J2EE) Java 2 Standard Edition (J2SE) Java 2 Micro Edition (Java ME) (successor of Personal Java and Embedded Java) 2000/01 First mobile phones with support for J2ME
  • 5. What is Java ME? Java ME : Java 2 Platform, Micro Edition “ Java for small devices” Java ME is downsized version on J2SE It is currently restricted to JRE 1.3 features Divided in configurations, profiles and optional APIs/JSRs
  • 6. Existence of Java ME In the early 1990s, Sun Microsystems created a new programming language called Oak with cross-platform support Primary focus on small handheld device with an LCD touch-screen and built-in wireless networking and infrared communications Market was not ready Internet market was booming now oak rename java It was now divided into two group J2SE & J2EE After a long time demand began to grow for Java on smaller devices and even on smart cards, thus returning Java to its roots. J2ME born later rename it as Java ME
  • 7. Advantage of Java ME “ Write Once, Run Anywhere” Portability across the widest range of devices Provide best solution for an extremely wide range of small device Secure Incorporation of high usability and value features Easy to master
  • 9. Configuration At the heart of the Java ME platform is the configuration. A configuration defines a minimal Java runtime environment suitable for a certain class or family of devices. In particular, a configuration defines: The capabilities of the Java virtual machine (VM) The native code that interfaces with the underlying system A set of Java runtime classes for running applications Minimal device requirements for memory and input/output mechanisms. Configuration CLDC CDC
  • 10. How CLDC, CDC Configurations came into existence Mobile phone , TV set-Top Boxes, Home appliances etc. having Limited processing power Limited graphical capability Limited battery power Lower power consumption Limited memory Working on intermittent connection and limited bandwidth CLDC targeted for? KVM based devices CDC targeted for? JVM based devices
  • 11. Connected Device Configuration A subset of Java Standard Edition. Contains almost all the libraries of Java SE except GUI related. Optimized for multi-threaded low memory conditions. 2 MB or more memory for Java platform Four profiles are based on CDC: Foundation Profile Personal Basis Profile Personal Profile Gaming Profile Designed for Mobile & Embedded Devices with higher Processing Power, Memory and Display. Current Release: CDC 1.1.2 (JSR 218)
  • 12. Connected Limited Device Configuration 160 – 512K of memory available for Java. Typically has limited power or battery operated. Network connectivity, often wireless, intermittent, low - bandwidth. Core Java class libraries available on a particular category of devices.  32 kilobytes memory for runtime memory allocation. Two profiles are based on CLDC: Mobile Information Device Profile Information Module Profile
  • 13. CLDC API Structure CLDC defines a core of APIs, mostly taken from the J2SE world. These include fundamental language classes in java.lang, stream classes from java.io, and simple collections from java.util. CLDC also specifies a generalized network API in javax.microedition.io.*;
  • 15. Profile A profile is layered on top of a configuration It is a collection of Java based APIs that supplement a Configuration to provide capabilities for a specific vertical market or device type (for example, wireless: mobile devices, set-top box etc.). The main goal for a profile is to provide flexibility to the Java Community while still maintaining portability across device types. Profiles are defined by open industry working groups (Samsung,Nokia, Sony ericsson,LG etc.)utilizing the Java Community Process Program. In this way industries can decide for themselves what elements are necessary to provide a complete solution targeted at their industry.
  • 16. Profile Profiles define the application life cycle model, the user interface, and access to device specific properties. Java ME Profiles: Mobile Information Device Profile (MIDP) PDA Profile (PDAP) Foundation Profile (FP), Personal Profile (PP) and Personal Basic Profile (PBP). RMI Profile Game Profile
  • 18. KVM Sun's Kilobyte virtual machine ~ 50K With libraries + KVM ~130K Designed from ground up to meet needs to mobile devices Highly configurable but limits us because of size restrictions
  • 19. KVM Limitations Doesn’t support float or double data types (CLDC 1.1 does) java.util greatly reduced Limited string, and I/O functionality No JNI or custom class loaders Change in classfile verification  preverification
  • 20. KVM Limitations java.lang subset and in some cases modified interface and implementation signatures Runtime - Reduced signature to memory operations - freeMemory(), gc(), totalMemory()) and exit() System (reduced signature) Threading – Thread groups or daemon threads Provide ~8 K of data storing facility {RMS} Unicode is supported, but far fewer encodings are supported
  • 22. MIDP MIDP stands for Mobile Information Device Profile. MIDP combined with the Connected Limited Device Configuration (CLDC), is the Java runtime environment for today's mobile information devices (MIDs) such as phones and set top box. Provide Graphical User Interface Currently MIDP 2.0/2.1 device in market A keypad, keyboard, or touch screen Two-way wireless networking capability Media Support Database support
  • 23. MIDP features Externally triggered Java ME activation is supported { SMS , MMS, CBS etc} Access native services {dial tel number, open system browser etc} User Interface Multimedia access { playing tone, songs etc} Gaming API Network Connectivity
  • 26. MIDlet What is MIDlet ? A MIDlet is a MID Profile application javax.microedition.midlet.MIDlet; The application must extend this class to allow the application management software (AMS)to control the MIDlet It Allows AMS to create, start, pause, and destroy a MIDlet javax.microedition.midlet.MIDlet; MyApp
  • 27. Application Management System AMS software must work in conjunction with the device's native system software Control app lifecycle Starting, Stopping & Pausing KVM Control by AMS Java ME app run under the control of KVM AMS list all the installed MIDlet on the system Task done by AMS Installation, Upgrade & Version management to removal of application software
  • 28. AMS Action & MIDlet State
  • 30. MIDlet lifecycle MIDlet belong to javax.microedition.midlet.*; package. Every Java ME MIDlet based on three method startApp pauseApp destroyApp startApp method The startApp method is called when the MIDlet is started. After startApp has completed, the MIDlet is in Active state. It check whether any elements have been set as the current screen (Display).
  • 31. MIDlet lifecycle pauseApp MIDlet application start with pause state. pauseApp call by external event like SMS, phone call etc. destroyApp When application wants to terminate MIDlet it calls destroyApp MIDlet goes into the Destroyed state    destroyApp method provides unconditional parameter false MIDlet refuse to terminate true AMS terminate the MIDlet notifyDestroyed notifies the AMS that the MIDlet has entered Destroyed state
  • 32. MIDlet lifecycle MIDlet import javax.microedition.midlet.MIDlet; public class FirstMidlet extends MIDlet { public void startApp() { // MIDlet in Active State } public void pauseApp() { //MIDlet in Pause state } public void destroyApp(boolean unconditional) { //MIDlet in Destroyed state } }
  • 33. Hands On Hands On try it your self
  • 34. Writing the code Using the text editor, enter source code, save the code as <name>.java Compiling the code <name>.class Pre-verification <name>.class { increase size upto 5%} Get JAD & JAR Run MIDlet on device Java ME Development Cycle
  • 36. MIDlet Suite The MIDlet suite is JAR & JAD file’s that contain one or more MIDlet JAR=Java Archive File JAD=Java Application Descriptor The JAD makes information available to the application manager. With this information, the manager can determine if the device can accommodate the MIDlet
  • 37. Inside JAR JSR is a production, packaged application generally consist of many files. In addition to Java classes, other files such as images and application data, known as resources, may be part of the package. You bundle all this information together into a single entity, a JAR file.
  • 38. Inside JAD The JAD file provides information about the JAR, there are six attributes that must be included into the JAD file. Required six must JAD attributes: MIDlet-Name -- Name of the MIDlet suite MIDlet-Version -- Version number of the MIDlet MIDlet-Vendor -- Who created the MIDlet MIDlet-<n> -- Information about the MIDlet(s) in the suite MIDlet-Jar-URL -- The URL of the JAR file MIDlet-Jar-Size -- The size, in bytes, of the JAR Optional attributes: MIDlet-Description: MIDlet-Delete-Confirm: MIDlet-Install-Notify:
  • 39. Inside manifest Reside inside the JAR file to provide the additional information about the JAR, there are six attributes that must be in the manifest file Mandatory Attributes: MIDlet-Name -- Name of the MIDlet suite MIDlet-Version -- Version number of the MIDlet MIDlet-Vendor -- Who created the MIDlet MIDlet-<n> -- Information about MIDlet(s) in the suite MicroEdition-Profile -- What profile is required by the MIDlet MicroEdition-Configuration -- Configuration is required by the MIDlet Optional attributes: MIDlet-Icon: MIDlet-Description: MIDlet-Info-URL: Location
  • 41. Over the Air OTA is Over the Air provisioning, users acquire the jad/jar as required via their browser MIDP OTA Specification – Device Functionality Support for HTTP 1.0 or 1.1 Discovery Application (to locate application and to download) AMS to manage OTA Application Provisioning life cycle.
  • 42. J2ME MIDP packages Application Lifecycle package javax.microedition.midlet User Interface package javax.microedition.lcdui Networking package javax.microedition.io Core packages java.lang, java.io, java.util Record Management Store javax.microedition.rms
  • 43. MIDP UI is divided into two levels: the High-level and the Low-level lcdui package
  • 45. lcdui package User-interface classes in javax.microedition.lcdui (and lcdui.games) Device’s display is represented by an instance of Display. Accessed from factory method getDisplay() Display keeps track of what is currently visible, which is an instance of Displayable Current state of the screen is changed by passing Displayable instances to Display’s setCurrent() method
  • 46. High Level UI High-level API’s for high portability (Screen) High – level MIDlet look and feel is same on all devices No direct access to device features Color, device inputs, screen size Implementation provides interaction (scrolling, navigation, drawing) Input key event handling is not available in high-level APIs by default . The high-level APIs are: Alert - A popup screen to notify the user about an event. Form - A screen to which Form Items can be added. The Items are also considered high-level APIs. List - A screen containing a scrollable list of choices. TextBox - A screen in which the user can enter or edit text.
  • 47. Example import javax.microedition.midlet.MIDlet; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Form; public class HelloMidlet extends MIDlet implements CommandListener{ private Form form = null; private final Command cmdExit = new Command(&quot;Exit&quot;,Command.EXIT,1); private final String name=“Hello World”; public void startApp() { form = new Form(name); form.addCommand(cmdExit); form.setCommandListener(this); Display.getDisplay(this).setCurrent(form); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable d) { destroyApp(true); notifyDestroyed(); } }
  • 48. Event Handling High Level Event Handling Low Level Event Handling
  • 49. Handling events in the high-level API is based on a listener model. CommandListener Interface ItemStateListener Interface Command - The javax.microedition.lcdui.*; package provides the Command class Command(String label, int commandType, int priority) High Level Event Handling
  • 50. High Level Event Handling Command Type - The type specifies the command's intent. The defined types are: BACK, CANCEL, EXIT, HELP, ITEM, OK, SCREEN, and STOP. ... Command exitCommand = new Command(&quot;Exit&quot;, Command. EXIT, 1); Command backCommand = new Command(&quot;Back&quot;, Command. BACK, 1); Command moreCommand = new Command(&quot;More&quot;, Command.SCREEN, 2); ...
  • 51. Canvas allows capturing of key-press events for most of the keys available on the device. The only way to respond keyboard input is by overriding the following methods protected void keyPressed(int keyCode) protected void keyReleased(int keyCode) protected void keyRepeated(int keyCode) Code snippet protected void keyPressed(int keyCode){ //handle key code } Low Level Event Handling
  • 52. Low Level Event Handling The minimal set of keys required by the MIDP specification to be captured is: The digits 0 through 9 The star or asterisk character (*) The pound or hash character (#) Standard key codes KEY_NUM0 To KEY_NUM9 UP ,DOWN ,LEFT ,RIGHT ,FIRE GAME_A ,GAME_B ,GAME_C ,GAME_D
  • 53. Full control over the pixel Low Level UI
  • 54. Low Level UI In contrast to the high-level API, the low-level API allows full control of the MID display at pixel level The low-level API is composed of the Canvas, Graphics The Canvas and Graphics classes work together to provide low-level control over a device. To create your own canvas must extends your class with Canvas class. To writing/drawing on Canvas must implement paint method public void paint(Graphics g) { … }
  • 55. Graphics object is used by the Canvas to do all 2D geometric rendering capability. Rendering of Graphics can be done directly to the display or to an off-screen image buffer. Graphics
  • 56. It provides method to handle the low level events{ key press, pointer events} Issue graphics object for drawing to display It provides methods to identify the device's capabilities and mapping of keys to game actions It can register Command Listener Canvas define following keys: KEY_NUM0,KEY_NUM1,KEY_NUM2,KEY_NUM3,KEY_NUM4, KEY_NUM5,KEY_NUM6,KEY_NUM7,KEY_NUM8,KEY_NUM9, KEY_STAR,KEY_POUND. Canvas
  • 57. Game action Key: UP,DOWN,LEFT,RIGHT,FIRE,GAME_A,GAME_B,GAME_C,and GAME_D. Code snippet public class MyCanvas extends Canvas{ public void paint(Graphics g){ g.drawString(...); } } Canvas
  • 58. Key Handling … protected void keyPressed(int keyCode) { switch (keyCode){ … case Canvas.KEY_NUM3: System.out.println(getKeyName(keyCode)); break; ... } } … Canvas
  • 59. Game Action Key Handling protected void keyPressed(int keyCode){ int action = 0; try { action = getGameAction(keyCode); switch(action){ case Canvas.DOWN: System.out.println(getKeyName(keyCode)); break; } } Canvas
  • 60. Canvas Pointer Event Handling … protected void pointerPressed(x, int y){ if(x>0 && y<50){ … . } } …
  • 61. Low Level External Interrupts Interruptions such as incoming calls to a Java ME application in a device invokes hideNotify() and showNotify() on any displaying canvas. The showNotify() method is called prior to the Canvas actually being made visible on the display, and the hideNotify() method is called after the Canvas has been removed from the display. /*called when an interrupt such as incoming call is received*/ protected void hideNotify() { } /*called when an interrupt such as incoming call is ended*/ protected void showNotify() { }
  • 62. Example import javax.microedition.lcdui.Canvas; import javax.microedition.lcdui.Graphics; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Image; public class MIDPCanvas extends Canvas implements CommandListener, Runnable { … public MIDPCanvas(DemoMidlet mid) { … } public void paint(Graphics g) { g.drawImage(offScreen, 0, 0, Graphics.LEFT | Graphics.TOP); g.drawImage(ball, ix_co, iy_co, Graphics.LEFT | Graphics.TOP); } protected void keyPressed(int keyCode) { int key = 0; try { key = getGameAction(keyCode); } catch (Exception ex) { key = keyCode; } switch (key) { case Canvas.LEFT: ix_co--; if(ix_co<0){ ix_co=0; } break; } } case Canvas.RIGHT: ix_co++; if ((ix_co + (iballWidth)) >= iScreenWidth) { ix_co = ix_co - 1; } break; case Canvas.UP: iy_co--; if(iy_co<0){ iy_co=0; } break; case Canvas.DOWN: iy_co++; if((iy_co + iballHeight)>=iScreenHight){ iy_co=iy_co-1; } break; } } }
  • 64. Generic Connection Framework The CLDC has define a set of APIs for I/O called the Generic Connection Framework. The GCF, part of the javax.microedition.io package, defines interfaces & Classes for the different kinds of I/O that are possible(such as HTTP, socket, or streams ). The CLDC does not actually define any I/O implementations these are left to the profiles and/or the OEM to define.
  • 65. GCF – Protocol Support Its support for different connection protocols Connector class is used to request to open a Connection Connector.Open(&quot;protocol:address;parameters&quot;); Opening various connection types Connector.Open(&quot;socket://…&quot;); Connector.Open(&quot;http://...&quot;); Connector.Open(&quot;datagram://…&quot;); Connector.Open(&quot;file://...&quot;);
  • 66. GCF - example import java.io.*; import javax.microedition.io.*; … public void run() { try { HttpConnection httpConn = (HttpConnection) Connector.open(textField.getString(), Connector.READ_WRITE); InputStream inputStrem = httpConn.openDataInputStream(); int i=0; ... while((i=inputStrem.read())!=-1){ … } … inputStrem.close(); httpConn.close(); } catch (Exception ex) { ex.printStackTrace(); } } …
  • 68. Game package API javax.microedition.lcdui.game.*; is compact and consists of only five classes. They are: Game Canvas Layer Layer Manager Sprite TiledLayer javax.microedition.lcdui.game.*;
  • 69. Canvas Known as low-level user interface, it provides a rich variety of possibilities to draw onto the display. A class which extends Canvas has to implement the method “paint ()” with instructions that draw elements in the screen. GameCanvas is a Canvas extension to simplify game development and to fix weak points from Canvas. Using GameCanvas is easier to control key events and update the screen. To control key events you just have to use the method getKeyStates() instead of using 3 methods (keyPressed, keyReleased keyRepeated) used in Canvas and to update the screen you just use flushGraphics() method. Canvas Vs Game Canvas
  • 70. Canvas Vs Game Canvas Using Canvas protected void keyPressed( int keyCode) { switch (getGameAction(keyCode)) { case UP: … break ;   } protected void keyRepeated( int keyCode) { switch (getGameAction(keyCode)) { case UP: break; } Using GameCanvas Public void getEventStatus(){ int key = getKeyStates(); if ((key & LEFT_PRESSED) != 0) { …  } }
  • 71. Simple record-oriented database (RMS) stored in Flash memory Device-independent API Records are arrays of bytes that live in record stores Record stores are shared within MIDlet suite MIDP allows for optional sharing of record stores between MIDlet suites Support for enumeration, sorting, and filtering Atomic update for single records RMS
  • 72. Sharing of record stores RMS
  • 73. Create record Store To create a recordstore you can use RecordStore.openRecordStore() with the second parameter set to true. //open record if present else create a record ... RecordStore rs = null; try { rs = RecordStore.openRecordStore(&quot;RecordName&quot;, true); } catch (Exception exe) { //unable to open record or create record } finally { try{ //to close the record store rs. closeRecordStore(); }catch(Exception ex){ } } ... RMS
  • 74. Close Record Store To close the record store you can call closeRecordStore() it will close specific Record Store ... try{ rs. closeRecordStore(); } catch (Exception ex){ } ... RMS
  • 75. Add Record to RecordStore To add record get bytes of record and call addRecord() to add the record to the record store ... String str= &quot;firstRecord&quot;; //get bytes of record byte[] rec = str.getBytes(); try { // added record to recordstore rs.addRecord(rec, 0, rec.length); } catch (Exception e) { } ... RMS
  • 76. Read Record from RecordStore Set the array of bytes using the record size and call getRecord() method to retrieve the Record Data. ... byte[] getData; try { for (int i = 1; i <= rs.getNumRecords(); i++) { getData = new byte[rs.getRecordSize(i)]; rs.getRecord(i, getData, 0); } } catch (Exception exe) { } ... RMS
  • 77. Delete Records form Record Store   To delete the record of specific id call the deleteRecord(int recordID) ... try{ for(int i=rs. getNumRecords(); i>0;i--) { rs.deleteRecord(i); } } catch(Exception ex){ } ... RMS
  • 78. RMS Deleting the Record Store   ... private final String S_LOGIN = “loginRS”; try{ RecordStore.deleteRecordStore(S_LOGIN); }catch(Exception ex){ } ...

Editor's Notes

  • #48: import javax.microedition.midlet.MIDlet; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Form; public class HelloMidlet extends MIDlet implements CommandListener{ private Form form = null; private final Command cmdExit = new Command(&amp;quot;Exit&amp;quot;,Command.EXIT,1); public void startApp() { form = new Form(&amp;quot;Hello World&amp;quot;); form.addCommand(cmdExit); form.setCommandListener(this); Display.getDisplay(this).setCurrent(form); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable d) { destroyApp(true); notifyDestroyed(); } }