<?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>NewInstance &#187; Java</title>
	<atom:link href="http://en.newinstance.it/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://en.newinstance.it</link>
	<description>Welcome to the official blog of Luigi R. Viggiano. Beware of imitations.</description>
	<lastBuildDate>Mon, 09 Jan 2012 20:29:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Java Life (Code Hard) rap music video</title>
		<link>http://en.newinstance.it/2011/12/06/java-life-code-hard-rap-music-video/</link>
		<comments>http://en.newinstance.it/2011/12/06/java-life-code-hard-rap-music-video/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 21:16:45 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Life, universe and everything]]></category>
		<category><![CDATA[2011]]></category>
		<category><![CDATA[JavaOne]]></category>
		<category><![CDATA[life]]></category>
		<category><![CDATA[music]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[rap]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://en.newinstance.it/?p=1228</guid>
		<description><![CDATA[Another funny video I found around. Related Posts: Java4ever Lady Java Android.jar sources Android sdk 2.2_r2 sources Suspend/Resume problem in Ubuntu Karmic 9.10 running on MacBook Pro 5.1]]></description>
			<content:encoded><![CDATA[<p><!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic -->Another funny video I found around.</p>
<p><img src="http://en.newinstance.it/wp-content/plugins/html5-and-flash-video-player/default_video_player.gif" /></p>
<div id="crp_related">
<h4>Related Posts:</h4>
<ul>
<li><a href="http://en.newinstance.it/2010/07/19/java4ever/" rel="bookmark" class="crp_title">Java4ever</a></li>
<li><a href="http://en.newinstance.it/2010/08/31/lady-java/" rel="bookmark" class="crp_title">Lady Java</a></li>
<li><a href="http://en.newinstance.it/2010/05/18/androidjar-sources/" rel="bookmark" class="crp_title">Android.jar sources</a></li>
<li><a href="http://en.newinstance.it/2010/12/01/android-sdk-2-2_r2-sources/" rel="bookmark" class="crp_title">Android sdk 2.2_r2 sources</a></li>
<li><a href="http://en.newinstance.it/2009/11/20/suspendresume-problem-in-ubuntu-karmic-910-running-on-macbook-pro-51/" rel="bookmark" class="crp_title">Suspend/Resume problem in Ubuntu Karmic 9.10 running on MacBook Pro 5.1</a></li>
</ul>
</div>
<div class="shr-publisher-1228"></div>
<p><!-- Start Shareaholic LikeButtonSetBottom Automatic -->
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F12%2F06%2Fjava-life-code-hard-rap-music-video%2F' data-shr_title='Java+Life+%28Code+Hard%29+rap+music+video'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F12%2F06%2Fjava-life-code-hard-rap-music-video%2F' data-shr_title='Java+Life+%28Code+Hard%29+rap+music+video'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F12%2F06%2Fjava-life-code-hard-rap-music-video%2F' data-shr_title='Java+Life+%28Code+Hard%29+rap+music+video'></a></div>
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<p><!-- End Shareaholic LikeButtonSetBottom Automatic --></p>
]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2011/12/06/java-life-code-hard-rap-music-video/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://dl.dropbox.com/u/2109153/Blog/The%20Java%20Life%20Rap%20Music%20Video.flv" length="27539780" type="video/x-flv" />
		</item>
		<item>
		<title>I/O Exception handling</title>
		<link>http://en.newinstance.it/2011/11/29/io-exception-handling/</link>
		<comments>http://en.newinstance.it/2011/11/29/io-exception-handling/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 13:53:16 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Opinions]]></category>
		<category><![CDATA[anti-patterns]]></category>
		<category><![CDATA[exception handling]]></category>
		<category><![CDATA[exceptions]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://en.newinstance.it/?p=1223</guid>
		<description><![CDATA[I very much prefer this approach: OutputStream out = new MyOutputStream(...); //may throw IOException try { //use the stream } finally { out.close(); } than this: OutputStream out = null; try { out = new MyOutputStream(...); //may throw IOException //use the stream } finally { if (out != null) { out.close(); } } I just [...]]]></description>
			<content:encoded><![CDATA[<p><!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic -->I very much prefer this approach:</p>
<pre class="brush:java">
OutputStream out = new MyOutputStream(...); //may throw IOException
try {
    //use the stream
} finally {
    out.close();
}
</pre>
<p>than this:</p>
<pre class="brush:java">
OutputStream out = null;
try {
    out = new MyOutputStream(...); //may throw IOException
    //use the stream
} finally {
    if (out != null) {
        out.close();
    }
}
</pre>
<p>I just find the first example correct and the second incorrect. I see the second &#8216;pattern&#8217; everywhere. </p>
<p>Opinions?
<div id="crp_related">
<h4>Related Posts:</h4>
<ul>
<li><a href="http://en.newinstance.it/2006/11/19/reading-javadocs-from-inside-the-original-zip-file/" rel="bookmark" class="crp_title">Reading Javadocs from inside the original zip file</a></li>
<li><a href="http://en.newinstance.it/2008/06/24/null-is-throwable/" rel="bookmark" class="crp_title">Null is throwable</a></li>
<li><a href="http://en.newinstance.it/2005/11/19/listening-changes-on-a-text-file-unix-tail-implementation-with-java/" rel="bookmark" class="crp_title">Listening changes on a text file (Unix Tail implementation with Java)</a></li>
<li><a href="http://en.newinstance.it/2010/09/10/using-files-in-your-interfaces-is-not-a-good-idea/" rel="bookmark" class="crp_title">Using Files in your interfaces is NOT a good idea</a></li>
<li><a href="http://en.newinstance.it/2006/10/19/automatic-transaction-management-with-pojos/" rel="bookmark" class="crp_title">Automatic transaction management with POJOs</a></li>
</ul>
</div>
<div class="shr-publisher-1223"></div>
<p><!-- Start Shareaholic LikeButtonSetBottom Automatic -->
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F11%2F29%2Fio-exception-handling%2F' data-shr_title='I%2FO+Exception+handling'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F11%2F29%2Fio-exception-handling%2F' data-shr_title='I%2FO+Exception+handling'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F11%2F29%2Fio-exception-handling%2F' data-shr_title='I%2FO+Exception+handling'></a></div>
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<p><!-- End Shareaholic LikeButtonSetBottom Automatic --></p>
]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2011/11/29/io-exception-handling/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>OSX Lion: some steps in the right direction</title>
		<link>http://en.newinstance.it/2011/07/28/osx-lion-some-steps-in-the-right-direction/</link>
		<comments>http://en.newinstance.it/2011/07/28/osx-lion-some-steps-in-the-right-direction/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 19:22:51 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[finder]]></category>
		<category><![CDATA[fixes]]></category>
		<category><![CDATA[flaws]]></category>
		<category><![CDATA[improvements]]></category>
		<category><![CDATA[leopard]]></category>
		<category><![CDATA[lion]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[Tricks]]></category>
		<category><![CDATA[workarounds]]></category>

		<guid isPermaLink="false">http://en.newinstance.it/?p=1122</guid>
		<description><![CDATA[When I first had to use OS X I had hard time with some things that weren&#8217;t working as expected. I thought they were usability bugs, but of course don&#8217;t try to argue about that with a veteran Apple user, because &#8220;you&#8217;re ugly and stupid, and that&#8217;s the way it should be! And OSX has [...]]]></description>
			<content:encoded><![CDATA[<p><!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><img src="http://en.newinstance.it/wp-content/uploads/2011/07/os-x-lion.jpg" alt="OS X Lion" title="OS X Lion" width="450" height="336" class="alignnone size-full wp-image-1178" /></p>
<p>When I first had to use OS X I had hard time with <a href="http://en.newinstance.it/2009/02/03/some-things-i-dont-like-about-my-mac/">some things that weren&#8217;t working as expected</a>. I thought they were usability bugs, but of course don&#8217;t try to argue about that with a veteran Apple user, because <em>&#8220;you&#8217;re ugly and stupid, and that&#8217;s the way it should be! And OSX has the best UI/UE evah!&#8221;</em>. I used to hate those <em>weird</em> feature, and finally it&#8217;s a pleasure to see some of those things going away (so <strong><u>I was right!</u></strong>).</p>
<p>I list here what has been improved and what still sucks. Of course, by my point of view.</p>
<h3>The enhancements that I (really) like</h3>
<ul>
<li>The full screen button on the top left, is a great thing. Also the fact that the apps get maximized in another screen, is a great idea. In fact, when one app is maximized, switching to other apps is a pain; having it maximized in another screen and the gesture to switch between screen is very practical. Apple guys, congrats for the innovative idea.</li>
<li>Also I like the dashboard on the left of the desktop.</li>
<li>Launchpad is nice. I like it. I don&#8217;t like that I cannot activate it with a shortcut, and I cannot use arrow keys to select which application to launch.</li>
</ul>
<h3>Finally <em>also</em> on OS X&#8230;</h3>
<ul>
<li>Windows resizing is decent: finally also OSX can resize windows not only from the bottom-right corner, but from all the frame around the window. So that grip <em>only</em> on that corner was lame, wasn&#8217;t it?!</li>
<li>The Terminal.app is improved, almost ok. I like the full screen mode, so I decided to give it a second chance, abandoning iTerm, at least for now. I had to create my own Settings, remapping some keys and colors, I attach it here: <a href='http://en.newinstance.it/wp-content/uploads/2011/07/Luigi.terminal.zip'>Luigi.terminal</a> for myself as backup and for whoever would find it useful. The home/end key still don&#8217;t work in man pages and less, but I learned that pressing capital G and g, do the trick everywhere, included in vim. Still wondering what&#8217;s hard about making that work.</li>
<li>The selection in list (example: file selection in Finder) with shift-up and shift-down, finally works as it should.</li>
<li>The crazy click-and-reclick-to-focus model has been finally replaced a more natural one. OSX is the very last OS to realize how focus has to be implemented.</li>
<li>With the App Store, finally apple has a kind of &#8216;package management&#8217; tool. Very nice looking, as well. I am wondering when they will realize that it should also provide the Uninstall feature. Since <a href="http://en.newinstance.it/2010/04/21/uninstalling-pkg-files-on-osx/">application installed from a .pkg file are impossible to uninstall</a>.</li>
<li>In Finder.app to jump to a file from another, you just type the letter corresponding to the name of the files, like in Windows Explorer o Linux Thunar/Nautilus. But, when you switch to column view, this functionality was not working anymore&#8230; with Lion it finally works. Keys are still faster than any mouse/touchpad; teechies know it.</li>
<li>Cut and paste in Finder was not working with Leopard. I managed to fix it with some research on google. I didn&#8217;t do anything to fix it on Lion, maybe they fixed it (if the fix I made before is not responsible for it still now).</li>
<li>They removed Front Row application. Great! That stuff was garbage. And it was popping out unwanted all the time, activated by some key combination (cmd-esc I think).</li>
<li>I was shocked to see that on Leopard you could do a &#8216;touch /foobar&#8217; without root privileges. What kind of Unix was that? They fixed this in latter version of Leopard and in Lion too.</li>
<li>I like the full screen in Safari. If I am not wrong, Safari was the only browser without a full screen before, now it has a nice one. Still Chrome does a better full screen, since it hides also the navigation bar and shows only the actual internet page, with no distractions.</li>
</ul>
<h3>I&#8217;m undecided on&#8230;</h3>
<ul>
<li>The scroll gesture has been inverted. I am getting used to it, but I still think that previous direction was more intuitive.</li>
<li>Font smoothing: I was strongly against it at beginning. Now I&#8217;m kind of neutral. I still hate it in the Terminal, btw, and I always disable that there.</li>
<li>All the animations. I like most of them, I don&#8217;t like the elastic bouncing that has been copied from the iPod/iPhones. Although they can be <a href="http://lifehacker.com/5824564/how-to-de+ios+ify-mac-os-x-lion">disabled</a>, I can live with it, so I&#8217;ll try them for some more time and decide later to keep or remove them.</li>
</ul>
<h3>This still sucks!</h3>
<ul>
<li>Enter to rename, instead of activating/opening.</li>
<li>You installed Lion, but what if you wanted to burn the DVD? You can, but it&#8217;s not so easy. This is quite unfair from Apple. On the tips below for a short guide.</li>
<li>The maximize round button on the top left corner of the windows, doesn&#8217;t maximize. That&#8217;s just stupid. Hope one day they will give the possibility to configure that behavior.</li>
<li>I never liked the menu bar shared between application. There&#8217;s nobody that will ever convince me that is a good idea. I know Ubuntu is copying stupid things like this, still doesn&#8217;t mean that is a good thing. </li>
<li>The windows close/minimize/maximize round buttons on the top left, and having no possibility to change that. I liked them on the right, but that&#8217;s ok, I am getting used to it.</li>
<li>The Finder still hides most of the files. I still haven&#8217;t understood what&#8217;s the criteria of the file hidden, and if there is a way to show all the files.</li>
<li>Java has always been late on OSX, and trickier to install with the documentation and sources&#8230; Lion doesn&#8217;t come with JRE, but you have to install it later. It&#8217;s not difficult, so it&#8217;s ok. What I don&#8217;t like is the directory layout they made up. I have to verify if the documentation and the sources can be installed and accessed easily. It was tricky for Leopard, hope they improved it. (but I don&#8217;t think so)
</ul>
<h3>New OS, new problems&#8230;</h3>
<ul>
<li>The gestures for showing the desktop was perfect before, now I get that wrong frequently, since it&#8217;s a gesture that the OS confuses with others. That&#8217;s a pity because I use the desktop a lot to store files I am working on, and having an easy way to access the desktop is quite important.</li>
<li>When you close an application with cmd-q, when you reopen it, it will show all the last opened documents. Even if you open a document on your desktop, it will also open it, plus the last opened documents&#8230; that&#8217;s not a good idea. Fortunately it can be disabled in the Preferences.</li>
<li>One friend of mine reported that the fullscreen doesn&#8217;t work great when you use multiple monitors. I didn&#8217;t tried it yet.</li>
<li>The scrollbars disappearing. That&#8217;s bad specially in the browser (iframes, and scrollable divs). In the applications it is sort of cool, btw.</li>
<li>Launchpad: you click on the icon and it will show the applications; you click again and you return to the desktop. Fine. Now try with Mission Control icon: click once and it shows active applications; click again and it makes a mess. Not so good. I removed Launchpad and Mission Control from the dock and learned to activate them with the gestures, so this doesn&#8217;t bother me anymore.</li>
<li>When my laptop goes out of battery, it shut down completely instead of freezing. Potentially corrupting data. I don&#8217;t know if this is a new &#8220;feature&#8221; of Lion. It really sucks, anyway.</li>
</ul>
<h2>Some handy tips</h2>
<p>With time, I got accustomed to some craziness of OS X, and I found the way to live with them. Or work-around them.</p>
<h3>Screen Lock shortcut</h3>
<p>I was complaining of the missing key combination to lock the screen on a mac. Actually I think that there is no real &#8216;lock&#8217; shortcut. But pressing ctrl+shift+eject send the screen to standby, and if your setting are appropriate when the screen is resumed the login screen can be displayed. </p>
<h3>Shortcuts</h3>
<p>OS X is full of mysteriously assigned shortcuts, like the lock screen above. And the boot ones&#8230;<br />
I found this link which is good to keep handy: <a href="http://support.apple.com/kb/ht1343">Mac OS X keyboard shortcuts</a>. </p>
<h3>How to redownload OSX Lion and Burn it on a DVD</h3>
<p>Once you have installed Lion, the installer app deletes itself. Like in &#8220;Mission: Impossible&#8221; movies. And from the App Store you cannot download it again.<br />
<a href="http://forums.macrumors.com/showthread.php?t=1105260#9">Here</a> is how to do:</p>
<blockquote><p>
Launch the App Store<br />
While holding down the OPTION key, click on the “Purchases” section<br />
You should see “OS X Lion” and “Install” should now be gray and you can click that to re-download Lion (you may have to re-authenticate within the App Store with your Apple ID).
</p></blockquote>
<p>To burn Lion on a DVD, <a href="http://lifehacker.com/5823096/how-to-burn-your-own-lion-install-dvd-or-flash-drive">here</a> is how to do it:</p>
<blockquote><p>
Getting Lion from the App Store is convenient, but if you want a physical copy of the installation, you can easily make your own Lion install DVD or USB drive with Disk Utility.<br />
If you want to do a clean installation of Lion (or you want to install it on a Hackintosh), you&#8217;ll need to install it on some sort of physical media. Apple will be releasing a flash drive installer for a whopping $70 in August, but you don&#8217;t need to wait (or pay twice the OS&#8217;s price) to get it. It&#8217;s very easy to burn Apple&#8217;s installer to a single layer DVD or flash drive of 5GB or larger.</p>
<p>Important: Note that the Lion installer deletes itself if you upgrade, so if you want to do this, you have to do it before you update your computer to Lion. You can always re-download Lion after the fact, but geez, who wants to do that? Once you&#8217;ve got it on your system, here&#8217;s what you do:</p>
<ol>
<li>Download Lion from the Mac App Store. The installer should show up in your Applications folder.
<li>Right-click on the installer and hit &#8220;Show Package Contents&#8221;. Navigate to Contents > SharedSupport and look for a file called &#8220;InstallESD.dmg&#8221;.</li>
<li>Open up Disk Utility and drag the DMG file into the left-hand sidebar. If you&#8217;re burning it to a DVD, insert your DVD, select the disk image in the sidebar, and hit the &#8220;Burn&#8221; button. Skip down to the last step to use it.</li>
<li>If you want to burn Lion to a USB flash drive, plug it in and click on it in the left-hand sidebar in Disk Utility. Go to the Partition tab and select &#8220;1 Partition&#8221; from the dropdown menu. Choose &#8220;Mac OS Extended (Journaled) on the left.</li>
<li>Hit the Options button under the partition table and choose &#8220;GUID Partition Table&#8221;. You&#8217;ll need this to make the drive bootable on a Mac. Hit the Apply button when you&#8217;re done to format your drive (note: it will erase everything on the drive).</li>
<li>Click on the &#8220;Restore&#8221; tab, choose the InstallESD.dmg file as the source and your flash drive as the destination. Hit the Apply button and it will create your bootable USB drive.</li>
<li>Reboot into OS X and hold the option key when you hear the startup chime. You can boot into your DVD or flash drive from there.</li>
</ol>
<p>You&#8217;ll not only be able to install Lion from this drive, but you&#8217;ll also be able to use Disk Utiltiy, recover from a Time Machine backup, and do everything else you could do with the old installation DVDs. Note that when you install Lion, it&#8217;ll create a recovery partition with all these features anyway, so you don&#8217;t need the DVD unless you&#8217;re doing a clean install. Though it&#8217;s always nice to have around in case something happens, like you erase your entire drive. Not that that&#8217;s ever happened to me 3 times in one week or anything.
</p></blockquote>
<h2>Conclusions</h2>
<p>Overall, I like the changes introduced by Lion. Still many things can be improved.<br />
That&#8217;s pretty much all I have to say about Lion.</p>
<p>If there is any new feature you don&#8217;t like and you would like to remove, have a look at this article <a href="http://lifehacker.com/5824564/how-to-de+ios+ify-mac-os-x-lion">How to De-iOs-ify Mac OS X Lion</a>; you may be lucky and find the way to restore some Leopard behavior.</p>
<div id="crp_related">
<h4>Related Posts:</h4>
<ul>
<li><a href="http://en.newinstance.it/2011/08/25/superdrive-not-working-anymore/" rel="bookmark" class="crp_title">Superdrive not working anymore</a></li>
<li><a href="http://en.newinstance.it/2009/02/03/some-things-i-dont-like-about-my-mac/" rel="bookmark" class="crp_title">Some things I don&#8217;t like about my Mac</a></li>
<li><a href="http://en.newinstance.it/2008/04/01/remote-desktop-and-the-black-screen/" rel="bookmark" class="crp_title">Remote Desktop and the Black Screen</a></li>
<li><a href="http://en.newinstance.it/2009/02/12/some-tips-for-iterm/" rel="bookmark" class="crp_title">Some tips for iTerm</a></li>
<li><a href="http://en.newinstance.it/2009/11/26/karmic-and-luks-usb-drive-encryption-made-almost-easy/" rel="bookmark" class="crp_title">Karmic and Luks: USB drive encryption made (almost) easy</a></li>
</ul>
</div>
<div class="shr-publisher-1122"></div>
<p><!-- Start Shareaholic LikeButtonSetBottom Automatic -->
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F07%2F28%2Fosx-lion-some-steps-in-the-right-direction%2F' data-shr_title='OSX+Lion%3A+some+steps+in+the+right+direction'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F07%2F28%2Fosx-lion-some-steps-in-the-right-direction%2F' data-shr_title='OSX+Lion%3A+some+steps+in+the+right+direction'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F07%2F28%2Fosx-lion-some-steps-in-the-right-direction%2F' data-shr_title='OSX+Lion%3A+some+steps+in+the+right+direction'></a></div>
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<p><!-- End Shareaholic LikeButtonSetBottom Automatic --></p>
]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2011/07/28/osx-lion-some-steps-in-the-right-direction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSH Bash Completion</title>
		<link>http://en.newinstance.it/2011/06/30/ssh-bash-completion/</link>
		<comments>http://en.newinstance.it/2011/06/30/ssh-bash-completion/#comments</comments>
		<pubDate>Thu, 30 Jun 2011 17:18:13 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[completion]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[reference]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://en.newinstance.it/?p=1072</guid>
		<description><![CDATA[Today I was having a look on how the git-completition is implemented. If you have not enabled the completition for git, I think you should really read my article on how to do it. So I found this two links, that explain the basics on how to implement bash completion for simple commands: An introduction [...]]]></description>
			<content:encoded><![CDATA[<p><!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic -->Today I was having a look on how the git-completition is implemented. If you have not enabled the completition for git, I think you should really read <a href="http://en.newinstance.it/2010/05/23/git-autocompletion-and-enhanced-bash-prompt/">my article</a> on how to do it.</p>
<p>So I found this two links, that explain the basics on how to implement bash completion for simple commands:</p>
<ul>
<li><a href="http://www.debian-administration.org/articles/316">An introduction to bash completion: part 1</a></li>
<li><a href="http://www.debian-administration.org/article/317/An_introduction_to_bash_completion_part_2">An introduction to bash completion: part 2</a></li>
</ul>
<p>And I implemented my completion for ssh, which takes the hostnames from the file ~/.ssh/known_hosts</p>
<pre class="brush:bash">
# Add bash completion for ssh: it tries to complete the host to which you
# want to connect from the list of the ones contained in ~/.ssh/known_hosts

__ssh_known_hosts() {
    if [[ -f ~/.ssh/known_hosts ]]; then
        cut -d " " -f1 ~/.ssh/known_hosts | cut -d "," -f1
    fi
}

_ssh() {
    local cur known_hosts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    known_hosts="$(__ssh_known_hosts)"

    if [[ ! ${cur} == -* ]] ; then
    	COMPREPLY=( $(compgen -W "${known_hosts}" -- ${cur}) )
        return 0
    fi
}

complete -o bashdefault -o default -o nospace -F _ssh ssh 2>/dev/null \
	|| complete -o default -o nospace -F _ssh ssh
</pre>
<p>To load it, save the above script into a file called &#8216;ssh-completion&#8217; then add &#8220;source ssh-completion&#8221; in your ~/.profile or ~/.bashrc. Some Linux distributions offer a directory  where you can deploy your completion scripts, for example debian should have them like /etc/bash-completion.d/foobar.bash. </p>
<p>Then go on the command line and type: </p>
<pre class="brush:bash">
$ ssh [tab]
</pre>
<p>If everything went fine, you should see a list of servers to which you recently connected.</p>
<p>I don&#8217;t go in detail to explain the above script, since there are good tutorials around for this purpose, including the links I included before.<br />
I only want to say that the &#8216;compgen&#8217; is an internal bash command, used in the above script: what it does is taking a list of words (-W ${known_hosts} option) from which to try to complete a given partial word (in the above example the ${cur} variable, which is the word at the cursor).</p>
<p>Since completion is usually implemented with bash scripts, it&#8217;s good to keep handy a <a href="http://www.gnu.org/software/bash/manual/bashref.html">bash reference manual</a>. </p>
<h3>Scared of bash scripts?</h3>
<p>I am. I continuously forget the syntax of loops and conditional expressions: I think that the bash language is quite obscure and counter-intuitive. So I guess that is also possible to implement completion as part of your program using your language of choice (Java in my case). You can implement a feature in your program that reads and analyzes the <tt>COMP_WORDS</tt> and <tt>COMP_CWORD</tt> environment variables, and generate the list of completion words, as the &#8216;compgen&#8217; bash built-in command does. And, if your language allows it, set those words into the <tt>COMPREPLY</tt> environment variable; in Java I think it&#8217;s not possible to alter environment variables, but you can just output the words on the standard output and use a brief script to set that output to the <tt>COMPREPLY</tt> variable.<br />
I&#8217;d suggest to bind this functionality to a &#8216;&#8211;completion&#8217; option that can be specified in the command line, as we usually do for the &#8211;help option. </p>
<p>See <a href="https://github.com/rtomayko/git-sh/blob/master/git-completion.bash">git-completion.bash</a> if you want an example of a complex completion script&#8230; bash can be hard. </p>
<h3>Update</h3>
<p>I just typed &#8216;complete&#8217; on my mac, and I discovered I have 408 commands binded to some completion script. Including a more advanced ssh script which implements the hostname suggestions.
<div id="crp_related">
<h4>Related Posts:</h4>
<ul>
<li><a href="http://en.newinstance.it/2010/05/23/git-autocompletion-and-enhanced-bash-prompt/" rel="bookmark" class="crp_title">GIT autocompletion and enhanced bash prompt</a></li>
<li><a href="http://en.newinstance.it/2010/04/06/how-to-create-launchers-in-osx/" rel="bookmark" class="crp_title">How to create launchers in OSX</a></li>
<li><a href="http://en.newinstance.it/2009/03/05/ant-macrodefs/" rel="bookmark" class="crp_title">Ant macrodefs</a></li>
<li><a href="http://en.newinstance.it/2009/02/27/execute-commands-in-modified-environment/" rel="bookmark" class="crp_title">Execute commands in modified environment</a></li>
<li><a href="http://en.newinstance.it/2011/06/01/checking-configuration-files-inside-jars/" rel="bookmark" class="crp_title">Checking configuration files inside jars</a></li>
</ul>
</div>
<div class="shr-publisher-1072"></div>
<p><!-- Start Shareaholic LikeButtonSetBottom Automatic -->
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F06%2F30%2Fssh-bash-completion%2F' data-shr_title='SSH+Bash+Completion'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F06%2F30%2Fssh-bash-completion%2F' data-shr_title='SSH+Bash+Completion'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F06%2F30%2Fssh-bash-completion%2F' data-shr_title='SSH+Bash+Completion'></a></div>
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<p><!-- End Shareaholic LikeButtonSetBottom Automatic --></p>
]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2011/06/30/ssh-bash-completion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Checking configuration files inside jars</title>
		<link>http://en.newinstance.it/2011/06/01/checking-configuration-files-inside-jars/</link>
		<comments>http://en.newinstance.it/2011/06/01/checking-configuration-files-inside-jars/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 11:36:36 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Opinions]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[hiding]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[making things simpler]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[unzip]]></category>
		<category><![CDATA[zip]]></category>

		<guid isPermaLink="false">http://en.newinstance.it/?p=1035</guid>
		<description><![CDATA[Are you habit to have some configuration files packaged inside the jar of your application? If so, you can still have a look at those configuration files in the running environment using the unzip Unix utility. $ unzip -p /opt/myapp/lib/my-app.jar log4j.properties log4j.rootLogger=INFO,stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Threshold=INFO log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{dd-MMM hh:mm} [%-5p] %m%n The -p option uncompress and prints [...]]]></description>
			<content:encoded><![CDATA[<p><!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic -->Are you habit to have some configuration files packaged inside the jar of your application? </p>
<p>If so, you can still have a look at those configuration files in the running environment using the unzip Unix utility.</p>
<pre class="brush:bash">
$ unzip -p /opt/myapp/lib/my-app.jar log4j.properties
log4j.rootLogger=INFO,stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Threshold=INFO
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{dd-MMM hh:mm} [%-5p] %m%n
</pre>
<p>The -p option uncompress and prints the file content to standard output.</p>
<p>I like to include resource files in the deployable artifact, unless I want those files to be modifiable without repackaging. Hiding most of configuration helps to keep things simpler for the end user, but still those files can be accessed for the technical support.</p>
<p>By the way, the above log4j configuration is the one I used to replace some System.out/System.err in a simple command line based application. I was thinking to remove the date part &#8216;%d{dd-MMM hh:mm}&#8217; and make it look like the output of ant/maven, but then I thought that -after all- the date is quite useful since the application in question is ran by cron redirecting the standard out into a file, so we keep that as a log of the last run, to have some clue in case of errors.</p>
<p><script type="text/javascript">var dzone_url = 'http://java.dzone.com/articles/checking-configuration-files'; var dzone_style = '2';</script><script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
<div id="crp_related">
<h4>Related Posts:</h4>
<ul>
<li><a href="http://en.newinstance.it/2010/12/01/android-sdk-2-2_r2-sources/" rel="bookmark" class="crp_title">Android sdk 2.2_r2 sources</a></li>
<li><a href="http://en.newinstance.it/2009/05/07/java-native-compilation/" rel="bookmark" class="crp_title">Java native compilation</a></li>
<li><a href="http://en.newinstance.it/2010/09/10/using-files-in-your-interfaces-is-not-a-good-idea/" rel="bookmark" class="crp_title">Using Files in your interfaces is NOT a good idea</a></li>
<li><a href="http://en.newinstance.it/2011/02/10/eclipse-save-actions/" rel="bookmark" class="crp_title">Eclipse Save Actions</a></li>
<li><a href="http://en.newinstance.it/2011/02/27/how-to-create-a-statically-linked-version-of-git-binaries/" rel="bookmark" class="crp_title">How to create a statically linked version of git binaries</a></li>
</ul>
</div>
<div class="shr-publisher-1035"></div>
<p><!-- Start Shareaholic LikeButtonSetBottom Automatic -->
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F06%2F01%2Fchecking-configuration-files-inside-jars%2F' data-shr_title='Checking+configuration+files+inside+jars'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F06%2F01%2Fchecking-configuration-files-inside-jars%2F' data-shr_title='Checking+configuration+files+inside+jars'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F06%2F01%2Fchecking-configuration-files-inside-jars%2F' data-shr_title='Checking+configuration+files+inside+jars'></a></div>
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<p><!-- End Shareaholic LikeButtonSetBottom Automatic --></p>
]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2011/06/01/checking-configuration-files-inside-jars/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JAXB Tip: one line of code to marshall and unmarshall xml.</title>
		<link>http://en.newinstance.it/2011/05/26/jaxb-tip-one-line-of-code-to-marshall-and-unmarshall-xml/</link>
		<comments>http://en.newinstance.it/2011/05/26/jaxb-tip-one-line-of-code-to-marshall-and-unmarshall-xml/#comments</comments>
		<pubDate>Thu, 26 May 2011 11:17:29 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JAXB]]></category>
		<category><![CDATA[quick tip]]></category>
		<category><![CDATA[shortening code]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://en.newinstance.it/?p=1019</guid>
		<description><![CDATA[I wrote in a previous article how easy it is to translate Java object to/from XML, without adding exotic library dependencies to your project; recently I&#8217;ve going through the code of one of my colleague and I discovered that the 3 line necessary to marshal and un-marshal the XML can be shortened to a single [...]]]></description>
			<content:encoded><![CDATA[<p><!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic -->I wrote in a <a href="http://en.newinstance.it/2010/08/05/javabeans-to-xml-with-no-libraries/">previous article</a> how easy it is to translate Java object to/from XML, without adding exotic library dependencies to your project; recently I&#8217;ve going through the code of one of my colleague and I discovered that the 3 line necessary to marshal and un-marshal the XML can be shortened to a single line using the <a href="http://download.oracle.com/javase/6/docs/api/javax/xml/bind/JAXB.html">JAXB</a> utility class:</p>
<pre class="brush:java">
JAXBContext context = JAXBContext.newInstance(ObjectToConvert.class);
Unmarshaller u = context.createUnmarshaller();
return (ObjectToConvert) u.unmarshal(xmlInputStream);

// becomes
return (ClassToConvert)JAXB.unmarshal(xmlInputStream, ObjectToConvert.class);

// and
JAXBContext context = JAXBContext.newInstance(objectInstanceToConvert.getClass());
Marshaller m = jc.createMarshaller();
m.marshal(objectInstanceToConvert, xmlOutputStream);

// becomes
JAXB.marshall(objectInstanceToConvert, xmlOutputStream)
</pre>
<p>Nice: one line of code to convert Java objects from/to XML. I didn&#8217;t notice this utility method in the JAXB library at first, so I was implementing those two methods in my code, more or less the same way. It&#8217;s always good to remove code.
<div id="crp_related">
<h4>Related Posts:</h4>
<ul>
<li><a href="http://en.newinstance.it/2010/08/05/javabeans-to-xml-with-no-libraries/" rel="bookmark" class="crp_title">JavaBeans to XML, with no libraries.</a></li>
<li><a href="http://en.newinstance.it/2009/03/27/mocking-jndi/" rel="bookmark" class="crp_title">Mocking JNDI</a></li>
<li><a href="http://en.newinstance.it/2005/06/11/infamous-programming-errors-on-curly-braced-blocks/" rel="bookmark" class="crp_title">Infamous programming errors on curly braced {blocks}</a></li>
<li><a href="http://en.newinstance.it/2009/05/20/svn-inconsistent-line-ending-style/" rel="bookmark" class="crp_title">svn: Inconsistent line ending style</a></li>
<li><a href="http://en.newinstance.it/2010/09/07/workaround-to-multi-threaded-testing/" rel="bookmark" class="crp_title">Workaround to multi threaded testing</a></li>
</ul>
</div>
<div class="shr-publisher-1019"></div>
<p><!-- Start Shareaholic LikeButtonSetBottom Automatic -->
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F05%2F26%2Fjaxb-tip-one-line-of-code-to-marshall-and-unmarshall-xml%2F' data-shr_title='JAXB+Tip%3A+one+line+of+code+to+marshall+and+unmarshall+xml.'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F05%2F26%2Fjaxb-tip-one-line-of-code-to-marshall-and-unmarshall-xml%2F' data-shr_title='JAXB+Tip%3A+one+line+of+code+to+marshall+and+unmarshall+xml.'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F05%2F26%2Fjaxb-tip-one-line-of-code-to-marshall-and-unmarshall-xml%2F' data-shr_title='JAXB+Tip%3A+one+line+of+code+to+marshall+and+unmarshall+xml.'></a></div>
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<p><!-- End Shareaholic LikeButtonSetBottom Automatic --></p>
]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2011/05/26/jaxb-tip-one-line-of-code-to-marshall-and-unmarshall-xml/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Eclipse Save Actions</title>
		<link>http://en.newinstance.it/2011/02/10/eclipse-save-actions/</link>
		<comments>http://en.newinstance.it/2011/02/10/eclipse-save-actions/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 11:22:25 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[ide]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://en.newinstance.it/?p=968</guid>
		<description><![CDATA[I recently started to use a feature in Eclipse 3.6.1 that I didn&#8217;t notice before: the &#8220;Save Actions&#8221;. Basically you can configure some actions that will be done automatically when you save a Java source. Some of them are really useful, like Organizing the imports, adding &#8216;final&#8217; to private member instances, etc. Here the screen-shot [...]]]></description>
			<content:encoded><![CDATA[<p><!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic -->I recently started to use a feature in Eclipse 3.6.1 that I didn&#8217;t notice before: the &#8220;Save Actions&#8221;.<br />
Basically you can configure some actions that will be done automatically when you save a Java source. Some of them are really useful, like Organizing the imports, adding &#8216;final&#8217; to private member instances, etc. Here the screen-shot of it, with my preferences:</p>
<p><div id="attachment_969" class="wp-caption alignnone" style="width: 310px"><a href="http://en.newinstance.it/wp-content/uploads/2011/02/2-10-2011-11-13-39-.png"><img src="http://en.newinstance.it/wp-content/uploads/2011/02/2-10-2011-11-13-39--300x236.png" alt="Eclipse Save Actions" title="eclipse save actions" width="300" height="236" class="size-medium wp-image-969" /></a><p class="wp-caption-text">Eclipse Save Actions</p></div></p>
<p>From now on, nomore unused imports and better immutable classes.</p>
<p><script type="text/javascript">var dzone_url = 'http://java.dzone.com/tips/eclipse-save-actions'; var dzone_style = '2';</script><script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
<div id="crp_related">
<h4>Related Posts:</h4>
<ul>
<li><a href="http://en.newinstance.it/2010/12/01/android-sdk-2-2_r2-sources/" rel="bookmark" class="crp_title">Android sdk 2.2_r2 sources</a></li>
<li><a href="http://en.newinstance.it/2008/06/19/setting-up-javahl-jni-support-in-eclipse-on-linux/" rel="bookmark" class="crp_title">Setting up JavaHL (JNI) support in Eclipse on Linux</a></li>
<li><a href="http://en.newinstance.it/2010/04/15/eclipse-slow-in-osx/" rel="bookmark" class="crp_title">Eclipse slow in OSX</a></li>
<li><a href="http://en.newinstance.it/2007/07/13/eclipse-33-is-hot-code-replacement-still-working/" rel="bookmark" class="crp_title">Eclipse 3.3: is &#8220;hot code replacement&#8221; still working?</a></li>
<li><a href="http://en.newinstance.it/2006/01/10/eclipse-workaround-to-firefox-missing-feature/" rel="bookmark" class="crp_title">Eclipse workaround to firefox missing feature</a></li>
</ul>
</div>
<div class="shr-publisher-968"></div>
<p><!-- Start Shareaholic LikeButtonSetBottom Automatic -->
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F02%2F10%2Feclipse-save-actions%2F' data-shr_title='Eclipse+Save+Actions'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F02%2F10%2Feclipse-save-actions%2F' data-shr_title='Eclipse+Save+Actions'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F02%2F10%2Feclipse-save-actions%2F' data-shr_title='Eclipse+Save+Actions'></a></div>
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<p><!-- End Shareaholic LikeButtonSetBottom Automatic --></p>
]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2011/02/10/eclipse-save-actions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Java Hangs When Converting 2.2250738585072012e-308</title>
		<link>http://en.newinstance.it/2011/02/03/java-hangs-when-converting-2-2250738585072012e-308/</link>
		<comments>http://en.newinstance.it/2011/02/03/java-hangs-when-converting-2-2250738585072012e-308/#comments</comments>
		<pubDate>Thu, 03 Feb 2011 14:55:55 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Opinions]]></category>
		<category><![CDATA[bug]]></category>

		<guid isPermaLink="false">http://en.newinstance.it/?p=966</guid>
		<description><![CDATA[Just discovered an interesting bug in Java interpreter and compiler, that makes them hang when converting the value 2.2250738585072012e-308. Nice to know. The bug has been reported to Oracle, but I supposed they will include this in their collection of bugs and sell it as &#8220;Oracle Database 12g&#8221; product. :-) Related Posts: Lady Java Oracle [...]]]></description>
			<content:encoded><![CDATA[<p><!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic -->Just discovered an interesting <a href="http://www.exploringbinary.com/java-hangs-when-converting-2-2250738585072012e-308/">bug</a> in Java interpreter and compiler, that makes them hang when converting the value 2.2250738585072012e-308.</p>
<p>Nice to know.</p>
<p>The bug has been reported to Oracle, but I supposed they will include this in their collection of bugs and sell it as &#8220;Oracle Database 12g&#8221; product. :-)
<div id="crp_related">
<h4>Related Posts:</h4>
<ul>
<li><a href="http://en.newinstance.it/2010/08/31/lady-java/" rel="bookmark" class="crp_title">Lady Java</a></li>
<li><a href="http://en.newinstance.it/2007/07/05/oracle-workarounds-use-jdk-14/" rel="bookmark" class="crp_title">Oracle workarounds: use JDK 1.4</a></li>
<li><a href="http://en.newinstance.it/2005/06/29/jug-torino-at-javaconference-italy/" rel="bookmark" class="crp_title">Jug Torino at JavaConference (Italy)</a></li>
<li><a href="http://en.newinstance.it/2011/05/26/jaxb-tip-one-line-of-code-to-marshall-and-unmarshall-xml/" rel="bookmark" class="crp_title">JAXB Tip: one line of code to marshall and unmarshall xml.</a></li>
<li><a href="http://en.newinstance.it/2008/07/02/disappointed-by-ganymede/" rel="bookmark" class="crp_title">Disappointed by Ganymede</a></li>
</ul>
</div>
<div class="shr-publisher-966"></div>
<p><!-- Start Shareaholic LikeButtonSetBottom Automatic -->
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F02%2F03%2Fjava-hangs-when-converting-2-2250738585072012e-308%2F' data-shr_title='Java+Hangs+When+Converting+2.2250738585072012e-308'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F02%2F03%2Fjava-hangs-when-converting-2-2250738585072012e-308%2F' data-shr_title='Java+Hangs+When+Converting+2.2250738585072012e-308'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F02%2F03%2Fjava-hangs-when-converting-2-2250738585072012e-308%2F' data-shr_title='Java+Hangs+When+Converting+2.2250738585072012e-308'></a></div>
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<p><!-- End Shareaholic LikeButtonSetBottom Automatic --></p>
]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2011/02/03/java-hangs-when-converting-2-2250738585072012e-308/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Unit test naming conventions</title>
		<link>http://en.newinstance.it/2011/01/28/unit-test-naming-conventions/</link>
		<comments>http://en.newinstance.it/2011/01/28/unit-test-naming-conventions/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 20:46:13 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Opinions]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[naming conventions]]></category>
		<category><![CDATA[Practices]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[unit testing]]></category>
		<category><![CDATA[xp]]></category>

		<guid isPermaLink="false">http://en.newinstance.it/?p=943</guid>
		<description><![CDATA[There are a certain number of naming conventions used for unit tests. At beginning, with JUnit 3, to define a test it was mandatory that the class name was named like MyClassTest, be extending from TestCase and all the test method names were starting with &#8216;test&#8217; as in &#8216;testMyMethod()&#8217;. I think that this is a [...]]]></description>
			<content:encoded><![CDATA[<p><!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic -->There are a certain number of naming conventions used for unit tests. At beginning, with JUnit 3, to define a test it was mandatory that the class name was named like MyClassTest, be extending from TestCase and all the test method names were starting with &#8216;test&#8217; as in &#8216;testMyMethod()&#8217;. I think that this is a good example of convetion over configuration.<br />
With JUnit 4 (or TestNG) this is nomore mandatory and it leaves the developer free to define his own naming convention. But then you &#8220;configure&#8221; the metod as a test using the annotation @Test.</p>
<p>There is a naming convention defined by <a href="http://en.wikipedia.org/wiki/Behavior_Driven_Development">BDD</a> which says that the test class and the test methods should describe the behavior you want to verify. </p>
<p>Examples:</p>
<p>having the test methods starting with should</p>
<pre class="brush:java">
public class WhenWindowControlCloseWindow {

    @Test
    public void shouldCloseWindows() {
         //...
    }
}
</pre>
<p>Or as in this example (from <a href="http://en.wikipedia.org/wiki/Behavior_Driven_Development">wikipedia</a>), which also uses comments to describe the test: given/when/then:</p>
<pre class="brush:java">
public class WindowControlBehavior {
    @Test
    public void shouldCloseWindows() {

        // Given
        WindowControl control = new WindowControl("My AFrame");
        AFrame frame = new AFrame();

        // When
        control.closeWindow();

        // Then
        ensureThat(!frame.isShowing());
    }
}
</pre>
<p>or another convention I saw:</p>
<pre class="brush:java">
public class WindowControlShould {
    @Test
    public void closeWindows() {
       //...
    }
}
</pre>
<p>The problem here is that you have 3 elements in a test: the &#8216;entity&#8217; subject of the test (usually a class name), the condition (&#8216;when calling some method with some specific parameters), and the expected result, that as we saw in BDD with the &#8220;<em>should</em>DoSomething&#8221; method name. So the problem is that with the class name and the method name we only have two elements to describe our test.<br />
To express the 3rd &#8216;entity&#8217; of the phrase, I tried to use inner classes to define tests like this:</p>
<pre class="brush:java">
public class WindowControl
    public static class WhenCloseWindow {
        @Test
        public void shouldCloseWindows() {
            //...
        }
    }
}
</pre>
<p>But it isn&#8217;t supported by JUnit4. </p>
<p>I thought that packages might help, like specifying them as </p>
<pre class="brush:java">
package com.mycompany.blah.blah.windowcontrol;
public static class WhenCloseWindow {
    @Test
    public void shouldCloseWindows() {
        //...
    }
}
</pre>
<p>But in this way you lose the possibility to invoke <tt>default</tt> and <tt>package</tt> accessible methods, which is a thing that I quite like in my tests.</p>
<p>My feeling now is that first the test methods were identified by a naming convention. Then with the annotation, the convention has been left to the developer to choose, or even the choice to not have a convention at all. The annotation, for me is more close to a configuration thing, which is replacing a convention; a sort of counter-tendency in the trend of convention over configuration paradigm. So if we start to call our test method <em>should</em>Something() are we not going back to the old convention <em>test</em>Something() ?<br />
Well I liked the conventions used in JUnit 3 and I don&#8217;t really see big improvements in using the annotations, or being free from extending the TestCase class, which was providing the <em>assert</em>* methods: with JUnit4 we have to static import those methods from the class Assert; I don&#8217;t see it as an improvement.<br />
My taste is that, if we can&#8217;t easily find a descriptive naming convention for what we are testing, relying on some comments could be the best thing. The example above &#8211; the one coming from wikipedia &#8211; is in fact using a naming convention <em>plus</em> some comments in the code. I think that using a comment on top of the method would have served better the purpose of describing the test.</p>
<p>Finally, some continuous integration tools are able to format the test names (class + method) to show a sentence describing the test nicely in natural English language.<br />
That is cool, but since we have the @Test annotation already there to configure the test, why not having a descriptive attribute that can be used from reporting tools, like: </p>
<pre class="brush:java">
@Test(description="when WindowController.closeWindow() is invoked the window is closed")
public void testCloseWindow() {
    //...
}
</pre>
<p>Or, since I criticized the @Test annotation, a short java comment would have sorted the same purpose for the tools willing to describe the test with a plain English description.</p>
<p>Since there isn&#8217;t around a really good naming convention for tests, since I don&#8217;t see real improvements using annotations and static imports&#8230; I think that JUnit 3 was doing right.</p>
<p>What do you think?<br />
<script type="text/javascript">var dzone_url = 'http://java.dzone.com/articles/unit-test-naming-conventions'; var dzone_style = '2';</script><script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
<div id="crp_related">
<h4>Related Posts:</h4>
<ul>
<li><a href="http://en.newinstance.it/2008/11/04/dynamic-tests-with-junit-3/" rel="bookmark" class="crp_title">Dynamic tests with JUnit 3</a></li>
<li><a href="http://en.newinstance.it/2005/12/07/unit-testing-internal-object-state/" rel="bookmark" class="crp_title">Unit Testing internal object state</a></li>
<li><a href="http://en.newinstance.it/2009/03/27/mocking-jndi/" rel="bookmark" class="crp_title">Mocking JNDI</a></li>
<li><a href="http://en.newinstance.it/2010/09/07/workaround-to-multi-threaded-testing/" rel="bookmark" class="crp_title">Workaround to multi threaded testing</a></li>
<li><a href="http://en.newinstance.it/2005/06/07/stringbuffer-considered-harmuful/" rel="bookmark" class="crp_title">StringBuffer considered harmuful</a></li>
</ul>
</div>
<div class="shr-publisher-943"></div>
<p><!-- Start Shareaholic LikeButtonSetBottom Automatic -->
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F01%2F28%2Funit-test-naming-conventions%2F' data-shr_title='Unit+test+naming+conventions'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F01%2F28%2Funit-test-naming-conventions%2F' data-shr_title='Unit+test+naming+conventions'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2011%2F01%2F28%2Funit-test-naming-conventions%2F' data-shr_title='Unit+test+naming+conventions'></a></div>
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<p><!-- End Shareaholic LikeButtonSetBottom Automatic --></p>
]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2011/01/28/unit-test-naming-conventions/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Android sdk 2.2_r2 sources</title>
		<link>http://en.newinstance.it/2010/12/01/android-sdk-2-2_r2-sources/</link>
		<comments>http://en.newinstance.it/2010/12/01/android-sdk-2-2_r2-sources/#comments</comments>
		<pubDate>Wed, 01 Dec 2010 08:40:07 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[android sources eclipse opensource development]]></category>

		<guid isPermaLink="false">http://en.newinstance.it/?p=917</guid>
		<description><![CDATA[Yesterday I took back some source samples I was using to learn android, so I got a good chance to build android-sdk-2.2_r2-src.jar for anyone that may need it. I remember to readers that there is a script to generate those on this blog post, where I also explain how to use those files. For the [...]]]></description>
			<content:encoded><![CDATA[<p><!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic -->Yesterday I took back some source samples I was using to learn android, so I got a good chance to build <a href="http://dl.dropbox.com/u/2109153/Downloads/Android/android-sdk-2.2_r2-src.jar">android-sdk-2.2_r2-src.jar</a> for anyone that may need it. </p>
<p>I remember to readers that there is a script to generate those on <a href="http://en.newinstance.it/2010/05/17/attaching-sources-to-androidjar-in-eclipse/">this blog post</a>, where I also explain how to use those files.</p>
<p>For the ones that want to avoid to run my buggy script, in <a href="http://en.newinstance.it/2010/05/18/androidjar-sources/">this blog post</a> you can find some source bundles for android versions, ready for use.</p>
<p>Recently I'm very busy at work and in the spare time so I am not posting regularly; my todo list (or topost list) for this blog is getting long.</p>
<p>Just in case I'll not find time to write here before... Happy Christmas.</p>
<p><script type="text/javascript">var dzone_url = 'http://mobile.dzone.com/news/android-sdk-22r2-sources'; var dzone_style = '2';</script><script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
<div id="crp_related">
<h4>Related Posts:</h4>
<ul>
<li><a href="http://en.newinstance.it/2010/05/18/androidjar-sources/" rel="bookmark" class="crp_title">Android.jar sources</a></li>
<li><a href="http://en.newinstance.it/2010/05/17/attaching-sources-to-androidjar-in-eclipse/" rel="bookmark" class="crp_title">Attaching sources to android.jar in Eclipse</a></li>
<li><a href="http://en.newinstance.it/2011/02/10/eclipse-save-actions/" rel="bookmark" class="crp_title">Eclipse Save Actions</a></li>
<li><a href="http://en.newinstance.it/2011/06/01/checking-configuration-files-inside-jars/" rel="bookmark" class="crp_title">Checking configuration files inside jars</a></li>
<li><a href="http://en.newinstance.it/2011/02/27/how-to-create-a-statically-linked-version-of-git-binaries/" rel="bookmark" class="crp_title">How to create a statically linked version of git binaries</a></li>
</ul>
</div>
<div class="shr-publisher-917"></div>
<p><!-- Start Shareaholic LikeButtonSetBottom Automatic -->
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2010%2F12%2F01%2Fandroid-sdk-2-2_r2-sources%2F' data-shr_title='Android+sdk+2.2_r2+sources'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2010%2F12%2F01%2Fandroid-sdk-2-2_r2-sources%2F' data-shr_title='Android+sdk+2.2_r2+sources'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2010%2F12%2F01%2Fandroid-sdk-2-2_r2-sources%2F' data-shr_title='Android+sdk+2.2_r2+sources'></a></div>
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<p><!-- End Shareaholic LikeButtonSetBottom Automatic --></p>
]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2010/12/01/android-sdk-2-2_r2-sources/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

