Blog / 20080714 aQute - Software Consultancy
Search
*

Bnd Goes to Java 5!

Java 5 is like a good wine. Once you've learned to appreciate it, other wines, that you used to enjoy, taste bland. They did not change, they are still the same but suddenly you get lack the sparkle and that aftertaste. Though iterators were an improvement over enumerators, they now suddenly look clumsy.

I actually ported bnd to Java 5 last year (and warned any users) but I was dumb enough to also make a lot of other changes (when will I learn). I kept the 1.4 version current but ended up making more and more changes only in the 1.4 version. However, I am now going to move all of the bnd code to Java 5 and maintain one version.

Why do I like Java 5? Well, I am a strong believer of less is more and Java 5 seems to be significantly more compact than Java 1.4. Yes, I know generic constructors are overly verbose but static construction methods can help there quite well. And you only construct an object once. Using the object is really a lot less work because you do not have to cast. I also really like the for loop, you usually can get rid of a variable and a line per loop.

Obviously, some of the libraries are very nice as well. The concurrency library is very useful. However, within the OSGi we severely restrict ourselves. We only use the minimum execution environment and the foundation profile.

As an exercise, I ported the Java framework API to Java 5 and it really helped. You can do interesting things with the ServiceReference that make the usage of services type-safe. We are having discussions inside the OSGi how to work with generics for the next release. Interestingly, there is push-back. The key reason is Java 2 ME. Small devices are currently on Java 1.4 but have not made the move to Java 5. One of the strengths of OSGi is the focus on broad deployment. With OSGi you can write a bundle that runs from a 8Mb embedded device all the way to a mainframe running an experimental version of Java 7. For this reason, we actually distribute our class files in 1.3 compatible format. Unfortunately, the syntax changes that Java 5 brought are at odds with this model. It is impossible (with the standard compilers) to compile Java 5 code to Java 1.3 or even 1.4. I do not really understand why not, because all generic information is stored in attributes. Attributes were designed to be ignored on earlier versions.

This is just one of the many places where it is visible that the VM is not very modular. Many of the additions made to Java 5 could have been released as an extension library instead of this once every 3 years big bang. The concurrency libs are very useful on Java 1.4, why not provide them there as well?

So it is good that we have the discussion inside the OSGi. The portability that OSGi provides has great value. However, for bnd it is high time to move on!

  Peter Kriens
Copyright 2006 aQute SARL, All Rights Reserved