Posts Tagged ‘mobile’

J2ME/MIDP: The hard parts (1)

Thursday, September 24th, 2009

This is going to be a series of articles about things that don’t go smooth when moving from J2SE to developing for J2ME in my case especially MIDP. It’s not intended to blame the guys behind J2ME and the MIDP APIs for what they’ve done – instead it’s intended to be a collection of common problems or traps developers used to J2SE could fall in.

First up: Simple often-used utility functions:

static boolean Boolean.parseBoolean(String s) missing

The lack of this method is really annoying once you have to cope with reading in configuration values. Many of them will be in boolean-like format but you will have no method to parse them into booleans.

A very simple re-write of this method could look like that:

public static boolean parseBoolean(String s) {
return s.equalsIgnoreCase(“true”) || s.equalsIgnoreCase(“yes”);
}

Since it could be so easy to write this function (and Integer.parseInt() still exists which seems more complex to me) I don’t understand why it has not been included.

String[] String.split() missing

Every now and then one will have to parse some input – and this is where split() comes in handy. Would have come. Luckily String.indexOf() exists which allows for the following re-implementation of String.split():

public static String[] split(String source, String separator) {
Vector nodes = new Vector();

int index = source.indexOf(separator);
while(index >= 0) {
nodes.addElement(source.substring(0, index));
source = source.substring(index + separator.length());
index = source.indexOf(separator);
}
nodes.addElement(source);

String[] result = new String[nodes.size()];
if(nodes.size() > 0) {
for(int i = 0; i < nodes.size(); i++) {
result[i] = (String)nodes.elementAt(i);
}
}

return result;
}

All in all this might not sound too bad since both “re-implementations” were pretty easy to write. But: Since Boolean and String are declared abstract you can’t subclass and by that extend those. So you will have to declare a “tool”-class for them – not the most elegant way in my opinion.

So these are methods I think many developers will use very regularly but J2ME/MIDP doesn’t provide them.

New Team. New Challenges.

Tuesday, September 22nd, 2009

In early September I started working in a new team. The main reason for this step was change itself. Since I’m still in training it’s always great to see something different and new. This helps me complete my picture of software development and also takes me to another company with business processes slightly different from those I’m used to.

I’m still a software developer. But the kind of software I’m developing has changed and so have my experiences and learnings. Of course they did not change completely – but they changed focus. For the last year I’ve mostly been developing server side applications combined with HTML/CSS/JavaScript. Although I would not see them as very large they were certainly more complex and more demanding on hardware than what I’m developing now. That thing which I’m entirely new to is development for mobile. This basically means developing for devices like the iPhone, Blackberry or Android. For me, this is a great opportunity. It’s helping me a lot to fine-tune my programming skills. Here are some examples of things I had already expected and some things I just experienced:

  • memory and processing power is so limited compared to desktop or even server environments (iPhone 3G: ~400MHz, 128MB of RAM, no swap! – Desktop: multi-core 1-2GHz, GB’s of RAM)
  • (only for the iPhone) memory management can be a tricky if you’ve always been developing in a garbage collected environment like the Java platform
  • SDKs like the iPhone SDK or Android SDK rely heavily on software design patterns. A developer using those SDks is at a loss if he’s does not only understand those but is also able to extend and re-use them

There are many things that come with this change for developers. First: one must be very careful with creating objects. Very careful! Even if you’re on platforms like Android or Blackberry which feature Java and by thus automatic Garbage Collection! Every object counts.

Those limitations and the way you deal with them really help developers get more experienced. By that it’s a great deal for both the company and me.

I’m looking forward to what comes next – and rest assured I will keep you updated about any further developments.