A Taste of JavaME Overview to Java’s approach to wireless mobile application development from a developer’s perspective Thomas Wiradikusuma [email_address] www.wiradikusuma.com Presentation to the 19 th Java User Group Meet Up (JaMU), March 4, 2006
Objective
To introduce JavaME as a platform for developing wireless mobile applications.
Wireless communication is one of the fastest growing technology.
Cell phones subscribers worldwide exceeded two billions in 2005.
More depended to the Internet, people want it accessible from mobile devices.
3+G is coming to town.
Meet JavaME
JavaME defined
A little history
Why JavaME?
Dynamic delivery of content
Offline access
Enhanced user experience and interactive content
Cross-platform compatibility
Security
The power of a modern object-oriented programming language
Large developer community
JavaME Architecture
JavaME Architecture, cont’d
Configurations:
Connected Device Configuration
Connected, Limited Device Configuration
Profiles:
Mobile Information Device Profile
PDA Profile
Foundation Profile
etc
Optional packages
Typically contains functionality independent of any particular vertical market segment or device family. The main goal is to allow the definition of APIs that can be added flexibly on top of a number of different profiles. One device can support multiple optional packages.
Miniaturized Standard Java APIs
No floating-point in CLDC 1.0.
No user class loading, object finalization, reflection, native methods, demon threads, thread groups, Collections API, etc.
Simpler Runtime and System, java.io, date functions, exception handling, etc.
TIPS:
Always refer to Javadoc.
When compiling, set Language Features and Target VM to lowest Java SDK available (IDEs can help this).
Developing MIDlet
Edit Source Code > Compile > Preverify > Package > Test or Deploy.
Free development tools:
J2ME Wireless Toolkit
EclipseME (an Eclipse plug-in)
NetBeans Mobility Pack (a NetBeans module)
Obfuscation: minimizing the size of MIDlet suite JARs. Originally designed to foil attempts to reverse engineer compiled bytecode, perform any combination of the following functions:
Renaming things to make them compact
Removing unused things
Inserting illegal or questionable data to confuse decompilers
Other useful tools:
Antenna (specialized Ant tasks to help with MIDlet suite builds)
J2ME Polish
Test your application in (varying) real devices as often as possible.
First MIDlet (“Hello World”)
User Interface
Event Handling
A command is something the user can invoke—you can think of it as a button. Like a button, it has a title, like “OK” or “Cancel,” and your application can respond appropriately when the user invokes the command. The premise is that you want a command to be available to the user, but you don't really care how it is shown on the screen or exactly how the user invokes it—keypad button, soft button, touch screen, whatever.
Persisting Data
“ Record stores”, small database containing pieces of data called records . Represented by instances of javax.microedition.rms.RecordStore.
Connecting to the World
All contained in the javax.microedition.io package and based around the Connection interface.
HTTP (and HTTPS in MIDP 2.0) is mandatory, others are optional.
Connecting to the World, cont’d
TIPS:
Use GET rather than POST.
Don't hard-code URLs.
Put network access in a separate thread.
Handle exceptions gracefully.
Clean up after yourself.
Game API
Simplifies writing 2D games.
GameCanvas’ advantages over Canvas:
Controls exactly when the display is updated
Controls region of the screen to update
Typical game loop:
Graphics g = getGraphics();
while(true) {
// Check for user input.
// Update game state.
// Draw stuff using g.
flushGraphics();
}
Layer, Sprite, TiledLayer and LayerManager
Special effects:
flashBacklight()
vibrate()
Optional Packages
JSR 120: Wireless Messaging API
JSR 135: Mobile Media API
JSR 172: Web Services Specification
JSR 177: Security and Trust Services
JSR 179: Location API
JSR 180: Session Initiation Protocol (SIP)
JSR 184: Mobile 3D Graphics
JSR 190: Event Tracking API
And a whole lot more…
Performance Issues
Benchmarking
Runtime.freeMemory()
Runtime.totalMemory()
System.currentTimeMilis()
Run multiple times and calculate the average
TIPS:
First make it run, the make it run right, then make it run fast
Create objects efficiently, reuse objects whenever possible
Use StringBuffer for string concatenation
Use arrays, not object collection
Use buffered I/O
Be clean
Make application responsive (“perceived performance”)
Use an obfuscator
Redesign / refactor
Run memory profiler
Manage resources efficiently
Don’t be too OO :-)
Resources
Websites:
wireless.java.sun.com
www.microjava.com
www.onjava.com/onjava/wireless
www.javagaming.com
www.microdevnet.com
Books:
Knudsen, Jonathan. Wireless Java Developing with J2ME, Second Edition . Apress. 2003.
Riggs, Roger, et al . Programming Wireless Devices with the Java™ 2 Platform, Micro Edition, Second Edition . Addison Wesley. 2003.
0 comments
Post a comment