<?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>Ashik’s IT Thoughts</title>
	<atom:link href="http://ashikuzzaman.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ashikuzzaman.wordpress.com</link>
	<description>Where I talk about my works and thoughts on my profession, IT Industry trends and technologies</description>
	<lastBuildDate>Wed, 18 Jan 2012 17:18:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='ashikuzzaman.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/7015f769331f77a8d0caf7534dadcb13?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Ashik’s IT Thoughts</title>
		<link>http://ashikuzzaman.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ashikuzzaman.wordpress.com/osd.xml" title="Ashik’s IT Thoughts" />
	<atom:link rel='hub' href='http://ashikuzzaman.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Finding Union and Intersection of 2 Large Lists</title>
		<link>http://ashikuzzaman.wordpress.com/2011/11/25/finding-union-and-intersection-of-2-large-lists/</link>
		<comments>http://ashikuzzaman.wordpress.com/2011/11/25/finding-union-and-intersection-of-2-large-lists/#comments</comments>
		<pubDate>Fri, 25 Nov 2011 18:15:25 +0000</pubDate>
		<dc:creator>ashikuzzaman</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ashikuzzaman.wordpress.com/?p=175</guid>
		<description><![CDATA[One of my colleague who works on performance tracking and tuning of applications asked for some helped around how to find the union and intersection of large lists. He works mostly on Python and Perl. Being a Java guy, I prepared a sample program for him to do this allowing to determine the size of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashikuzzaman.wordpress.com&amp;blog=679859&amp;post=175&amp;subd=ashikuzzaman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of my colleague who works on performance tracking and tuning of applications asked for some helped around how to find the union and intersection of large lists. He works mostly on Python and Perl. Being a Java guy, I prepared a sample program for him to do this allowing to determine the size of the lists by himself. He was happy to get the program and once I explained him a bit about the retailAll(), addAll() and removeAll() API of Java and how I used those to determine the union and intersection, it was very clear to him. I am giving that program here in case it helps you as a reference implementation.</p>
<p><code><br />
package com.salesforce.test;</p>
<p>import java.util.List;<br />
import java.util.ArrayList;<br />
import java.util.Date;</p>
<p>/**<br />
 * To compiple: javac -d . ListPerformanceTest.java<br />
 * To run: java com.salesforce.test.ListPerformanceTest<br />
 *<br />
 * @author ashik<br />
 */<br />
public class ListPerformanceTest {</p>
<p>	private int LOOP_COUNT = 50000;<br />
	private List firstList;<br />
	private List secondList;</p>
<p>	public ListPerformanceTest() {<br />
		firstList = new ArrayList();<br />
		secondList = new ArrayList();<br />
		for(int i = 0; i &lt; LOOP_COUNT; i++) {<br />
			if(i % 3 != 0 || i % 5 != 0) {<br />
				firstList.add(&quot;ashik - &quot; + i);<br />
			}<br />
			if(i % 9 != 0) {<br />
				secondList.add(&quot;ashik - &quot; + i);<br />
			}<br />
		}<br />
	}</p>
<p>	public static void main(String[] args) {<br />
		System.out.println(&quot;\nListPerformanceTest starts.....\n&quot;);<br />
		ListPerformanceTest perf = new ListPerformanceTest();<br />
		List intersection = new ArrayList();<br />
		List union = new ArrayList();</p>
<p>		Date d1 = new Date(System.currentTimeMillis());<br />
		System.out.println("d1 = " + d1);<br />
		for(String value : perf.firstList) {<br />
			System.out.println("value for firstList = " + value);<br />
		}<br />
		Date d2 = new Date(System.currentTimeMillis());<br />
		System.out.println("d2 = " + d2);<br />
		for(String value : perf.secondList) {<br />
			System.out.println("value for secondList = " + value);<br />
		}<br />
		Date d3 = new Date(System.currentTimeMillis());<br />
		System.out.println("d3 = " + d3);</p>
<p>		System.out.println("perf.firstList.size() = " + perf.firstList.size() + " and perf.secondList.size() = " + perf.secondList.size());</p>
<p>		if(perf.firstList.size() &gt;= perf.secondList.size()) {<br />
			intersection.addAll(perf.firstList);<br />
			intersection.retainAll(perf.secondList);<br />
		} else {<br />
			intersection.addAll(perf.secondList);<br />
			intersection.retainAll(perf.firstList);<br />
		}<br />
		Date d4 = new Date(System.currentTimeMillis());<br />
		System.out.println("d4 = " + d4);<br />
		System.out.println("intersection.size() = " + intersection.size());</p>
<p>		if(perf.firstList.size() &gt;= perf.secondList.size()) {<br />
			union.addAll(perf.firstList);<br />
			union.removeAll(perf.secondList);<br />
			union.addAll(perf.secondList);<br />
		} else {<br />
			union.addAll(perf.secondList);<br />
			union.removeAll(perf.firstList);<br />
			union.addAll(perf.firstList);<br />
		}<br />
		Date d5 = new Date(System.currentTimeMillis());<br />
		System.out.println("d5 = " + d5);<br />
		System.out.println("union.size() = " + union.size());</p>
<p>		System.out.println("\nListPerformanceTest ends.....\n");<br />
	}</p>
<p>}<br />
</code></p>
<p>The significant part from the output when you run the program is given below.<br />
<code><br />
d3 = Fri Nov 25 10:03:36 PST 2011<br />
perf.firstList.size() = 46666 and perf.secondList.size() = 44444<br />
d4 = Fri Nov 25 10:03:55 PST 2011<br />
intersection.size() = 42222<br />
d5 = Fri Nov 25 10:04:14 PST 2011<br />
union.size() = 48888<br />
</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ashikuzzaman.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ashikuzzaman.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ashikuzzaman.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ashikuzzaman.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ashikuzzaman.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ashikuzzaman.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ashikuzzaman.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ashikuzzaman.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ashikuzzaman.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ashikuzzaman.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ashikuzzaman.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ashikuzzaman.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ashikuzzaman.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ashikuzzaman.wordpress.com/175/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashikuzzaman.wordpress.com&amp;blog=679859&amp;post=175&amp;subd=ashikuzzaman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ashikuzzaman.wordpress.com/2011/11/25/finding-union-and-intersection-of-2-large-lists/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/abb0fb1e422697731365d56e1ab8692b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ashik</media:title>
		</media:content>
	</item>
		<item>
		<title>Removing an element from a Collection while iterating over it</title>
		<link>http://ashikuzzaman.wordpress.com/2011/08/11/removing-an-element-from-a-collection-while-iterating-over-it/</link>
		<comments>http://ashikuzzaman.wordpress.com/2011/08/11/removing-an-element-from-a-collection-while-iterating-over-it/#comments</comments>
		<pubDate>Fri, 12 Aug 2011 01:59:08 +0000</pubDate>
		<dc:creator>ashikuzzaman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://ashikuzzaman.wordpress.com/?p=165</guid>
		<description><![CDATA[Can you remove an element from a collection while iterating over it? Answer: No, you can&#8217;t. What kind of error will you get in Java if you make an attempt? Compile time or Runtime? Answer: Runtime. The details of the exception will be as below. Check this along with a sample program that I wrote. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashikuzzaman.wordpress.com&amp;blog=679859&amp;post=165&amp;subd=ashikuzzaman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Can you remove an element from a collection while iterating over it? Answer: No, you can&#8217;t. </p>
<p>What kind of error will you get in Java if you make an attempt? Compile time or Runtime? Answer: Runtime.</p>
<p>The details of the exception will be as below. Check this along with a sample program that I wrote. You can try to compile and run it yourself to see the result.</p>
<p>Exception in thread &#8220;main&#8221; java.util.ConcurrentModificationException<br />
	at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:449)<br />
	at java.util.AbstractList$Itr.next(AbstractList.java:420)</p>
<p><code><br />
package com.salesforce.test;</p>
<p>import java.util.List;<br />
import java.util.ArrayList;</p>
<p>/**<br />
 * To compiple: javac -d . RemoveListTest.java<br />
 * To run: java com.salesforce.test.RemoveListTest<br />
 *<br />
 * @author ashik<br />
 */<br />
public class RemoveListTest {</p>
<p>	public List counts = new ArrayList();</p>
<p>	public RemoveListTest() {<br />
		counts.add(0);<br />
		counts.add(1);<br />
		counts.add(2);<br />
		counts.add(3);<br />
		counts.add(4);<br />
		counts.add(5);<br />
		counts.add(6);<br />
		counts.add(7);<br />
		counts.add(8);<br />
		counts.add(9);<br />
		counts.add(10);<br />
		counts.add(11);<br />
		counts.add(12);<br />
		counts.add(13);<br />
		counts.add(14);<br />
	}</p>
<p>	public static void main(String[] args) {<br />
		System.out.println("\nRemoveListTest starts.....\n");<br />
		RemoveListTest rlt = new RemoveListTest();<br />
		List results = new ArrayList();<br />
		for(Integer count : rlt.counts) {<br />
			System.out.println("count before removing = " + count);<br />
			if(count % 3 == 1) {<br />
				results.add(count);<br />
                                // rlt.counts.remove(count); // you will get runtime error if you uncomment it<br />
			}<br />
		}</p>
<p>		for(Integer result : results) {<br />
			System.out.println("result = " + result);<br />
			rlt.counts.remove(result);<br />
		}<br />
		for(Integer count : rlt.counts) {<br />
			System.out.println("count after removing = " + count);<br />
		}</p>
<p>		System.out.println("\nRemoveListTest ends.....\n");<br />
	}<br />
}<br />
</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ashikuzzaman.wordpress.com/165/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ashikuzzaman.wordpress.com/165/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ashikuzzaman.wordpress.com/165/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ashikuzzaman.wordpress.com/165/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ashikuzzaman.wordpress.com/165/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ashikuzzaman.wordpress.com/165/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ashikuzzaman.wordpress.com/165/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ashikuzzaman.wordpress.com/165/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ashikuzzaman.wordpress.com/165/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ashikuzzaman.wordpress.com/165/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ashikuzzaman.wordpress.com/165/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ashikuzzaman.wordpress.com/165/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ashikuzzaman.wordpress.com/165/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ashikuzzaman.wordpress.com/165/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashikuzzaman.wordpress.com&amp;blog=679859&amp;post=165&amp;subd=ashikuzzaman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ashikuzzaman.wordpress.com/2011/08/11/removing-an-element-from-a-collection-while-iterating-over-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/abb0fb1e422697731365d56e1ab8692b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ashik</media:title>
		</media:content>
	</item>
		<item>
		<title>Waiting for NoteSlate</title>
		<link>http://ashikuzzaman.wordpress.com/2011/02/11/waiting-for-noteslate/</link>
		<comments>http://ashikuzzaman.wordpress.com/2011/02/11/waiting-for-noteslate/#comments</comments>
		<pubDate>Fri, 11 Feb 2011 09:57:33 +0000</pubDate>
		<dc:creator>ashikuzzaman</dc:creator>
				<category><![CDATA[IT]]></category>

		<guid isPermaLink="false">http://ashikuzzaman.wordpress.com/?p=161</guid>
		<description><![CDATA[A few days back my Google Reader RSS Feed took me to www.noteslate.com and from then onwards NoteSlate is roaming around my mind. I believe Kindle solved my problem of reading books, iPad solved the problem of a personal organizer cum web surfing but none of them really addressed the issue properly of writing or [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashikuzzaman.wordpress.com&amp;blog=679859&amp;post=161&amp;subd=ashikuzzaman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A few days back my Google Reader RSS Feed took me to www.noteslate.com and from then onwards NoteSlate is roaming around my mind. I believe Kindle solved my problem of reading books, iPad solved the problem of a personal organizer cum web surfing but none of them really addressed the issue properly of writing or taking notes. NoteSlate will do that if I understood correctly what there current ad shows. Ah, I have to wait 5 more months to verify it!</p>
<p><a href="http://ashikuzzaman.files.wordpress.com/2011/02/noteslate_off.jpg"><img class="alignnone size-full wp-image-162" title="NoteSlate_off" src="http://ashikuzzaman.files.wordpress.com/2011/02/noteslate_off.jpg" alt="" width="800" height="490" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ashikuzzaman.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ashikuzzaman.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ashikuzzaman.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ashikuzzaman.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ashikuzzaman.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ashikuzzaman.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ashikuzzaman.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ashikuzzaman.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ashikuzzaman.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ashikuzzaman.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ashikuzzaman.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ashikuzzaman.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ashikuzzaman.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ashikuzzaman.wordpress.com/161/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashikuzzaman.wordpress.com&amp;blog=679859&amp;post=161&amp;subd=ashikuzzaman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ashikuzzaman.wordpress.com/2011/02/11/waiting-for-noteslate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/abb0fb1e422697731365d56e1ab8692b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ashik</media:title>
		</media:content>

		<media:content url="http://ashikuzzaman.files.wordpress.com/2011/02/noteslate_off.jpg" medium="image">
			<media:title type="html">NoteSlate_off</media:title>
		</media:content>
	</item>
		<item>
		<title>I won the first round of the Chess Tournament in Salesforce.com</title>
		<link>http://ashikuzzaman.wordpress.com/2011/01/25/i-won-the-first-round-of-the-chess-tournament-in-salesforce-com/</link>
		<comments>http://ashikuzzaman.wordpress.com/2011/01/25/i-won-the-first-round-of-the-chess-tournament-in-salesforce-com/#comments</comments>
		<pubDate>Tue, 25 Jan 2011 20:59:48 +0000</pubDate>
		<dc:creator>ashikuzzaman</dc:creator>
				<category><![CDATA[Chess]]></category>
		<category><![CDATA[Official]]></category>

		<guid isPermaLink="false">http://ashikuzzaman.wordpress.com/?p=151</guid>
		<description><![CDATA[I played the first round of the four round chess tournament in Salesforce.com. I won with White, although I felt I am out of touch by a good margin due to the lack of practice. My opponent was Didier Prophete who is PMTS and sits in 3rd floor in the same building as I do. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashikuzzaman.wordpress.com&amp;blog=679859&amp;post=151&amp;subd=ashikuzzaman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I played the first round of the four round chess tournament in Salesforce.com. I won with White, although I felt I am out of touch by a good margin due to the lack of practice. My opponent was Didier Prophete who is PMTS and sits in 3rd floor in the same building as I do. Also I took lot more time than my opponent to move.</p>
<p>However, I will do some practice before next rounds so that I don&#8217;t make simple miscalculations.</p>
<p><a href="http://www.chess.com/emboard.html?id=589523">http://www.chess.com/emboard.html?id=589523</a></p>
<p>Soon after this, I exchanged the queens to make sure there is nothing left in the board except my Rook and Didier&#8217;s Bishop while I have a bunch of queens side passed pawns to march for promotion. So he resigned here while I had some 3 minutes left in the clock as opposed to his 9 minutes.</p>
<p>Last few days I finished Himu Rimande and Kichukhkhon by Humayun Ahmed.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ashikuzzaman.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ashikuzzaman.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ashikuzzaman.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ashikuzzaman.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ashikuzzaman.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ashikuzzaman.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ashikuzzaman.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ashikuzzaman.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ashikuzzaman.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ashikuzzaman.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ashikuzzaman.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ashikuzzaman.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ashikuzzaman.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ashikuzzaman.wordpress.com/151/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashikuzzaman.wordpress.com&amp;blog=679859&amp;post=151&amp;subd=ashikuzzaman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ashikuzzaman.wordpress.com/2011/01/25/i-won-the-first-round-of-the-chess-tournament-in-salesforce-com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/abb0fb1e422697731365d56e1ab8692b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ashik</media:title>
		</media:content>
	</item>
		<item>
		<title>Computers With Attitude</title>
		<link>http://ashikuzzaman.wordpress.com/2010/12/19/computers-with-attitude/</link>
		<comments>http://ashikuzzaman.wordpress.com/2010/12/19/computers-with-attitude/#comments</comments>
		<pubDate>Sun, 19 Dec 2010 22:19:47 +0000</pubDate>
		<dc:creator>ashikuzzaman</dc:creator>
				<category><![CDATA[IT]]></category>

		<guid isPermaLink="false">http://ashikuzzaman.wordpress.com/?p=142</guid>
		<description><![CDATA[I thought it&#8217;s funny but I believe all the major O/S vendors are already capable of creating something this now.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashikuzzaman.wordpress.com&amp;blog=679859&amp;post=142&amp;subd=ashikuzzaman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I thought it&#8217;s funny but I believe all the major O/S vendors are already capable of creating something this now.</p>
<p><a href="http://picasaweb.google.com/lh/photo/7oSiwP_axwQQOFvQT_hTrw?feat=embedwebsite"><img src="http://lh5.ggpht.com/_Ukfp6yZvVtw/TQ5o8TqJvhI/AAAAAAAAFec/gRhaY6nWwpE/s800/Computer%20with%20attitude.jpg" height="474" width="420" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ashikuzzaman.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ashikuzzaman.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ashikuzzaman.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ashikuzzaman.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ashikuzzaman.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ashikuzzaman.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ashikuzzaman.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ashikuzzaman.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ashikuzzaman.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ashikuzzaman.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ashikuzzaman.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ashikuzzaman.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ashikuzzaman.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ashikuzzaman.wordpress.com/142/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashikuzzaman.wordpress.com&amp;blog=679859&amp;post=142&amp;subd=ashikuzzaman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ashikuzzaman.wordpress.com/2010/12/19/computers-with-attitude/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/abb0fb1e422697731365d56e1ab8692b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ashik</media:title>
		</media:content>

		<media:content url="http://lh5.ggpht.com/_Ukfp6yZvVtw/TQ5o8TqJvhI/AAAAAAAAFec/gRhaY6nWwpE/s800/Computer%20with%20attitude.jpg" medium="image" />
	</item>
		<item>
		<title>Small Java Program To Convert Unicode Character Filled Sentences To Native or UTF-8 Character Filled Sentences</title>
		<link>http://ashikuzzaman.wordpress.com/2010/12/19/small-java-program-to-convert-unicode-character-filled-sentences-to-native-or-utf-8-character-filled-sentences/</link>
		<comments>http://ashikuzzaman.wordpress.com/2010/12/19/small-java-program-to-convert-unicode-character-filled-sentences-to-native-or-utf-8-character-filled-sentences/#comments</comments>
		<pubDate>Sun, 19 Dec 2010 20:58:30 +0000</pubDate>
		<dc:creator>ashikuzzaman</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Official]]></category>

		<guid isPermaLink="false">http://ashikuzzaman.wordpress.com/?p=138</guid>
		<description><![CDATA[My colleague John asked for a tool from me last week so that he can finish the translations / localization works that he was doing. To solve it in a lazy way, I did some google around a bit but couldn’t figure out any easy tool that will convert Unicode characters \uxxxx to native locales. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashikuzzaman.wordpress.com&amp;blog=679859&amp;post=138&amp;subd=ashikuzzaman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My colleague John asked for a tool from me last week so that he can finish the translations / localization works that he was doing. To solve it in a lazy way, I did some google around a bit but couldn’t figure out any easy tool that will convert Unicode characters \uxxxx to native locales. There are plenty of tools available to convert natives to UTF-8 and even the below simple command works in java for native to utf-8 : </p>
<p><code>native2ascii.exe -encoding UTF-8  your-input-file-name.properties your-output-file-name.properties</code></p>
<p>So what I have done is just written a small java program that will help you to achieve the <strong>reverse</strong> of it i.e. converting from unicode to native / utf-8. Here are the steps you will need to perform. </p>
<p><code>package com.salesforce.test;</p>
<p>import java.io.*;</p>
<p>/**<br />
 * To compile: javac -d . SfdcUnicodeToNativeConverter.java<br />
 * To run: java com.salesforce.test.SfdcUnicodeToNativeConverter<br />
 *<br />
 * @author ashik<br />
 */<br />
public class SfdcUnicodeToNativeConverter {</p>
<p>   private static String fileName = "output.properties";</p>
<p>   private static String sentenceToConvert = "cmgt_configurator/Sfdc_common_summary_32=\u304a\u652f\u6255\u3044\u60c5\u5831\u306e\u5165\u529b";</p>
<p>   /*<br />
    \u304a\u652f\u6255\u3044\u60c5\u5831\u306e\u5165\u529b<br />
    \u304a\u652f\u6255\u3044\u6761\u4ef6 &amp; \u5951\u7d04\u671f\u9593\u306e\u7de8\u96c6<br />
    \u6b64\u8ba2\u5355\u7684\u603b\u4f63\u91d1+<br />
    \u82e5\u8981\u7e7c\u7e8c\u7d50\u5e33\uff0c\u60a8\u5fc5\u9808\u8a73\u95b1\u8b80\u4e26\u63a5\u53d7\u4ee5\u4e0b\u6240\u5217\u6bcf\u500b\u7522\u54c1\u7684\u689d\u6b3e\u3002<br />
   */<br />
   public static void writeOutput(String str, String fileName) {<br />
	   System.out.println("Unicode to Native Conversion Starts...");<br />
       try {<br />
           FileOutputStream fos = new FileOutputStream(fileName);<br />
           Writer out = new OutputStreamWriter(fos, "UTF8");<br />
           out.write(str);<br />
           out.close();<br />
       } catch (IOException e) {<br />
           e.printStackTrace();<br />
       }<br />
       System.out.println("Unicode to Native Conversion Successful!");<br />
   }</p>
<p>   public static void main(String[] args) {<br />
      writeOutput(sentenceToConvert, fileName);<br />
   }</p>
<p>}<br />
</code></p>
<p>1.	Make sure sure you have JDK installed in your system. Set the environment variable JAVA_HOME in to point to JDK (alternatively there is a shorter way that I can show you).<br />
2.	Copy the source java file from the following network location into your machine &#8211; \\moorea\departments\AppStore\Comergent\Programs\SfdcUnicodeToNativeConverter.java<br />
3.	Open the source file in TextPad or Crimson Editor and replace the value for the variable <strong>sentenceToConvert</strong> to the actual sentence that you are trying to translate / convert.<br />
4.	Compile the java file that I wrote using the command javac -d . SfdcUnicodeToNativeConverter.java<br />
5.	Run the program to generate the output file using the command java com.salesforce.test.SfdcUnicodeToNativeConverter<br />
6.	A new file named output.properties should be generated in the same folder from where you ran the program.<br />
7.	Open this file with Altova Xml Spy or Notepad with UTF-8 Encoding to preserve the file format correctly. You may see some characters that look like junk. Don’t worry, those are not junks.<br />
8.	Copy the content from the file in Xml Spy or Notepad and paste those into a new MS Excel Spreadsheet. Now you should see the native characters properly. You can use those for translation purposes I your models.</p>
<p>I have tried to write down the steps above clearly as you will need to perform those repeatedly for each line of translations for each locale. Being a little innovative, you can use the steps above for multi-line translations as well by adding proper \n&#8221; + &#8221; to hold many properties / values in the sentenceToConvert variables. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ashikuzzaman.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ashikuzzaman.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ashikuzzaman.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ashikuzzaman.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ashikuzzaman.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ashikuzzaman.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ashikuzzaman.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ashikuzzaman.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ashikuzzaman.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ashikuzzaman.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ashikuzzaman.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ashikuzzaman.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ashikuzzaman.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ashikuzzaman.wordpress.com/138/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashikuzzaman.wordpress.com&amp;blog=679859&amp;post=138&amp;subd=ashikuzzaman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ashikuzzaman.wordpress.com/2010/12/19/small-java-program-to-convert-unicode-character-filled-sentences-to-native-or-utf-8-character-filled-sentences/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/abb0fb1e422697731365d56e1ab8692b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ashik</media:title>
		</media:content>
	</item>
		<item>
		<title>Salesforce Chatter Desktop and Salesforce Mobile</title>
		<link>http://ashikuzzaman.wordpress.com/2010/10/19/salesforce-chatter-desktop-and-salesforce-mobile/</link>
		<comments>http://ashikuzzaman.wordpress.com/2010/10/19/salesforce-chatter-desktop-and-salesforce-mobile/#comments</comments>
		<pubDate>Tue, 19 Oct 2010 18:45:10 +0000</pubDate>
		<dc:creator>ashikuzzaman</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Official]]></category>

		<guid isPermaLink="false">http://ashikuzzaman.wordpress.com/?p=136</guid>
		<description><![CDATA[I just installed Salesforce Chatter Desktop and Salesforce Mobile. Interesting. If you want to download or know more, follow the link below. http://www.salesforce.com/chatter/desktop-mobile-collaboration/<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashikuzzaman.wordpress.com&amp;blog=679859&amp;post=136&amp;subd=ashikuzzaman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I just installed Salesforce Chatter Desktop and Salesforce Mobile. Interesting. If you want to download or know more, follow the link below.</p>
<p><a href="http://www.salesforce.com/chatter/desktop-mobile-collaboration/">http://www.salesforce.com/chatter/desktop-mobile-collaboration/</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ashikuzzaman.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ashikuzzaman.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ashikuzzaman.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ashikuzzaman.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ashikuzzaman.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ashikuzzaman.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ashikuzzaman.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ashikuzzaman.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ashikuzzaman.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ashikuzzaman.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ashikuzzaman.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ashikuzzaman.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ashikuzzaman.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ashikuzzaman.wordpress.com/136/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashikuzzaman.wordpress.com&amp;blog=679859&amp;post=136&amp;subd=ashikuzzaman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ashikuzzaman.wordpress.com/2010/10/19/salesforce-chatter-desktop-and-salesforce-mobile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/abb0fb1e422697731365d56e1ab8692b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ashik</media:title>
		</media:content>
	</item>
		<item>
		<title>Convert Http URL to Https URL &#8211; A Short Sample Code</title>
		<link>http://ashikuzzaman.wordpress.com/2010/03/15/convert-http-url-to-httpss-url-a-short-sample-code/</link>
		<comments>http://ashikuzzaman.wordpress.com/2010/03/15/convert-http-url-to-httpss-url-a-short-sample-code/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 03:31:06 +0000</pubDate>
		<dc:creator>ashikuzzaman</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[https]]></category>
		<category><![CDATA[sample]]></category>

		<guid isPermaLink="false">http://ashikuzzaman.wordpress.com/?p=127</guid>
		<description><![CDATA[Here is an example of how you convert an Http URL to a secured URL (Https). Here I am assuming the URL will be fully standard i.e. even the default port 80 will be written after colon as :80 and same for default https port :443. package com.google.test; /** * To compiple: javac -d . [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashikuzzaman.wordpress.com&amp;blog=679859&amp;post=127&amp;subd=ashikuzzaman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here is an example of how you convert an Http URL to a secured URL (Https). Here I am assuming the URL will be fully standard i.e. even the default port 80 will be written after colon as :80 and same for default https port :443.</p>
<p><code><br />
package com.google.test;</p>
<p>/**</p>
<p> * To compiple: javac -d . ConvertHttpToHttps.java</p>
<p> * To run: java com.google.test.ConvertHttpToHttps</p>
<p> *</p>
<p> * @author ashik</p>
<p> */<br />
public final class ConvertHttpToHttps {</p>
<p>	private static String url = "http://configure.google.com:80/AppStore/en/US/enterpriseMgr/AppStore";</p>
<p>	public static void main (String[] args) {<br />
		System.out.println("url before replacing = " + url);<br />
		System.out.println("url after replacing = " + convert(url));<br />
	}</p>
<p>	public static String convert(String url) {<br />
		StringBuffer result = new StringBuffer();<br />
		if(url.startsWith("http://")) {<br />
			String strColon = url.substring(7);<br />
			result.append("https://");<br />
			int colonIndex = strColon.indexOf(":");<br />
			String portNumber = strColon.substring(0, colonIndex);<br />
			result.append(portNumber);<br />
			result.append(":443" + strColon.substring(colonIndex+3));<br />
		}<br />
		return result.toString();<br />
	}</p>
<p>}<br />
</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ashikuzzaman.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ashikuzzaman.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ashikuzzaman.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ashikuzzaman.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ashikuzzaman.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ashikuzzaman.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ashikuzzaman.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ashikuzzaman.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ashikuzzaman.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ashikuzzaman.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ashikuzzaman.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ashikuzzaman.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ashikuzzaman.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ashikuzzaman.wordpress.com/127/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashikuzzaman.wordpress.com&amp;blog=679859&amp;post=127&amp;subd=ashikuzzaman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ashikuzzaman.wordpress.com/2010/03/15/convert-http-url-to-httpss-url-a-short-sample-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/abb0fb1e422697731365d56e1ab8692b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ashik</media:title>
		</media:content>
	</item>
		<item>
		<title>Replacing $ in a String in Java</title>
		<link>http://ashikuzzaman.wordpress.com/2010/03/13/replacing-in-a-string-in-java/</link>
		<comments>http://ashikuzzaman.wordpress.com/2010/03/13/replacing-in-a-string-in-java/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 11:25:39 +0000</pubDate>
		<dc:creator>ashikuzzaman</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[dollar]]></category>
		<category><![CDATA[escape]]></category>
		<category><![CDATA[matcher]]></category>
		<category><![CDATA[pattern]]></category>
		<category><![CDATA[replace]]></category>
		<category><![CDATA[sign]]></category>

		<guid isPermaLink="false">http://ashikuzzaman.wordpress.com/?p=118</guid>
		<description><![CDATA[I faced an issue in my project where we read a password for an admin user first from a file which has a dummy or wrong password written in it. Then I read the password from database and replace the dummy password with the real password that I get from Database. So the code was [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashikuzzaman.wordpress.com&amp;blog=679859&amp;post=118&amp;subd=ashikuzzaman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I faced an issue in my project where we read a password for an admin user first from a file which has a dummy or wrong password written in it. Then I read the password from database and replace the dummy password with the real password that I get from Database. So the code was something very simple like this (this is actually different from original).</p>
<p><code><br />
String myXmlDoc = readALargeXmlAsString();<br />
String realPassword = readFromDatabase();<br />
String password = myXmlDoc.replaceAll("dummyPassword", realPassword);<br />
</code></p>
<p>All on a sudden we found that this replacement started failing after the password of that admin user was changed recently.  Here is the exception log.<br />
<code><br />
Exception in thread "main" java.lang.IllegalArgumentException: Illegal group reference<br />
        at java.util.regex.Matcher.appendReplacement(Matcher.java:706)<br />
        at java.util.regex.Matcher.replaceAll(Matcher.java:806)<br />
        at java.lang.String.replaceAll(String.java:2000)<br />
        at com.salesforce.test.StringReplaceTest.main(StringReplaceTest.java:34)<br />
</code></p>
<p>So I figured out from the log that it&#8217;s actually the replaceAll() pattern matching method that is causing the failure when you have $ in your replacement string (not in the pattern itself). So as per the first code example, if you had a $ character as one of the characters for realPassword, then it would throw the exception above. While the solution was to use a different admin for now who doesn&#8217;t have a password containing $ sign, I sat down to investigate it in detail and write a long term solution.</p>
<p>First I reproduced the issue in 3 different ways. Here is a code that will tell you depending on where you are putting the $ sign, the exception stack trace will be different. I give you the code and the compile and run instructions so that you can test it yourself.<br />
<code><br />
package com.salesforce.test;</p>
<p>/**<br />
 * To compile: javac -d . StringReplaceTest.java<br />
 * To run: java com.salesforce.test.StringReplaceTest<br />
 * or, 	   java com.salesforce.test.StringReplaceTest start<br />
 * or, 	   java com.salesforce.test.StringReplaceTest middle<br />
 * or, 	   java com.salesforce.test.StringReplaceTest end<br />
 * @authot ashik<br />
 */<br />
public class StringReplaceTest {</p>
<p>	public static void main(String[] args) {</p>
<p>		System.out.println("\nStringReplaceTest starts.....\n");</p>
<p>		String firstStr = "I am a Java programmer working in USA. Chess is my hobby and here in USA lot of people play chess.";</p>
<p>		System.out.println("firstStr before replacing = " + firstStr);</p>
<p>		String positionPOfDollarSign = "";<br />
		if(args.length &gt; 0) {<br />
			positionPOfDollarSign = args[0];<br />
		}<br />
		String secondStr = "";<br />
		if("start".equalsIgnoreCase(positionPOfDollarSign)) {<br />
			secondStr = firstStr.replaceAll("USA", "$PUT_A_VALUE123"); // illegal group reference<br />
		} else if("middle".equalsIgnoreCase(positionPOfDollarSign)) {<br />
			secondStr = firstStr.replaceAll("USA", "PUT_A_VALUE$123"); //  String index out of range: 15<br />
		} else if("end".equalsIgnoreCase(positionPOfDollarSign)) {<br />
			secondStr = firstStr.replaceAll("USA", "PUT_A_VALUE123$"); // java.lang.IndexOutOfBoundsException: No group 1<br />
		} else {<br />
			secondStr = firstStr.replaceAll("USA", "PUT_A_VALUE123"); // no error<br />
		}</p>
<p>		System.out.println("\nsecondStr after replacing firstStr = " + secondStr);</p>
<p>		System.out.println("\nStringReplaceTest ends.....\n");<br />
	}</p>
<p>}<br />
</code></p>
<p>Developing the fix was a little tricky as replacing the $ and \ characters (these 2 are what makes trouble) using regular methods like <strong>Spring.split()</strong> or <strong>StringTokenizer</strong> class doesn&#8217;t work as those itself can&#8217;t process $ correctly. So I had to do my search and replace based on the String.indexOf() and String.substring(). Here is my fix and I would like to know your feedback on this. Please note that Apache StringUtils will be a very good resource to use here instead of trying to write the algorithm yourself.</p>
<p><code><br />
package com.google.test;</p>
<p>import java.util.StringTokenizer;<br />
import java.util.regex.Matcher;<br />
import java.util.regex.Pattern;</p>
<p>/**<br />
 * To compiple: javac -d . SfdcReplaceSubstring3.java<br />
 * To run: java com.google.test.SfdcReplaceSubstring3<br />
 *<br />
 * @author ashik<br />
 */<br />
public final class SfdcReplaceSubstring3 {</p>
<p> // private static String firstStr = "I am a Java programmer and a $Chess$ player working in USA. $Chess$ is my hobby and here in USA lot of people play $Chess$. USA had a great Chess player named Bobby Fischer.";</p>
<p> private static String firstStr = "Java, Apex, $Chess$ and Oracle - which one do you like? I guess Chess. If not $Chess$ then what else?";</p>
<p> private static String patternToSearch = "$Chess$";</p>
<p> private static String[] replacementStrFromDB = { null, "", " ", "PUT_A_VALUE123",<br />
   "PUT#A^VALUE!123?a+b/c&gt;d", "PUT$A$VALUE123", "$PUT_A_VALUE123",<br />
   "PUT_A_$VALUE123", "PUT_A_VALUE123$", "PUT_A_VALUE$123",<br />
   "PUT_A_VALUE123$", "\\$PUT_A_VALUE123", "\\\\$PUT_A_VALUE123",<br />
   "\\PUT_A_VALUE123", "\\\\PUT_A_VALUE123", "\\PUT_A_VALUE$123",<br />
   "\\\\PUT_A_VALUE$123", "\\PUT_A_VALUE123$", "\\\\PUT_A_VALUE123$",<br />
   "$PUT_A_VALUE$123$" };</p>
<p> public static void main(String[] args) {<br />
  System.out.println("\nfirstStr before replacing = " + firstStr);<br />
  System.out.println("\npatternToSearch = " + patternToSearch);<br />
  // System.out.println("Direct replacement: " +<br />
  // matcher.replaceAll("PUT\\$A\\$VALUE123"));<br />
  for (int i = 0; i &lt; replacementStrFromDB.length; i++)<br />
   try {<br />
    System.out.println(&quot;\nExecuted test#&quot;<br />
      + (i + 1)<br />
      + &quot;: &quot;<br />
      + &quot;firstStr after replacing with &quot;<br />
      + replacementStrFromDB[i]<br />
      + &quot; = &quot;<br />
      + replace(firstStr, patternToSearch,<br />
        replacementStrFromDB[i]));<br />
   } catch (Exception e) {<br />
    System.out.println(&quot;\nExecuted test#&quot; + (i + 1) + &quot;: &quot;<br />
      + &quot;Exception while replacing firstStr with &quot;<br />
      + replacementStrFromDB[i] + &quot; = &quot; + e.getMessage());<br />
   }<br />
 }</p>
<p> public static String replace(String text, String searchString,<br />
   String replacement) {<br />
  int start = 0;<br />
  int end = text.indexOf(searchString, start);<br />
  if (end == -1) {<br />
   return text;<br />
  }<br />
  int replLength = searchString.length();<br />
  StringBuilder buf = new StringBuilder();<br />
  while (end != -1) {<br />
   buf.append(text.substring(start, end)).append(replacement);<br />
   start = end + replLength;<br />
   end = text.indexOf(searchString, start);<br />
  }<br />
  buf.append(text.substring(start));<br />
  return buf.toString();<br />
 }</p>
<p>}<br />
</code></p>
<p>Update: This post attracted the attention of my friend Nitol wwith whom I have worked early in my career. He suggested to use Apache StringUtils for problems like this. Special thanks to him. It reminds me how many Apache open source libraries I have used earlier when I was in Bangladesh and after coming to USA, I don&#8217;t get time to sync up myself with the latest open source changes and often try to solve problems that has already been solved by numerous people (re-inventing the wheel). I will keep my eye on it from now on and allow myself to be a little lazy programmmer.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ashikuzzaman.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ashikuzzaman.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ashikuzzaman.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ashikuzzaman.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ashikuzzaman.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ashikuzzaman.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ashikuzzaman.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ashikuzzaman.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ashikuzzaman.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ashikuzzaman.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ashikuzzaman.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ashikuzzaman.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ashikuzzaman.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ashikuzzaman.wordpress.com/118/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashikuzzaman.wordpress.com&amp;blog=679859&amp;post=118&amp;subd=ashikuzzaman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ashikuzzaman.wordpress.com/2010/03/13/replacing-in-a-string-in-java/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/abb0fb1e422697731365d56e1ab8692b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ashik</media:title>
		</media:content>
	</item>
		<item>
		<title>How To Unescape HTML in Java</title>
		<link>http://ashikuzzaman.wordpress.com/2009/11/04/how-to-unescape-html-in-java/</link>
		<comments>http://ashikuzzaman.wordpress.com/2009/11/04/how-to-unescape-html-in-java/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 03:46:17 +0000</pubDate>
		<dc:creator>ashikuzzaman</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java java unescape html algorithm]]></category>

		<guid isPermaLink="false">http://ashikuzzaman.wordpress.com/?p=99</guid>
		<description><![CDATA[I was writing an Html unescape algorithm in Java today. What I came out with is the one below. There is a problem in the algorithm below that eats up some space or characters for some corner cases. Can you figure out what the problem is? I wrote the class in a way so that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashikuzzaman.wordpress.com&amp;blog=679859&amp;post=99&amp;subd=ashikuzzaman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was writing an Html unescape algorithm in Java today. What I came out with is the one below. There is a problem in the algorithm below that eats up some space or characters for some corner cases. Can you figure out what the problem is?</p>
<p>I wrote the class in a way so that you can compile and run it in command prompt and can see the output right away. You can do some trial and error and figure out the issue in the algorithm below.</p>
<p><code>package com.salesforce.test;</p>
<p>import java.util.*;</p>
<p>/**<br />
 * To compiple: javac -d . StringUtils.java<br />
 * To run: java com.salesforce.test.StringUtils<br />
 *<br />
 * @authot ashik<br />
 */<br />
public class StringUtils {</p>
<p>  private StringUtils() {}</p>
<p>  /**<br />
   * the characters to unescape<br />
   */<br />
  public static HashMap htmlEntities = new HashMap();<br />
  static {<br />
    htmlEntities.put("&#60;","&lt;&quot;); htmlEntities.put(&quot;&lt;&quot;,&quot;"); htmlEntities.put("&gt;","&gt;");<br />
    htmlEntities.put("&#39;","\'"); htmlEntities.put("&apos;","\'");<br />
    htmlEntities.put("&#34;","\""); htmlEntities.put("&quot;","\"");<br />
    htmlEntities.put("&#38;","&amp;"); htmlEntities.put("&amp;","&amp;");<br />
    htmlEntities.put("&#32;"," "); htmlEntities.put("&nbsp;"," ");<br />
  }</p>
<p>  public static final String unescapeHTML(String source, int start){<br />
     int i,j;</p>
<p>     i = source.indexOf("&amp;", start);<br />
     if (i &gt; -1) {<br />
        j = source.indexOf(";" ,i);<br />
        if (j &gt; i) {<br />
           String entityToLookFor = source.substring(i , j + 1);<br />
           System.out.println("source = " + source + ", entityToLookFor = " + entityToLookFor + ", i = " + i + " and j = " + j);<br />
           if(entityToLookFor.lastIndexOf("&amp;") &gt; entityToLookFor.indexOf("&amp;")) {<br />
	           i = entityToLookFor.lastIndexOf("&amp;") + 1;<br />
	           System.out.println("Before source = " + source + ", entityToLookFor = " + entityToLookFor + ", i = " + i + " and j = " + j);<br />
	           entityToLookFor = entityToLookFor.substring(entityToLookFor.lastIndexOf("&amp;"));<br />
	           System.out.println("After  source = " + source + ", entityToLookFor = " + entityToLookFor + ", i = " + i + " and j = " + j);<br />
           }<br />
           String value = (String)htmlEntities.get(entityToLookFor);<br />
           if (value != null) {<br />
             source = new StringBuffer().append(source.substring(0 , i)).append(value).append(source.substring(j + 1)).toString();<br />
             return unescapeHTML(source, i + 1); // recursive call<br />
           }<br />
         }<br />
     }<br />
     return source;<br />
  }</p>
<p>  public static void main(String args[]) throws Exception {<br />
      // to see accented character to the console<br />
      java.io.PrintStream ps = new java.io.PrintStream(System.out, true, "Cp850");</p>
<p>      ps.println("Finally: Ashik's Quote &lt;Test Ok = &quot; + unescapeHTML(&quot;Ashik&#39;s Quote &lt;Test Ok&quot;, 0));<br />
      ps.println(&quot;-----------&quot;);<br />
      ps.println(&quot;Finally: M&amp; M &gt; 5 = &quot; + unescapeHTML(&quot;M&amp; M &gt; 5&quot;, 0));<br />
      ps.println(&quot;-----------&quot;);<br />
      ps.println(&quot;Finally: M &amp; M &gt; 5 = &quot; + unescapeHTML(&quot;M &amp; M &gt; 5&quot;, 0));<br />
      ps.println(&quot;-----------&quot;);<br />
      ps.println(&quot;Finally: M &amp;M &gt; 5 = &quot; + unescapeHTML(&quot;M &amp;M &gt; 5&quot;, 0));<br />
      ps.println(&quot;-----------&quot;);<br />
      ps.println(&quot;Finally: M&amp; M&gt; 5 = &quot; + unescapeHTML(&quot;M&amp; M&gt; 5&quot;, 0));<br />
      ps.println(&quot;-----------&quot;);<br />
      ps.println(&quot;Also: \n--&gt;&quot; + unescapeHTML(&quot;Apos\&#39;trophie &amp; &quot;quote&quot; is &lt;present&gt;&quot;, 0));<br />
      ps.println(&quot;-----------&quot;);<br />
      ps.println(&quot;Also: \n--&gt;&quot; + unescapeHTML(&quot;Please check for empty&nbsp;space in Order&nbsp;Review tab.&quot;, 0));<br />
      ps.println(&quot;-----------&quot;);<br />
      ps.println(&quot;Also: \n--&gt;&quot; + unescapeHTML(&quot;Also check for Billing Information &amp; Subscription Information &amp; Order&nbsp;Review tabs.&quot;, 0));<br />
      ps.println(&quot;-----------&quot;);<br />
      ps.println(&quot;Also: \n--&gt;&quot; + unescapeHTML(&quot;It&apos;s difficult to check today&apos;s capitalization strategy for all tabs.&quot;, 0));<br />
      ps.println(&quot;-----------&quot;);<br />
      ps.println(&quot;Also: \n--&gt;&quot; + unescapeHTML(&quot;Remember that 12 is &gt; 9 is &gt; 4&quot;, 0));<br />
      ps.println(&quot;-----------&quot;);<br />
      ps.println(&quot;Also: \n--&gt;&quot; + unescapeHTML(&quot;Similarly 8 is &lt; 10 is &lt; 15&quot;, 0));<br />
      ps.println(&quot;-----------&quot;);<br />
      ps.println(&quot;Also: \n--&gt;&quot; + unescapeHTML(&quot;Shakespeare said,&quot;To be or not to be that is the question.&quot;&quot;, 0));<br />
      ps.println(&quot;-----------&quot;);<br />
      ps.println(&quot;Also: \n--&gt;&quot; + unescapeHTML(&quot;Think &amp; think about New York&#39;s &lt;best pizza&gt; as the \&quot;ultimate\&quot; pizza!&quot;, 0));<br />
      ps.println(&quot;-----------&quot;);<br />
      ps.println(&quot;Also: \n--&gt;&quot; + unescapeHTML(&quot;Apos&#39;trophie &amp; &quot;quote&quot; is &lt;present&gt;&quot;, 0));<br />
      ps.println(&quot;-----------&quot;);<br />
  }</p>
<p>}<br />
</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ashikuzzaman.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ashikuzzaman.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ashikuzzaman.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ashikuzzaman.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ashikuzzaman.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ashikuzzaman.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ashikuzzaman.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ashikuzzaman.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ashikuzzaman.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ashikuzzaman.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ashikuzzaman.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ashikuzzaman.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ashikuzzaman.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ashikuzzaman.wordpress.com/99/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashikuzzaman.wordpress.com&amp;blog=679859&amp;post=99&amp;subd=ashikuzzaman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ashikuzzaman.wordpress.com/2009/11/04/how-to-unescape-html-in-java/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/abb0fb1e422697731365d56e1ab8692b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ashik</media:title>
		</media:content>
	</item>
	</channel>
</rss>
