Making a list

…and checking it twice?

Today just a quick post about making Lists in Java. It’s something I find myself doing quite often, especially when writing unit tests.

The classic way of intializing a List would be:

Item item1 = new Item();
Item item2 = new Item();
Item item3 = new Item();

List<Item> items = new ArrayList<Item>();
items.add( item1 );
items.add( item2 );
items.add( item3 );

Now, a while ago I learned a new trick: the double-brace:

List<Item> items = new ArrayList<Item>() {{
    add( item1 );
    add( item2 );
    add( item3 );

This actually created an anonymous subclass of ArrayList, and allows you to call the methods straight on it.

But… the most elegant way I found actually requires nothing special, just the API:

List<Item> items = Arrays.asList(
    item1, item2, item3 );

This takes advantage of the fact that Arrays.asList() takes its parameters as a generic var-args array.

Who said Java couldn’t be elegant every once in a while? :P

On free, open and libre…

I have undertaken a bit of an experiment in releasing PageTurner: it’s free as in speech but not as in beer.

I’d like to share my reasoning behind it and the results so far.


Currently there are 3 versions of PageTurner:

  1. OSS Version: Available for download on my site or by building the source yourself. Also downloadable through the excellent F-Droid app-store. Free both as in beer and speech.
  2. Ad-supported version: free as in beer and available in the Android Market
  3. Paid version: available in the Android Market for 50 eurocents, or 99 dollar-cents (I wouldn’t let me go lower).

Now, you might have noticed that though this app is completely Free (libre) and open source, it actually looks like every other commercial, closed-source app in the market with an ad-supported version and a paid “pro” version.

What is free software?

Before I get into my reasoning for going with this pricing scheme, I’d like to take a little side-trip into my views on the benefits of free software.

Often people think it just means “software available at no cost”, leading to the distinction between free as in beer or free as in speech. In Dutch we translate it as “vrije” software, meaning it grants you (the user) freedom. But how does it do that?

  1. You (or someone you trust) can inspect the software by reading the source code to make sure it doesn’t do anything you don’t want it to. If the software sends your data to some marketing agency or tries to take over your machine, it will be there in the code.
  2. If you want, you can adapt the software to your needs and change its behaviour to better suit you.
  3. You can learn how the software works and use it as a basis for your own work. Some restrictions may apply here.
  4. You may share the software with your friends, both in the original version or with the changes you have made.

The first point might sound esotheric since you probably don’t want to go through the hassle of checking and building the software. You don’t always need to though. The F-Droid Market I mentioned earlier make it their business to check apps and build them from source so that they can be 100% sure that no nasty stuff creeps in there.

OSS/Free Pricing

Now, as you might have noticed, none of the points about free software say anything about price. By now you’ll probably be saying: “yeah, true but every single open source app I know is downloadable free of charge!”, and you’d be absolutely right. The reason for that of course is mainly point 4: it doesn’t make much sense to charge people to get your software if they’re then allowed to give it away for free. In a sense you’d be competing with yourself.

Applied to PageTurner

It is my personal belief that people aren’t unwilling to pay for things they like, as long as you make it easy and convenient for them. In fact, they’re generally willing to pay to save themselves some work. On the other hand there’s also a group of people that will gladly put in some effort if it saves them some money. I decided to try and accommodate both groups, while still honouring all the ideals behind free software and hopefully recouping some of the expenses I incur in running the backend-services for PageTurner.

So, how does it work? PageTurner really consists of 2 parts:

  • An Android reader app
  • A back-end server to store sync-points

Both of these components are Free with the source code available on my Github page. That means that if you want to you could easily:

  1. set up your own back-end server
  2. change 1 line of source code in the Android app
  3. Compile/package the android app and install it on your devices

You’d be up and running with 100% functionality without having to pay anyone, except perhaps for the server.

If however you’re like most people you will not want the hassle of setting up your own server. That’s why I also run a back-end server and my builds of the Android app point towards this server. If you get a build from the market, it will be able to connect to this server out of the box.

If you get the OSS version from any place, it will require an Access Key to connect to the server. Right now I’m giving anybody who contributes to the project in any way (donations, translations, testing) a free key. I might eventually set up a page where you can buy a key through PayPal in an automated way.

All 3 versions of the app are functionally identical. The only difference is that the OSS version has a preference where you can input your key, and this field is missing from the Ad-supported and Pro version. The keys are checked by the server against the keys in its database and depending on that your requests will be processed or refused.

I believe this gives users the full spectrum of freedom ranging from setting up everything yourself and keeping your wallet closed to having someone (me) take care of everything and paying for that either by watching ads or through a small one-time fee.

The Big Question

To me this seemed like a good way to find a balance between generating some revenue from my app and honouring my belief in Free Software. I have seen very little apps try anything similar though, so I’m very curious to your opinion about my strategy.

So far responses have been positive, but I invite critical thinking. Just keep the language nice :)

A quick Java puzzle

OK, no peeking…

Say I have a class A and a class B:

public class A {
	protected static Integer value = 5;
	public static Integer getValue() {
		return value;
public class B extends A {	
	public static void changeValue() {
public class Test {
	public static void main(String argv[]) {		

Now… what does this print?
Read the full post »

Full-blooded domain models

I’m an OO-guy, plain and simple. I like a smart domain-model because it just fits the way I think about software design. It generally also makes it a hell of a lot easier to test your business logic.

So.. why do we see the Anemic domain model so often? In my opinion O/R mapping is a big culprit. Let me explain.

Read the full post »

What’s your perfect e-reader?

If you have been anywhere near me in the last couple of weeks, you probably know I’m writing an Android e-book reader app.

Now, I have been cranking out features on a fairly good pace and I have a lot more stuff planned. The thing is: I know what’s important to me as a reader, but I’d like to know what’s important to other users as well.

So… I put the question to you:

If you could dream up your perfect e-reader app, what features would it have?

Read the full post »

Introducing: PageTurner

A new synchronizing e-book reader for Android.

This post is no longer updated. Check here for the PageTurner download page.

Update: the code is now on GitHub.

Those of you that know me or follow my Goodreads know that I’m a fairly avid reader. As avid as I may be though, my wife manages to read a lot more books than I do. Does she read faster? Very well possible, but that’s not the reason. She can read so much more because her primary reading device is her phone, so she can catch a lot of little reading moments.

I used to read on a Sony e-reader and switched to an Android tablet at the start of the year. I have my tablet with me quite often, but still not exactly all the time. I’ve tried reading on my phone on those times that I did not have my tablet, but it soon got tiresome to find the point I had left off reading and then do the same thing again once I grabbed my tablet again.

I figured there should be some way to automatically keep my reading progress in sync on both devices. What I found was a work-around for FBReader that could kind of do it, but it required your device to be rooted. So… what’s a geek to do? Write your own of course! :)

Read the full post »

Self-documenting Service interfaces

I’m mocking up a quick example project for a presentation about Fitnesse and when I had to draw up some quick business services I was once again reminded of how much I hate Exceptions.

Let me explain: Exceptions are a pain to create and to handle… often you end up throwing some kind of generic BusinessException and stuffing a String in there or at the most making a subclass for the business method. Making a different Exception for each thing that can go wrong is not only tiresome to write, it also makes using the interface a pain because of the try {} catch structure needed.

So… here’s what I came up with :)

Read the full post »

Just a quick laugh..

This blog doesn’t always have to be about serious or geeky stuff… so here’s something that made me laugh. It is April 1st after all!

You probably all know this lady and her song about sharks:

… but I also stumbled on this Dutch version, which made me smile with it’s amateur charm.. it’s so bad it’s good :)

So… see you next time :)


Just a quick rant this morning, something that occurred to me in the shower….

Object-oriented languages were hailed as a great advance in software engineering because they helped you create “generic and reusable components”…. great, but I call BS.

This little nugget of wisdom has been around for years and is still taught at many universities… and it’s also the cause of lots of pain and misery in software projects. Why? Because generic and reusable components suck.

Read the full post »

Splattering brains on the Wii :)

My Wii had been gathering more and more dust, since I spend most of my gaming time (which isn’t much to begin with) on the XBox360… but no more :) I picked up House of the Dead Overkill for the Wii and learned how shooting zombies with your wife can be a truly binding experience…
Read the full post »

  • Google ads