Você está na página 1de 21

Introduction to Java and J2ME 

Development

Using BlackBerry Development Tols  
Platform for Developing Applications

1
Agenda

Introduction to J2ME
 Overview of J2ME architecture & APIs
 Toolkits for Application Development
 Sample Application
J2ME: Advanced Topics
 Best Practices
 Application Deployment
 MIDP 2.0

2
J2ME Architecture

• A standard subset of the Java (J2SE) class libraries
– “to enable Java applications to run on small computing 
devices”
• Defines a Virtual Machine called the KVM
– Optimized for use on small devices
• Recognizes that small devices vary greatly in their 
nature
– J2ME defines Configurations (baseline) and Profiles 
(application­specific)
– Target Devices: Mobile phones, PDA’s, Car navigation 
systems, embedded devices

3
J2ME CLDC 1.0 Configuration

• Configurations
– Core set of classes that provide the minimal features that all 
devices in this configuration must support

•  “Connected Limited Device Configuration”
•  Defines configurations for devices with:
•  Variable network coverage
•  Slow processing speed
•  Limited memory 

•  Target Devices:
•  Mobile phones
•  Low­end PDA’s

4
J2ME CLDC 1.0 Configuration

• CLDC 1.0 provides the following Java libraries:
Library Example
java.io InputStream
     Standard java input/output library OutputStream
java.lang String,  Byte
      Standard java extended language  Thread
library
java.util Vector
      Standard java utilities library Random
javax.microedition.io HttpConnection
      CLDC­specific input/output library StreamConnection
5
J2ME MIDP 1.0 Profile

• Profiles
– Classes geared towards specific types of applications 
(uses of a device)
• “Mobile Information Device Profile”
• Built on top of CLDC 1.0, with extra APIs for:
• Defining and controlling applications
• Displaying text and graphics
• Persistent data storage
• Network connectivity
• Applications built using MIDP/CLDC are referred to as 
MIDlets
• MIDlets sharing code/data are referred to as MIDlet suites

6
J2ME MIDP 1.0 Profile

• MIDP 1.0 provides the following Java libraries:
Library Example
javax.microedition.midlet MIDlet
      MIDP application library
javax.microedition.lcdui Screen,  Graphics
      LCD user interface library Textbox, 
CommandListener
javax.microedition.rms RecordStore
      Record Management System (data 
storage)

7
BlackBerry J2ME API Extensions

• All BlackBerry Java devices support CLDC & MIDP 1.0
• RIM has developed extensions to the standard J2ME libraries to 
enable more flexible and customized integration with BlackBerry 
features
• Developers can write new applications for BlackBerry using 
these Java APIs
• Java APIs for BlackBerry enable you to develop custom client 
applications that provide:
• Robust & customizable User Interface
• Persistent Data Storage on the handheld 
• Event Listening & System interfaces
• Secure wireless transport via HTTP(S) and Email

8
BlackBerry J2ME API Extensions

For more advanced applications:
– Integration with BlackBerry Email & PIM 
applications
– Bulk data loading and backup/restore via 
Desktop Manager
– Always­on & Auto­started ‘background 
threads’ & PUSH

9
BlackBerry J2ME API Extensions

       Library             Example
net.rim.device.api.system TrackwheelListener, KeyListener, 
   BlackBerry system­level library Application

net.rim.device.api.ui Screen,  Graphics
     Fundamental user interface library UiApplication
net.rim.device.api.ui.container MainScreen,  FullScreen
     UI objects that contain other elements PopupScreen

net.rim.device.api.ui.component EditField,  ListField
     UI objects that reside within a container Menu

net.rim.device.api.util Array,  HashTable
      Extended utilities library StringUtilities

net.rim.device.api.i18n ResourceBundle
      Internationalization support Locale

10
J2ME Architecture for BlackBerry

Java Applications

   APIs for BlackBerry   J2ME APIs 
  (UI, System, compression,  (MIDP & CLDC)
etc.)
Java Virtual Machine

BlackBerry Handheld (Radio, LCD, RAM, Keyboard etc.)

11
J2ME Wireless Toolkit

• Supports development of MIDP/CLDC applications
• Includes an environment that allows for compilation, 
execution and packaging of applications
• Can be integrated with a compatible IDE (eg. Sun 
ONE Studio Mobile Edition) that allows for debugging 
and editing source code and emulation
• J2ME Wireless Toolkit 2.0 supports MIDP 2.0 
applications

12
BlackBerry JDE

• Custom client applications are built with the 
BlackBerry Java Development Environment (JDE)
• BlackBerry JDE v3.7
– Based on Java 2, Micro Edition (J2ME):  MIDP/CLDC 1.0
– Full featured Integrated Development Environment (IDE) 
with Handheld Simulators, MDS Simulator, Debugging & 
Optimization tools
– Robust Java API set
• BlackBerry JDE v4.0
– Release date: September 2004
– MIDP 2.0 and CLDC 1.1 support
– Enhanced BlackBerry API’s

13
Sample Application

1. Launch Application 2. List of Customers 3. Create New Call Report 4. Enter Details & Submit

BlackBerry  Web/App  Data Store


Server Server

14
Sample Application

1. Launch Application 2. List of Customers 3. Create New Call Report 4. Enter Details & Submit

HTTP

BlackBerry  Web/App  Data Store


Server Server

http://myWebServer/bb/callReport

15
Sample Application

1. Launch Application 2. List of Customers 3. Create New Call Report 4. Enter Details & Submit

J2EE/.NET 
HTTP ODBC/SQL

BlackBerry  Web/App  Data Store


Server Server

HTTP Interface  App Logic &  Connector Interface 


(Receive Data) User  (ODBC, J2EE, .NET)
Management
http://myWebServer/bb/callReport

16
J2ME Best Practices

Use Device Resources Wisely…Plan Ahead!!
• Minimize application size
– Limit the number of features
– Object design – create single objects for common tasks and reuse them
– Place resource data on the server
• Large resources that each user will only require a subset of
• Minimize run­time memory use
– Use scalar types (int, boolean) instead of objects (String, Integer)
– Don’t depend entirely on the garbage collector
• Avoid creating a lot of objects quickly
• Reuse objects
– Move computation to server
• Perform data filtering, sorting, etc. on the server before sending it to the 
device
• Completely process and manipulate data as needed before indicating to the 
user that new data has arrived.  This hides latency from user

17
J2ME Best Practices

Code with Performance in Mind
• Use local variables
– Generally quicker to access local variables than class members
• Use threads for lengthy operations ( > than 1/10 second)
– Stop the operation from blocking the main UI thread
• Set appropriate access and declaration type
– Declare members as private whenever possible
– Declare classes as final if they will not be extended
– Carefully use static and final – understand the performance impact 
on both class and primitive types
• Carefully optimize loops and mathematical operations

See the JDE Developer Guide for more performance tips

18
J2ME Application Deployment

• MIDlets are packaged into a JAR file
• On BlackBerry, JAR files are converted to COD 
files 
• JAR file includes:
– Manifest
– Java classes
– Resource files
• JAD file accompanies JAR
– Contains description (attributes) about MIDlet
– Allows application manager to verify the MIDlet is 
suited for device before downloading 

19
JAD File Example

MIDlet­Name: CallReporter
MIDlet­Version:1.0.0
MIDlet­Vendor: RIM
MIDlet­Description: Custom CRM Application
MIDlet­Jar­Size: 15289
MIDlet­Jar­URL: www.blackberry.com/download/CRM

20
Questions?

21

Você também pode gostar