<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CoffeaElectronica</title>
	<atom:link href="http://coffeaelectronica.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://coffeaelectronica.com/blog</link>
	<description>A smooth well-coded brew.</description>
	<lastBuildDate>Sun, 29 Aug 2010 03:47:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Finding Your Center</title>
		<link>http://coffeaelectronica.com/blog/2010/08/finding-your-center/</link>
		<comments>http://coffeaelectronica.com/blog/2010/08/finding-your-center/#comments</comments>
		<pubDate>Sun, 29 Aug 2010 03:47:30 +0000</pubDate>
		<dc:creator>Christopher J. Stehno</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Tidbits]]></category>

		<guid isPermaLink="false">http://coffeaelectronica.com/blog/?p=760</guid>
		<description><![CDATA[Way back when I was in high school my typing teacher (yes, on a mechanical typewriter) taught us how to center blocks of text on a page. This has been a useful skill as I got into web development and programming as not everything has a built-in &#8220;center&#8221; alignment property. I have never been asked [...]]]></description>
			<content:encoded><![CDATA[<p>Way back when I was in high school my typing teacher (yes, on a mechanical typewriter) taught us how to center blocks of text on a page. This has been a useful skill as I got into web development and programming as not everything has a built-in &#8220;center&#8221; alignment property. </p>
<p>I have never been asked how to do this, so it may be common knowledge, but I thought I would share anyway since I have not been blogging much. Basically, think about your viewing area as a page and what you are centering as a rectangle drawn on that page. Now fold that page in half and you will see that half of your rectangle is contained on half the page&#8230; makes sense. You are finding the horizontal position (x coordinate) of the left edge of your rectangle by subtracting half of its width from half the width of the page:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">x = [page_width]/2 - [item_width]/2</div></td></tr></tbody></table></div>
<p>or after a little simplification</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">x = ( [page_width] - [item_width] )/2</div></td></tr></tbody></table></div>
<p>This is exactly the same way you would center vertically. The equation from above expressed with more meaningful terms:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">y = ( [page_height] - [item_height] )/2</div></td></tr></tbody></table></div>
<p>Now to bring this into the Java world you can center a JFrame in the center of your monitor screen:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adimension+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Dimension</span></a> frameSize <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adimension+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Dimension</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">800</span>,<span style="color: #cc66cc;">600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adimension+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Dimension</span></a> screenSize <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Atoolkit+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Toolkit</span></a>.<span style="color: #006633;">getDefaultToolkit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getScreenSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">int</span> x <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>screenSize.<span style="color: #006633;">width</span><span style="color: #339933;">-</span>frameSize.<span style="color: #006633;">width</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">int</span> y <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>screenSize.<span style="color: #006633;">height</span><span style="color: #339933;">-</span>frameSize.<span style="color: #006633;">height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />
frame.<span style="color: #006633;">setBounds</span><span style="color: #009900;">&#40;</span> x, y, frameSize.<span style="color: #006633;">width</span>, frameSize.<span style="color: #006633;">height</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Not too bad at all, but it has always surprised me that Swing does not provide helper methods to center components inside of other components.</p>
<img src="http://coffeaelectronica.com/blog/?ak_action=api_record_view&id=760&type=feed" alt="" /><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://coffeaelectronica.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://coffeaelectronica.com/blog/2010/08/finding-your-center/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android Tips: Astro and Dropbox</title>
		<link>http://coffeaelectronica.com/blog/2010/08/android-tips-astro-and-dropbox/</link>
		<comments>http://coffeaelectronica.com/blog/2010/08/android-tips-astro-and-dropbox/#comments</comments>
		<pubDate>Sun, 15 Aug 2010 17:39:41 +0000</pubDate>
		<dc:creator>Christopher J. Stehno</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Tidbits]]></category>

		<guid isPermaLink="false">http://coffeaelectronica.com/blog/?p=749</guid>
		<description><![CDATA[After walking around with a myTouch Android phone for almost a year now, I figured I should share some of my tips. Email Attachments The default behavior (at least on Android 1.6) for attachments in the Google Mail app is that you can attach photos to an email but no other type of file. Attaching [...]]]></description>
			<content:encoded><![CDATA[<p>After walking around with a myTouch Android phone for almost a year now, I figured I should share some of my tips.</p>
<p><strong>Email Attachments</strong></p>
<p>The default behavior (at least on Android 1.6) for attachments in the Google Mail app is that you can attach photos to an email but no other type of file. Attaching photos is nice, but sometimes you want to send something other than a photo, like a document or music file. The <a href="http://www.appbrain.com/app/com.metago.astro">Astro</a> and <a href="http://www.appbrain.com/app/com.dropbox.android">Dropbox</a> applictions provide some nice additional capabilities, including email attachments: </p>
<p><i>Astro</i></p>
<p>The <a href="http://www.appbrain.com/app/com.metago.astro">Astro</a> file manager app provides a full-fledged file explorer for your Android phone. By installing this app you are also provided with an additional email attachment handler so that when you try and attach a file to your email you have the option of using Astro, which allows you to attach any file. You can also &#8220;share&#8221; files from Astro directly to create an email with the selected file.</p>
<p><em>Dropbox</em></p>
<p>Another alternative is to sign up for <a href="http://dropbox.com">Dropbox</a> and install the <a href="http://www.appbrain.com/app/com.dropbox.android">Dropbox app</a> which allows you to &#8220;share&#8221; any file as a link to your dropbox or as an email attachment.</p>
<p><strong>File Sync-ing</strong></p>
<p>These apps also add some nice file sync features.</p>
<p><em>Astro</em></p>
<p>With Astro you can move files around your phone as you would expect from a file explorer; however, you can also install plugins that allow access to FTP servers, or other computers on your network. I was able to connect to my Networked Attached Storage and transfer files to and from my phone while it was connected to my wireless network.</p>
<p><em>Dropbox</em></p>
<p>You can use dropbox to sync files between your phone and your dropbox-enabled computers. the nice part is that dropbox will not pull a file onto your phone unless you tell it to&#8230; the downside is that currently it has no built-in way that I have found to delete the local copy of a file while still keeping it in dropbox. I did figure out that you can use Astro to delete the file from the dropbox directory and it will still exist on the dropbox server. if you need it back you can just pull it back down. I have used this trick when I purchased Amazon music on my phone so that I could easily add it to my full collection.</p>
<p>The dropbox app is great for keeping files handy when you need them. while I was doing my job search I was able to keep resumes and other relevant documents available as needed and up to date and easily sharable.</p>
<img src="http://coffeaelectronica.com/blog/?ak_action=api_record_view&id=749&type=feed" alt="" /><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://coffeaelectronica.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://coffeaelectronica.com/blog/2010/08/android-tips-astro-and-dropbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Official Nook For Android</title>
		<link>http://coffeaelectronica.com/blog/2010/07/official-nook-for-android/</link>
		<comments>http://coffeaelectronica.com/blog/2010/07/official-nook-for-android/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 17:18:34 +0000</pubDate>
		<dc:creator>Christopher J. Stehno</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[nook]]></category>

		<guid isPermaLink="false">http://coffeaelectronica.com/blog/?p=741</guid>
		<description><![CDATA[After creating apps for every other platform, BN finally decided to create a full-featured Android app for reading their ebooks (ala nook). I came up with a work-around a few months ago (see Android Nook Reader) but I never even used it because it was such a pain in the butt. The BN Nook App [...]]]></description>
			<content:encoded><![CDATA[<p>After creating apps for every other platform, BN finally decided to create a full-featured <a href="http://www.barnesandnoble.com/u/nook-for-android/379002287/?">Android app</a> for reading their ebooks (ala nook). I came up with a work-around a few months ago (see <a href="http://coffeaelectronica.com/blog/2010/03/android-nook-reader/">Android Nook Reader</a>) but I never even used it because it was such a pain in the butt.</p>
<p>The BN Nook App works great. It syncs up nicely with your online account and let&#8217;s you download your books and read them with a number of different fonts and font sizes. It does not seem to sync up your &#8220;last read&#8221; point as advertised, but maybe I am doing something wrong.</p>
<p>This will be great for when I am waiting around in waiting rooms or want to catch a quick read somewhere without needing to carry the nook itself. Bravo BN!</p>
<img src="http://coffeaelectronica.com/blog/?ak_action=api_record_view&id=741&type=feed" alt="" /><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://coffeaelectronica.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://coffeaelectronica.com/blog/2010/07/official-nook-for-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Page and Updates</title>
		<link>http://coffeaelectronica.com/blog/2010/07/new-page-and-updates/</link>
		<comments>http://coffeaelectronica.com/blog/2010/07/new-page-and-updates/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 16:25:19 +0000</pubDate>
		<dc:creator>Christopher J. Stehno</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://coffeaelectronica.com/blog/?p=736</guid>
		<description><![CDATA[In case you haven&#8217;t noticed, I have added a new static page to this site. The Software page will be a starting point for a list of my favorite and recommended software. It won&#8217;t have any reviews, but it will be a general list of what I use and recommend. Reviews will come as I [...]]]></description>
			<content:encoded><![CDATA[<p>In case you haven&#8217;t noticed, I have added a new static page to this site. The <a href="http://coffeaelectronica.com/blog/software">Software </a>page will be a starting point for a list of my favorite and recommended software. It won&#8217;t have any reviews, but it will be a general list of what I use and recommend. Reviews will come as I have time and energy for them.</p>
<p>If you are following along, you may have noticed that I have been pretty quiet for a few months. I have been in unemployment mode which tends to mean that I am spending most of my time combing through job sites, working on my &#8220;branding&#8221;, and trying to keep from going crazy being stuck at home. </p>
<p>I have a few post ideas that I will try to start working on and I hope that my new job will give me some good post ideas as well.</p>
<p>On the Android front&#8230; I am trying to get the SDK and development tools all setup on my 64-bit win7 box, but have run into issues. My intended updates to the CoffeaElectronica app are still pending; I may have to setup a virtual linux box or something to get a good environment setup again.</p>
<p>Also, the WordPress 3 upgrade tweaked my theme settings a bit and I have not been able to figure out how to get my sidebar panels to look right yet.</p>
<img src="http://coffeaelectronica.com/blog/?ak_action=api_record_view&id=736&type=feed" alt="" /><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://coffeaelectronica.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://coffeaelectronica.com/blog/2010/07/new-page-and-updates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sorting in JavaScript</title>
		<link>http://coffeaelectronica.com/blog/2010/04/sorting-in-javascript/</link>
		<comments>http://coffeaelectronica.com/blog/2010/04/sorting-in-javascript/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 23:14:17 +0000</pubDate>
		<dc:creator>Christopher J. Stehno</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tidbits]]></category>

		<guid isPermaLink="false">http://coffeaelectronica.com/blog/?p=703</guid>
		<description><![CDATA[Every now and then you need to sort something in JavaScript and though, it's not all that hard to do, it is not the best-documented feature. Here is a quick little summary of how to do it.]]></description>
			<content:encoded><![CDATA[<p>Every now and then you need to sort something in JavaScript and though, it&#8217;s not all that hard to do, it is not the best-documented feature. Here is a quick little summary of how to do it.</p>
<p>You call the sort function of an array with your comparator. A JavaScript comparator is just a function that returns -1, 0, or 1 depending on whether a is less than b, a is equal to b, or a is greater than b:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">myarray.<span style="color: #660066;">sort</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>b<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>a <span style="color: #339933;">&lt;</span> b<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>a <span style="color: #339933;">==</span> b<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// a &gt; b</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>This is just an example, your function can base the comparison on whatever you want, but it needs to return -1,0,1. Say you had a set of custom JavaScript objects that you want sorted by age:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> people <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'Bob'</span><span style="color: #339933;">,</span>age<span style="color: #339933;">:</span><span style="color: #CC0000;">21</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'Fred'</span><span style="color: #339933;">,</span>age<span style="color: #339933;">:</span><span style="color: #CC0000;">34</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'Dan'</span><span style="color: #339933;">,</span>age<span style="color: #339933;">:</span><span style="color: #CC0000;">19</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>You could easily sort them using</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">people.<span style="color: #660066;">sort</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>b<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>a.<span style="color: #660066;">age</span> <span style="color: #339933;">&lt;</span> b.<span style="color: #660066;">age</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>a.<span style="color: #660066;">age</span> <span style="color: #339933;">==</span> b.<span style="color: #660066;">age</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// a &gt; b</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Not too hard to do. It&#8217;s actually very similar to the Java Comparator interface.</p>
<img src="http://coffeaelectronica.com/blog/?ak_action=api_record_view&id=703&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://coffeaelectronica.com/blog/2010/04/sorting-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Hosting?</title>
		<link>http://coffeaelectronica.com/blog/2010/03/java-hosting/</link>
		<comments>http://coffeaelectronica.com/blog/2010/03/java-hosting/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 23:11:35 +0000</pubDate>
		<dc:creator>Christopher J. Stehno</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Hosting]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Thoughts]]></category>

		<guid isPermaLink="false">http://coffeaelectronica.com/blog/?p=700</guid>
		<description><![CDATA[I love Java. I love the language. I love the JVM and I love the ever-increasing list of languages that run on the JVM. One thing that I really don&#8217;t like is the high cost of hosting Java web applications. Yes, if you search around you can find some that say they provide Java hosting [...]]]></description>
			<content:encoded><![CDATA[<p>I love Java. I love the language. I love the JVM and I love the ever-increasing list of languages that run on the JVM. One thing that I really don&#8217;t like is the high cost of hosting Java web applications. Yes, if you search around you can find some that say they provide Java hosting via Tomcat or Jetty, but unless you get a dedicated server you are not really getting much out of it and there tend to be a lot of limitations involved.</p>
<p>I pay about $72 annually for hosting, and with that I get very limited support for hosting Java web applications. Basically I get a shared Tomcat instance that I cannot configure or restart myself, which is pretty useless beyond very simple applications. I don&#8217;t even have java command line access to run my own server from my account. In order to get true, useful, Java hosting you need to bump up your monthly cost quite a bit. Real Java hosting generally starts around $300 per year and goes up from there if you really need to get serious with it (adequate RAM, and JVM configurations). Google App Engine is on the right track but it&#8217;s limiting; you are limited to JPA or JDO and not even the full power of either of those along with other limitations. Where is the affordable yet functional Java web hosting for the developer or hobbyist with no real budget?</p>
<p>I then decided to look into some of the other web development languages and found that Ruby (on Rails) has a lot of the same issues with good inexpensive hosting. That struck me as odd since I would think RoR would have lower memory and system requirements. I also looked into Python and found that there seems to be very few options available for it. The big winner in the hosting support I guess should come as no surprise&#8230; PHP. PHP has come standard with every hosting package I have ever had or have ever really looked into&#8230; at no extra cost. I guess this is why it remains to be so popular.</p>
<p>I think I will have to dig deeper into PHP for some of my personal web projects. If not that, I may have to look at setting up my own server outside my firewall, which just brings up all kinds of other problems.</p>
<img src="http://coffeaelectronica.com/blog/?ak_action=api_record_view&id=700&type=feed" alt="" /><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://coffeaelectronica.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://coffeaelectronica.com/blog/2010/03/java-hosting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android Nook Reader</title>
		<link>http://coffeaelectronica.com/blog/2010/03/android-nook-reader/</link>
		<comments>http://coffeaelectronica.com/blog/2010/03/android-nook-reader/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 15:57:39 +0000</pubDate>
		<dc:creator>Christopher J. Stehno</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[nook]]></category>

		<guid isPermaLink="false">http://coffeaelectronica.com/blog/?p=695</guid>
		<description><![CDATA[I have found it a little odd that Barnes &#038; Noble does not have an Android ebook reader considering the fact that the nook itself is an Android device. I would say that maybe they are waiting until they sell a certain number of nooks first, but they already have an iPhone reader app. The [...]]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_697" class="wp-caption alignright" style="width: 110px"><a href="http://coffeaelectronica.com/blog/wp-content/uploads/2010/03/barcode-ereader.jpg"><img src="http://coffeaelectronica.com/blog/wp-content/uploads/2010/03/barcode-ereader.jpg" alt="" title="http://ereader.com/android" width="100" height="100" class="size-full wp-image-697" /></a><p class="wp-caption-text">Link to eReader App</p></div>I have found it a little odd that Barnes &#038; Noble does not have an Android ebook reader considering the fact that the <a href="http://nook.com">nook</a> itself is an Android device. I would say that maybe they are waiting until they sell a certain number of nooks first, but they already have an iPhone reader app. The whole thing gets even more interesting when you find out that B&#038;N owns <a href="http://ereader.com">eReader.com</a>, who has a reader for Android. Perhaps they are just in the process or re-branding it or there are some other odd licensing issues keeping them from taking the final step.</p>
<p>But, you can take that step yourself! Download the eReader Android app and install it on your phone (it&#8217;s not in the Android market). You can then mount your phone via USB to your computer and add your nook ebooks (pdb files) to the ereader directory of your sdcard. The annoying part, well more annoying part, is that when you open the book for the first time you will need to enter the name and credit card information used to purchase it. It&#8217;s your default card data at B&#038;N. I wonder how bright an idea that is considering I tend to swap out the cards I use from time to time&#8230; could get interesting.</p>
<p>Anyway, once you enter your credentials you have full access to the ebook, just like reading it on your nook. I would not be surprised to find out that the ebooks on the two sites are exactly the same. I will have to look into it in more detail.</p>
<p>Happy e-reading!</p>
<img src="http://coffeaelectronica.com/blog/?ak_action=api_record_view&id=695&type=feed" alt="" /><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://coffeaelectronica.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://coffeaelectronica.com/blog/2010/03/android-nook-reader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Consolidation</title>
		<link>http://coffeaelectronica.com/blog/2010/02/project-consolidation/</link>
		<comments>http://coffeaelectronica.com/blog/2010/02/project-consolidation/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 19:01:24 +0000</pubDate>
		<dc:creator>Christopher J. Stehno</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://coffeaelectronica.com/blog/?p=688</guid>
		<description><![CDATA[I have been consolidating all of my personal projects and prototypes trying to get everything setup on <a href="http://gitscm.org">Git</a> and <a href="http://github.com">GitHub</a>.]]></description>
			<content:encoded><![CDATA[<p>I have been consolidating all of my personal projects and prototypes trying to get everything setup on <a href="http://gitscm.org">Git</a> and <a href="http://github.com">GitHub</a>. I have used <a href="http://sourceforge.net">SourceForge</a> for years, but have lately found their project management model a bit on the heavy side. I have really taking a liking to Git for my personal projects, so GitHub was an easy choice. GitHub provides good Git integration with lightweight wiki and bug-tracking as well as some other handy features like code archive downloading.</p>
<p>I have most of my projects converted over, though most of them will be going through some refactoring soon (package names, testing, personal code reviews, etc) so that they are all brought up to at least some minimum level of quality. I will also need to update some of my archived blog posts so that they point to the correct project repositories.</p>
<p>In general, I don&#8217;t think anybody else really cares about most of this stuff, but there is some useful code in there among the fluff and flair. There are a number of prototype and proof-of-concept type projects in there that I am not sure even work any more&#8230; so, I have some work to do. <img src='http://coffeaelectronica.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>My GitHub Dashboard is located at: <a href="http://github.com/cjstehno">http://github.com/cjstehno</a>, just be warned, currently all of the code is in a state of flux.</p>
<p>Enjoy!</p>
<img src="http://coffeaelectronica.com/blog/?ak_action=api_record_view&id=688&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://coffeaelectronica.com/blog/2010/02/project-consolidation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding Duplicate Ints: Ruby and Groovy</title>
		<link>http://coffeaelectronica.com/blog/2010/02/finding-duplicate-ints-ruby-and-groovy/</link>
		<comments>http://coffeaelectronica.com/blog/2010/02/finding-duplicate-ints-ruby-and-groovy/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 03:25:39 +0000</pubDate>
		<dc:creator>Christopher J. Stehno</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Puzzle]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Tidbits]]></category>

		<guid isPermaLink="false">http://coffeaelectronica.com/blog/?p=683</guid>
		<description><![CDATA[I am going back to my old standard playtime function, <a href="http://coffeaelectronica.com/blog/2008/02/interview-question-find-2-matching-ints/">finding the duplicated integer</a> in a set of integers. I have been playing around a lot more with Groovy lately and I realized that I had never really done a Groovy version of that little function.]]></description>
			<content:encoded><![CDATA[<p>I am going back to my old standard playtime function, <a href="http://coffeaelectronica.com/blog/2008/02/interview-question-find-2-matching-ints/">finding the duplicated integer</a> in a set of integers. I have been playing around a lot more with Groovy lately and I realized that I had never really done a <a href="http://groovy.codehaus.org">Groovy</a> version of that little function.</p>
<div class="codecolorer-container groovy default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="groovy codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20def"><span style="color: #000000; font-weight: bold;">def</span></a> findDups<span style="color: #66cc66;">&#40;</span> n <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; n.<a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20sort"><span style="color: #663399;">sort</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20for"><span style="color: #b1b100;">for</span></a><span style="color: #66cc66;">&#40;</span> i <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20in"><span style="color: #b1b100;">in</span></a> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>..<span style="color: #006600;">n</span>.<a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20size"><span style="color: #663399;">size</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20if"><span style="color: #b1b100;">if</span></a><span style="color: #66cc66;">&#40;</span>n<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">==</span> n<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20return"><span style="color: #000000; font-weight: bold;">return</span></a> n<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>In this case, I am allowing null to be the value returned when no duplicate is found. It does seem to be a more realistic value for Groovy. It&#8217;s a pretty straight forward function, along the same lines as the other languages. I thought maybe I could find some really cool feature of Groovy that would make this radically different from the Java version&#8230; nope. It does collapse nicely down to a single line though:</p>
<div class="codecolorer-container groovy default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="groovy codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20def"><span style="color: #000000; font-weight: bold;">def</span></a> findDups<span style="color: #66cc66;">&#40;</span> n <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span> n.<a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20sort"><span style="color: #663399;">sort</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20for"><span style="color: #b1b100;">for</span></a><span style="color: #66cc66;">&#40;</span> i <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20in"><span style="color: #b1b100;">in</span></a> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>..<span style="color: #006600;">n</span>.<a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20size"><span style="color: #663399;">size</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20if"><span style="color: #b1b100;">if</span></a><span style="color: #66cc66;">&#40;</span>n<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">==</span> n<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20return"><span style="color: #000000; font-weight: bold;">return</span></a> n<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>If you like that sort of thing.</p>
<p>Shortly after, I decided to do a quick little <a href="http://ruby-lang.org">Ruby</a> version as well:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">def</span> findDups<span style="color:#006600; font-weight:bold;">&#40;</span> n <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; n.<span style="color:#9900CC;">sort</span>!<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">for</span> i <span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span>..<span style="color:#9900CC;">n</span>.<span style="color:#9900CC;">size</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span>n<span style="color:#006600; font-weight:bold;">&#91;</span>i<span style="color:#006600; font-weight:bold;">&#93;</span> == n<span style="color:#006600; font-weight:bold;">&#91;</span>i<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">then</span> <span style="color:#0000FF; font-weight:bold;">return</span> n<span style="color:#006600; font-weight:bold;">&#91;</span>i<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">nil</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>Nothing exciting in either case, but worth doing for completeness.</p>
<img src="http://coffeaelectronica.com/blog/?ak_action=api_record_view&id=683&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://coffeaelectronica.com/blog/2010/02/finding-duplicate-ints-ruby-and-groovy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My Final Answer</title>
		<link>http://coffeaelectronica.com/blog/2010/01/my-final-answer/</link>
		<comments>http://coffeaelectronica.com/blog/2010/01/my-final-answer/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 00:50:55 +0000</pubDate>
		<dc:creator>Christopher J. Stehno</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[Tidbits]]></category>

		<guid isPermaLink="false">http://coffeaelectronica.com/blog/?p=679</guid>
		<description><![CDATA[I use the Java &#8216;final&#8217; keyword quite a bit and I often get asked why. I guess the quick answer would be, &#8220;why not&#8221;? I tend to use &#8216;final&#8217; for instance variables, method parameters and local variables. The keyword can also be used to make classes and methods final but I leave that for the [...]]]></description>
			<content:encoded><![CDATA[<p>I use the Java &#8216;final&#8217; keyword quite a bit and I often get asked why. I guess the quick answer would be, &#8220;why not&#8221;?</p>
<p>I tend to use &#8216;final&#8217; for instance variables, method parameters and local variables. The keyword can also be used to make classes and methods final but I leave that for the cases when I actually want that specific functionality.</p>
<p>Final instance variables (private fields) are useful for case when you want to specify the value once and then never again. This is helpful when configuring an object through Constructor dependency injection:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyController <span style="color: #000000; font-weight: bold;">implements</span> Controller <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> MyService myService<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> MyController<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> MyService myService<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">myService</span> <span style="color: #339933;">=</span> myService<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// other methods</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>This allows you to configure the service object in the controller and not have to worry about any of the other methods overwriting it.</p>
<p>Using final for method parameters is quite handy since it keeps you from unexpectedly overwriting one. Consider the following code:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> count<span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> list, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> name<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> count <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; Iterator<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> names <span style="color: #339933;">=</span> list.<span style="color: #006633;">iterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>names.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; name <span style="color: #339933;">=</span> names.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>name.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> count<span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> count<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>which contains a possibly hard to find variable overwrite error, which becomes quite obvious when you use final</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> count<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> list, <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> name<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> count <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; Iterator<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> names <span style="color: #339933;">=</span> list.<span style="color: #006633;">iterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>names.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> nme <span style="color: #339933;">=</span> names.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>nme.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> count<span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> count<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Local variables are made final for basically the same reason.</p>
<p>Now, I know that simply because a variable is final does not mean it&#8217;s internal data cannot change, such as</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">final</span> Map<span style="color: #339933;">&lt;</span>String,Date<span style="color: #339933;">&gt;</span> dates <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>String,Date<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
dates.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Anniversary&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// will work fine</span><br />
dates.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Birthday&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">// will work fine</span></div></td></tr></tbody></table></div>
<p>The final keyword does not make them immutable, you just cannot overwrite them. Final makes you think a bit before overwriting a variable with a new object and it can sometimes point out, and save you from, potential bugs.</p>
<p><div id="attachment_680" class="wp-caption alignleft" style="width: 267px"><a href="http://coffeaelectronica.com/blog/wp-content/uploads/2010/01/save-actions.png"><img src="http://coffeaelectronica.com/blog/wp-content/uploads/2010/01/save-actions-257x300.png" alt="" title="save-actions" width="257" height="300" class="size-medium wp-image-680" /></a><p class="wp-caption-text">Eclipse Save Actions</p></div>Making your IDE do the work for you. If you use Eclipse (or one of its derivatives) you can have it automatically add &#8216;final&#8217; to your code. Go into the Preferences and search for &#8220;Save Actions&#8221; and you should get something like what is show here. I generally auto-final method parameters and local variables since I have found that making private fields final can cause issues with some reflection and/or byte-code manipulation techniques.</p>
<p>Once you have the save actions setup, you will automatically have final added every time you save a file. I would imagine IntelliJ and NetBeans both have some similar functionality available.</p>
<p>Ultimately, the use of final comes down to personal preference. I find it useful and helpful to use the final keyword throughout my code. If you don&#8217;t then you really don&#8217;t have to use it unless you find a case where it&#8217;s absolutely necessary. To me, though, I figure why not use it?</p>
<p>And that&#8217;s my final answer. </p>
<img src="http://coffeaelectronica.com/blog/?ak_action=api_record_view&id=679&type=feed" alt="" /><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://coffeaelectronica.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://coffeaelectronica.com/blog/2010/01/my-final-answer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
