<?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>CertPal &#187; CertPal</title>
	<atom:link href="http://www.certpal.com/blogs/author/certpal/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.certpal.com/blogs</link>
	<description>Technology and certifications</description>
	<lastBuildDate>Mon, 26 Jul 2010 17:34:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Java Neuroph tutorial &#8211; The code classifier</title>
		<link>http://www.certpal.com/blogs/2010/07/java-neuroph-tutorial-the-code-classifier/</link>
		<comments>http://www.certpal.com/blogs/2010/07/java-neuroph-tutorial-the-code-classifier/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 17:34:59 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[neural]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=844</guid>
		<description><![CDATA[The Neuroph API can be used to train neural networks in java. This experiment tries to use the API to enable automatic classification of source code based on the programming language it belongs to]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F07%2Fjava-neuroph-tutorial-the-code-classifier%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F07%2Fjava-neuroph-tutorial-the-code-classifier%2F" height="61" width="51" /></a></div><p><a href="http://www.certpal.com/blogs/wp-content/uploads/neuroph_logo.png"><img class="alignright size-full wp-image-666" title="neuroph_logo" src="http://www.certpal.com/blogs/wp-content/uploads/neuroph_logo.png" alt="" width="257" height="148" /></a> An <a href="http://www.ibm.com/developerworks/library/l-neural/" target="_blank">article was written a while back</a> about how neural networks can be used to classify source code. Yes the source code that you write to feed to compilers / interpreters.</p>
<p>The article explains at a high level what method could be used to perform this activity. In the end the author claims some level of success and wonders how other neural-network implementations / techniques would solve the same problem. This got me curious enough and I spent a weekend trying to crack this with Neuroph, the neural network library for java. I present to you my analysis and results below. For the impatient here is the code-classifier <a href="http://www.certpal.com/NeuralWeb/index.html" target="_blank">DEMO</a>.</p>
<h2>Why solve this problem with neural networks ?</h2>
<p>So where do we begin ? How about the question &#8216;Why do we need neural networks to solve this problem ?&#8217;. Well actually it might not be the &#8216;best&#8217; way to solve the problem. A lexer is a better solution to this problem since it can scan the source file and probably give you a much better accuracy on the clasification. But neural networks are also great for this problem since they can keep learning based on the input that is provided. Add one more programming language into the bag and the network can learn about this language without a programmer needing to type extra code into a lexer.</p>
<h2>So how do we do it ?</h2>
<p>One of the features that differentiates one source code type from another is the keywords used by the programming language in question. So lets target that. Our neural network will try to identify if source code belongs to the java language or the python language. </p>
<p>It takes as its input a list of all keywords available in both languages. Mind you that there may even be some overlap between the keywords. For example the keyword &#8216;if&#8217; is used in both languages. But there may be keywords that are used solely in one language alone.</p>
<p><strong>Neural network viewed in graph mode: (The network is too huge to fit into this picture <img src='http://www.certpal.com/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )<br />
</strong></p>
<p><a href="http://www.certpal.com/blogs/wp-content/uploads/neural_code_classifier.png"><img class="aligncenter size-full wp-image-848" title="neural_code_classifier" src="http://www.certpal.com/blogs/wp-content/uploads/neural_code_classifier.png" alt="" width="738" height="552" /></a></p>
<p>A middle layer will contain a few nodes that will back propagate anything that it learns. The output layer (just one node) will decide if the language is java / python. The value will range from 0-1, where 0 represents closeness to python and 1 represents closeness to java.</p>
<h2>How do we train it ?</h2>
<p>The process of training is made easy by the neuroph API. First we need a few java / python files. A program was written that reads each file and splits it based on the whitespace delimiter. Based on a known set of keywords, the network is fed the number of times a keyword appears in a source file.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>Map<span style="color: #339933;">&lt;</span>Double, Double<span style="color: #339933;">&gt;</span> map <span style="color: #339933;">:</span> keywordStrength<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    Collection<span style="color: #339933;">&lt;</span>Double<span style="color: #339933;">&gt;</span> values <span style="color: #339933;">=</span> map.<span style="color: #006633;">values</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Vector<span style="color: #339933;">&lt;</span>Double<span style="color: #339933;">&gt;</span> input <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Vector<span style="color: #339933;">&lt;</span>Double<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    input.<span style="color: #006633;">addAll</span><span style="color: #009900;">&#40;</span>values<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    SupervisedTrainingElement supervisedTrainingElement <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SupervisedTrainingElement<span style="color: #009900;">&#40;</span>input,output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    trainingSet.<span style="color: #006633;">addElement</span><span style="color: #009900;">&#40;</span>supervisedTrainingElement<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>For example, recognized keywords may be &#8216;public&#8217; represented by the input index 0 and &#8216;static&#8217; represented by the input index 1.  A java file may contain the word pubic 10 times and static 5 times. The input to the network in this case would be 10 5. We can now use these numbers to tell the network &#8216;Hey if you see this pattern it is likely that the source code belongs to language X&#8217;. Neat !. Once the network is trained you can load it and use the same process to classify source code for any given input String.</p>
<h2>Well&#8230; show us some stats:</h2>
<p>Before I say anything else, I did not expect this approach to succeed more than 10-20% of the time. This is because the number of files that I trained this network with was around 20. Java + Python included. But I was surprised to see the network classifying the data correctly most of the time. There were very few cases where it failed.</p>
<p>The real test for this network is now in your hands. I made a java web app on top of this &#8216;code classifier&#8217; application and built a simple UI using Jquery. You can type in any code / junk you want and hit the trained network. If it manages to classify your code correctly at least 60% of the time, I would consider that an enormous victory (for Neuroph ?) <img src='http://www.certpal.com/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So what are you waiting for, <a href="http://www.certpal.com/NeuralWeb/index.html" target="_blank">take her for a spin</a>.</p>
<h2>How do I game the results:</h2>
<p>This is pretty simple. There are certain rules you must follow. Not following them will give you weird results <img src='http://www.certpal.com/blogs/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>1. Make sure that your code does not contain comments. I do not strip comments from code before analyzing them for keywords. Including java like keywords in a python file comment will confuse the network.<br />
2. Input only those files that will compile / run correctly on Java / Python. In theory you could feed in a Shakespeare novel to my network and it will still try to classify it as source code <img src='http://www.certpal.com/blogs/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>So does the network work for you ? Feel free to leave a comment.</p>
<p><em>I also wrote a simpler <a href="http://www.certpal.com/blogs/2010/04/java-neural-networks-and-neuroph-a-tutorial/" target="_new">tutorial for Neuroph</a> that is less practical and more academic. Check it out if it interests you</em></p>
<p><script type="text/javascript">var dzone_url = 'http://www.certpal.com/blogs/2010/07/java-neuroph-tutorial-the-code-classifier/';</script><br />
<script type="text/javascript">var dzone_title = 'Java Neuroph tutorial - The code classifier';</script><br />
<script type="text/javascript">var dzone_blurb = 'The Neuroph API can be used to train neural networks in java. This experiment tries to use the API to enable automatic classification of source code based on the programming language it belongs to. ';</script><br />
<script type="text/javascript">var dzone_style = '2';</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script></p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F07%2Fjava-neuroph-tutorial-the-code-classifier%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F07%2Fjava-neuroph-tutorial-the-code-classifier%2F" height="61" width="51" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2010/07/java-neuroph-tutorial-the-code-classifier/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Testing in production</title>
		<link>http://www.certpal.com/blogs/2010/06/testing-in-production/</link>
		<comments>http://www.certpal.com/blogs/2010/06/testing-in-production/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 15:58:31 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[production]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=819</guid>
		<description><![CDATA[Do you test your code in production ? If you do not you might want to consider these scenarios and rethink if it makes sense to test in the live environment. What is your opinion and why ?]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F06%2Ftesting-in-production%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F06%2Ftesting-in-production%2F" height="61" width="51" /></a></div><p><a href="http://www.certpal.com/blogs/wp-content/uploads/bomb_fuse.png"><img class="alignright size-full wp-image-825" title="bomb_fuse" src="http://www.certpal.com/blogs/wp-content/uploads/bomb_fuse.png" alt="" width="128" height="128" /></a>Do you ever test your code after it has been deployed to production ? During my first few years programming, I thought this was a bad idea and was told repeatedly told not to test anything in Prod.</p>
<p>After being bitten time and again by environment related problems, I decided to make it a point to perform a smoke test in Prod before handing it to users. Even if it meant a transaction with real money was involved.</p>
<p>Let me take a few moments to recite some of the follies that befell me when I did not test in Prod.</p>
<ul>
<li>Code moves to production. We find out that the SSL certificates in QA are installed in a different configuration when compared to Prod. The isSecure() flag on the HttpServletRequest returned a different value because of this and the code bombed.</li>
</ul>
<ul>
<li>A process tries to check in and check out files from clear case. The live environment has some clear case triggers that prevent check in based on certain rules. These rules are absent in QA. Kaboom.</li>
</ul>
<ul>
<li>A web service provider used an unsigned certificate in prod and didnt tell us about it. The cert chain hierarchy broke and the application stopped working.</li>
</ul>
<ul>
<li>An insert into a table in DEV was done using dummy user GUIDs. When the code was moved to Prod, we found out that all production GUIDs are of length 42 but the test GUIDs were of length 30.</li>
</ul>
<ul>
<li>And so on&#8230;</li>
</ul>
<p>I think it is justifiable to even test code in Prod when money is involved. Just test for a transaction value of one  dollar and then roll it back. Sure beats a customer coming back to you and telling you that your system is broken.</p>
<p>But enough about what I think. What do you think ? Do you test your code in the live environment ? Take a small yes / no poll and if you feel the answer should be no, feel free to leave a comment.</p>
Note: There is a poll embedded within this post, please visit the site to participate in this post's poll.
<p><script type="text/javascript">var dzone_url = 'http://www.certpal.com/blogs/2010/06/testing-in-production/';</script><br />
<script type="text/javascript">var dzone_title = 'Testing in production';</script><br />
<script type="text/javascript">var dzone_blurb = 'Do you test your code in production ? If you do not you might want to consider these scenarios and rethink if it makes sense to test in the live environment. ';</script><br />
<script type="text/javascript">var dzone_style = '2';</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script> </p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F06%2Ftesting-in-production%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F06%2Ftesting-in-production%2F" height="61" width="51" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2010/06/testing-in-production/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Eclipse tips and tricks &#8211; Part 3</title>
		<link>http://www.certpal.com/blogs/2010/06/eclipse-tips-and-tricks-part-3/</link>
		<comments>http://www.certpal.com/blogs/2010/06/eclipse-tips-and-tricks-part-3/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 16:00:15 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=771</guid>
		<description><![CDATA[The following eclipse tips and tricks can be used to save the time you spend writing code in the IDE. Learn how to customize key bindings ; code suggestions ; workspaces ; revert back to your local history etc. ]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F06%2Feclipse-tips-and-tricks-part-3%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F06%2Feclipse-tips-and-tricks-part-3%2F" height="61" width="51" /></a></div><p style="text-align: center;"><a href="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_logo.png"><img class="aligncenter size-full wp-image-775" style="border: 1px solid #cccccc;" title="eclipse_tips_tricks_3_logo" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_logo.png" alt="" width="128" height="128" /></a></p>
<p>Here are a few more tips / tricks with which you can save time when you use the eclipse IDE.</p>
<h2><span style="color: #333399;"><strong>Assign Key bindings:</strong></span></h2>
<p><span style="color: #333399;"><strong><br />
</strong></span></p>
<p><a href="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_2.png"><img class="aligncenter size-full wp-image-781" title="eclipse_tips_tricks_3_2" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_2.png" alt="" width="655" height="411" /></a></p>
<p>Navigate to <span style="color: #333399;"><strong>Window -&gt; Preferences -&gt; General -&gt; Keys</strong></span></p>
<p>You will find that there are many key bindings that are not assigned to actions that you might do on a daily basis. For example, when I start up on a new project, it is highly likely that I will introduce a lot of Value Objects (or Transfer / Data object, whatever you like to call them). A slick feature is to generate the &#8216;Getters and Setters&#8217; for them using the &#8216;Source -&gt; Generate getter and setter&#8217; command from the Main menu.</p>
<p>You can either do that or you can assign a shortcut key to this action and get it done quickly. I use Alt+Shift+Q, +G (Yeah not the easiest combination. I know <img src='http://www.certpal.com/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ). To restart eclipse I use Ctrl + F12. You might want to look at other bindings like</p>
<ul>
<li>Generate hashCode</li>
<li> Generate toString()</li>
<li> New package</li>
<li> New class</li>
</ul>
<p>And so on&#8230;</p>
<h2><span style="color: #333399;"><strong>Reduce number of code suggestions:</strong></span></h2>
<p><span style="color: #333399;"><strong><br />
</strong></span></p>
<p><a href="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_1.png"><img class="aligncenter size-full wp-image-778" title="eclipse_tips_tricks_3_1" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_1.png" alt="" width="565" height="263" /></a></p>
<p>The shortcut I use the most in eclipse is perhaps ctrl+space. Code completion is a real time saver. It can however be annoying when you press ctrl+space more than once by mistake. This by default, brings about suggestions for SWT templates among other things. You can turn this off by navigating to <span style="color: #333399;"><strong>Window -&gt; Preferences -&gt; Java -&gt; Edtior -&gt; Code Assist.</strong></span></p>
<h2><span style="color: #333399;"><strong>Import preferences:</strong></span></h2>
<p><span style="color: #333399;"><strong><br />
</strong></span></p>
<p><strong><a href="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_7.png"><img class="aligncenter size-full wp-image-789" title="eclipse_tips_tricks_3_7" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_7.png" alt="" width="465" height="209" /></a><br />
</strong></p>
<p>If you are like me, your hard disk probably has more than 100 eclipse Workspaces. Developers usually customize their workspaces and it can take a while to do this. When you switch to the new workspace, some of the customization is lost because they were workspace specific. You can get them back easily by exporting your preferences in the old workspace and importing them again in the new one. Use the <span style="color: #333399;"><strong>File -&gt; Export / Import</strong></span> option to do this. Preferences like code formatting, code templates, default compiler settings etc will be readily available.</p>
<h2><strong><span style="color: #333399;">Remember more workspaces: (Works on myeclipse)</span></strong></h2>
<h2><strong><span style="color: #333399;"><br />
</span></strong></h2>
<p><strong><a href="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_6.png"><img class="aligncenter size-full wp-image-786" title="eclipse_tips_tricks_3_6" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_6.png" alt="" width="489" height="131" /></a><br />
</strong></p>
<p>Use this technique to allow eclipse to give you more drop down choices when you startup. By default eclipse remembers the last 5 workspaces used. You can increase / decrease this number by navigating to <span style="color: #333399;"><strong>Window -&gt; Preferences -&gt; General -&gt; Startup and Shutdown -&gt; Workspaces.</strong></span></p>
<h2><span style="color: #333399;"><strong>Associate eclipse with an external browser like firefox :</strong></span></h2>
<p><span style="color: #333399;"><strong><br />
</strong></span></p>
<p><strong><a href="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_3.png"><img class="aligncenter size-full wp-image-782" title="eclipse_tips_tricks_3_3" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_3.png" alt="" width="697" height="491" /></a><br />
</strong></p>
<p>Eclipse uses the system default browser. In most cases this is IE (gulp). You can change that by defining an external browser by navigating to <span style="color: #333399;"><strong>Window -&gt; Preferences -&gt; General -&gt; Web Browser.</strong></span>. This is great when you combine it with a plugin like Firebug. You get to code and debug HTML / CSS / Javascript all at once.</p>
<h2><span style="color: #333399;"><strong>Work with local history:</strong></span></h2>
<p><span style="color: #333399;"><strong><br />
</strong></span></p>
<p>Screwed up your java file and then saved it ? Yikes. Local history comes to your rescue. Every edit and save that you make in a file is saved as a local history in eclipse. Make use of this to revert changes when necessary.</p>
<p>To use this feature, right click on the file of your choice and click <span style="color: #333399;"><strong>Compare With -&gt; Local hisory. </strong></span>That should open up the entries in the &#8216;History&#8217; view.<br />
<a href="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_4.png"><img class="aligncenter size-full wp-image-783" title="eclipse_tips_tricks_3_4" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_4.png" alt="" width="355" height="162" /></a></p>
<p>Clicking on any of the history entries will open a diff window telling you the difference between the current entry and the previous edits. Ah ! time is saved.</p>
<p><a href="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_5.png"><img class="aligncenter size-full wp-image-784" title="eclipse_tips_tricks_3_5" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_5.png" alt="" width="747" height="156" /></a></p>
<p>This is a 3 part article. If you would like to browse through the other tips, you can find them here</p>
<p><a href="http://www.certpal.com/blogs/2009/08/eclipse-tips-and-tricks-part-1/" target="_blank">Eclipse tips and tricks</a> &#8211; Part 1</p>
<p><a href="http://www.certpal.com/blogs/2009/09/eclipse-tips-and-tricks-part-2/" target="_blank"> Eclipse tips and tricks </a> &#8211; Part 2</p>
<p><script type="text/javascript">// <![CDATA[
  var dzone_url = 'http://www.certpal.com/blogs/2010/06/eclipse-tips-and-tricks-part-3/';
// ]]&gt;</script><br />
<script type="text/javascript">// <![CDATA[
  var dzone_title = 'Eclipse tips and tricks';
// ]]&gt;</script><br />
<script type="text/javascript">// <![CDATA[
  var dzone_blurb = 'The following eclipse tips and tricks can be used to save the time you spend writing code in the IDE. Learn how to customize key bindings ; code suggestions ; workspaces ; revert back to your local history etc. ';
// ]]&gt;</script><br />
<script type="text/javascript">// <![CDATA[
  var dzone_style = '2';
// ]]&gt;</script><br />
<script src="http://widgets.dzone.com/links/widgets/zoneit.js"></script></p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F06%2Feclipse-tips-and-tricks-part-3%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F06%2Feclipse-tips-and-tricks-part-3%2F" height="61" width="51" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2010/06/eclipse-tips-and-tricks-part-3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to improve your programming skills</title>
		<link>http://www.certpal.com/blogs/2010/06/how-to-improve-your-programming-skills/</link>
		<comments>http://www.certpal.com/blogs/2010/06/how-to-improve-your-programming-skills/#comments</comments>
		<pubDate>Mon, 07 Jun 2010 16:35:55 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=732</guid>
		<description><![CDATA[Everyone introduces bugs into their code, whether they like it or not. Here are a few ways through which you can reduce the number of bugs in your code. Or at least, try ;)]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F06%2Fhow-to-improve-your-programming-skills%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F06%2Fhow-to-improve-your-programming-skills%2F" height="61" width="51" /></a></div><p>Ever visit sites like <a href="http://www.topcoder.com/tc/" target="_blank">topcoder.com</a> and solve a problem or two ? No ? You should and do so regularly. It will help find tune your programming / design skills. This is because solving the problems requires going though the following thought process</p>
<ol>
<li>Understanding the problem.</li>
<li>Thinking up a solution that covers all use cases.</li>
<li>Executing your thought process through code.</li>
<li>Testing.</li>
</ol>
<p>Now as simple as that sounds, it is not so easy to get right. Especially when you are competing with thousands of fellow coders for time. And when time is a constrain you usually select the first solution that comes to your head, which might not necessarily be the best. So there is that risk of your code timing out even if it is following the right logic. I would love to delve into a problem right about now and throw in some examples and illustration, but you get the point.</p>
<p>When the thought process that we follow is not well defined and we lose focus, it often leads to buggy code. Don&#8217;t believe me ? Here are some bugs I caught in a code base on a recent project.</p>
<p><a href="http://www.certpal.com/blogs/2010/03/bugs-the-most-common-kind/" target="_blank">Bug 1</a></p>
<p><a href="http://www.certpal.com/blogs/2010/04/yet-another-bug/" target="_blank">Bug 2</a></p>
<p><a href="http://www.certpal.com/blogs/2010/06/more-bugs/" target="_blank">Bug 3</a></p>
<p>There were more bugs identified after development than what is listed here. But what I wanted to highlight was that the problem was introduced into the system due to lack of focus and clarity of thought. Well, more often than not anyway. Other times the bug sneaks into the system because the number of test cases to test a method were not sufficient. </p>
<p>Have a look at this google research <a href="http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html" target="_blank">blog post about broken binary search and merge sort algorithms</a> for example. They pretty much have the same bug as the <a href="http://www.certpal.com/blogs/2010/04/yet-another-bug/" target="_blank">date calculation bug</a> that I highlighted in a different post. We are all prone to creating bugs, but we can minimize the number of ones we introduce into the system.</p>
<p>So what have I learned from introducing bugs so far ?</p>
<ol>
<li>As long as you keep your skills sharp and practice solving problems, the number of bugs you introduce will reduce. I try to visit sites like <a href="http://www.topcoder.com/tc/" target="_blank">topcoder.com</a> or <a href="http://codingbat.com/" target="_blank">codingbat.com</a> whenever I find the time.</li>
<li>Learning from other&#8217;s mistakes and best practices can save you tons of time.</li>
<li>Try not to cram in your work within X hours. This tends to focus the effort on finishing the code on time instead of writing it neat and bug free.</li>
</ol>
<p>As always its easier said than done. But hey, its never too late eh ? As for finding the bugs in the first place&#8230;</p>
<ol>
<li>Use a tool like <a href="http://findbugs.sourceforge.net/" target="_self">FindBugs</a> after you are done coding. You will be surprised at how many problems turn up.</li>
<li>Try to maintain a code coverage of at least 80 %. Tools like <a href="http://emma.sourceforge.net/" target="_blank">Emma</a> can help you track this.</li>
</ol>
<p><script type="text/javascript">var dzone_url = 'http://www.certpal.com/blogs/2010/06/how-to-improve-your-programming-skills/';</script><br />
<script type="text/javascript">var dzone_title = 'How to improve your programming skills';</script><br />
<script type="text/javascript">var dzone_blurb = 'Everyone introduces bugs into their code, whether they like it or not. Here are a few ways through which you can reduce the number of bugs in your code. Or at least, try <img src='http://www.certpal.com/blogs/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ';</script><br />
<script type="text/javascript">var dzone_style = '2';</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script> </p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F06%2Fhow-to-improve-your-programming-skills%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F06%2Fhow-to-improve-your-programming-skills%2F" height="61" width="51" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2010/06/how-to-improve-your-programming-skills/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>More bugs</title>
		<link>http://www.certpal.com/blogs/2010/06/more-bugs/</link>
		<comments>http://www.certpal.com/blogs/2010/06/more-bugs/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 09:02:32 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[bug]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=742</guid>
		<description><![CDATA[Another bug that I stumbled across while testing some code. Squashed this one after some analysis.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F06%2Fmore-bugs%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F06%2Fmore-bugs%2F" height="61" width="51" /></a></div><p style="text-align: center;"><a href="http://www.certpal.com/blogs/wp-content/uploads/bug.png"><img class="aligncenter size-full wp-image-637" style="border: 1px dashed blue;" title="bug" src="http://www.certpal.com/blogs/wp-content/uploads/bug.png" alt="" width="213" height="176" /></a></p>
<p>I ran into another sweet little bug that I thought I would share with you. This one cropped up after it passed a few tests. See if you can spot the problem. Without further delay here it is</p>
<p><strong>Problem:</strong></p>
<p>A record needs to be inserted with a new identity number. This number is obtained as the next maximum ID value from a set of elements in a XML file. The following code is supposed to obtain the next ID from the XML. Lets skip the XML related code since that just adds clutter. </p>
<p><strong>Code:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">int</span> max <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span> DataType data <span style="color: #339933;">:</span> someListFromTheXml <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>max <span style="color: #339933;">&lt;</span> data.<span style="color: #006633;">getId</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>
         max <span style="color: #339933;">=</span> data.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
s_logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; Max id: &quot;</span> <span style="color: #339933;">+</span> max<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">return</span> max<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>See anything wrong with it ? Its got a pretty big flaw. The logic works only for odd number of elements. When the number of elements is even, it fails. Here&#8217;s an illustration</p>
<p><strong>Test cases:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Test
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>... <span style="color: #006633;">args</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> input1 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">int</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> input2 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">int</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> input3 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">2</span>,<span style="color: #cc66cc;">3</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">int</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> input4 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">2</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">4</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        Test test <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Test<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        test.<span style="color: #006633;">go</span><span style="color: #009900;">&#40;</span>input1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        test.<span style="color: #006633;">go</span><span style="color: #009900;">&#40;</span>input2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        test.<span style="color: #006633;">go</span><span style="color: #009900;">&#40;</span>input3<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        test.<span style="color: #006633;">go</span><span style="color: #009900;">&#40;</span>input4<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        test.<span style="color: #006633;">go</span><span style="color: #009900;">&#40;</span>input5<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> go<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> input<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> max<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #339933;">:</span>input<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>max <span style="color: #339933;">&lt;</span> id<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                max <span style="color: #339933;">=</span> id<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; Max id: &quot;</span> <span style="color: #339933;">+</span> max<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Here&#8217;s the output:</p>
<p>Max id: 2<br />
Max id: 2<br />
Max id: 4<br />
Max id: 4<br />
Max id: 6</p>
<p>The logic incorrectly assigns the max to id+1. Instead it should have stored the current max and returned max+1 at the end of the loop. Sigh. </p>
<p>In hind sight a Xpath expression would have done nicely here. Something like max(/Parent/child/@value)+1. Still that is no excuse for the faulty logic <img src='http://www.certpal.com/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><script type="text/javascript">var dzone_url = 'http://www.certpal.com/blogs/2010/06/more-bugs/';</script><br />
<script type="text/javascript">var dzone_title = 'More bugs';</script><br />
<script type="text/javascript">var dzone_blurb = 'Another bug that I stumbled across while testing some code. Squashed this one after some analysis.';</script><br />
<script type="text/javascript">var dzone_style = '2';</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script> </p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F06%2Fmore-bugs%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F06%2Fmore-bugs%2F" height="61" width="51" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2010/06/more-bugs/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Crypt DES and 8 character truncated passwords</title>
		<link>http://www.certpal.com/blogs/2010/05/crypt-des-and-8-character-truncated-passwords/</link>
		<comments>http://www.certpal.com/blogs/2010/05/crypt-des-and-8-character-truncated-passwords/#comments</comments>
		<pubDate>Tue, 18 May 2010 14:38:00 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[crypt]]></category>
		<category><![CDATA[des]]></category>
		<category><![CDATA[encryption]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=734</guid>
		<description><![CDATA[Be wary of the crypt + DES encryption method as it truncates passwords to 8 characters in length. The users are usually not informed of the truncation which leads the account vulnerable to password guesses]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F05%2Fcrypt-des-and-8-character-truncated-passwords%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F05%2Fcrypt-des-and-8-character-truncated-passwords%2F" height="61" width="51" /></a></div><p><a href="http://www.certpal.com/blogs/wp-content/uploads/security_lock.png"><img class="alignright size-full wp-image-503" title="security_lock" src="http://www.certpal.com/blogs/wp-content/uploads/security_lock.png" alt="" width="79" height="104" /></a>Many passwords in linux are encrypted using the <a href="http://en.wikipedia.org/wiki/Crypt_%28Unix%29" target="_blank">crypt() utility</a>. The user is usually not aware of the difference between a crypt and a MD5 encryption. Well it can turn out to be important, especially if crypt uses the default DES-based scheme to perform the encryption.</p>
<p>The problem with crypt() + Traditional DES is that it truncates the password length to 8 characters. Users are not usually aware of this and assume that the entire length of the password has been saved and encrypted. Take the apache tool htpasswd for example. It uses <a href="http://httpd.apache.org/docs/2.0/programs/htpasswd.html" target="_blank">crypt() to encrypt passwords</a> (It may also use its own MD5 routine) into a password file. The following command creates a new user in a password file</p>
<p>htpasswd password_file new_user</p>
<p>After this command is executed, you are prompted for a password. If the password is greater than 8 characters, for example &#8211; 123456789, it will still be accepted and no warning will be provided that it was truncated. So providing the password 12345678 will also allow you to be authenticated into the system. Why is this bad ?</p>
<ul>
<li>The time taken to crack 8 character passwords is shorter (in relative comparison).</li>
</ul>
<ul>
<li>It is also likely that the password was truncated in these scenarios, so an attacker may well target passwords that are exactly 8 characters in length.</li>
</ul>
<ul>
<li>Some people have the knack of prefixing the password with the username first. Bad idea if your username happens to be 8 characters long <img src='http://www.certpal.com/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ul>
<ul>
<li>The user may not even be aware of the problem, since he/she assumes that the password is strong and greater than 8 characters.</li>
</ul>
<p>So the next time you provide a password to a system, you might want to know how they get saved into a persistence store and what encryption is used.</p>
<p><script type="text/javascript">var dzone_url = 'http://www.certpal.com/blogs/2010/05/crypt-des-and-8-character-truncated-passwords/';</script><br />
<script type="text/javascript">var dzone_title = 'Crypt DES and 8 character truncated passwords';</script><br />
<script type="text/javascript">var dzone_blurb = 'Be wary of the crypt + DES encryption method as it truncates passwords to 8 characters in length. The users are usually not informed of the truncation which leads the account vulnerable to password guesses';</script><br />
<script type="text/javascript">var dzone_style = '2';</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script></p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F05%2Fcrypt-des-and-8-character-truncated-passwords%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F05%2Fcrypt-des-and-8-character-truncated-passwords%2F" height="61" width="51" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2010/05/crypt-des-and-8-character-truncated-passwords/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learn to secure your application with Google Jarlsberg</title>
		<link>http://www.certpal.com/blogs/2010/05/learn-to-secure-your-application-with-google-jarlsberg/</link>
		<comments>http://www.certpal.com/blogs/2010/05/learn-to-secure-your-application-with-google-jarlsberg/#comments</comments>
		<pubDate>Mon, 10 May 2010 06:00:38 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=721</guid>
		<description><![CDATA[Learn to secure your application with Google Jarlsberg, a small cheesy application written by google with intentional security holes.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F05%2Flearn-to-secure-your-application-with-google-jarlsberg%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F05%2Flearn-to-secure-your-application-with-google-jarlsberg%2F" height="61" width="51" /></a></div><p><a href="http://www.certpal.com/blogs/wp-content/uploads/google_jarlsberg.png"><img class="alignright size-full wp-image-724" title="google_jarlsberg" src="http://www.certpal.com/blogs/wp-content/uploads/google_jarlsberg.png" alt="" width="84" height="85" /></a>I came across an interesting application today. Google has released an application named Jarlsberg that is full of security holes. The intent is to make developers learn how these holes work and put them in a position to combat the security vulnerabilities.</p>
<p>You can <a href="http://jarlsberg.appspot.com/" target="_blank">visit the app</a> to learn more. Security flaws to be detected are classified under the following categories</p>
<ul>
<li>Black box. You dont know the code</li>
<li>White box. Requires you to see the code to understand how to break it.</li>
<li>Gray box. Some code will be made visible.</li>
</ul>
<p>I also came across an <a href="http://code.google.com/edu/submissions/jarlsberg/Jarlsberg_Instructor_Guide.pdf" target="_blank">instructor&#8217;s guide</a> that has problems to be solved in the application, graded by their difficulty level.</p>
<p>What better way to learn an exploit than to perform it on a test system ? Some of the exploits involve</p>
<ul>
<li><a href="http://jarlsberg.appspot.com/part2#2__cross_site_scripting" target="_blank">XSS and related challenges</a></li>
<li><a href="http://jarlsberg.appspot.com/part4#4__path_traversal" target="_blank">Path traversal exploits</a></li>
<li><a href="http://jarlsberg.appspot.com/part4#4__denial_of_service" target="_blank">DOS</a></li>
<li><a href="http://jarlsberg.appspot.com/part5#5__buffer_and_integer_overflow" target="_blank">Buffer overflow</a></li>
<li><a href="http://jarlsberg.appspot.com/part5#5__sql_injection" target="_blank">SQL Injection</a></li>
</ul>
<p>and so much more. <a href="http://jarlsberg.appspot.com/" target="_blank">Give it a try now</a></p>
<p><script type="text/javascript">var dzone_url = 'http://www.certpal.com/blogs/2010/05/learn-to-secure-your-application-with-google-jarlsberg/';</script><br />
<script type="text/javascript">var dzone_title = 'Learn to secure your application with Google Jarlsberg';</script><br />
<script type="text/javascript">var dzone_blurb = 'Learn to secure your application with Google Jarlsberg, a small cheesy application written by google with intentional security holes.';</script><br />
<script type="text/javascript">var dzone_style = '2';</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script> </p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F05%2Flearn-to-secure-your-application-with-google-jarlsberg%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F05%2Flearn-to-secure-your-application-with-google-jarlsberg%2F" height="61" width="51" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2010/05/learn-to-secure-your-application-with-google-jarlsberg/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to configure log4j for a web app</title>
		<link>http://www.certpal.com/blogs/2010/05/how-to-configure-log4j-for-a-web-app/</link>
		<comments>http://www.certpal.com/blogs/2010/05/how-to-configure-log4j-for-a-web-app/#comments</comments>
		<pubDate>Thu, 06 May 2010 06:48:04 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[log4j]]></category>
		<category><![CDATA[logs]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=698</guid>
		<description><![CDATA[A tutorial on configuring log4j for a java web application. This page shows you how to configure log4j for your application and the standards to follow while doing the same. Some examples are provided to aid the reader]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F05%2Fhow-to-configure-log4j-for-a-web-app%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F05%2Fhow-to-configure-log4j-for-a-web-app%2F" height="61" width="51" /></a></div><p><a href="http://www.certpal.com/blogs/wp-content/uploads/server_log.png"><img class="alignright size-full wp-image-703" title="server_log" src="http://www.certpal.com/blogs/wp-content/uploads/server_log.png" alt="server log" width="113" height="146" /></a>I often see environments where web applications use log4j for logging into files using various appenders. That is all well and good until I see that the logs are getting written into the application server&#8217;s logs. In JBOSS for example this is server.log. So why is this a bad idea ?</p>
<p><strong>Why not to write into server.log:</strong></p>
<ol>
<li>An application server&#8217;s log is supposed to be used by the app server and not by your application.</li>
<li>This log is supposed to contain app server level information like loading war files / exceptions that were handed over to the container etc.</li>
<li>Weeding through the logs of about 10 applications to find a particular debug / error line is going to be crazy.</li>
<li>A PROD logging configuration should never have a console appender. The reason your application logs are getting logged into the server&#8217;s logs could be that your log4j configuration defines a console appender. This could mean you are logging the same thing in 2 places (assuming there is another file appender defined for your app).</li>
</ol>
<p>Ideally each application should manage its own logging needs. Many developers seem to be unaware of a class named <a href="http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/DOMConfigurator.html" target="_blank">DomConfigurator</a> in the log4j API that can load a log4j XML and configure it for your application. Here are the steps I usually take to prepare an application for logging</p>
<ol>
<li> Write a custom class that implements ServletContextListener like the one shown below. The class looks for a context param named log4jFileName that is defined in web.xml. This locates the log4j XML configuration file. This will configure log4j before other classes use it.</li>
</ol>
<p><strong>Custom listener:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> StartupListener <span style="color: #000000; font-weight: bold;">implements</span> ServletContextListener
<span style="color: #009900;">&#123;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> contextDestroyed<span style="color: #009900;">&#40;</span>ServletContextEvent arg0<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Cleanup code goes here</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> contextInitialized<span style="color: #009900;">&#40;</span>ServletContextEvent sce<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        Logger logger <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        ServletContext servletContext <span style="color: #339933;">=</span> sce.<span style="color: #006633;">getServletContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">String</span> log4jFile <span style="color: #339933;">=</span> servletContext.<span style="color: #006633;">getInitParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;log4jFileName&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        DOMConfigurator.<span style="color: #006633;">configure</span><span style="color: #009900;">&#40;</span>log4jFile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        logger <span style="color: #339933;">=</span> LogManager.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>StartupListener.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        logger.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Loaded: &quot;</span> <span style="color: #339933;">+</span> log4jFile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>2. In your web.xml define the listener and a context param like so</p>
<p><strong>Web.xml entries:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>log4jFileName<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         /usr/local/app/log4j/config/log4jConfig.xml
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/context-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        com.yourpackage.YourListener
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>3. Now configure your log4jConfig.xml appropriately to ensure that your application logs are logged under an appropriate path. Use a file appender like <a href="http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/RollingFileAppender.html" target="_blank">RollingFileAppender</a> to handle the retention policy for your applications.</p>
<p>Here is a sample log4j XML to help you</p>
<p><strong>Sample log4j XML: (Customize as necessary)</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;log4j:configuration</span> xmlns:log4j = <span style="color: #ff0000;">&quot;http://jakarta.apache.org/log4j/&quot;</span> debug = <span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;appender</span> name = <span style="color: #ff0000;">&quot;FILE&quot;</span> class = <span style="color: #ff0000;">&quot;org.apache.log4j.RollingFileAppender&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param</span> name = <span style="color: #ff0000;">&quot;File&quot;</span> value = <span style="color: #ff0000;">&quot;/usr/local/path/to/application.log&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param</span> name = <span style="color: #ff0000;">&quot;MaxFileSize&quot;</span> value = <span style="color: #ff0000;">&quot;5MB&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param</span> name = <span style="color: #ff0000;">&quot;MaxBackupIndex&quot;</span> value = <span style="color: #ff0000;">&quot;50&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;layout</span> class = <span style="color: #ff0000;">&quot;org.apache.log4j.PatternLayout&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param</span> name = <span style="color: #ff0000;">&quot;ConversionPattern&quot;</span> value = <span style="color: #ff0000;">&quot;[%d{dd/MM/yy hh:mm:ss:sss z}] %5p %c{2}: %m%n&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/layout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/appender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;category</span> name = <span style="color: #ff0000;">&quot;com.your.application.package&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;priority</span> value = <span style="color: #ff0000;">&quot;debug&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/category<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;category</span> name = <span style="color: #ff0000;">&quot;org.apache.catalina&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;priority</span> value = <span style="color: #ff0000;">&quot;error&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/category<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;category</span> name = <span style="color: #ff0000;">&quot;org.hibernate&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;priority</span> value = <span style="color: #ff0000;">&quot;error&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/category<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;root<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;priority</span> value = <span style="color: #ff0000;">&quot;info&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;appender-ref</span> ref = <span style="color: #ff0000;">&quot;FILE&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/root<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/log4j:configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>That is pretty much it. This will ensure that your application&#8217;s logs are logged elsewhere from the server&#8217;s own logs. Makes managing log files a little easier. </p>
<p><script type="text/javascript">var dzone_url = 'http://www.certpal.com/blogs/2010/05/how-to-configure-log4j-for-a-web-app/';</script><br />
<script type="text/javascript">var dzone_title = 'How to configure log4j for a web app';</script><br />
<script type="text/javascript">var dzone_blurb = 'A tutorial on configuring log4j for a java web application. ';</script><br />
<script type="text/javascript">var dzone_style = '2';</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script> </p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F05%2Fhow-to-configure-log4j-for-a-web-app%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F05%2Fhow-to-configure-log4j-for-a-web-app%2F" height="61" width="51" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2010/05/how-to-configure-log4j-for-a-web-app/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Yet another bug</title>
		<link>http://www.certpal.com/blogs/2010/04/yet-another-bug/</link>
		<comments>http://www.certpal.com/blogs/2010/04/yet-another-bug/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 05:23:37 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[bug]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=686</guid>
		<description><![CDATA[Yet annother bug caused by a silly mistake. Bugs like these are easy to catch although they are not so evident when they are introduced into the code.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F04%2Fyet-another-bug%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F04%2Fyet-another-bug%2F" height="61" width="51" /></a></div><p><a href="http://www.certpal.com/blogs/wp-content/uploads/bug.png"><img class="aligncenter" style="border: 1px dashed blue;" title="bug" src="http://www.certpal.com/blogs/wp-content/uploads/bug.png" alt="" width="213" height="176" /></a></p>
<p>I came across another silly little bug today. Take a look at the code below (assume &#8216;days&#8217; is a parameter and that this snippet is part of a larger function)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Date</span> now <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">long</span> nowMillis <span style="color: #339933;">=</span> now.<span style="color: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">Timestamp</span> nowTimestamp <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Timestamp</span><span style="color: #009900;">&#40;</span>nowMillis<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">long</span> future <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3600</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">24</span> <span style="color: #339933;">*</span> days <span style="color: #339933;">*</span> <span style="color: #cc66cc;">1000</span><span style="color: #339933;">;</span>
<span style="color: #003399;">Timestamp</span> expiryTimestamp <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Timestamp</span><span style="color: #009900;">&#40;</span>nowMillis <span style="color: #339933;">+</span> future<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>nowTimestamp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>expiryTimestamp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Can you tell what is wrong with it ? What the code intends to do is to set an expiry timestamp to an element &#8211; X days from today. A caller called this code snippet with the value 5. Well there is nothing wrong so far. Here is the output</p>
<p>2010-<strong>04</strong>-<strong>27</strong> 10:37:10.497<br />
2010-<strong>05</strong>-<strong>02</strong> 10:37:10.497</p>
<p>So then came along an element that needed an expiry of around 40 days. The caller calls with the value 40. Guess what the output is</p>
<p>2010-04-<strong>27</strong> 10:38:43.372<br />
2010-04-<span style="color: #ff0000;"><strong>17</strong></span> 17:35:56.076</p>
<p>Umm&#8230; so the expiry date is *before* the current date. Super. So what is going wrong ? The value of future in this case is -838967296. Although future is a long type, the data type that is being calculated to assign a value to it, is int. An int cannot take anything more than Integer.MAX_VALUE (2147483647).</p>
<p>If future had been calculated correctly, its value would be 3456000000. Instead what is being presented is the wrapped around value obtained after adding the remainder to Integer.MIN_VALUE.</p>
<p>I guess that just goes to show that if it aint broke you may still need to fix it later. Of course that depends on what your definition of &#8216;broke&#8217; is <img src='http://www.certpal.com/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><script type="text/javascript">var dzone_url = 'http://www.certpal.com/blogs/2010/04/yet-another-bug/';</script><br />
<script type="text/javascript">var dzone_title = 'Yet another bug';</script><br />
<script type="text/javascript">var dzone_blurb = 'Yet annother bug caused by a silly mistake. Bugs like these are easy to catch although they are not so evident when they are introduced into the code.';</script><br />
<script type="text/javascript">var dzone_style = '2';</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script></p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F04%2Fyet-another-bug%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F04%2Fyet-another-bug%2F" height="61" width="51" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2010/04/yet-another-bug/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Eclipse and the conflicting shortcut problem</title>
		<link>http://www.certpal.com/blogs/2010/04/eclipse-conflicting-shortcuts-problem/</link>
		<comments>http://www.certpal.com/blogs/2010/04/eclipse-conflicting-shortcuts-problem/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 06:14:22 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[shortcut]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=677</guid>
		<description><![CDATA[Eclipse shortcuts can sometimes conflict with the ones defined by other applications. These series of steps should help you resolve these conflicts]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F04%2Feclipse-conflicting-shortcuts-problem%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F04%2Feclipse-conflicting-shortcuts-problem%2F" height="61" width="51" /></a></div><p><a href="http://www.certpal.com/blogs/wp-content/uploads/shortcut_failure.png"><img class="alignright size-full wp-image-682" title="shortcut_failure" src="http://www.certpal.com/blogs/wp-content/uploads/shortcut_failure.png" alt="" width="165" height="143" /></a>I moved all development activities to linux recently. Part of the migration process involved getting used to some new apps like <a href="http://kopete.kde.org/" target="_blank">Kopete</a> / Pidgin / KDE Snapshot etc. It was a breeze until I started debugging my code in eclipse.</p>
<p>I frequently use the eclipse keyboard shortcuts to cut down the time I spend coding / debugging. One of my favorite is Ctrl + Shift + i , which will open up the inspection box for a particular variable. This shortcut just did not work. For quite a few days I did not understand why. The other shortcuts like fix imports ( ctrl + shift + o ) seemed to be working fine. That&#8217;s when I stumbled across a <a href="http://docs.kde.org/stable/en/kdenetwork/kopete/configuring.html" target="_blank">kopete shortcut</a>.</p>
<p>The shortcut Ctrl + Shift + i was also used by kopete to read messages. According to the documentation this was a global short cut that was valid in any KDE application. I closed kopete just to confirm that it was contributing to the problem and voila, Ctrl + Shift + i started to work inside eclipse once again. So the next time a shortcut does not work in eclipse you might want to</p>
<ol>
<li>Look at the Wondow -&gt; Preferences -&gt; Keys and ensure that the key is bound.</li>
<li>If it is bound, check other applications and make sure this is not a global shortcut used elsewhere.</li>
<li>If it is a global shortcut, change the key binding in eclipse or the other application.</li>
<li>Relax</li>
</ol>
<p><script type="text/javascript">var dzone_url = 'http://www.certpal.com/blogs/2010/04/eclipse-conflicting-shortcuts-problem';</script><br />
<script type="text/javascript">var dzone_title = 'Eclipse and the conflicting shortcut problem';</script><br />
<script type="text/javascript">var dzone_blurb = 'Eclipse shortcuts can sometimes conflict with the ones defined by other applications. These series of steps should help you resolve these conflicts';</script><br />
<script type="text/javascript">var dzone_style = '2';</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script> </p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F04%2Feclipse-conflicting-shortcuts-problem%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F04%2Feclipse-conflicting-shortcuts-problem%2F" height="61" width="51" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2010/04/eclipse-conflicting-shortcuts-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java neural networks and Neuroph &#8211; A tutorial</title>
		<link>http://www.certpal.com/blogs/2010/04/java-neural-networks-and-neuroph-a-tutorial/</link>
		<comments>http://www.certpal.com/blogs/2010/04/java-neural-networks-and-neuroph-a-tutorial/#comments</comments>
		<pubDate>Sun, 18 Apr 2010 16:26:38 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[neural]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=650</guid>
		<description><![CDATA[Getting started with java neural networks is easy with Neuroph. The visual GUI and the java interface provide a mechanism for beginners to play around with the API.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F04%2Fjava-neural-networks-and-neuroph-a-tutorial%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F04%2Fjava-neural-networks-and-neuroph-a-tutorial%2F" height="61" width="51" /></a></div><p><a href="http://www.certpal.com/blogs/wp-content/uploads/neuroph_logo.png"><img class="alignright size-full wp-image-666" title="neuroph_logo" src="http://www.certpal.com/blogs/wp-content/uploads/neuroph_logo.png" alt="" width="257" height="148" /></a>The java neural network <a href="http://neuroph.sourceforge.net/" target="_blank">Neuroph</a> was making news recently about its <a href="http://netbeans.dzone.com/neuroph-hadoop-nb" target="_blank">integration with Hadoop</a>. Neural networks can solve some interesting problems once they are trained. This article aims to provide the baby steps necessary to writing your first java program that loads a trained neural network.</p>
<p>Before you even begin to read anything that follows, a basic understanding of neural network terminology and the concept behind the same is necessary. The following articles are great starting points to understanding neural networks</p>
<p><a href="http://www.dzone.com/links/neuroph_smart_java_apps_with_neural_networks_part.html" target="_blank">Neuroph and neural networks &#8211; Part 1</a></p>
<p><a href="http://www.dzone.com/links/neuroph_smart_java_apps_with_neural_networks_part_2.html" target="_blank">Neuroph and neural networks &#8211; Part 2</a></p>
<p><a href="http://www.dzone.com/links/neuroph_smart_java_apps_with_neural_networks_part_3.html" target="_blank">Neuroph and neural networks &#8211; Part 3</a></p>
<p><a href="http://www.ibm.com/developerworks/library/l-neural/" target="_blank">Intro to neural networks </a></p>
<h2><strong>Cars and Signals:</strong></h2>
<p>We will  simulate the scenario where cars wait at a signal and move only when the lights are green. This simple example should help get you started. Our aim is to define a neural network with the easyNeurons swing application; train it; import it into java and use it in an application.</p>
<p>There are 3 states for this signal</p>
<p>1. Red &#8211; Stay where you are</p>
<p>2. Yellow &#8211; Start your engines</p>
<p>3. Green &#8211; Go</p>
<p>The neural network will take 3 inputs and its architecture will be based on the multi layer perceptron setting. A hidden layer with 4 nodes will decide the output. The output itself will be based on one node, whose value will determine if the cars can move or not. This is what our network looks like so far</p>
<p><strong>Create the network in neuroph: Network -&gt; Multi layer Perceptron</strong></p>
<p><a href="http://www.certpal.com/blogs/wp-content/uploads/neuroph_traffic_create.png"><img class="aligncenter size-full wp-image-652" title="neuroph_traffic_create" src="http://www.certpal.com/blogs/wp-content/uploads/neuroph_traffic_create.png" alt="" width="422" height="165" /></a></p>
<p><strong>Basic network with no training: View -&gt; Graph<br />
</strong></p>
<p style="text-align: center;">
<p style="text-align: center;"><a href="http://www.certpal.com/blogs/wp-content/uploads/traffic_graph_no_train.png"><img class="aligncenter size-full wp-image-651" style="border: 1px dashed blue;" title="traffic_graph_no_train" src="http://www.certpal.com/blogs/wp-content/uploads/traffic_graph_no_train.png" alt="" width="286" height="204" /></a></p>
<p>Now we need to train the network so that the output will be as expected when the signals change. The rules are pretty simple and are shown below.To train the network we create a training set</p>
<p><strong>Neuroph training set:</strong></p>
<p><a href="http://www.certpal.com/blogs/wp-content/uploads/neuroph_traffic_train.png"><img class="aligncenter size-full wp-image-653" title="neuroph_traffic_train" src="http://www.certpal.com/blogs/wp-content/uploads/neuroph_traffic_train.png" alt="" width="301" height="204" /></a></p>
<p><strong>Train the network to respond to the inputs:</strong></p>
<p><a href="http://www.certpal.com/blogs/wp-content/uploads/neuroph_traffic_train_2.png"><img class="aligncenter size-full wp-image-654" title="neuroph_traffic_train_2" src="http://www.certpal.com/blogs/wp-content/uploads/neuroph_traffic_train_2.png" alt="" width="513" height="519" /></a></p>
<p>After the training rules have been laid out, it is time to train this network. Simply press on the Train button and select the appropriate training set to use.</p>
<p><strong>Set the parameters by which the network should learn:</strong></p>
<p><a href="http://www.certpal.com/blogs/wp-content/uploads/neuroph_traffic_train_3.png"><img class="aligncenter size-full wp-image-655" title="neuroph_traffic_train_3" src="http://www.certpal.com/blogs/wp-content/uploads/neuroph_traffic_train_3.png" alt="" width="323" height="243" /></a></p>
<p><strong>The trained network:</strong></p>
<p><a href="http://www.certpal.com/blogs/wp-content/uploads/neuroph_traffic_train_4.png"><img class="aligncenter size-full wp-image-656" title="neuroph_traffic_train_4" src="http://www.certpal.com/blogs/wp-content/uploads/neuroph_traffic_train_4.png" alt="" width="543" height="463" /></a></p>
<p>Now that we have our network trained, lets try giving it an input. An input of 0 0 1 means the signal is green and the vehicles can go through. The output produced in this case is shown below. The output will vary based on the function used in the training set / error rate and other factors. But what is to be highlighted here is that the output is nearing 1 when the signal is green. Our network works as expected.</p>
<p><strong>Signal is green and output is 1 (well almost <img src='http://www.certpal.com/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ):</strong></p>
<p style="text-align: center;"><a href="http://www.certpal.com/blogs/wp-content/uploads/neuroph_traffic_train_4.png"></a><a href="http://www.certpal.com/blogs/wp-content/uploads/neuroph_traffic_train_5.png"><img class="aligncenter size-full wp-image-657" style="border: 1px dashed blue;" title="neuroph_traffic_train_5" src="http://www.certpal.com/blogs/wp-content/uploads/neuroph_traffic_train_5.png" alt="" width="318" height="220" /></a></p>
<p>We can confirm how this decision was taken by the network by highlighting the weights. Additionally by representing the size of each node with respect to the activation contributed for that node, we can visualize how the input message propagates</p>
<p><strong>Weight / Activation  highlighting:</strong></p>
<p style="text-align: center;"><a href="http://www.certpal.com/blogs/wp-content/uploads/neuroph_traffic_train_6.png"><img class="aligncenter size-full wp-image-660" style="border: 1px dashed blue;" title="neuroph_traffic_train_6" src="http://www.certpal.com/blogs/wp-content/uploads/neuroph_traffic_train_6.png" alt="" width="309" height="222" /></a></p>
<p>So now that we have a neural network up and running, how do we actually use this inside java code ? Its pretty simple. Save the project as a .nnet file. Lets call this neural_traffic.nnet. To load the nnet file into your java project, simple use the classes provided by Neuroph like so</p>
<p><strong>Loading a neural network into java:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TestTrafficNeural
<span style="color: #009900;">&#123;</span>
    NeuralNetwork network <span style="color: #339933;">=</span> NeuralNetwork.<span style="color: #006633;">load</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;neural_traffic.nnet&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">new</span> TestTrafficNeural<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">go</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> go<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        calculate<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        calculate<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        calculate<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> calculate<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">double</span>... <span style="color: #006633;">input</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        network.<span style="color: #006633;">setInput</span><span style="color: #009900;">&#40;</span>input<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        network.<span style="color: #006633;">calculate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">Vector</span> output <span style="color: #339933;">=</span> network.<span style="color: #006633;">getOutput</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">Double</span> answer <span style="color: #339933;">=</span> output.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>answer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The code produces the following output</p>
<p>-1.6360230873976706E-6<br />
-4.140786100885251E-6<br />
0.9684448970000741</p>
<p>You can also define and train the network on the fly with code. But you would not want to do this for cases where large sets of inputs and nodes are involved. For simple problems the time taken to train a network is usually a few seconds. For large images ( Assuming you are trying to recognize images with Neuroph ) it can take a couple of hours.</p>
<p>This example is pretty easy to do and is certainly not a practical use case for real world problems. However I hope it gets you excited about using neural networks in your programs. With Neuroph doing this is pretty simple.<br />
<script type="text/javascript">var dzone_url = 'http://www.certpal.com/blogs/2010/04/java-neural-networks-and-neuroph-a-tutorial/';</script><br />
<script type="text/javascript">var dzone_title = 'Java neural networks and Neuroph - A tutorial';</script><br />
<script type="text/javascript">var dzone_blurb = 'Getting started with java neural networks is easy with Neuroph. The visual GUI and the java interface provide a mechanism for beginners to play around with the API.';</script><br />
<script type="text/javascript">var dzone_style = '2';</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script> </p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F04%2Fjava-neural-networks-and-neuroph-a-tutorial%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F04%2Fjava-neural-networks-and-neuroph-a-tutorial%2F" height="61" width="51" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2010/04/java-neural-networks-and-neuroph-a-tutorial/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>What is an AtomServer ?</title>
		<link>http://www.certpal.com/blogs/2010/04/what-is-an-atomserver/</link>
		<comments>http://www.certpal.com/blogs/2010/04/what-is-an-atomserver/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 15:25:43 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[atom]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=642</guid>
		<description><![CDATA[An introduction to the atom server and its possible use cases. The ATOM publishing protocol can be used to interact with feed entries. The ATOM server works with the ATOM Publishing protocol and stores the entries into its DB.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F04%2Fwhat-is-an-atomserver%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F04%2Fwhat-is-an-atomserver%2F" height="61" width="51" /></a></div><p>I had the opportunity to work with the ATOM protocol in detail recently. One of the products related to ATOM that I stumbled across is the <a href="http://atomserver.codehaus.org/" target="_blank">AtomServer.</a> If you dont already know it, ATOM is accompanied by a publishing protocol. Its called ATOMPub in short. Unlike RSS this protocol allows you to perform CRUD operations on the entries that you define under a feed.</p>
<p>What does that mean ? For example, you could have an entry in a feed which you wish to edit. You can edit / remove this entry using PUT / DELETE HTTP requests to an appropriate URL hosted by a server. So this protocol allows a user to interact with the feed (among other things. The ATOM XML format can be extended).</p>
<p>So what does the ATOMServer do and where does it fit in here ? The ATOMServer provides a RESTful interface and a RDBMS that stores the entries that the user interacts with. A user may wish to store 10 entries in a feed and then later retrieve and edit them as needed. To do this in an ATOM server the following operations would be invoked</p>
<ol>
<li> 10 PUT / POST requests to store the entries</li>
<li>A GET operation to retrieve the entry.</li>
<li>A few PUT requests to edit existing entries</li>
</ol>
<p>You can go through the <a href="http://atomserver.codehaus.org/docs/protocol_basics.html#insert-post" target="_blank">protocol basics</a> . The Google <a href="http://code.google.com/apis/gdata/" target="_blank">GData API</a> uses ATOMPub as the protocol to talk to various services such as Blogger / Google spreadsheet / Youtube etc etc. Whether they use an ATOMServer like product behind the scenes is debatable. The ATOMServer is by itself made up of pluggable components. You could easily replace the RDBMS store with a custom store of your own for example.</p>
<p>So where is an ATOMServer useful ? If you have existing services that need to be Atom enabled, the ATOMServer can provide the framework necessary to accomplish that. The ATOMServer can act as a layer that serves feed readers. The results for a feed can initially be fetched from an external source, such as an existing API or a file.</p>
<p>A search query that needs to refresh a feed every 30 minutes for example can be integrated with an ATOMServer. On the first call the search results would be fetched and stored into the ATOMServer DB. All subsequent feed reader calls to the ATOMServer for the next 30 minutes can be configured to get the cached data from the DB instead of the search query (A little coding into the ATOMServer framework would be required ). It is a simple use case and I am sure many more exist.</p>
<p>Another way to integrate ATOM into your APIs / services is to use <a href="http://abdera.apache.org/" target="_blank">Apache Abdera</a>. Abdera provides APIs that can generate ATOM XMLs. The ATOMServer is by itself built on top of Abdera. So if you need more flexibility you can go ahead and use Abdera directly.</p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F04%2Fwhat-is-an-atomserver%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F04%2Fwhat-is-an-atomserver%2F" height="61" width="51" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2010/04/what-is-an-atomserver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bugs &#8211; The most common kind</title>
		<link>http://www.certpal.com/blogs/2010/03/bugs-the-most-common-kind/</link>
		<comments>http://www.certpal.com/blogs/2010/03/bugs-the-most-common-kind/#comments</comments>
		<pubDate>Sat, 27 Mar 2010 04:02:18 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=627</guid>
		<description><![CDATA[Bugs are introduced into code inevitably. Most bugs are introduced due to minor errors made in logic or errors introduced when code is copied and pasted into a location. This highlights the need for tools like FindBugs]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F03%2Fbugs-the-most-common-kind%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F03%2Fbugs-the-most-common-kind%2F" height="61" width="51" /></a></div><p style="text-align: center;"><a href="http://www.certpal.com/blogs/wp-content/uploads/bug.png"><img class="aligncenter size-full wp-image-637" style="border: 1px dashed #4665FF;" title="bug" src="http://www.certpal.com/blogs/wp-content/uploads/bug.png" alt="" width="213" height="176" /></a></p>
<p style="text-align: center;">
<p style="text-align: left;">I was testing an application today and came across a bug. A screen had some CRUD operations on a resource. The problem was, whatever I did, the system would perform the operation and tell me that the resource already existed. This left me scratching my head for quite a while. I add a resource and it says it already exists and then adds it. Delete and update also do the same.</p>
<p>So the debugging process started and I sat down with eclipse to get to the root of the problem. I verified that indeed the CRUD operations were reflecting in the persistence store. Then I came across these magical lines of code</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> S_SOMETHING_EXISTS <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;something.already.exists&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> S_SOMETHING_ADD_SUCCESS <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;something.already.exists&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> S_SOMETHING_DELETE_FAIL <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;something.already.exists&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> S_SOMETHING_DELETE_SUCCESS <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;something.already.exists&quot;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This left me smacking my head. It should have been</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> S_SOMETHING_EXISTS <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;something.already.exists&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> S_SOMETHING_ADD_SUCCESS <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;something.add.success&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> S_SOMETHING_DELETE_FAIL <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;something.delete.failed&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> S_SOMETHING_DELETE_SUCCESS <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;something.delete.success&quot;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The bug was introduced when I copied the first constant and pasted it three times. I forgot to change the keys <img src='http://www.certpal.com/blogs/wp-includes/images/smilies/icon_mrgreen.gif' alt=':mrgreen:' class='wp-smiley' /> . My point is, most of the bugs that I see introduced into the system are due to silly mistakes like the one above. This is where tools like FindBugs (which can be extended with your own rules) and CheckStyle and other bug finder / code review tools come in handy. A human code review is also a great tool. This little bug served as a reminder as to why we have such tools. To a developer this bug might seem small, but wait till an end user sees the message and says &#8216;What gives !&#8217;.</p>
<p><script type="text/javascript">// <![CDATA[
var dzone_url = 'http://www.certpal.com/blogs/2010/03/bugs-the-most-common-kind/';
// ]]&gt;</script><br />
<script type="text/javascript">// <![CDATA[
var dzone_title = 'Bugs - The most common kind';
// ]]&gt;</script><br />
<script type="text/javascript">// <![CDATA[
var dzone_blurb = 'Bugs are introduced into code inevitably. Most bugs are introduced due to minor errors made in logic or errors introduced when code is copied and pasted into a location. This highlights the need for tools like FindBugs';
// ]]&gt;</script><br />
<script type="text/javascript">// <![CDATA[
var dzone_style = '2';
// ]]&gt;</script><br />
<script src="http://widgets.dzone.com/links/widgets/zoneit.js"></script></p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F03%2Fbugs-the-most-common-kind%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F03%2Fbugs-the-most-common-kind%2F" height="61" width="51" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2010/03/bugs-the-most-common-kind/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Application support for java developers in linux</title>
		<link>http://www.certpal.com/blogs/2010/03/application-support-for-java-developers-in-linux/</link>
		<comments>http://www.certpal.com/blogs/2010/03/application-support-for-java-developers-in-linux/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 04:28:06 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=618</guid>
		<description><![CDATA[Linux, for java developers, can support a wide range of tools / applications. Developers and users alike can be just as productive at what they did in windows. Here are a list of applications used in windows and their alternative / support in linux, just in case you are wondering if making the switch is smooth and easy.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F03%2Fapplication-support-for-java-developers-in-linux%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F03%2Fapplication-support-for-java-developers-in-linux%2F" height="61" width="51" /></a></div><p>One of the things I hear often from someone wanting to try linux and leave windows is that they are afraid that they will no longer be able perform some of the things they used to do. That is so wrong. Be it from the perspective of a developer or a casual user linux offers a wide range of apps to suit your needs. Here is a table of things I used to do in windows that I can still do in linux</p>
<table border="1" cellspacing="0" cellpadding="4" width="100%" bordercolor="#000000">
<col width="85*"></col>
<col width="85*"></col>
<col width="85*"></col>
<thead>
<tr valign="TOP">
<th width="33%">Application</th>
<th width="33%">Windows</th>
<th width="33%">Suse Linux &#8211; KDE desktop</th>
</tr>
</thead>
<tbody>
<tr valign="TOP">
<td width="33%"><strong>Chat</strong></td>
<td width="33%">Gtalk, Skype</td>
<td width="33%">Kopete / pidgin for gtalk</p>
<p>Skype is supported</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Development</strong></td>
<td width="33%">Eclipse / myeclipse / Netbeans</td>
<td width="33%">All of them have linux flavours</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Screenshot</strong></td>
<td width="33%">Gadwin printscreen</td>
<td width="33%">Ksnapshot</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Browsing</strong></td>
<td width="33%">Chrome / Firefox / Opera</td>
<td width="33%">They are all supported. Chrome support is getting better</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>SQL Client</strong></td>
<td width="33%">Squirrel SQL</td>
<td width="33%">Supported. Java runs anywhere <img src='http://www.certpal.com/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Application server</strong></td>
<td width="33%">Tomcat / Glassfish</td>
<td width="33%">Supported</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Web server</strong></td>
<td width="33%">Apache</td>
<td width="33%">Supported</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Video player</strong></td>
<td width="33%">DivX , VLC</td>
<td width="33%">VLC is supported</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Package management</strong></td>
<td width="33%">None</td>
<td width="33%">Yast,yum, apt etc etc</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Firewall</strong></td>
<td width="33%">Inbuilt / Zone alarm</td>
<td width="33%">IP Tables. Much more flexible</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Database</strong></td>
<td width="33%">Postgres</td>
<td width="33%">Supported</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Desktop customization</strong></td>
<td width="33%">Not bad</td>
<td width="33%">Amazing. You can add widgets, multiple panels etc etc</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Multiple desktop support</strong></td>
<td width="33%">No</td>
<td width="33%">Yes</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Dual screen / Nvidia drivers</strong></td>
<td width="33%">Yes</td>
<td width="33%">Yes</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Remote desktop</strong></td>
<td width="33%">Windows / VNC</td>
<td width="33%">Supported</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Windows applications</strong></td>
<td width="33%">Yes (Duh)</td>
<td width="33%">Simulate with WINE</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Office</strong></td>
<td width="33%">Windows office</td>
<td width="33%">Open office. Not great but ok. You can use an online office suite if needed.</td>
</tr>
</tbody>
</table>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">
<p><!-- 		@page { margin: 0.79in } 		TD P { margin-bottom: 0in } 		TH P { margin-bottom: 0in } 		P { margin-bottom: 0.08in } --></p>
<table border="1" cellspacing="0" cellpadding="4" width="100%" bordercolor="#000000">
<col width="85*"></col>
<col width="85*"></col>
<col width="85*"></col>
<thead>
<tr valign="TOP">
<th width="33%">Application</th>
<th width="33%">Windows</th>
<th width="33%">Linux</th>
</tr>
</thead>
<tbody>
<tr valign="TOP">
<td width="33%"><strong>Chat</strong></td>
<td width="33%">Gtalk, Skype</td>
<td width="33%">Kopete / pidgin for gtalk</p>
<p>Skype is supported</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Development</strong></td>
<td width="33%">Eclipse / myeclipse / Netbeans</td>
<td width="33%">All of them have linux flavours</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Screenshot</strong></td>
<td width="33%">Gadwin printscreen</td>
<td width="33%">Ksnapshot</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Browsing</strong></td>
<td width="33%">Chrome / Firefox / Opera</td>
<td width="33%">They are all supported. Chrome support is getting better</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>SQL Client</strong></td>
<td width="33%">Squirrel SQL</td>
<td width="33%">Supported. Java runs anywhere <img src='http://www.certpal.com/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Application server</strong></td>
<td width="33%">Tomcat / Glassfish</td>
<td width="33%">Supported</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Web server</strong></td>
<td width="33%">Apache</td>
<td width="33%">Supported</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Video player</strong></td>
<td width="33%">DivX , VLC</td>
<td width="33%">VLC is supported</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Package management</strong></td>
<td width="33%">None</td>
<td width="33%">Yast,yum, apt etc etc</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Firewall</strong></td>
<td width="33%">Inbuilt / Zone alarm</td>
<td width="33%">IP Tables. Much more flexible</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Database</strong></td>
<td width="33%">Postgres</td>
<td width="33%">Supported</td>
</tr>
<tr valign="TOP">
<td width="33%"><strong>Desktop customization</strong></td>
<td width="33%">Not bad</td>
<td width="33%">Amazing. You can add widgets, multiple panels etc etc</td>
</tr>
</tbody>
</table>
</div>
<p>The list above is just a sample of the applications I use. I am sure there are more use cases.</p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F03%2Fapplication-support-for-java-developers-in-linux%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F03%2Fapplication-support-for-java-developers-in-linux%2F" height="61" width="51" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2010/03/application-support-for-java-developers-in-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to open multiple SSH tunnels</title>
		<link>http://www.certpal.com/blogs/2010/03/howto-ssh-tunnel-multiple/</link>
		<comments>http://www.certpal.com/blogs/2010/03/howto-ssh-tunnel-multiple/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 08:07:52 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[tunnel]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=602</guid>
		<description><![CDATA[OpenSSH can be used to open multiple tunnels to remote services via SSH. Local ports can be opened up and the information communicated with these ports can be relayed to a remote machine. This tutorial explains how to open many ssh tunnels]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F03%2Fhowto-ssh-tunnel-multiple%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F03%2Fhowto-ssh-tunnel-multiple%2F" height="61" width="51" /></a></div><p style="text-align: center;"><a href="http://www.certpal.com/blogs/wp-content/uploads/tunnel.png"><img class="aligncenter size-full wp-image-603" style="border: 1px dashed black;" title="tunnel" src="http://www.certpal.com/blogs/wp-content/uploads/tunnel.png" alt="" width="282" height="170" /></a></p>
<p style="text-align: left;">
<p style="text-align: left;">I use remote linux services often and exposing them as local services can be performed securely using SSH. For example you can access a tomcat server or email server hosted at IP 1.2.3.4 by opening a secure SSH tunnel between your local machine and the target address &#8211; 1.2.3.4.</p>
<p>The <a href="http://www.openssh.com/" target="_blank">OpenSSH tool</a> can be used to perform SSH related activities on your machine. Simply install it with yum, apt-get or Yast, if it is not already available. Once you have it use the following command to open multiple SSH tunnels to your services</p>
<p><strong>Open tunnel and execute commands:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh</span> 1.2.3.4 <span style="color: #660033;">-lmyUser</span> <span style="color: #660033;">-L</span> <span style="color: #000000;">3098</span>:1.2.3.4:<span style="color: #000000;">21</span> <span style="color: #660033;">-L</span> <span style="color: #000000;">3099</span>:1.2.3.4:<span style="color: #000000;">80</span> <span style="color: #660033;">-L</span> <span style="color: #000000;">3100</span>:1.2.3.4:<span style="color: #000000;">443</span></pre></td></tr></table></div>

<p>The command is explained below</p>
<p><strong>1.2.3.4</strong> &#8211; Your target IP</p>
<p><strong>l</strong> &#8211; The user to login as</p>
<p><strong>L</strong> &#8211; A local tunnel to a remote port</p>
<p><strong>3098</strong> &#8211; The local port to use when establishing this tunnel</p>
<p><strong>21</strong> &#8211; The remote port at 1.2.3.4 to which the tunnel will be established</p>
<p>Multiple tunnels can be opened by specifying multiple -L flags. For example http://localhost:3099 will now redirect to http://1.2.3.4:80/ That is a fancy way of saying all HTTP requests ( 80 is the default port ) for 1.2.3.4 can now be reached locally at port 3099.</p>
<p>Note that the above command will also log you into the remote system. If you want to open the tunnels alone, use the -N switch and the -f switch as shown below</p>
<p><strong>Open tunnels only:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-f</span> myUser<span style="color: #000000; font-weight: bold;">@</span>1.2.3.4 <span style="color: #660033;">-L</span> <span style="color: #000000;">3099</span>:1.2.3.4:<span style="color: #000000;">25</span> <span style="color: #660033;">-N</span></pre></td></tr></table></div>

<p>The -f switch asks SSH to work in the background and -N asks SSH not to execute any commands.</p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F03%2Fhowto-ssh-tunnel-multiple%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F03%2Fhowto-ssh-tunnel-multiple%2F" height="61" width="51" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2010/03/howto-ssh-tunnel-multiple/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
