Sun Java Solaris Communities My SDN Account Join SDN
 
FAQ

Downloading Code to a MIDP Device

 
 



Question

How do I download code to a device running MIDP on KVM?

  • I have a Java program (installed) that can download other Java classes and run them. Preferably the download would work over the wireless connection, but a wired installation is an option (albeit less desirable).

  • I went to talks at JavaOne which suggested on a device running MIDP on KVM, the security manager prevents the dynamic downloading and running of code. But I was new to all the different J2ME, KVM, MIDP, CLDC terms then, so I might have been confused. Can I do what I described above? Is there any way to come close to it?

Tip

This is actually a tough question to answer briefly because the answer is both yes and no.

KVM itself supports dynamic downloading, and loads all the classfiles (except those that have been "romized" in advance) into the Java heap dynamically at runtime.

However, CLDC and MIDP specifications restrict the scope of dynamic classloading, and allow an application to load classes only from its own JAR file. This restriction was added to CLDC and MIDP because CLDC and MIDP cannot afford to support the full Java 2 Platform, Standard Edition security model, and downloading classes from arbitrary locations could open various security holes in the absence of a security manager.

Here are the assumptions that lead to this restriction:

  • Single security domain. All classes running in a KVM run in a single security context. No class can be given more or less privileges. There would be no way for the code doing the downloading to restrict the privileges of the downloaded code. In addition, the fact that MIDP specifies that all classes come from a single JAR file extends the idea of a single security context to the entire application that gets loaded. It also makes the downloading and installation a bounded system, which is easier to manage from the device and user perspective.

  • No restriction on class loading. It is outside of the CLDC specification how classes get to the device, or how they are handled and made available to run. There are no classloaders; all class loading behavior is device specific.

It is possible that you might be able to accomplish what you want outside of the CLDC and MIDP specs. But the solution would not be portable. Note also that class loaders and security managers are supported by PersonalJava platform and JSR-0036 for the J2ME Connected Device Configuration. Those might be options for you to consider.

Acknowledgments

Many thanks to JDC member Antero Taivalsaari and Roger Riggs for contributing to this answer.

.
. . .
. Note: If you have a question to which you need an answer, try the Mobility Forums. You can read through the existing topics or register for your free Sun Developer Network membership and post new messages or threads. For more information, go to the Why Register page. .
.
.

Back To Top