Package java.lang provides the basic java programming features but is a run down version of J2SE java.lang package. The basic features included in J2ME's java.lang package are
Essential Java classes/interfaces
Wrapper classes for primitive data types and related functions
Float was not supported in CLDC1.0/MIDP1.0 but is supported since CLDC1.1/MIDP2.0. To use Float in MIDP1.0 devices you will have to write your own Float class. A simple example for Float calculations in MIDP1.0 is given in the next section "J2ME User Interfaces".
Runtime and System Classes
Both these classes have gc() method which can be used for forcible garbage collection. You can use this garbage collector after the high memory foot print objects like images are killed.
System class's getProperty() function can be used to query different device properties like CLDC version, MIDP version, encoding etc. This method comes very handy when you want to know what features your device supports.
On the other hand with class Runtime, runtime environment can be queried for free memory and total memory. As the code snippet shows getRuntime() method is used to get a handle to Runtime and to query for your applications memory footprint use methods totalMemory() and freeMemory().
Code to query device properties
package com.j2me.salsa.conf;
// Midlet class's package
import javax.microedition.midlet.MIDlet;
//Midlet's User interface API
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
//import javax.microedition.midlet.*;
public class DeviceConf extends MIDlet
implements CommandListener {
private Form helloForm;
private Command exitCommand;
/**
* Midlet constructor
* */
public DeviceConf() {
exitCommand = new Command("Exit", Command.EXIT, 1);
helloForm = new Form(“Device Specs”);
// Use System.getProperty() to query device configurations
helloForm.append("Platform : "
+ System.getProperty("microedition.platform") + "\n");
helloForm.append("Encoding : "
+ System.getProperty("microedition.encoding") + "\n");
helloForm.append("Configuration : "
+ System.getProperty("microedition.configuration") + "\n");
helloForm.append("Profiles : "
+ System.getProperty("microedition.profiles") + "\n");
helloForm.append("Locale : "
+ System.getProperty("microedition.locale") + "\n");
// Use java.lang's Runtime class to query device memory
helloForm.append("Total Memory: "
+ Runtime.getRuntime().totalMemory() + "\n");
helloForm.append("Free Memory: "
+ Runtime.getRuntime().freeMemory() + "\n");
// Forcibly call garbage collector
Runtime.getRuntime().gc();
helloForm.addCommand(exitCommand);
helloForm.setCommandListener(this);
}
/**
* The paused state changed to active state.
*/
protected void startApp() {
Display.getDisplay(this).setCurrent(helloForm);
}
/**
* The MIDlet frees as much resources as it can.
*/
protected void pauseApp() {}
protected void destroyApp(boolean bool) {}
/**
* Midlet event handling
*/
public void commandAction(Command cmd, Displayable disp) {
if (cmd == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
}
|
List of some of the basic properties which can be queried using System.getProperty() and their purpose is given below. We can also know the information about supported optional packages like Bluetooth, Multimedia etc. When any system property is returned as "null" then it means that the feature is not supported by the device.
Basic Specifications
microedition.platform: Device
model
microedition.configuration : Device configuration.
microedition.profiles : Device configuration.
microedition.locale : Current locale.
microedition.encoding: Supoported Charecter encoding
microedition.jtwi.version: Java Technology for the Wireless Industry (JTWI)
is a high level specification for Java based mobile technologies.
FileConnection API and PIM API
microedition.io.file.FileConnection.version:
Device File System Access
microedition.pim.version: Personal Information Management(PIM) to access phone
book, to do lists etc
fileconn.dir.photos: Image capture through your Mobile camera.
fileconn.dir.videos: Vedio capture through your Mobile camera.
fileconn.dir.tones: Ring tones default directory.
fileconn.dir.memorycard: Memory Card / SD Card / Flash Drive root directory
fileconn.dir.private: Working directory of midlet
Messaging API
wireless.messaging.sms.smsc:
Short Message Service Center (SMSC) address used for sending the messages.
wireless.messaging.mms.mmsc: Multimedia Message Service Center (MMSC) address
used for sending the messages.
Mobile Media API
microedition.media.version:
Mobile Media API (MMAPI) for audio, vedio and other media support.
supports.mixing: Support for media mixing.
supports.audio.capture: Support for audio capture.
supports.video.capture: Support for vedio capture.
supports.recording: Support for recording
audio.encodings: List of supported audio formats.
video.encodings: List of vedio formats
video.snapshot.encodings: List of image formats
streamable.contents: List of supported streamable content.
Other popular Optional Packages and features
microedition.commports:
List of commports
microedition.hostname Local address of the device.
microedition.location.version: Location API
microedition.sip.version: Session Initiation Protocol
microedition.m3g.version: Mobile 3D Graphics (M3G)
microedition.global.version: Mobile Internationalization API
microedition.chapi.version: Content Handler API, JSR 211
microedition.smartcardslots: List of smartcard slots
bluetooth.api.version: Bluetooth version.
Device Specific System Properties
Device vendors have some vendor specific properties like Nokia has "com.nokia.mid.dateformat" which are specific to a particular vendor.
This is not an exhaustive list of system properties but gives you basic important properties. Going forward you can add the above system properties in the DeviceConf.java and check out all the system properties.
This simple program can save you a lot of headache in future whenever you want to know your device configurations and capabilities.
Custom configurations
We can also create and access the custom key value pairs from the JAD file in the code. Method MIDlet.getAppProperty() is used to get value pair configured in the JAD file.
Listing of a JAD file with user defined value
MIDlet-1: Configuration Demo, Demo.png, com.jme.conf.Demo MIDlet-Jar-Size: 1640 MIDlet-Jar-URL: Demo.jar MIDlet-Name: Demo MIDlet-Vendor: Unknown MIDlet-Version: 1.0 MicroEdition-Configuration: CLDC-1.0 MicroEdition-Profile: MIDP-2.0 myGreeting: Hello World!!! |
Code for access to JAD Parameter
"myGreeting"
Form.append(MIDlet.getAppProperty("myGreeting"));
J2ME Wireless Toolkit Tip: Application Property can be configured in the "User Defined" tab in the "Settings screen".
Reading resources
Java.lang.Class has a method getResourceAsStream(String name) which can be used to read resources at the location specified as input parameter.
InputStream is = getClass().getResourceAsStream(filename.txt); |
If midlet package is the skeleton of MIDP then java.lang package is the flesh and blood.
| j2meSalsa goodies | |
| Execute Device Config Sample online | Select "Device Configuration" on the online emulator on your left frame. |
| Download demo code for deploying directly to WTK | Click here to download Zip File Containing WTK compatible file structure. |
site comments powered by Disqus
This page is a part of
a frames based web site. If you have landed on this page from a search engine
click here to view the complete page.