<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Maddox on J2EE</title>
	<atom:link href="http://maddoxonj2ee.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://maddoxonj2ee.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Wed, 24 Sep 2008 01:10:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='maddoxonj2ee.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Maddox on J2EE</title>
		<link>http://maddoxonj2ee.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://maddoxonj2ee.wordpress.com/osd.xml" title="Maddox on J2EE" />
	<atom:link rel='hub' href='http://maddoxonj2ee.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Iterate Through A HashMap</title>
		<link>http://maddoxonj2ee.wordpress.com/2008/09/24/iterate-through-a-hashmap/</link>
		<comments>http://maddoxonj2ee.wordpress.com/2008/09/24/iterate-through-a-hashmap/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 01:10:44 +0000</pubDate>
		<dc:creator>leonardodosdos</dc:creator>
				<category><![CDATA[Lessond Learned (In Software Development)]]></category>
		<category><![CDATA[HashMap]]></category>
		<category><![CDATA[Iterator]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[keySet()]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[Set]]></category>
		<category><![CDATA[TreeMap]]></category>

		<guid isPermaLink="false">http://maddoxonj2ee.wordpress.com/?p=15</guid>
		<description><![CDATA[Although HashMap is not an implementation of Collection, it can still be looped through using one of its methods, the &#8216;keyset()&#8217; method, which returns a set view of keys which contains an Iterator object. For example, if I have a HashMap object &#8216;myHashMap&#8217; that contains &#60;Integer, String&#62; to loop through it: Set&#60;Integer&#62; keys = myHashMap.keySet(); [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maddoxonj2ee.wordpress.com&amp;blog=4946554&amp;post=15&amp;subd=maddoxonj2ee&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Although HashMap is not an implementation of Collection, it can still be looped through using one of its methods, the <b>&#8216;keyset()&#8217;</b> method, which returns a set view of keys which contains an Iterator object.</p>
<p>For example, if I have a HashMap object <b>&#8216;myHashMap&#8217;</b> that contains &lt;Integer, String&gt; to loop through it:</p>
<pre style="border:1px dashed rgb(153,153,153);overflow:auto;font-family:Andale Mono,Lucida Console,Monaco,fixed,monospace;color:rgb(0,0,0);background-color:rgb(238,238,238);font-size:12px;line-height:14px;width:100%;padding:5px;">
<code>
Set&lt;Integer&gt; keys = myHashMap.keySet();
Iterator&lt;Integer&gt; iterator = keys.iterator();
Integer key;
String value;
while (iterator.hasNext()) {
 key = iterator.next();
 value = myHashMap.get(key);
}
</code>
</pre>
<p>
If you want your keys to be ordered in a certain way, use TreeMap instead of HashMap.<br />
<br />
Hope this helps!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/maddoxonj2ee.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/maddoxonj2ee.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/maddoxonj2ee.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/maddoxonj2ee.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/maddoxonj2ee.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/maddoxonj2ee.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/maddoxonj2ee.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/maddoxonj2ee.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/maddoxonj2ee.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/maddoxonj2ee.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/maddoxonj2ee.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/maddoxonj2ee.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/maddoxonj2ee.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/maddoxonj2ee.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maddoxonj2ee.wordpress.com&amp;blog=4946554&amp;post=15&amp;subd=maddoxonj2ee&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://maddoxonj2ee.wordpress.com/2008/09/24/iterate-through-a-hashmap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eeb1e7261ef4265841f0a395781e4928?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leonardodosdos</media:title>
		</media:content>
	</item>
		<item>
		<title>Avoid Array Expansion</title>
		<link>http://maddoxonj2ee.wordpress.com/2008/09/24/avoid-array-expansion/</link>
		<comments>http://maddoxonj2ee.wordpress.com/2008/09/24/avoid-array-expansion/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 01:10:09 +0000</pubDate>
		<dc:creator>leonardodosdos</dc:creator>
				<category><![CDATA[Lessond Learned (In Software Development)]]></category>
		<category><![CDATA[array expansion]]></category>
		<category><![CDATA[ArrayList]]></category>
		<category><![CDATA[HashMap]]></category>
		<category><![CDATA[HashSet]]></category>
		<category><![CDATA[HashTable]]></category>
		<category><![CDATA[initial capacity]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[StringBuffer]]></category>
		<category><![CDATA[StringBuilder]]></category>
		<category><![CDATA[Vector]]></category>

		<guid isPermaLink="false">http://maddoxonj2ee.wordpress.com/?p=13</guid>
		<description><![CDATA[I&#8217;ve also learned about defining the initial capacity for ArrayList, Vector, HashMap, HashSet, HashTable, and even StringBuffer and StringBuilder objects. For example when we initialize an ArrayList we usually do this: ArrayList myList = new ArrayList(); There&#8217;s really nothing wrong with it except that if the number of contents we add inside the ArrayList exceeds [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maddoxonj2ee.wordpress.com&amp;blog=4946554&amp;post=13&amp;subd=maddoxonj2ee&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve also learned about defining the initial capacity for ArrayList, Vector, HashMap, HashSet, HashTable, and even StringBuffer and StringBuilder objects.</p>
<p>For example when we initialize an ArrayList we usually do this:<br />
</p>
<pre style="font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;color:#000000;background-color:#eee;font-size:12px;border:1px dashed #999999;line-height:14px;overflow:auto;width:100%;padding:5px;">
<code>
ArrayList myList = new ArrayList();
</code>
</pre>
<p>
There&#8217;s really nothing wrong with it except that if the number of contents we add inside the ArrayList exceeds the default initial capacity which is ten (10), a larger array is created and the contents of the old array will be passed to the new array.  The old array will then be reclaimed by the garbage collector.<br />
<br />
This is an expensive process and unnecessary.<br />
<br />
The solution?<br />
<br />
Try approximating the number of contents that would be contained by your array.<br />
</p>
<pre style="font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;color:#000000;background-color:#eee;font-size:12px;border:1px dashed #999999;line-height:14px;overflow:auto;width:100%;padding:5px;">
<code>
ArrayList myList = new ArrayList(<b>32</b>);
</code>
</pre>
<p>
It is better that your array capacity will be bigger than the actual contents than have it smaller.<br />
<br />
Hope this helps!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/maddoxonj2ee.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/maddoxonj2ee.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/maddoxonj2ee.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/maddoxonj2ee.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/maddoxonj2ee.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/maddoxonj2ee.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/maddoxonj2ee.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/maddoxonj2ee.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/maddoxonj2ee.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/maddoxonj2ee.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/maddoxonj2ee.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/maddoxonj2ee.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/maddoxonj2ee.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/maddoxonj2ee.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maddoxonj2ee.wordpress.com&amp;blog=4946554&amp;post=13&amp;subd=maddoxonj2ee&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://maddoxonj2ee.wordpress.com/2008/09/24/avoid-array-expansion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eeb1e7261ef4265841f0a395781e4928?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leonardodosdos</media:title>
		</media:content>
	</item>
		<item>
		<title>Detecting Empty Strings</title>
		<link>http://maddoxonj2ee.wordpress.com/2008/09/24/detecting-empty-strings/</link>
		<comments>http://maddoxonj2ee.wordpress.com/2008/09/24/detecting-empty-strings/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 01:09:16 +0000</pubDate>
		<dc:creator>leonardodosdos</dc:creator>
				<category><![CDATA[Lessond Learned (In Software Development)]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[optimize]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[string detection]]></category>

		<guid isPermaLink="false">http://maddoxonj2ee.wordpress.com/?p=11</guid>
		<description><![CDATA[This is another common way of detecting empty strings that we see out there &#8211; which can be improved: if (myString.equals("") { //code } This is faster: if (myString.length() == 0 { //code } Hope this helps.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maddoxonj2ee.wordpress.com&amp;blog=4946554&amp;post=11&amp;subd=maddoxonj2ee&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is another common way of detecting empty strings that we see out there &#8211; which can be improved:<br />
</p>
<pre style="font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;color:#000000;background-color:#eee;font-size:12px;border:1px dashed #999999;line-height:14px;overflow:auto;width:100%;padding:5px;">
<code>
if (myString.equals("") {
    //code
}
</code>
</pre>
<p>
This is faster:<br />
</p>
<pre style="font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;color:#000000;background-color:#eee;font-size:12px;border:1px dashed #999999;line-height:14px;overflow:auto;width:100%;padding:5px;">
<code>
if (myString.length() == 0 {
    //code
}
</code>
</pre>
<p>
Hope this helps.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/maddoxonj2ee.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/maddoxonj2ee.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/maddoxonj2ee.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/maddoxonj2ee.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/maddoxonj2ee.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/maddoxonj2ee.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/maddoxonj2ee.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/maddoxonj2ee.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/maddoxonj2ee.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/maddoxonj2ee.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/maddoxonj2ee.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/maddoxonj2ee.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/maddoxonj2ee.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/maddoxonj2ee.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maddoxonj2ee.wordpress.com&amp;blog=4946554&amp;post=11&amp;subd=maddoxonj2ee&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://maddoxonj2ee.wordpress.com/2008/09/24/detecting-empty-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eeb1e7261ef4265841f0a395781e4928?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leonardodosdos</media:title>
		</media:content>
	</item>
		<item>
		<title>Avoid Method Invocation In Loop</title>
		<link>http://maddoxonj2ee.wordpress.com/2008/09/24/avoid-method-invocation-in-loop/</link>
		<comments>http://maddoxonj2ee.wordpress.com/2008/09/24/avoid-method-invocation-in-loop/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 01:07:55 +0000</pubDate>
		<dc:creator>leonardodosdos</dc:creator>
				<category><![CDATA[Lessond Learned (In Software Development)]]></category>
		<category><![CDATA[accident]]></category>
		<category><![CDATA[ArrayList]]></category>
		<category><![CDATA[infinite loop]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[optimize]]></category>
		<category><![CDATA[server crash]]></category>
		<category><![CDATA[speed]]></category>

		<guid isPermaLink="false">http://maddoxonj2ee.wordpress.com/?p=9</guid>
		<description><![CDATA[This is probably the most common thing that we see out there: for (int i = 0; i &#60; list.size(); i++) { //some code here } So what&#8217;s wrong with it? Well, making the method invocation list.size() as part of the loop will force it to be executed at least as many times as the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maddoxonj2ee.wordpress.com&amp;blog=4946554&amp;post=9&amp;subd=maddoxonj2ee&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is probably the most common thing that we see out there:<br />
</p>
<pre style="font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;color:#000000;background-color:#eee;font-size:12px;border:1px dashed #999999;line-height:14px;overflow:auto;width:100%;padding:5px;">
<code>
for (int i = 0; i &lt; <b>list.size()</b>; i++) {
    //some code here
}
</code>
</pre>
<p>
So what&#8217;s wrong with it?  Well, making the method invocation <b>list.size()</b> as part of the loop will force it to be executed at least as many times as the loop body.  This causes unnecessary overhead.<br />
<br />
This is a much better way (but should be done with caution):<br />
</p>
<pre style="font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;color:#000000;background-color:#eee;font-size:12px;border:1px dashed #999999;line-height:14px;overflow:auto;width:100%;padding:5px;">
<code>
for (int i = 0; i &lt; size; i++) {
   //some code here
}
</code>
</pre>
<p>
Unless the method invocation returns a different value each time it is called, the above method should be done.<br />
<br />
Is there danger in doing this?  Yes.  There was one time when I was editing someone else&#8217;s code, in my haste and carelessness due to time pressure, I blindly followed this rule which resulted in an <b>infinite loop</b>!.<br />
</p>
<pre style="font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;color:#000000;background-color:#eee;font-size:12px;border:1px dashed #999999;line-height:14px;overflow:auto;width:100%;padding:5px;">
<code>
int length = list.length();
while (length == 0) {
    //code
}
</code>
</pre>
<p>
I didn&#8217;t notice the length of the ArrayList was changing each time inside the loop!  As you know this is an infinite loop and would cause harm to the application&#8217;s performance even a server crash.<br />
<br />
But good thing it was fixed before deploying.  Lesson learned.<br />
<br />
In summary, placing method invocations outside of the loop is an ideal practice but should be done with caution.  It will only call the method once rather than calling it as many times as the loop body which saves a lot of overhead and memory.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/maddoxonj2ee.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/maddoxonj2ee.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/maddoxonj2ee.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/maddoxonj2ee.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/maddoxonj2ee.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/maddoxonj2ee.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/maddoxonj2ee.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/maddoxonj2ee.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/maddoxonj2ee.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/maddoxonj2ee.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/maddoxonj2ee.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/maddoxonj2ee.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/maddoxonj2ee.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/maddoxonj2ee.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maddoxonj2ee.wordpress.com&amp;blog=4946554&amp;post=9&amp;subd=maddoxonj2ee&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://maddoxonj2ee.wordpress.com/2008/09/24/avoid-method-invocation-in-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eeb1e7261ef4265841f0a395781e4928?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leonardodosdos</media:title>
		</media:content>
	</item>
		<item>
		<title>StringBuilder vs. StringBuffer</title>
		<link>http://maddoxonj2ee.wordpress.com/2008/09/24/stringbuilder-vs-stringbuffer/</link>
		<comments>http://maddoxonj2ee.wordpress.com/2008/09/24/stringbuilder-vs-stringbuffer/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 01:06:29 +0000</pubDate>
		<dc:creator>leonardodosdos</dc:creator>
				<category><![CDATA[Lessond Learned (In Software Development)]]></category>
		<category><![CDATA[concatenation]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[StringBuffer]]></category>
		<category><![CDATA[StringBuilder]]></category>
		<category><![CDATA[sychronize]]></category>

		<guid isPermaLink="false">http://maddoxonj2ee.wordpress.com/?p=7</guid>
		<description><![CDATA[Use StringBuilder instead of StringBuffer specially with loops if there is no need for synchronization. ex. StringBuffer buffer = new StringBuffer(““); for (int i = 0; i &#60; size; i++) { buffer.append(“Some text here...“); } use StringBuilder builder = new StringBuilder(““); for (int i = 0; i &#60; size; i++) { buffer.append(“Some text here...“); } [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maddoxonj2ee.wordpress.com&amp;blog=4946554&amp;post=7&amp;subd=maddoxonj2ee&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Use StringBuilder instead of StringBuffer specially with loops if there is no need for synchronization.<br />
<br />
ex.<br />
</p>
<pre style="font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;color:#000000;background-color:#eee;font-size:12px;border:1px dashed #999999;line-height:14px;overflow:auto;width:100%;padding:5px;">
<code>
StringBuffer buffer = new StringBuffer(““);
for (int i = 0; i &lt; size; i++) {
    buffer.append(“Some text here...“);
}
</code>
</pre>
<p>
use<br />
</p>
<pre style="font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;color:#000000;background-color:#eee;font-size:12px;border:1px dashed #999999;line-height:14px;overflow:auto;width:100%;padding:5px;">
<code>
StringBuilder builder = new StringBuilder(““);
for (int i = 0; i &lt; size; i++) {
    buffer.append(“Some text here...“);
}
</code>
</pre>
<p>
They both have very similar functionalities except that StirngBuffer is synchronized and will cost more overhead compared to StringBuilder w/c is not.  StringBuffer on the other hand must be used when there are threading issues.<br />
<br />
Avoid using String to concatenate in loops.<br />
<br />
ex.<br />
</p>
<pre style="font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;color:#000000;background-color:#eee;font-size:12px;border:1px dashed #999999;line-height:14px;overflow:auto;width:100%;padding:5px;">
<code>
String text = “”;
for (int i = 0; i &lt; size; i++) {
    text += text + “ more text...”;
}
</code>
</pre>
<p>
Doing so calls a StringBuffer every time there is a String to concatenate and thus costing extra and unnecessary overhead.<br />
<br />
There are a lot of articles out there that you can search through Google explaining this in detail and showing benchmarks.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/maddoxonj2ee.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/maddoxonj2ee.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/maddoxonj2ee.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/maddoxonj2ee.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/maddoxonj2ee.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/maddoxonj2ee.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/maddoxonj2ee.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/maddoxonj2ee.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/maddoxonj2ee.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/maddoxonj2ee.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/maddoxonj2ee.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/maddoxonj2ee.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/maddoxonj2ee.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/maddoxonj2ee.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maddoxonj2ee.wordpress.com&amp;blog=4946554&amp;post=7&amp;subd=maddoxonj2ee&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://maddoxonj2ee.wordpress.com/2008/09/24/stringbuilder-vs-stringbuffer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eeb1e7261ef4265841f0a395781e4928?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leonardodosdos</media:title>
		</media:content>
	</item>
	</channel>
</rss>
