Header
Home | Sitemap  
Sections
Archive
Su Mo Tu We Th Fr Sa
1
2345678
9101112131415
16171819202122
23242526272829
30
Syndication



System Properties

by

image

 
System Properties
The CLDC/MIDP supports system properties, which are key-value pairs that represent
information about the platform and environment in which MIDP applications execute.
Conceptually these are the same type of properties that you find in J2SE. Unfortunately, there is
no java.util.Properties class in CLDC/MIDP to facilitate your handling of properties.
The MIDP specification defines only a small set of standard properties, which are shown in Table
3.4. Implementations may support additional, manufacturer-specific system properties, but these
are nonstandard. You should be aware of what manufacturer- or platform-specific features you use
in order to anticipate portability issues.
Like J2SE applications, MIDP applications can retrieve a system property using the
java.lang.System class. To retrieve the value of a property, use the System class method
String getProperty(String key)
This method retrieves the property value associated with the key whose value is specified in the
call.
Table 3.4. Standard CLDC System Properties
Property Key Description Default
Value
microedition.configuration Name and version of the supported
configuration
CLDC-1.0
microedition.encoding Default character encoding set used by
the platform
ISO8859-1
microedition.locale Name of the platform's current locale null
microedition.platform Name of the host platform or device null
microedition.profiles Names of all supported profiles null
Listing 3.2 illustrates the retrieval of system properties in a MIDlet. The code expands the
example in Listing 3.1.
Listing 3.2 MIDlets have direct access to all four of the standard system properties
defined by the CLDC specification.
45
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
/**
Creates the "Hello world" program in J2ME MIDP.
Note that the class must be public so that the device
application management software can instantiate it.
*/
public class HelloWorld extends MIDlet
{
...
public void startApp()
{
// Create a Displayable widget.
form = new Form("Hello World");
// Add a string to the form.
String msg = "My first MIDlet!";
form.append(msg);
// This app simply displays the single form created
// above.
display = Display.getDisplay(this);
display.setCurrent(form);
printSystemProperties();
}
/**
Prints the values of the standard system properties
using the System.getProperty() call.
*/
protected void printSystemProperties()
{
String conf;
String profiles;
String platform;
String encoding;
String locale;
conf = System.getProperty("microedition.configuration");
System.out.println(conf);
profiles = System.getProperty("microedition.profiles");
System.out.println(profiles);
platform = System.getProperty("microedition.platform");
System.out.println(platform);
encoding = System.getProperty("microedition.encoding");
System.out.println(encoding);
locale = System.getProperty("microedition.locale");
System.out.println(locale);
System.out.println();
}
46
}
Notice the addition of the call to the method printSystemProperties() at the end of the
startApp() method. This method simply retrieves and prints to standard output the values of
the five standard MIDP system properties. The data that the program writes to standard output is
shown next:
CLDC-1.0
MIDP-1.0
j2me
ISO-8859-1
en_US
The fourth line of the output just reproduced indicates the character encoding set that the current
CLDC/MIDP platform implementation uses. The last line of the output indicates the current locale.
Locale specifications include two parts: The first part indicates the language setting, while the
second part indicates the country code. The International Standards Organization (ISO) publishes
two standards that define the set of accepted values for language and country codes. You can find
references to these documents in the References appendix at the end of this book.
In the simple example shown in Listing 3.2, I show only how you could retrieve these values. In
subsequent chapters, I'll show examples of how you can use these values for practical applications.
455 times read

Related news

» Application Properties
by admin posted on Sep 26,2007
» System Properties
by admin posted on Jul 08,2007
» MIDlet Program Structure
by admin posted on Sep 26,2007
» The MIDP UI Component Model
by admin posted on Sep 26,2007
» The HttpConnection Interface
by admin posted on Jul 08,2007


More Top News
Cisco Wireless Networking
Most Popular
Featured Author