Vote 2

The Power of Ant (Build System)

August 27th, 2008

I am using Ant (Java based build system) for our project. Ant is an exceptionally powerful build system and should be the only build system you will ever need. You don't really need code monsters like Maven (or pile of …. as Bileblogger loves to say). With little effort here's what I achieved in few hours (aside from the obvious capability of compiling, running, building jar files etc.):
Read more (497 words) »

Vote 3

Java Quiz: Why StringBuilder Should be Used Instead of StringBuffer?

August 23rd, 2008

First tell me what is the best way to concatenate large number of String objects? Is it a + b?

Most Java developers know not to use a + b (+ operator) because of huge performance problems, they use StringBuffer instead. In fact I did some tests in the past which confirms this folklore. However some of you may not know there is new kid on the block - StringBuilder. Read more (116 words) »

Vote 4

How To Delete Property From java.util.Properties

August 23rd, 2008

This isn't a trick question. For a long time you couldn't delete a property from java.util.Properties class. In the recent versions too Java doesn't reveal that it has added the functionality. However as java.util.Properties now extends Hashtable, you can delete a property by:

Read more (67 words) »

Vote 2

Is Ruby very syntax rich? Do you like it? I don’t.

August 19th, 2008

I tried delving into Ruby couple of times in the past. Every time I had this weird feeling of what am I doing here when I am already very well conversant with a simpler language - Java, which gives me everything I need. Ruby just felt very syntax rich, may ways and interesting tricks to do stuff and so on.While these may be appealing to a script-kiddie, nice syntactical sugars do not help much in the long run or help you create robust code (unless you love flying whales and a service which fails every other day).

I am not afraid of developing CRUD interfaces nor do I find it time consuming. What value can I get from RoR? Every time I delve into Ruby & RoR, I come back feeling unsatisfied. What am I missing here?

Read more (315 words) »

Vote 1

Apache Ant: How To Set Property When Initially Unset

August 19th, 2008

Also: How To Flexibly Pass JVM parameters to Apache Ant Java (Runtime) Task

Apache Ant is an excellent Java based build & deployment system using XML configuration file. In Ant properties are extensively used to configure tasks, conditionally run targets and more. In short they are an intergral part of build system. My requirement was simple. I wanted to pass JVM arguments to the Java runtime. However sometime I wanted to invoke it without passing any special runtime arguments. Unfortunately jvmarg element doesn't like it when its value is an empty string or even a string with spaces. Finding no way to fool it, I then tried to find a way to set the property to something when it is initially not set (while invoking). This proved surprisingly hard to do. Here is an elegant (I think) solution I came up with. Read more (231 words) »

Vote 1

Apache Ant: How To Include Multiple Jar Files In A Single Jar File

August 19th, 2008

Apache Ant is an excellent and popular Java based build system. It has several built-in commands (tasks in Ant lingo) one of which allows you to create Jar file from your existing class file and resources. What if you wanted to include not just class files but selective contents of other jar files too and make a single big jar file?

Ant provides an undocumented way to include the contents of multiple jar files within a single jar file.
Read more (180 words) »

Vote 1

Db4o Note: Db4o.configure() != Db4o.newConfiguration()

August 19th, 2008

In earlier versions of Db4o we used Db4o.configure() to configure all Db4o database globally (across all ObjectContainer). However in 7.2 (and above) versions of Db4o Db4o.configure() has been deprecated and it is suggested to use Db4o.newConfiguration() instead. Unfortuanately they do not clearly mention anywhere that these two functions are not equivalent. I assumed they are equivalent like Db4o.set()is equivalent Db4o.store() or Db4o.get() is equivalent to Db4o.queryByExample().

Read more (201 words) »

Vote 2

Biggest Db4o Gotcha!

August 18th, 2008

Db4o is an excellent open source object database for Java & .NET platform by Carl Rosenberger's team. I highly recommend it for rapid prototyping and RAD. It transparently handles object storage and retrieval. Today I will talk about the single biggest gotcha in Db4o which is bound to stumble any newcomer as well as pros who haven't been using it in a while.

In Db4o you can create an complex objects with other objects as its member and Db4o will save them all like a champ with a single set() (now store()) method. So intuitively you try to use the same concept for updating the database. This is where you will stumble. Db4o by default doesn't recurse when updating an object.The stranger aspect is that when you save it to the database with a store or set and then retrieve it again it will appear to work fine. However after you close and re-open the database your data will be lost! This is the single most baffling feature I found in Db4o.

Read more (318 words) »

Vote 1

How To Debug Smack API (Java XMPP Library)

August 17th, 2008

Smack is an excellent Java XMPP Library. While creating a pubsub broker in XMPP I faced a strange issue where few messages were missing. I then found a simple way to debug the Smack library. Just start your JVM (java) with the following option:
Read more (81 words) »

Vote 1

How To Pass Command Line Arguments To Ant Task / Script

August 17th, 2008

Ant is a popular, high quality Java based build and deployment tool from Apache Foundation. You can invoke Java programs in ant using the java task. Optionally you may want to pass it command line arguments. Here is how you can do it.

Read more (89 words) »