Skip to main content

Java ME + SE Application Development

2 replies [Last post]
len00x
Offline
Joined: 2007-12-15
Points: 0

Hello,

I want to implement a multi-platform application which should run on common devices using Java SE and on mobile ones using Java ME.
The main functionality can be easily implemented for both. But some things, like GUI or access to other interfaces (e.g. bluetooth) are very different between SE and ME.
What's the best way to develop such multi-plattform applications? I have planned to encapsulate ME/SE specific functionality into classes sharing a common interface. Is there something similar like the "#IFDEF" in C++?

Best regards,

P.S: I am using Eclipse 3 for development at the moment.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sfitzjava
Offline
Joined: 2003-06-15
Points: 0

I have seen demos of Netbeans supporting a feature much like #IFDEF.... but didn't java get started as a way to avoid this type of thing?! Of course and there is very simple and ObjectOriented ways to do this.

I wrote a project called Microbus out in the dev.java.net repository that runs on both ME and SE. It can determines the platform it is on or can be told by the constructor, and then loads the implementation classes accordingly. In fact it optimizes for SE by using an ArrayList while on ME it has to use Vector. All of that without having to code any platform specific logic or special preprocessors.

In addition you can use ant to build and load only those classes specific to the platforms needs, thus reducing the code size.

As for Bluetooth another java.net project Marge has your back. It is the JSR82 implementation for JavaSE. Bruno Ghisi wrote about it back in this blog entry(1).

When developing GUI for ME if you use the CustomItem you end up writing a class that looks very much like a Java Component. The difference here is that in one case you extend CustomItem, and in the other you extend JComponent, or Component. To address this you can have wrapper classes which contain a painter class, and are in the same package as their other platform (SE/ME) counterpart. The painter class is common to for both ME and SE, while the wrapper is platform specific, but turns out to be nothing more than an adapter pattern.

Friends don't let friends use #IFDEF. Trust me to debug code like that is a nightmare without stepping through each line to determine what path is really being taken.

Best wishes,
-Shawn

(1)-http://weblogs.java.net/blog/brunogh/archive/2007/09/jsr_82_is_not_o_1.html

Message was edited by: sfitzjava

terrencebarr
Offline
Joined: 2004-03-04
Points: 0

Hi,

There are a number of things to consider, in particular that the user interaction will be very different between desktop and a mobile device - meaning that even if you use the same UI toolkit you will need to be very conscious about screen elements, layout, traversal, input methods, etc.

But the toolkit part of the job got much easier with the introduction of LWUIT (https://lwuit.dev.java.net/). Currently the library is built for MIDP platforms but it can be ported to Java SE as well giving you a common toolkit across multiple platforms. In fact, we have an alpha version of LWUIT for use in the LWUIT resource editor tool but in order to use LWUIT for general applications on Java SE that port needs more work. But using LWUIT as the common toolkit layer for all your platforms would simplify things a lot.

As for conditional compilation - Java of course doesn't support that directly, but there are multiple external (preprocessing-)tools that do. I am not sure which of these work with Eclipse but NetBeans certainly is a good choice and supports "configurations" and "abilities" and has conditional compilation features built-in that preprocess the application code based on the selected configurations. It works quite well - you should give it a try.

Hope that helps. Cheers,

-- Terrence