Ubuntu

Flipped open the Wired magazine at a bookstore just now, and saw Ubuntu listed as one of the “Ways to ditch DRM”. Guess it’s another prompt for me to shift to the new OS. Been experiencing Ubuntu for the past few weeks and I felt that it’s a good OS for a Unix newbie like me.

I’ve already downloaded a copy of the OS itself, and phishie also gave me the free CD they sent him today. So now I’ll just have to backup my current stuff, pop the OS in and hope that there’s sufficient support for the hardware on my laptop…

Java Virtual Hosting

I had a client recently who wanted a functional website built. By functional I meant he cared more about the features of his site than the design. Due to the site requirements and manpower issues on my side I initially recommended a Java web host. However as I started out in search of one, I soon realize that it was more challenging than I perceived.

Firstly, there were few Java web hosts. Despite being free to implement, there were many more PHP and ASP web hosts. Several blogs reasoned that there was difficulty supporting it, such as sharing JVM instances and Tomcat restarting.

Secondly, many of those Java web hosts I found did not come cheap. Due to the abovementioned reason those that do support it charge higher for it. There were some that were cheap, but those had shared instances or did not really know how to maintain a servlet engine. Some don’t allow restarts.

Thirdly, there isn’t that much demand in Java virtual hosting. This also added to the cost factor. Projects small enough will usually go for PHP or alternative technologies that are easier to implement, manage and have cheaper virtual hosting solutions. Projects big enough to use Java would have purchased their own boxes to deal with it.

Given these factors I would probably switch the project to PHP or not take it at all than to risk an unstable deployment.

Anonymous Inner Class Constructors

Have been writing anonymous inner class for many years, when I suddenly hit a question today while writing a quick dirty test class. I needed to initialize stuff within the anon inner class, but how?

Found this link to teach me how to do that — just by using braces { }.

Musings of Laurie

Solved my problem, but had me thinking. I can’t call super() to call the parent constructor, what if I do not want to override the default constructor? After an hour of thinking, I realized the answer was right there too. To declare the anon inner class I have already specified which constructor to call before the declaration of the anon inner class, like this:


// i'm calling the JButton(String) constructor
new JButton("asd") {
  {
    // override constructor
  }
};

Certification doesn’t mean you know and remember everything!

Autoboxing

In Java SE 5, autoboxing was introduced to automatically convert between primitives and primitive wrappers. Primitives means basic types such as int, short, long, etc. Corresponding wrappers are Integer, Short, Long, and… nope, no Etc. To understand this, let’s look at the interaction between primitive and their wrappers before SE 5.


int originalInt = 3;

// convert primitive 3 to wrapper
Integer intWrapper = new Integer(originalInt);

// convert wrapper to primitive
int intPrimitive = intWrapper.intValue();

// store primitive in ArrayList
ArrayList list = new ArrayList();
list.add(new Integer(3));

// retrieve primitive in ArrayList
Integer wrapped = (Integer)list.get(0);
int unwrapped = wrapped.intValue();

// short-cut to retrieve primitive, less readable
int fastUnwrap = ((Integer)list.get(0)).intValue();

As shown above, a common usage of wrappers is when you need to store primitives as Objects. The ArrayList accepts an Object to be added, so it cannot add an int directly. However, we can make use of an Integer wrapper to put the number into the ArrayList, and take it out subsequently.

With SE 5, Java automatically generates necessary code to convert between primitives and wrappers during compilation. Let’s look at the new way with Autoboxing.


int originalInt = 3;

// convert primitive 3 to wrapper - Java will auto-convert
Integer intWrapper = originalInt;

// convert wrapper to primitive - Java will auto-convert
int intPrimitive = intWrapper;

// store primitive in ArrayList - generics added
ArrayList list = new ArrayList();
list.add(3);

// retrieve primitive in ArrayList
int unwrapped = list.get(0);

As you can see, all the scenarios have been simplified. Adding generics allows direct adding and retrieval of primitive types without any casting or wrapping. Despite being a useful convenient feature, programmers who pick up SE 5 directly without knowledge of the old way may not understand the rationale or even find it confusing (especially the ArrayList). Comparing and understanding the differences between the above code snippets will help in understanding Autoboxing.

System Quality

A lot of software is being produced today. Yet I personally feel that there are many that do not meet quality standards. Granted, there’s no perfect system and bugs will exist in systems, but how many are really satisfied with the system the wrote? How many admit to themselves that despite being launched, it’s not good at all?

Reading this reminds me of the comparison between completion and success. Systems that get to production are just completed but may be barely usable, or even helpful in the production environment. I’ve seen systems that are so difficult to use and buggy that manual processes have to be employed in tandem with the system. It actually results in double work instead of achieving any efficiency.

In this era where software houses compete to offer the lowest price to build a system; where anyone can pick up a book or read an online tutorial and be able to code; the quality of systems will only hit an all-time low. When that happens software will not be bought because it is cheaper (or even free), but at how stable it is and how well it is able to perform its intended function. This should help promote the necessity for the quality of system, and in turn, the quality of developers.