Java Reference
In-Depth Information
Tip On the topic of cleaning up after yourself, it is always a good idea when programming in a small plat-
form such as MIDP to set any object references to null as soon as you finish using them. Doing so will help
the garbage collector to perform its job.
No Reflection
CLDC does not support the Reflection API. The target devices of CLDC/MIDP are simply too
small to allow it. Although most developers don't need to use reflection directly, this omission
has important implications. Without reflection, no Remote Method Invocation (RMI) is possible.
Without RMI, JINI is not possible. Therefore, bare-bones CLDC/MIDP implementations cannot
run JINI. If you want to run JINI, you'll need to investigate one of the larger J2ME profiles, most
likely the Personal Profile (see Chapter 1) and the RMI Optional API (JSR 66).
No Native Methods
Native methods are not supported in CLDC (and, by extension, MIDP). The specification does
not support a way to access native device methods from Java. Although the MIDP implemen-
tation does, of course, include native methods, they are compiled into the implementation
itself. Applications cannot define new native methods.
Don't worry about losing access to platform-specific features, however, because device
vendors are likely to implement proprietary APIs in addition to MIDP. For details, check the
developer web site of the manufacturer or network carrier of your device. Bear in mind that
your use of vendor- or device-specific APIs will limit the audience of your application. In
certain instances (games, for example), it makes sense to distribute multiple versions of an
application targeted at specific devices.
No User Classloading
As we discussed in Chapter 1, one of the strengths of the Java platform is the ability to load
classes at runtime. Unfortunately, because of resource constraints and security concerns, CLDC
does not allow you to define your own classloaders. The application manager that runs MIDlets
has a classloader, but you cannot access it or use it yourself in any way.
Multithreading
Using threads is much as you remember it from J2SE, as long as you keep things simple. Creating
new threads, starting them, and using the handy java.lang . Runnable interface are the same as
in J2SE. One important omission in CLDC 1.0 is the interrupt() method, which is not present
in the java.lang.Thread class. In CLDC 1.1, the interrupt() method is available.
The pause() , resume() , and stop() methods (which are deprecated in the J2SE SDK) are
also absent. Thread groups and daemon threads are not supported in CLDC/MIDP; thread
naming is not supported in CLDC 1.0 but is available in CLDC 1.1.
 
Search WWH ::




Custom Search