Thursday, January 29, 2009

Blog Layout Template Change

I changed the layout of my blog to a white background, this is because some readers found it difficult to read the blog.

Hope the new template is okay :-)

Tuesday, January 27, 2009

Weekly Source Code: Strings Are Immutable

Happy New Year 2009! :)

The String type that is actually a class in both Java and C# are immutable meaning that once you create it, it can't get changed and manipulating it will create a new string object.

This is import for when you want to populate a string in a loop (like a for loop) since everytime it will create a new string that have a performance impact on your code.

For example:

String val = null;
for (int i = 0; i < 100; i++)
val += i;
val += ", ";

The code above will create a new string object everytime for 100 times, you might not see or notice the impact but it does have a performance impact (test it if you wish).

Its better to use a string builder/buffer class and then append the string values to it since the object is only created once.

For example:

StringBuilder val = new StringBuilder();
for (int i = 0; i < 100; i++)

The above C# code use the string builder without performance impact.

Note that in C# its called the StringBuilder class where in Java its the StringBuffer class both is similar in functionality.

Sunday, January 25, 2009

Back From Uganda

Ladies & Gents!

I had a good trip to Uganda and is back to work today :) I was off-sick for a week since I had malaria that damaged my liver but the malaria is gone now.

I will post some photos and a story soon.