<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title><![CDATA[Coder Passion - All Forums]]></title>
		<link>http://coderpassion.comuf.com/</link>
		<description><![CDATA[Coder Passion - http://coderpassion.comuf.com]]></description>
		<pubDate>Fri, 19 Mar 2010 13:29:57 -0700</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[Unix Socket Server/Client]]></title>
			<link>http://coderpassion.comuf.com/thread-82.html</link>
			<pubDate>Wed, 24 Feb 2010 00:12:07 -0800</pubDate>
			<dc:creator>shazin</dc:creator>
			<guid isPermaLink="false">http://coderpassion.comuf.com/thread-82.html</guid>
			<description><![CDATA[Unix supports a great API to write socket programs. The following example shows a simple hello world server which sends a message to the client once connected.<br />
<br />
<span style="font-weight: bold;">helloworldserver.c</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>#include &lt;sys/socket.h&gt;<br />
#include &lt;sys/types.h&gt;<br />
#include &lt;netdb.h&gt;<br />
#include &lt;netinet/in.h&gt;<br />
#include &lt;stdio.h&gt;<br />
#include &lt;stdlib.h&gt;<br />
<br />
int main(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;struct sockaddr_in sin;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sin.sin_family = AF_INET;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sin.sin_port = htons( 10000 );<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sin.sin_addr.s_addr = INADDR_ANY;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int sd = socket( AF_INET, SOCK_STREAM, 0 );<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bind( sd, (struct sockaddr *)&amp;sin, sizeof(sin) );<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("Binding to localhost...&#92;n");<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;listen( sd, 10 );<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("Listening on Port 1000...&#92;n");<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int ssd = accept( sd, NULL, NULL );<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("Connected to Client&#92;n");<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;char message[100&#93; = "Hello, World!";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;write( ssd, message, sizeof(message) );<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;close( ssd );<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;close( sd );<br />
}</code></div></div>
<br />
<span style="font-weight: bold;">helloworldclient.c</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>#include &lt;sys/socket.h&gt;<br />
#include &lt;sys/types.h&gt;<br />
#include &lt;netdb.h&gt;<br />
#include &lt;netinet/in.h&gt;<br />
#include &lt;stdio.h&gt;<br />
#include &lt;stdlib.h&gt;<br />
<br />
int main(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;struct sockaddr_in sin;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;struct hostent *hp;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hp = gethostbyname("localhost");<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sin.sin_family = AF_INET;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sin.sin_port = htons( 10000 );<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sin.sin_addr.s_addr = ((struct in_addr *)hp-&gt;h_addr)-&gt;s_addr;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int sd = socket( AF_INET, SOCK_STREAM, 0 );<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;connect( sd, (struct sockaddr *)&amp;sin, sizeof(sin) );<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("Connected to Server...&#92;n");<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;char message[100&#93;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;read( sd, message, sizeof(message) );<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("Message Received : %s&#92;n",message);<br />
<br />
}</code></div></div>
]]></description>
			<content:encoded><![CDATA[Unix supports a great API to write socket programs. The following example shows a simple hello world server which sends a message to the client once connected.<br />
<br />
<span style="font-weight: bold;">helloworldserver.c</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>#include &lt;sys/socket.h&gt;<br />
#include &lt;sys/types.h&gt;<br />
#include &lt;netdb.h&gt;<br />
#include &lt;netinet/in.h&gt;<br />
#include &lt;stdio.h&gt;<br />
#include &lt;stdlib.h&gt;<br />
<br />
int main(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;struct sockaddr_in sin;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sin.sin_family = AF_INET;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sin.sin_port = htons( 10000 );<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sin.sin_addr.s_addr = INADDR_ANY;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int sd = socket( AF_INET, SOCK_STREAM, 0 );<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bind( sd, (struct sockaddr *)&amp;sin, sizeof(sin) );<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("Binding to localhost...&#92;n");<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;listen( sd, 10 );<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("Listening on Port 1000...&#92;n");<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int ssd = accept( sd, NULL, NULL );<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("Connected to Client&#92;n");<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;char message[100] = "Hello, World!";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;write( ssd, message, sizeof(message) );<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;close( ssd );<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;close( sd );<br />
}</code></div></div>
<br />
<span style="font-weight: bold;">helloworldclient.c</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>#include &lt;sys/socket.h&gt;<br />
#include &lt;sys/types.h&gt;<br />
#include &lt;netdb.h&gt;<br />
#include &lt;netinet/in.h&gt;<br />
#include &lt;stdio.h&gt;<br />
#include &lt;stdlib.h&gt;<br />
<br />
int main(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;struct sockaddr_in sin;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;struct hostent *hp;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hp = gethostbyname("localhost");<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sin.sin_family = AF_INET;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sin.sin_port = htons( 10000 );<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sin.sin_addr.s_addr = ((struct in_addr *)hp-&gt;h_addr)-&gt;s_addr;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int sd = socket( AF_INET, SOCK_STREAM, 0 );<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;connect( sd, (struct sockaddr *)&amp;sin, sizeof(sin) );<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("Connected to Server...&#92;n");<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;char message[100];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;read( sd, message, sizeof(message) );<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("Message Received : %s&#92;n",message);<br />
<br />
}</code></div></div>
]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Symbian OS Goes Open Source]]></title>
			<link>http://coderpassion.comuf.com/thread-81.html</link>
			<pubDate>Mon, 08 Feb 2010 19:50:50 -0800</pubDate>
			<dc:creator>shazin</dc:creator>
			<guid isPermaLink="false">http://coderpassion.comuf.com/thread-81.html</guid>
			<description><![CDATA[The popular Mobile Phone Operating System Symbian is now Open Sourced to invite developers around the world to come together and collaborate. <br />
<br />
<a href="http://developer.symbian.org/" target="_blank">Developer Symbian</a>]]></description>
			<content:encoded><![CDATA[The popular Mobile Phone Operating System Symbian is now Open Sourced to invite developers around the world to come together and collaborate. <br />
<br />
<a href="http://developer.symbian.org/" target="_blank">Developer Symbian</a>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Abstract Factory Pattern using Java]]></title>
			<link>http://coderpassion.comuf.com/thread-80.html</link>
			<pubDate>Fri, 22 Jan 2010 00:46:27 -0800</pubDate>
			<dc:creator>shazin</dc:creator>
			<guid isPermaLink="false">http://coderpassion.comuf.com/thread-80.html</guid>
			<description><![CDATA[Factory Pattern is a widely used efficient pattern that eliminates the need of Constructing objects in the client code. Instead the Factory creates and delivers objects as required by the client. This method eliminates the need to instantiate (use the new keyword) with a client code.<br />
<br />
A small example demonstrates this pattern.<br />
<span style="font-weight: bold;">Beverage.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public interface Beverage {<br />
&nbsp;&nbsp;&nbsp;&nbsp;void addSugar();<br />
&nbsp;&nbsp;&nbsp;&nbsp;void stir();<br />
}</code></div></div>
<br />
<span style="font-weight: bold;">Tea.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public class Tea implements Beverage {<br />
&nbsp;&nbsp;&nbsp;&nbsp;public void addSugar(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Sugar Added to Tea");<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public void stir(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Tea stirred");<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>
<br />
<span style="font-weight: bold;">Coffee.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public class Coffee implements Beverage {<br />
&nbsp;&nbsp;&nbsp;&nbsp;public void addSugar(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Sugar Added to Coffee");<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public void stir(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Coffee stirred");<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>
<span style="font-weight: bold;">BeverageFactory.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public abstract class BeverageFactory {<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static final int COFFEE = 1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static final int TEA = COFFEE + 1;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static Beverage getBeverage(int whichBeverage){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch(whichBeverage){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case 1 : return new Coffee();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case 2 : return new Tea();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default : return null;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
}</code></div></div>
<br />
<span style="font-weight: bold;">FactoryTest.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public class FactoryTest {<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String[&#93; args){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Beverage tea = BeverageFactory.getBeverage(BeverageFactory.TEA);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tea.addSugar();&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tea.stir();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Beverage coffee = BeverageFactory.getBeverage(BeverageFactory.COFFEE);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;coffee.addSugar();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;coffee.stir();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>
]]></description>
			<content:encoded><![CDATA[Factory Pattern is a widely used efficient pattern that eliminates the need of Constructing objects in the client code. Instead the Factory creates and delivers objects as required by the client. This method eliminates the need to instantiate (use the new keyword) with a client code.<br />
<br />
A small example demonstrates this pattern.<br />
<span style="font-weight: bold;">Beverage.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public interface Beverage {<br />
&nbsp;&nbsp;&nbsp;&nbsp;void addSugar();<br />
&nbsp;&nbsp;&nbsp;&nbsp;void stir();<br />
}</code></div></div>
<br />
<span style="font-weight: bold;">Tea.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public class Tea implements Beverage {<br />
&nbsp;&nbsp;&nbsp;&nbsp;public void addSugar(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Sugar Added to Tea");<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public void stir(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Tea stirred");<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>
<br />
<span style="font-weight: bold;">Coffee.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public class Coffee implements Beverage {<br />
&nbsp;&nbsp;&nbsp;&nbsp;public void addSugar(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Sugar Added to Coffee");<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public void stir(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Coffee stirred");<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>
<span style="font-weight: bold;">BeverageFactory.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public abstract class BeverageFactory {<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static final int COFFEE = 1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static final int TEA = COFFEE + 1;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static Beverage getBeverage(int whichBeverage){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch(whichBeverage){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case 1 : return new Coffee();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case 2 : return new Tea();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default : return null;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
}</code></div></div>
<br />
<span style="font-weight: bold;">FactoryTest.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public class FactoryTest {<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String[] args){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Beverage tea = BeverageFactory.getBeverage(BeverageFactory.TEA);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tea.addSugar();&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tea.stir();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Beverage coffee = BeverageFactory.getBeverage(BeverageFactory.COFFEE);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;coffee.addSugar();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;coffee.stir();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>
]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Portable Ubuntu]]></title>
			<link>http://coderpassion.comuf.com/thread-79.html</link>
			<pubDate>Tue, 15 Dec 2009 22:01:23 -0800</pubDate>
			<dc:creator>shazin</dc:creator>
			<guid isPermaLink="false">http://coderpassion.comuf.com/thread-79.html</guid>
			<description><![CDATA[Ubuntu is the fastest growing linux distribution thus far. Ubuntu is based on Debian linux and allows utmost user friendliness and power. <br />
<br />
Portable Ubuntu is a windows application that allows you to use ubuntu in windows as if you are using a windows application. <br />
<br />
<a href="http://portableubuntu.demonccc.com.ar/" target="_blank">Check it out</a>]]></description>
			<content:encoded><![CDATA[Ubuntu is the fastest growing linux distribution thus far. Ubuntu is based on Debian linux and allows utmost user friendliness and power. <br />
<br />
Portable Ubuntu is a windows application that allows you to use ubuntu in windows as if you are using a windows application. <br />
<br />
<a href="http://portableubuntu.demonccc.com.ar/" target="_blank">Check it out</a>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Top 10 Google Chrome features to boost your productivity]]></title>
			<link>http://coderpassion.comuf.com/thread-78.html</link>
			<pubDate>Thu, 26 Nov 2009 21:21:40 -0800</pubDate>
			<dc:creator>jemswhite</dc:creator>
			<guid isPermaLink="false">http://coderpassion.comuf.com/thread-78.html</guid>
			<description><![CDATA[Hi,<br />
1. Ultimate browser speed<br />
2. Integrated search into address bar<br />
3. New tab opens with your favorite links and most visited pages<br />
4. Get most of your screen<br />
5. One-click bookmarks with categorizing<br />
6. Shortcuts to web apps<br />
7. Offline mode based on Google Gears<br />
8. Tabs management<br />
9. Independent processes for opened tabs]]></description>
			<content:encoded><![CDATA[Hi,<br />
1. Ultimate browser speed<br />
2. Integrated search into address bar<br />
3. New tab opens with your favorite links and most visited pages<br />
4. Get most of your screen<br />
5. One-click bookmarks with categorizing<br />
6. Shortcuts to web apps<br />
7. Offline mode based on Google Gears<br />
8. Tabs management<br />
9. Independent processes for opened tabs]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Windows 7 or vista..?]]></title>
			<link>http://coderpassion.comuf.com/thread-77.html</link>
			<pubDate>Thu, 26 Nov 2009 21:19:55 -0800</pubDate>
			<dc:creator>jemswhite</dc:creator>
			<guid isPermaLink="false">http://coderpassion.comuf.com/thread-77.html</guid>
			<description><![CDATA[Hi to all<br />
I am planning to buy new laptop.But confused little which system to buy.So please share your experience so i can get some ideas.which one is better..?]]></description>
			<content:encoded><![CDATA[Hi to all<br />
I am planning to buy new laptop.But confused little which system to buy.So please share your experience so i can get some ideas.which one is better..?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Send Sensitive Messages via norbt]]></title>
			<link>http://coderpassion.comuf.com/thread-76.html</link>
			<pubDate>Wed, 18 Nov 2009 00:03:04 -0800</pubDate>
			<dc:creator>shazin</dc:creator>
			<guid isPermaLink="false">http://coderpassion.comuf.com/thread-76.html</guid>
			<description><![CDATA[Ever wondered sending sensitive information such as Credit Card No, Passwords, Email Addresses, Phone Nos or merely anything that you think is confidential via mail or IM is not safe?<br />
The odds are in favor of you. Mails and IMs can be eavesdropped and the information can be crawled by bots. So what is the solution?<br />
<br />
<a href="https://norbt.com/" target="_blank">norbt</a><br />
<br />
norbt allows you to create locked text and allows to give a question and answer for that text to be revealed. So that text will be only visible to those who know the answer to that question.]]></description>
			<content:encoded><![CDATA[Ever wondered sending sensitive information such as Credit Card No, Passwords, Email Addresses, Phone Nos or merely anything that you think is confidential via mail or IM is not safe?<br />
The odds are in favor of you. Mails and IMs can be eavesdropped and the information can be crawled by bots. So what is the solution?<br />
<br />
<a href="https://norbt.com/" target="_blank">norbt</a><br />
<br />
norbt allows you to create locked text and allows to give a question and answer for that text to be revealed. So that text will be only visible to those who know the answer to that question.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Tweet Control]]></title>
			<link>http://coderpassion.comuf.com/thread-75.html</link>
			<pubDate>Tue, 10 Nov 2009 04:43:19 -0800</pubDate>
			<dc:creator>shazin</dc:creator>
			<guid isPermaLink="false">http://coderpassion.comuf.com/thread-75.html</guid>
			<description><![CDATA[Tweet Control is a small java application which lets you <br />
<br />
<ol type="1">
<li>Shutdown</li>
<li>Restart</li>
<li>Logoff <br />
</li></ol>
<br />
   <br />
your Windows, Linux PC using Twitter!<br />
<br />
Tweet Control is based on Twitter4J <br />
which is an open source Java Library for Twitter API<br />
<br />
<a href="http://yusuke.homeip.net/twitter4j/en/index.html" target="_blank">http://yusuke.homeip.net/twitter4j/en/index.html</a><br />
<br />
Tweet Control along with Twitter4J Library is attached. Check it out.]]></description>
			<content:encoded><![CDATA[Tweet Control is a small java application which lets you <br />
<br />
<ol type="1">
<li>Shutdown</li>
<li>Restart</li>
<li>Logoff <br />
</li></ol>
<br />
   <br />
your Windows, Linux PC using Twitter!<br />
<br />
Tweet Control is based on Twitter4J <br />
which is an open source Java Library for Twitter API<br />
<br />
<a href="http://yusuke.homeip.net/twitter4j/en/index.html" target="_blank">http://yusuke.homeip.net/twitter4j/en/index.html</a><br />
<br />
Tweet Control along with Twitter4J Library is attached. Check it out.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Decorator Pattern using Java]]></title>
			<link>http://coderpassion.comuf.com/thread-74.html</link>
			<pubDate>Thu, 05 Nov 2009 01:06:45 -0800</pubDate>
			<dc:creator>shazin</dc:creator>
			<guid isPermaLink="false">http://coderpassion.comuf.com/thread-74.html</guid>
			<description><![CDATA[In any Object oriented programming language "Composition over Inheritance" is advised. Composition allows flexibility in code and is easy to maintain and enhance. <br />
<br />
To create composition the widely used pattern is Decorator Pattern. If we take a Christmas Tree as an example, it may be decorated with Light, Candy. So if we are to inherit Christmas Tree and create each unique combination of Decoration, There will be many classes with different combination of decorations at different prices and if we introduce another deco ratable item Star then there will be a lot of code change which is harder to maintain. This is where decorator pattern comes in handy the example shows you how to implement the above scenario,<br />
<br />
<span style="font-weight: bold;">Decoratable.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public interface Decoratable {<br />
&nbsp;&nbsp;&nbsp;&nbsp;public double cost();<br />
}</code></div></div>
<br />
<span style="font-weight: bold;">ChristmasTree.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public class ChristmasTree implements Decoratable {<br />
&nbsp;&nbsp;&nbsp;&nbsp;//Price of Christmas Tree<br />
&nbsp;&nbsp;&nbsp;&nbsp;public double cost(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 1.0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>
<br />
<span style="font-weight: bold;">Light.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public class Light implements Decoratable {<br />
&nbsp;&nbsp;&nbsp;&nbsp;private Decoratable root;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;public Light(Decoratable root){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.root = root;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;//Price of Light + Price of root<br />
&nbsp;&nbsp;&nbsp;&nbsp;public double cost(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return root.cost() + 0.5;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>
<br />
<span style="font-weight: bold;">Candy.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public class Candy implements Decoratable {<br />
&nbsp;&nbsp;&nbsp;&nbsp;private Decoratable root;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public Candy(Decoratable root){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.root = root;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;//Price of Candy + Price of root<br />
&nbsp;&nbsp;&nbsp;&nbsp;public double cost(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return root.cost() + 0.75;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<br />
}</code></div></div>
<br />
<span style="font-weight: bold;">Star.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public class Star implements Decoratable {<br />
&nbsp;&nbsp;&nbsp;&nbsp;private Decoratable root;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public Star(Decoratable root){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.root = root;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Price of Star + Price of root<br />
&nbsp;&nbsp;&nbsp;&nbsp;public double cost(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return root.cost() + 1.50;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>
<br />
<span style="font-weight: bold;">DecoratorTest.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public class DecoratorTest {<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String[&#93; args){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Christmas Tree without any decoration<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Decoratable target = new ChristmasTree();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Price of the Christmas Tree " + target.cost());<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Christmas Tree decorated with Light<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;target = new Light(target);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Price of the Christmas Tree with Light " + target.cost());&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Christmas Tree decorated with Light, Candy<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;target = new Candy(target);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Price of the Christmas Tree with Light, Candy " + target.cost());<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Christmas Tree decorated with Light, Candy, Star<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;target = new Star(target);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Price of the Christmas Tree with Light, Candy, Star " + target.cost());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<br />
}</code></div></div>
]]></description>
			<content:encoded><![CDATA[In any Object oriented programming language "Composition over Inheritance" is advised. Composition allows flexibility in code and is easy to maintain and enhance. <br />
<br />
To create composition the widely used pattern is Decorator Pattern. If we take a Christmas Tree as an example, it may be decorated with Light, Candy. So if we are to inherit Christmas Tree and create each unique combination of Decoration, There will be many classes with different combination of decorations at different prices and if we introduce another deco ratable item Star then there will be a lot of code change which is harder to maintain. This is where decorator pattern comes in handy the example shows you how to implement the above scenario,<br />
<br />
<span style="font-weight: bold;">Decoratable.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public interface Decoratable {<br />
&nbsp;&nbsp;&nbsp;&nbsp;public double cost();<br />
}</code></div></div>
<br />
<span style="font-weight: bold;">ChristmasTree.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public class ChristmasTree implements Decoratable {<br />
&nbsp;&nbsp;&nbsp;&nbsp;//Price of Christmas Tree<br />
&nbsp;&nbsp;&nbsp;&nbsp;public double cost(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 1.0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>
<br />
<span style="font-weight: bold;">Light.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public class Light implements Decoratable {<br />
&nbsp;&nbsp;&nbsp;&nbsp;private Decoratable root;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;public Light(Decoratable root){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.root = root;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;//Price of Light + Price of root<br />
&nbsp;&nbsp;&nbsp;&nbsp;public double cost(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return root.cost() + 0.5;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>
<br />
<span style="font-weight: bold;">Candy.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public class Candy implements Decoratable {<br />
&nbsp;&nbsp;&nbsp;&nbsp;private Decoratable root;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public Candy(Decoratable root){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.root = root;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;//Price of Candy + Price of root<br />
&nbsp;&nbsp;&nbsp;&nbsp;public double cost(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return root.cost() + 0.75;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<br />
}</code></div></div>
<br />
<span style="font-weight: bold;">Star.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public class Star implements Decoratable {<br />
&nbsp;&nbsp;&nbsp;&nbsp;private Decoratable root;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public Star(Decoratable root){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.root = root;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Price of Star + Price of root<br />
&nbsp;&nbsp;&nbsp;&nbsp;public double cost(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return root.cost() + 1.50;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>
<br />
<span style="font-weight: bold;">DecoratorTest.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public class DecoratorTest {<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String[] args){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Christmas Tree without any decoration<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Decoratable target = new ChristmasTree();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Price of the Christmas Tree " + target.cost());<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Christmas Tree decorated with Light<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;target = new Light(target);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Price of the Christmas Tree with Light " + target.cost());&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Christmas Tree decorated with Light, Candy<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;target = new Candy(target);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Price of the Christmas Tree with Light, Candy " + target.cost());<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Christmas Tree decorated with Light, Candy, Star<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;target = new Star(target);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Price of the Christmas Tree with Light, Candy, Star " + target.cost());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<br />
}</code></div></div>
]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Android OS Test Run]]></title>
			<link>http://coderpassion.comuf.com/thread-73.html</link>
			<pubDate>Mon, 24 Aug 2009 10:06:38 -0700</pubDate>
			<dc:creator>shazin</dc:creator>
			<guid isPermaLink="false">http://coderpassion.comuf.com/thread-73.html</guid>
			<description><![CDATA[If you still didn't get a chance to test the Android OS or you feel hesitant in buying one without properly getting a feel of the Android OS now you can run it in VMWare and decide. I was able to download a live cd image from <a href="http://code.google.com/p/live-android/" target="_blank">Live Android</a><br />
<br />
<img src="http://lh5.ggpht.com/_QPC3c0XV7a0/SpLG4b2JL6I/AAAAAAAAABk/4imkJxjXf4c/Android1.jpg" border="0" alt="[Image: Android1.jpg&#93;" /><br />
<br />
<img src="http://lh3.ggpht.com/_QPC3c0XV7a0/SpLG4eyDTyI/AAAAAAAAABo/oyBX9UsMa4Y/Android2.JPG" border="0" alt="[Image: Android2.JPG&#93;" /><br />
<br />
The UI Looks fascinating at the first glance and you can explore more.]]></description>
			<content:encoded><![CDATA[If you still didn't get a chance to test the Android OS or you feel hesitant in buying one without properly getting a feel of the Android OS now you can run it in VMWare and decide. I was able to download a live cd image from <a href="http://code.google.com/p/live-android/" target="_blank">Live Android</a><br />
<br />
<img src="http://lh5.ggpht.com/_QPC3c0XV7a0/SpLG4b2JL6I/AAAAAAAAABk/4imkJxjXf4c/Android1.jpg" border="0" alt="[Image: Android1.jpg]" /><br />
<br />
<img src="http://lh3.ggpht.com/_QPC3c0XV7a0/SpLG4eyDTyI/AAAAAAAAABo/oyBX9UsMa4Y/Android2.JPG" border="0" alt="[Image: Android2.JPG]" /><br />
<br />
The UI Looks fascinating at the first glance and you can explore more.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Runtime Exception Handling in Java]]></title>
			<link>http://coderpassion.comuf.com/thread-72.html</link>
			<pubDate>Sun, 23 Aug 2009 22:41:39 -0700</pubDate>
			<dc:creator>shazin</dc:creator>
			<guid isPermaLink="false">http://coderpassion.comuf.com/thread-72.html</guid>
			<description><![CDATA[When writing java code we must handle checked exceptions which may be thrown by constructors or methods we use. But throwing of Runtime Exceptions can not be guaranteed, so developers hardly write any code that will catch Runtime Exceptions. Thus when a Runtime Exception such as a NumberFormatException is thrown, Threads abruptly exit after printing the stack trace. This could be prevented by assigning an implementation of Thread.UncaughtExceptionHandler (Java 1.5+ ) to the thread we are invoking.<br />
<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>/*<br />
 * @author Shazin Sadakath<br />
 *<br />
*/<br />
<br />
public class ThreadTest implements Runnable{<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String[&#93; args){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread t = new Thread(new ThreadTest());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.setUncaughtExceptionHandler(new UncaughtExceptionHandler());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.start();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public void run(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new IllegalArgumentException("This is a Runtime Exception and must be caught");<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;private static class UncaughtExceptionHandler implements Thread.UncaughtExceptionHandler{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public void uncaughtException(Thread t, Throwable th){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Custom Error Handling");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(t.getName() + " Threw " + th);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>
]]></description>
			<content:encoded><![CDATA[When writing java code we must handle checked exceptions which may be thrown by constructors or methods we use. But throwing of Runtime Exceptions can not be guaranteed, so developers hardly write any code that will catch Runtime Exceptions. Thus when a Runtime Exception such as a NumberFormatException is thrown, Threads abruptly exit after printing the stack trace. This could be prevented by assigning an implementation of Thread.UncaughtExceptionHandler (Java 1.5+ ) to the thread we are invoking.<br />
<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>/*<br />
 * @author Shazin Sadakath<br />
 *<br />
*/<br />
<br />
public class ThreadTest implements Runnable{<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String[] args){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread t = new Thread(new ThreadTest());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.setUncaughtExceptionHandler(new UncaughtExceptionHandler());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.start();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public void run(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new IllegalArgumentException("This is a Runtime Exception and must be caught");<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;private static class UncaughtExceptionHandler implements Thread.UncaughtExceptionHandler{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public void uncaughtException(Thread t, Throwable th){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Custom Error Handling");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(t.getName() + " Threw " + th);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>
]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Google Code Jam 2009 Practice]]></title>
			<link>http://coderpassion.comuf.com/thread-71.html</link>
			<pubDate>Thu, 20 Aug 2009 00:46:54 -0700</pubDate>
			<dc:creator>shazin</dc:creator>
			<guid isPermaLink="false">http://coderpassion.comuf.com/thread-71.html</guid>
			<description><![CDATA[I have been just playing around with some practices posted on Google Code Jam 2009, and successfully completed the Alien Number System. <br />
<br />
I would just like to share the code with you all. The code is not optimized. Wrote it within 2 hours.<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>import java.util.*;<br />
import java.io.*;<br />
<br />
public class AlienNumber{<br />
&nbsp;&nbsp;&nbsp;&nbsp;private static int digits = -1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;private static int sourceIndex = -1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;private static String targetNo = null;<br />
&nbsp;&nbsp;&nbsp;&nbsp;private static List&lt;String&gt; sourcenos = new ArrayList&lt;String&gt;();<br />
&nbsp;&nbsp;&nbsp;&nbsp;private static List&lt;String&gt; targetnos = new ArrayList&lt;String&gt;();<br />
&nbsp;&nbsp;&nbsp;&nbsp;private static boolean found = false;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String[&#93; args)throws Exception{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BufferedReader br = new BufferedReader(new FileReader(args[0&#93;));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int noOfCases = Integer.parseInt(br.readLine().trim());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int i = 0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while(i &lt; noOfCases){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String[&#93; params = br.readLine().split("&#92;&#92;s+");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;targetNo = params[0&#93;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;createSourceNos(params[1&#93;);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;createTargetNos(params[2&#93;);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.printf("Case #%d: %s%n", (i+1), targetnos.get(sourceIndex));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clearAll();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i++;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void createSourceNos(String noSystem){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while(!found){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(digits==-1){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printNos("",noSystem.substring(1), sourcenos);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printNos(sourcenos.get(digits),noSystem, sourcenos);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;digits = -1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sourceIndex = sourcenos.size()-1;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sourcenos = null;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void createTargetNos(String noSystem){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while(digits&lt;=sourceIndex){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(digits==-1){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printNos("",noSystem.substring(1), targetnos);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printNos(targetnos.get(digits),noSystem, targetnos);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;digits = -1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void printNos(String pre, String noSystem, List&lt;String&gt; nos){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(int j=0;j&lt;noSystem.length();j++){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String no = pre + noSystem.charAt(j);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nos.add(no);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(no.equals(targetNo)){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;found = true;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;digits++;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;private static void clearAll(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;digits = -1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sourceIndex = -1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;targetnos = null;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sourcenos = new ArrayList&lt;String&gt;();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;targetnos = new ArrayList&lt;String&gt;();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;found = false;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.gc();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>
<br />
<a href="http://code.google.com/codejam/" target="_blank">Google Code Jam 2009</a>]]></description>
			<content:encoded><![CDATA[I have been just playing around with some practices posted on Google Code Jam 2009, and successfully completed the Alien Number System. <br />
<br />
I would just like to share the code with you all. The code is not optimized. Wrote it within 2 hours.<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>import java.util.*;<br />
import java.io.*;<br />
<br />
public class AlienNumber{<br />
&nbsp;&nbsp;&nbsp;&nbsp;private static int digits = -1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;private static int sourceIndex = -1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;private static String targetNo = null;<br />
&nbsp;&nbsp;&nbsp;&nbsp;private static List&lt;String&gt; sourcenos = new ArrayList&lt;String&gt;();<br />
&nbsp;&nbsp;&nbsp;&nbsp;private static List&lt;String&gt; targetnos = new ArrayList&lt;String&gt;();<br />
&nbsp;&nbsp;&nbsp;&nbsp;private static boolean found = false;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String[] args)throws Exception{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BufferedReader br = new BufferedReader(new FileReader(args[0]));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int noOfCases = Integer.parseInt(br.readLine().trim());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int i = 0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while(i &lt; noOfCases){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String[] params = br.readLine().split("&#92;&#92;s+");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;targetNo = params[0];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;createSourceNos(params[1]);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;createTargetNos(params[2]);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.printf("Case #%d: %s%n", (i+1), targetnos.get(sourceIndex));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clearAll();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i++;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void createSourceNos(String noSystem){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while(!found){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(digits==-1){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printNos("",noSystem.substring(1), sourcenos);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printNos(sourcenos.get(digits),noSystem, sourcenos);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;digits = -1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sourceIndex = sourcenos.size()-1;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sourcenos = null;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void createTargetNos(String noSystem){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while(digits&lt;=sourceIndex){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(digits==-1){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printNos("",noSystem.substring(1), targetnos);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printNos(targetnos.get(digits),noSystem, targetnos);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;digits = -1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void printNos(String pre, String noSystem, List&lt;String&gt; nos){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(int j=0;j&lt;noSystem.length();j++){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String no = pre + noSystem.charAt(j);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nos.add(no);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(no.equals(targetNo)){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;found = true;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;digits++;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;private static void clearAll(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;digits = -1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sourceIndex = -1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;targetnos = null;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sourcenos = new ArrayList&lt;String&gt;();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;targetnos = new ArrayList&lt;String&gt;();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;found = false;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.gc();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>
<br />
<a href="http://code.google.com/codejam/" target="_blank">Google Code Jam 2009</a>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[JavaScript in Java]]></title>
			<link>http://coderpassion.comuf.com/thread-70.html</link>
			<pubDate>Sun, 16 Aug 2009 21:29:53 -0700</pubDate>
			<dc:creator>shazin</dc:creator>
			<guid isPermaLink="false">http://coderpassion.comuf.com/thread-70.html</guid>
			<description><![CDATA[Starting from Java 1.6 an API for executing scripting languages as been included. This allows to execute scripting languages such as JavaScript from within a Java Application. This enables great flexibility when it comes to volatile codes because changing a code doesn't require recompilation. <br />
<br />
An instance of the uses follows;<br />
<br />
<br />
<span style="font-weight: bold;">Java Source File : ScriptTest.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>import javax.script.*;<br />
import java.io.*;<br />
<br />
public class ScriptTest{<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String[&#93; args){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ScriptEngineManager mgr = new ScriptEngineManager();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ScriptEngine engine = mgr.getEngineByName("JavaScript");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InputStream is = null;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;is = new FileInputStream("script.js");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}catch(FileNotFoundException fnfe){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fnfe.printStackTrace();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;engine.eval(new InputStreamReader(is));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}catch(ScriptException e){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>
<span style="font-weight: bold;">JavaScript Source File : script.js</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>var no1 = 10;<br />
var no2 = 67;<br />
<br />
var total = no1 + no2;<br />
<br />
println("Total is " + total);</code></div></div>
<br />
Executing the ScriptTest class will print the total of the no1 and no2 <br />
by executing the .js file. At the moment by default only JavaScript is supported with this API. You can change the script.js file and see the result changing without recompiling the .java file.]]></description>
			<content:encoded><![CDATA[Starting from Java 1.6 an API for executing scripting languages as been included. This allows to execute scripting languages such as JavaScript from within a Java Application. This enables great flexibility when it comes to volatile codes because changing a code doesn't require recompilation. <br />
<br />
An instance of the uses follows;<br />
<br />
<br />
<span style="font-weight: bold;">Java Source File : ScriptTest.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>import javax.script.*;<br />
import java.io.*;<br />
<br />
public class ScriptTest{<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String[] args){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ScriptEngineManager mgr = new ScriptEngineManager();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ScriptEngine engine = mgr.getEngineByName("JavaScript");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InputStream is = null;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;is = new FileInputStream("script.js");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}catch(FileNotFoundException fnfe){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fnfe.printStackTrace();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;engine.eval(new InputStreamReader(is));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}catch(ScriptException e){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>
<span style="font-weight: bold;">JavaScript Source File : script.js</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>var no1 = 10;<br />
var no2 = 67;<br />
<br />
var total = no1 + no2;<br />
<br />
println("Total is " + total);</code></div></div>
<br />
Executing the ScriptTest class will print the total of the no1 and no2 <br />
by executing the .js file. At the moment by default only JavaScript is supported with this API. You can change the script.js file and see the result changing without recompiling the .java file.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Google Wave Preview]]></title>
			<link>http://coderpassion.comuf.com/thread-69.html</link>
			<pubDate>Thu, 06 Aug 2009 21:14:23 -0700</pubDate>
			<dc:creator>shazin</dc:creator>
			<guid isPermaLink="false">http://coderpassion.comuf.com/thread-69.html</guid>
			<description><![CDATA[<img src="http://www.blogcdn.com/www.engadget.com/media/2009/08/google-wave-top-hed-rm-eng-12.jpg" border="0" alt="[Image: google-wave-top-hed-rm-eng-12.jpg&#93;" /><br />
<img src="http://www.blogcdn.com/www.engadget.com/media/2009/08/google-wave-smaller-window-rm-eng.jpg" border="0" alt="[Image: google-wave-smaller-window-rm-eng.jpg&#93;" /><br />
<img src="http://www.blogcdn.com/www.engadget.com/media/2009/08/google-wave-cluttered-rm-eng.jpg" border="0" alt="[Image: google-wave-cluttered-rm-eng.jpg&#93;" /><br />
<img src="http://www.blogcdn.com/www.engadget.com/media/2009/08/google-wave-swedish-chef-rm-eng-1.jpg" border="0" alt="[Image: google-wave-swedish-chef-rm-eng-1.jpg&#93;" /><img src="http://www.blogcdn.com/www.engadget.com/media/2009/08/google-wave-iphone-pics-rm-eng.jpg" border="0" alt="[Image: google-wave-iphone-pics-rm-eng.jpg&#93;" /><img src="http://www.blogcdn.com/www.engadget.com/media/2009/08/google-wave-life-of-brian-rm-en-g1.jpg" border="0" alt="[Image: google-wave-life-of-brian-rm-en-g1.jpg&#93;" /><br />
<br />
Source : <a href="http://www.engadget.com" target="_blank">Engadget</a>]]></description>
			<content:encoded><![CDATA[<img src="http://www.blogcdn.com/www.engadget.com/media/2009/08/google-wave-top-hed-rm-eng-12.jpg" border="0" alt="[Image: google-wave-top-hed-rm-eng-12.jpg]" /><br />
<img src="http://www.blogcdn.com/www.engadget.com/media/2009/08/google-wave-smaller-window-rm-eng.jpg" border="0" alt="[Image: google-wave-smaller-window-rm-eng.jpg]" /><br />
<img src="http://www.blogcdn.com/www.engadget.com/media/2009/08/google-wave-cluttered-rm-eng.jpg" border="0" alt="[Image: google-wave-cluttered-rm-eng.jpg]" /><br />
<img src="http://www.blogcdn.com/www.engadget.com/media/2009/08/google-wave-swedish-chef-rm-eng-1.jpg" border="0" alt="[Image: google-wave-swedish-chef-rm-eng-1.jpg]" /><img src="http://www.blogcdn.com/www.engadget.com/media/2009/08/google-wave-iphone-pics-rm-eng.jpg" border="0" alt="[Image: google-wave-iphone-pics-rm-eng.jpg]" /><img src="http://www.blogcdn.com/www.engadget.com/media/2009/08/google-wave-life-of-brian-rm-en-g1.jpg" border="0" alt="[Image: google-wave-life-of-brian-rm-en-g1.jpg]" /><br />
<br />
Source : <a href="http://www.engadget.com" target="_blank">Engadget</a>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Simple Neuron Network using Java]]></title>
			<link>http://coderpassion.comuf.com/thread-68.html</link>
			<pubDate>Wed, 22 Jul 2009 22:17:32 -0700</pubDate>
			<dc:creator>shazin</dc:creator>
			<guid isPermaLink="false">http://coderpassion.comuf.com/thread-68.html</guid>
			<description><![CDATA[A Neural Network is a collection of Neurons connected together to make a decision based on how they all react.<br />
<br />
Biologically speaking every Neuron in our brain has a Thresh Hold, a maximum amount of electrical current it can tolerate. A Neuron will not fire until it exceeds this thresh hold. The input that comes into a Neuron in the form of a electrical current is called Weight if the Weight &gt; Thresh Hold then the neuron will fire.<br />
<br />
A Neuron can take in either one Weight or many.<br />
<br />
The following example shows a simple Implementation of a Neuron that enables the use of And &amp; Or operator logic. <br />
<br />
Neuron.java <br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public class Neuron{<br />
&nbsp;&nbsp;&nbsp;&nbsp;private Neuron[&#93; neurons;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;private float threshHold;<br />
&nbsp;&nbsp;&nbsp;&nbsp;private float weight;<br />
&nbsp;&nbsp;&nbsp;&nbsp;private boolean fired;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;public Neuron(float threshHold){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.threshHold = threshHold;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public void setWeight(float weight){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.weight = weight;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public float getWeight(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return weight;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public boolean isFired(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return fired;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public void connectNeurons(Neuron... neurons){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(neurons != null){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.neurons = neurons;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public float fire(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(neurons != null){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float totalWeight = 0.0f;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(int i=0;i&lt;neurons.length;i++){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;totalWeight += neurons[i&#93;.getWeight();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fired = totalWeight &gt; threshHold;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return totalWeight;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else if(weight != 0.0f){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fired = weight &gt; threshHold;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return weight;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new RuntimeException("Neither weight nor neurons to make a decision");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
<br />
}</code></div></div>
<br />
AndOperator.java<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public class AndOperator{<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String[&#93; args){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * A | B | Result<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * --------------<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 1 | 1 |&nbsp;&nbsp; 1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 1 | 0 |&nbsp;&nbsp; 0<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 0 | 1 |&nbsp;&nbsp; 0<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 0 | 0 |&nbsp;&nbsp; 0<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Neuron andOperator = new Neuron(1.5f); //Threshhold is 1.5<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Neuron operand1 = new Neuron(0.0f); //Threshhold is 0.0 because no decision is made<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Neuron operand2 = new Neuron(0.0f); //from these neurons&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;operand1.setWeight(1.0f); //Both operands carry a weight of 1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;operand2.setWeight(1.0f);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;andOperator.connectNeurons(operand1,operand2);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//If both operands have a weight of 1 or more only<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//the Neuron will fire<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;andOperator.fire();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("AndOperator Result : "+andOperator.isFired());<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;operand1.setWeight(1.0f); //operand1 carry a weight of 1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;operand2.setWeight(0.0f); //operand2 carry a weight of 0<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//If both operands have a weight of 1 or more only<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//the Neuron will fire<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;andOperator.fire();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("AndOperator Result : "+andOperator.isFired());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>
<br />
OrOperator.java<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public class OrOperator{<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String[&#93; args){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * A | B | Result<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * --------------<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 1 | 1 |&nbsp;&nbsp; 1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 1 | 0 |&nbsp;&nbsp; 1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 0 | 1 |&nbsp;&nbsp; 1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 0 | 0 |&nbsp;&nbsp; 0<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Neuron andOperator = new Neuron(0.9f); //Threshhold is 0.9<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Neuron operand1 = new Neuron(0.0f); //Threshhold is 0.0 because no decision is made<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Neuron operand2 = new Neuron(0.0f); //from these neurons&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;operand1.setWeight(0.0f); //Both operands carry a weight of 0<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;operand2.setWeight(0.0f);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;andOperator.connectNeurons(operand1,operand2);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//If both operands have a weight of 0 or less only<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//the Neuron will not fire<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;andOperator.fire();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("AndOperator Result : "+andOperator.isFired());<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;operand1.setWeight(1.0f); //operand1 carry a weight of 1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;operand2.setWeight(0.0f); //operand2 carry a weight of 0<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//If both operands have a weight of 0 or less only<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//the Neuron will not fire<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;andOperator.fire();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("AndOperator Result : "+andOperator.isFired());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>
]]></description>
			<content:encoded><![CDATA[A Neural Network is a collection of Neurons connected together to make a decision based on how they all react.<br />
<br />
Biologically speaking every Neuron in our brain has a Thresh Hold, a maximum amount of electrical current it can tolerate. A Neuron will not fire until it exceeds this thresh hold. The input that comes into a Neuron in the form of a electrical current is called Weight if the Weight &gt; Thresh Hold then the neuron will fire.<br />
<br />
A Neuron can take in either one Weight or many.<br />
<br />
The following example shows a simple Implementation of a Neuron that enables the use of And &amp; Or operator logic. <br />
<br />
Neuron.java <br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public class Neuron{<br />
&nbsp;&nbsp;&nbsp;&nbsp;private Neuron[] neurons;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;private float threshHold;<br />
&nbsp;&nbsp;&nbsp;&nbsp;private float weight;<br />
&nbsp;&nbsp;&nbsp;&nbsp;private boolean fired;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;public Neuron(float threshHold){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.threshHold = threshHold;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public void setWeight(float weight){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.weight = weight;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public float getWeight(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return weight;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public boolean isFired(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return fired;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public void connectNeurons(Neuron... neurons){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(neurons != null){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.neurons = neurons;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public float fire(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(neurons != null){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float totalWeight = 0.0f;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(int i=0;i&lt;neurons.length;i++){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;totalWeight += neurons[i].getWeight();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fired = totalWeight &gt; threshHold;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return totalWeight;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else if(weight != 0.0f){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fired = weight &gt; threshHold;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return weight;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new RuntimeException("Neither weight nor neurons to make a decision");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
<br />
}</code></div></div>
<br />
AndOperator.java<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public class AndOperator{<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String[] args){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * A | B | Result<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * --------------<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 1 | 1 |&nbsp;&nbsp; 1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 1 | 0 |&nbsp;&nbsp; 0<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 0 | 1 |&nbsp;&nbsp; 0<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 0 | 0 |&nbsp;&nbsp; 0<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Neuron andOperator = new Neuron(1.5f); //Threshhold is 1.5<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Neuron operand1 = new Neuron(0.0f); //Threshhold is 0.0 because no decision is made<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Neuron operand2 = new Neuron(0.0f); //from these neurons&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;operand1.setWeight(1.0f); //Both operands carry a weight of 1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;operand2.setWeight(1.0f);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;andOperator.connectNeurons(operand1,operand2);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//If both operands have a weight of 1 or more only<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//the Neuron will fire<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;andOperator.fire();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("AndOperator Result : "+andOperator.isFired());<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;operand1.setWeight(1.0f); //operand1 carry a weight of 1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;operand2.setWeight(0.0f); //operand2 carry a weight of 0<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//If both operands have a weight of 1 or more only<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//the Neuron will fire<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;andOperator.fire();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("AndOperator Result : "+andOperator.isFired());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>
<br />
OrOperator.java<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>public class OrOperator{<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String[] args){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * A | B | Result<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * --------------<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 1 | 1 |&nbsp;&nbsp; 1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 1 | 0 |&nbsp;&nbsp; 1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 0 | 1 |&nbsp;&nbsp; 1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 0 | 0 |&nbsp;&nbsp; 0<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Neuron andOperator = new Neuron(0.9f); //Threshhold is 0.9<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Neuron operand1 = new Neuron(0.0f); //Threshhold is 0.0 because no decision is made<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Neuron operand2 = new Neuron(0.0f); //from these neurons&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;operand1.setWeight(0.0f); //Both operands carry a weight of 0<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;operand2.setWeight(0.0f);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;andOperator.connectNeurons(operand1,operand2);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//If both operands have a weight of 0 or less only<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//the Neuron will not fire<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;andOperator.fire();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("AndOperator Result : "+andOperator.isFired());<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;operand1.setWeight(1.0f); //operand1 carry a weight of 1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;operand2.setWeight(0.0f); //operand2 carry a weight of 0<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//If both operands have a weight of 0 or less only<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//the Neuron will not fire<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;andOperator.fire();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("AndOperator Result : "+andOperator.isFired());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>
]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[We expect more !!]]></title>
			<link>http://coderpassion.comuf.com/thread-67.html</link>
			<pubDate>Mon, 20 Jul 2009 09:22:15 -0700</pubDate>
			<dc:creator>shamil</dc:creator>
			<guid isPermaLink="false">http://coderpassion.comuf.com/thread-67.html</guid>
			<description><![CDATA[Need tutorials on how to use eclipse, maven, hibernate, facade.. and these should be very basic tutorials so i could understand .. it would be a great help if u could add these ASAP..]]></description>
			<content:encoded><![CDATA[Need tutorials on how to use eclipse, maven, hibernate, facade.. and these should be very basic tutorials so i could understand .. it would be a great help if u could add these ASAP..]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Dynamic Event Listener]]></title>
			<link>http://coderpassion.comuf.com/thread-66.html</link>
			<pubDate>Fri, 17 Jul 2009 22:59:56 -0700</pubDate>
			<dc:creator>shazin</dc:creator>
			<guid isPermaLink="false">http://coderpassion.comuf.com/thread-66.html</guid>
			<description><![CDATA[Event Listeners are crucial part of java. Event Listeners are interfaces thus needs to be implemented each time we need to use one. But java provides a Dynamic way to create Event Listeners using Java reflection. This eliminates the need of writing unnecessary implementation classes.<br />
<br />
The following code snippet shows an example use of EventHandler<br />
<br />
<span style="font-weight: bold;">DynamicEventListener.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>import java.beans.*;<br />
import javax.swing.*;<br />
import java.awt.*;<br />
import java.awt.event.*;<br />
<br />
public class DynamicEventListener extends JFrame{<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String[&#93; args){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new DynamicEventListener();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public DynamicEventListener(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setSize(400,400);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setLocationRelativeTo(null);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setDefaultCloseOperation(EXIT_ON_CLOSE);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setLayout(new BorderLayout());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JButton button = new JButton("Quit");<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Dynamically Creating ActionListener implementation<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;button.addActionListener((ActionListener) EventHandler.create(ActionListener.class, this, "dispose"));<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.add(BorderLayout.NORTH,button);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setVisible(true);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
}</code></div></div>
]]></description>
			<content:encoded><![CDATA[Event Listeners are crucial part of java. Event Listeners are interfaces thus needs to be implemented each time we need to use one. But java provides a Dynamic way to create Event Listeners using Java reflection. This eliminates the need of writing unnecessary implementation classes.<br />
<br />
The following code snippet shows an example use of EventHandler<br />
<br />
<span style="font-weight: bold;">DynamicEventListener.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>import java.beans.*;<br />
import javax.swing.*;<br />
import java.awt.*;<br />
import java.awt.event.*;<br />
<br />
public class DynamicEventListener extends JFrame{<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String[] args){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new DynamicEventListener();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public DynamicEventListener(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setSize(400,400);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setLocationRelativeTo(null);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setDefaultCloseOperation(EXIT_ON_CLOSE);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setLayout(new BorderLayout());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JButton button = new JButton("Quit");<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Dynamically Creating ActionListener implementation<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;button.addActionListener((ActionListener) EventHandler.create(ActionListener.class, this, "dispose"));<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.add(BorderLayout.NORTH,button);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setVisible(true);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
}</code></div></div>
]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Oval Shaped Transparent Frame in Java]]></title>
			<link>http://coderpassion.comuf.com/thread-65.html</link>
			<pubDate>Wed, 15 Jul 2009 21:54:23 -0700</pubDate>
			<dc:creator>shazin</dc:creator>
			<guid isPermaLink="false">http://coderpassion.comuf.com/thread-65.html</guid>
			<description><![CDATA[You can create Transparent custom shaped Frames in java easily. The following code snippet shows an example<br />
<br />
<span style="font-weight: bold;">OvalShapedFrame.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>import javax.swing.*;<br />
import java.awt.*;<br />
import java.awt.geom.*;<br />
import com.sun.awt.AWTUtilities;<br />
<br />
public class OvalShapedFrame extends JFrame{<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;public OvalShapedFrame(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setUndecorated(true);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setSize(400,400);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setLocationRelativeTo(null);&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setDefaultCloseOperation(EXIT_ON_CLOSE);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setAlwaysOnTop(true);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AWTUtilities.setWindowOpacity(this,0.8f);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AWTUtilities.setWindowShape(this,new Ellipse2D.Float(0,0,getWidth(),getHeight()/2));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}catch(Exception e){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setVisible(true);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String[&#93; args){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new OvalShapedFrame();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<br />
}</code></div></div>
<img src="http://lh4.ggpht.com/_-sOQvDwKIas/Sl6xjCohdII/AAAAAAAAADs/tclJ0MgVnFY/s144/OvalShapedFrame.JPG" border="0" alt="[Image: OvalShapedFrame.JPG&#93;" />]]></description>
			<content:encoded><![CDATA[You can create Transparent custom shaped Frames in java easily. The following code snippet shows an example<br />
<br />
<span style="font-weight: bold;">OvalShapedFrame.java</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>import javax.swing.*;<br />
import java.awt.*;<br />
import java.awt.geom.*;<br />
import com.sun.awt.AWTUtilities;<br />
<br />
public class OvalShapedFrame extends JFrame{<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;public OvalShapedFrame(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setUndecorated(true);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setSize(400,400);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setLocationRelativeTo(null);&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setDefaultCloseOperation(EXIT_ON_CLOSE);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setAlwaysOnTop(true);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AWTUtilities.setWindowOpacity(this,0.8f);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AWTUtilities.setWindowShape(this,new Ellipse2D.Float(0,0,getWidth(),getHeight()/2));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}catch(Exception e){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setVisible(true);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String[] args){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new OvalShapedFrame();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<br />
}</code></div></div>
<img src="http://lh4.ggpht.com/_-sOQvDwKIas/Sl6xjCohdII/AAAAAAAAADs/tclJ0MgVnFY/s144/OvalShapedFrame.JPG" border="0" alt="[Image: OvalShapedFrame.JPG]" />]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Gradient Animation in Java]]></title>
			<link>http://coderpassion.comuf.com/thread-64.html</link>
			<pubDate>Tue, 14 Jul 2009 04:36:15 -0700</pubDate>
			<dc:creator>shazin</dc:creator>
			<guid isPermaLink="false">http://coderpassion.comuf.com/thread-64.html</guid>
			<description><![CDATA[This is a small example of the use of Java2D API.<br />
<br />
<span style="font-weight: bold;">GradientAnimation.java</span><br />
<br />
import javax.swing.JFrame;<br />
import java.awt.*;<br />
import java.awt.geom.*;<br />
import java.util.*;<br />
import java.awt.event.*;<br />
<br />
public class GradientAnimation extends JFrame{<br />
	private float x1;<br />
	private float y1;	<br />
<br />
	private float x2;<br />
	private float y2;<br />
	<br />
	public void paint(Graphics g){<br />
		Graphics2D g2 = (Graphics2D) g;<br />
		g2.setPaint(new GradientPaint(x1, y1, Color.BLACK, x2, y2, Color.GREEN, true));<br />
		g2.fill(new Rectangle.Float(0,0,getWidth(),getHeight()));		<br />
	}<br />
<br />
	public GradientAnimation(){<br />
		x1 = 1;<br />
		y1 = 1;<br />
		x2 = 10;<br />
		y2 = 10;<br />
		this.setSize(400,400);<br />
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);<br />
		this.setLocationRelativeTo(null);						<br />
		this.setVisible(true);<br />
		this.setResizable(false);<br />
		this.setTitle("Gradient Animation");				<br />
		Timer timer = new Timer();<br />
		timer.scheduleAtFixedRate(new TimerTask(){<br />
			public void run(){<br />
				x1 += 1;<br />
				y1 += 1;<br />
				x2 += 1;<br />
				y2 += 1;<br />
				repaint();				<br />
			}<br />
		},0,100);<br />
	}<br />
<br />
	public static void main(String[&#93; args){<br />
		new GradientAnimation();		<br />
	}	<br />
}]]></description>
			<content:encoded><![CDATA[This is a small example of the use of Java2D API.<br />
<br />
<span style="font-weight: bold;">GradientAnimation.java</span><br />
<br />
import javax.swing.JFrame;<br />
import java.awt.*;<br />
import java.awt.geom.*;<br />
import java.util.*;<br />
import java.awt.event.*;<br />
<br />
public class GradientAnimation extends JFrame{<br />
	private float x1;<br />
	private float y1;	<br />
<br />
	private float x2;<br />
	private float y2;<br />
	<br />
	public void paint(Graphics g){<br />
		Graphics2D g2 = (Graphics2D) g;<br />
		g2.setPaint(new GradientPaint(x1, y1, Color.BLACK, x2, y2, Color.GREEN, true));<br />
		g2.fill(new Rectangle.Float(0,0,getWidth(),getHeight()));		<br />
	}<br />
<br />
	public GradientAnimation(){<br />
		x1 = 1;<br />
		y1 = 1;<br />
		x2 = 10;<br />
		y2 = 10;<br />
		this.setSize(400,400);<br />
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);<br />
		this.setLocationRelativeTo(null);						<br />
		this.setVisible(true);<br />
		this.setResizable(false);<br />
		this.setTitle("Gradient Animation");				<br />
		Timer timer = new Timer();<br />
		timer.scheduleAtFixedRate(new TimerTask(){<br />
			public void run(){<br />
				x1 += 1;<br />
				y1 += 1;<br />
				x2 += 1;<br />
				y2 += 1;<br />
				repaint();				<br />
			}<br />
		},0,100);<br />
	}<br />
<br />
	public static void main(String[] args){<br />
		new GradientAnimation();		<br />
	}	<br />
}]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Observer Pattern using Java]]></title>
			<link>http://coderpassion.comuf.com/thread-62.html</link>
			<pubDate>Fri, 03 Jul 2009 01:50:53 -0700</pubDate>
			<dc:creator>shazin</dc:creator>
			<guid isPermaLink="false">http://coderpassion.comuf.com/thread-62.html</guid>
			<description><![CDATA[Observer pattern is a pattern used when there are many different objects (Observer) depend on changes on a particular object (Observable).  <br />
<br />
For instance javax.swing packages event management is designed using Observer pattern. There may be several implementations of Listener (Observer) that are observing a JButton's (Observable) click, mouseEntered, mouseExited etc. events.<br />
<br />
Following code snippet shows a small implementation of Observer Design Pattern.<br />
<br />
<span style="font-weight: bold;">Consumer.java</span><br />
<br />
public class Consumer {<br />
	private String name;<br />
<br />
	public Consumer(String name){<br />
		this.name = name;<br />
	}<br />
<br />
	public void update() {<br />
		System.out.println(name + " Updated");<br />
	}<br />
}<br />
<br />
<span style="font-weight: bold;">Producer.java</span><br />
<br />
public class Producer {<br />
	private Market supplyMarket;<br />
<br />
	public Producer(Market sm){<br />
		supplyMarket = sm;<br />
	}<br />
	<br />
	public void notifyMarket() {<br />
		supplyMarket.updateConsumers();<br />
	}<br />
}<br />
<br />
<span style="font-weight: bold;">Market.java</span><br />
<br />
import java.util.*;<br />
<br />
public class Market {<br />
	private Set&lt;Consumer&gt; consumers;<br />
<br />
	public Market(){<br />
		consumers = new HashSet&lt;Consumer&gt;();<br />
	}<br />
	<br />
	public void updateConsumers() {<br />
		Iterator&lt;Consumer&gt; it = consumers.iterator();<br />
		while(it.hasNext()){<br />
			it.next().update();<br />
		}			<br />
	}<br />
<br />
	public void addConsumer(Consumer consumer){<br />
		consumers.add(consumer);<br />
	}<br />
}<br />
<br />
<br />
<span style="font-weight: bold;">ObserverTest.java</span><br />
public class ObserverTest{<br />
	public static void main(String[&#93; args){<br />
		//Market is the Observable <br />
		Market stockMarket = new Market();<br />
<br />
		//Producer is the manipulator of the market<br />
		Producer dialog = new Producer(stockMarket);<br />
<br />
		//Consumer is the Observer of the Observable (Market)<br />
		Consumer shareHolder1 = new Consumer("Shazin");<br />
		Consumer shareHolder2 = new Consumer("Shahim");<br />
<br />
		stockMarket.addConsumer(shareHolder1);	<br />
		stockMarket.addConsumer(shareHolder2);<br />
<br />
		//When there is something to be notified producer notifies<br />
		//the Market in turn market notifies all the consumers of that <br />
		//Market		<br />
		dialog.notifyMarket();<br />
	}<br />
}]]></description>
			<content:encoded><![CDATA[Observer pattern is a pattern used when there are many different objects (Observer) depend on changes on a particular object (Observable).  <br />
<br />
For instance javax.swing packages event management is designed using Observer pattern. There may be several implementations of Listener (Observer) that are observing a JButton's (Observable) click, mouseEntered, mouseExited etc. events.<br />
<br />
Following code snippet shows a small implementation of Observer Design Pattern.<br />
<br />
<span style="font-weight: bold;">Consumer.java</span><br />
<br />
public class Consumer {<br />
	private String name;<br />
<br />
	public Consumer(String name){<br />
		this.name = name;<br />
	}<br />
<br />
	public void update() {<br />
		System.out.println(name + " Updated");<br />
	}<br />
}<br />
<br />
<span style="font-weight: bold;">Producer.java</span><br />
<br />
public class Producer {<br />
	private Market supplyMarket;<br />
<br />
	public Producer(Market sm){<br />
		supplyMarket = sm;<br />
	}<br />
	<br />
	public void notifyMarket() {<br />
		supplyMarket.updateConsumers();<br />
	}<br />
}<br />
<br />
<span style="font-weight: bold;">Market.java</span><br />
<br />
import java.util.*;<br />
<br />
public class Market {<br />
	private Set&lt;Consumer&gt; consumers;<br />
<br />
	public Market(){<br />
		consumers = new HashSet&lt;Consumer&gt;();<br />
	}<br />
	<br />
	public void updateConsumers() {<br />
		Iterator&lt;Consumer&gt; it = consumers.iterator();<br />
		while(it.hasNext()){<br />
			it.next().update();<br />
		}			<br />
	}<br />
<br />
	public void addConsumer(Consumer consumer){<br />
		consumers.add(consumer);<br />
	}<br />
}<br />
<br />
<br />
<span style="font-weight: bold;">ObserverTest.java</span><br />
public class ObserverTest{<br />
	public static void main(String[] args){<br />
		//Market is the Observable <br />
		Market stockMarket = new Market();<br />
<br />
		//Producer is the manipulator of the market<br />
		Producer dialog = new Producer(stockMarket);<br />
<br />
		//Consumer is the Observer of the Observable (Market)<br />
		Consumer shareHolder1 = new Consumer("Shazin");<br />
		Consumer shareHolder2 = new Consumer("Shahim");<br />
<br />
		stockMarket.addConsumer(shareHolder1);	<br />
		stockMarket.addConsumer(shareHolder2);<br />
<br />
		//When there is something to be notified producer notifies<br />
		//the Market in turn market notifies all the consumers of that <br />
		//Market		<br />
		dialog.notifyMarket();<br />
	}<br />
}]]></content:encoded>
		</item>
	</channel>
</rss>
<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Analytics Code -->
