<< July 2012 | Home | September 2012 >>

Java Maps and load factors

When writing Java code be that for standalone Java, Domino agents or even XPages you often need a data structure to map keys to values. In Java this is a map (java.util.Map) and it works much like a List in LotusScript. Maps are used a lot but since Map is an interface you need an implementation whih is most often a java.util.HashMap.

The way to construct a HashMap is using one of the constructors and if you are like me a couple of months ago you just use the default constructor that is the one that doesn't take any arguments. Now this is well and fine if you know what you're doing. Most times the use of the default constructor is the wrong choice and can / will lead to memory being wasted and even worse is worse performance when adding more than 12 elements.

Lets take each in turn. The wasted memory comes from the classes used internally inside a HashMap to keep track of keys and values. For this post knowing that not filling the map (e.g. creating a HashMap using the default constructor and only stuffing 5 elements in it) will waste memory. A most excellent introduction is From Java Code to Java Heap. On a related note a key take-away from that article is to consider LinkedList instead of ArrayList if you not know the ultimate number of elements and hence cannot size correctly at object construction.

This memory waste can be avoided by always using the constructor that takes an initial size and hence size the Map correctly. Now it turns out that that's only part of the story as a HashMap also has what's called a "load factor". The load factor is a decimal number - i.e. a percentage - specifying how much the map may be filled before an extension and hence a full rehash of the keys take place. This means that with the default load factor of 0.75 you may only put 12 elements in a HashMap before it is extended and hence you take a performance hit. Again size your map correctly from the get go taking the load factor into consideration. The last point is that the size should always a power of 2 meaning that if you specify a size of 20 it will actually be 32.

A most nice discussion that caused me to look deeper into this can be hear on episode 391 of the Java Posse podcast (Java Posse #391 - Newscast for August 10th 2012) from 0:58 to 1:05.

The monkeysphere

This blog post has been lingering for a while but on This Week in Tech (TWIT) episode 344 between 1:06:50-1:11:00 there is an interesting discussion about Dunbar's number and the concepts of artificiel scarecity. Dunbar's number is used to discuss what's called the "monkeysphere" (What is the Monkeysphere?). It's very interesting and applies very well to our new networked and highly social World. I highly recommend listening to the audio and and reading the acticles if you're into social software.

Notes 8.x shortcut of the day

If you haven't docked the Open menu in Notes 8 on the left you want to be able to access it using the keyboard. As always the shortcut list is to the rescue. Ctrl-Shift-L shows a list of all shortcuts and in that list you find "Open list" which is what you want. The shortcut for "Open list" is Alt-B so put away that mouse and use the keyboard.

Update: Just relealized that it works just as well with the Open list docked.

Reusing IBM Connections Atom date formatting for custom widgets

In a recent IBM Connections project I needed to display dates in the same as IBM Connections does it that is full dates sometimes but also using "yesterday", "today" etc. Plus it needed to cater for the fact that the customer might at some future point in time allow the user to change the UI language. Coding this is tedious and would take quite some time so I wanted to figure out if IBM Connections had some libraries that could help me.

And it did.

By messing around in Firebug I found out that the way IBM Connections does it is by using a nifty JavaScript object called lconn.core.DateUtil.AtomDateToString. This object is actually a helper object that does two things - first it is able to convert an Atom date/time string (such as 2012-08-01T12:44:42.713Z) into a JavaScript Date object and then format it according to i18n settings and the language set in the UI.

Once I knew what to look for in the IBM Connections code it was simple enough. They do it by adding a hidden span-tag (CSS class "lotusHidden") with a special tagging CSS class called "formatDate" as shown below.

<span class="formatDate lotusHidden">
Then using dojo.query they locate the nodes with the formatDate CSS class, use the utility class to convert the Atom date string and then remove the "lotusHidden" CSS class to make it visible.
// expand dates
if (lconn && lconn.core && lconn.core.DateUtil && 
lconn.core.DateUtil.AtomDateToString) {
   dojo.query(".formatDate", root).forEach(function(item){

IBM THINK - the app

Explore how progress happens with the THINK exhibit app, for kids, innovators and forward thinkers.

From the very beginning, we've sought to improve the way we live. We've worked to make our world more efficient, accessible, and safe. While each leap of progress has required its own intelligence and hard work, many seem to follow a distinct, repeatable pattern.

The app is available in the Apple AppStore.

Tags : , , ,

Customizing the feature titles for IBM Connections mobile plus new URL handlers which are (almost) useful

Luis Benitez already blogged this (How To Customize the IBM Connections Mobile App for iOS, Android & BlackBerry) but I think it is so important that it bears mentioning again. With the latest update to IBM Connections (version CR2) you know have the option to customize the mobile apps using a new mobile-config.xml file. It allows you to configure settings to do with login and the general configuration of the app. An important point is also that it allows you to change the title of the features in the app which is great if you have change feature names in the web UI. We have customers that change some of the Danish translations (especially for Community because they feel that the Danish word really isn't representative of the feature) so making that feature name change apply to the mobile UI's are great.

To install the fixes simply download the IBM Connections CR2 jar-files and follow the steps from the technote (technote 1595154) to update IBM Connections. Please note that you need the newest update installer to perform the update.

As if this wasn't enough Chris Reckling recently blogged (Custom URLs in IBM Connections Mobile Apps) on the new URL handlers that were added to the Connections mobile apps for iOS and Android. This means you can add a link in an email to take you directly to Profiles or a profile as well as Communities or a community. The URL's are easy to use and pretty straight forward - to open John Does profile one could use ibmscp://com.ibm.connections/profiles?email=jdon%40example.com from anywhere on the app. Pretty neat.

There's also a URL handlers to configure the app for a user to allow for easier set up of the app.

The URL handlers are great but I think it is too bad they didn't add support for all features now they were at it. For instance having a direct link capability into Activities would be killer as it would allow you to add links to the email notifications that would take you to the mobile app instead of the web UI. Would have been soo cool and would have been something I could use now - having the Communities part is nice but I receive way more Activities notifications by email so a link capability there is worth much more to me. I hoping it will make it into the next update.


Just wanted to point people towards the heir to the "LotusKnows" twitter id which is a good way to stay on top of all things Lotus. The new id to follow is @IBMLotusND.

Tags :