<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>ViralPatel.net</title>
	
	<link>http://viralpatel.net/blogs</link>
	<description>Tutorials, Java, J2EE, Struts, AJAX, JavaScript, CSS, Web 2.0, MySQL, Articles</description>
	<lastBuildDate>Wed, 10 Mar 2010 12:02:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/viralpatelnet" /><feedburner:info uri="viralpatelnet" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>viralpatelnet</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Understanding jQuery animate() function</title>
		<link>http://feedproxy.google.com/~r/viralpatelnet/~3/kfrWQMtveXA/understanding-jquery-animate-function.html</link>
		<comments>http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html#comments</comments>
		<pubDate>Tue, 09 Mar 2010 13:08:15 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[jQuery Effects]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2045</guid>
		<description><![CDATA[jQuery animate() function is very powerful API to manipulate html elements and add animation functionality. The use of animate function is very simple. First lets check the syntax of this function.
.animate( properties, [ duration ], [ easing ], [ callback ] )

properties: A map of CSS properties that the animation will move toward.
duration: A string [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.viralpatel.net/jquery-logo.png" alt="" title="jquery-logo" width="236" height="85" class="alignright size-full wp-image-1108" />jQuery animate() function is very powerful API to manipulate html elements and add animation functionality. The use of animate function is very simple. First lets check the syntax of this function.</p>
<p><strong>.animate( properties, [ duration ], [ easing ], [ callback ] )</strong></p>
<ul>
<li>properties: A map of CSS properties that the animation will move toward.</li>
<li>duration: A string or number determining how long the animation will run.</li>
<li>easing: A string indicating which easing function to use for the transition.</li>
<li>callback: A function to call once the animation is complete.</li>
</ul>
<p><strong>.animate( properties, options )</strong></p>
<ul>
<li>properties: A map of CSS properties that the animation will move toward.</li>
<li>options: A map of additional options to pass to the method. Supported keys:
<ul>
<li>duration: A string or number determining how long the animation will run.</li>
<li>easing: A string indicating which easing function to use for the transition.</li>
<li>complete: A function to call once the animation is complete.</li>
<li>step: A function to be called after each step of the animation.</li>
<li>queue: A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately.</li>
<li>specialEasing: A map of one or more of the CSS properties defined by the properties argument and their corresponding easing functions (added 1.4).</li>
</ul>
</li>
</ul>
<p>Lets learn the animate() function with set of examples.</p>
<p>First include the jQuery javascript library in your html file. Add following in your html &lt;HEAD&gt; tag:</p>
<pre class="brush: xml;">
&lt;SCRIPT type=&quot;text/javascript&quot;
		src=&quot;http://code.jquery.com/jquery-latest.js&quot;&gt;&lt;/SCRIPT&gt;
</pre>
<p>For all the demos, we will use a sample DIV tag for animating. Following is the div code and its stylesheet.</p>
<pre class="brush: xml;">
&lt;style type=&quot;text/css&quot;&gt;
#content {
	background-color:#ffaa00;
	width:300px;
	height:30px;
	padding:3px;
}
&lt;/style&gt;
&lt;input type=&quot;button&quot; id=&quot;animate&quot; value=&quot;Animate&quot;/&gt;
&lt;div id=&quot;content&quot;&gt;Animate Height&lt;/div&gt;
</pre>
<h2>Animate height/width</h2>
<p>Animating height and width in jQuery is very easy. Lets assume you have a DIV that you want to animate i.e. increase the height.</p>
<pre class="brush: jscript;">
$(&quot;#animate&quot;).click(function() {
	$(&quot;#content&quot;).animate(
			{&quot;height&quot;: &quot;80px&quot;},
			&quot;fast&quot;);
});
</pre>
<p><strong>Demo 1:</strong><br />
<iframe src="http://viralpatel.net/blogs/demo/jquery/animate-demo/animate-height.html" width="100%" height="150px" frameborder="0"></iframe></p>
<p>Also following will be the code to animate Width of the element.</p>
<pre class="brush: jscript;">
$(&quot;#animate&quot;).click(function() {
	$(&quot;#content&quot;).animate(
			{&quot;width&quot;: &quot;350px&quot;},
			&quot;fast&quot;);
});
</pre>
<p><strong>Demo 2:</strong><br />
<iframe src="http://viralpatel.net/blogs/demo/jquery/animate-demo/animate-width.html" width="100%" height="120px" frameborder="0"></iframe></p>
<h2>Animate opacity</h2>
<pre class="brush: jscript;">
$(&quot;#animate&quot;).click(function() {
	$(&quot;#content&quot;).animate(
			{&quot;opacity&quot;: &quot;0.15&quot;},
			&quot;slow&quot;);
});
</pre>
<p><strong>Demo 3:</strong><br />
<iframe src="http://viralpatel.net/blogs/demo/jquery/animate-demo/animate-opacity.html" width="100%" height="120px" frameborder="0"></iframe></p>
<h2>Moving elements using animate()</h2>
<pre class="brush: xml;">
&lt;STYLE&gt;
#content {
	background-color:#6688ff;
	position:absolute;
	width:100px;
	height:100px;
	padding:3px;
	margin-top:5px;
	left: 100px;
}
&lt;/STYLE&gt;
&lt;input type=&quot;button&quot; id=&quot;left&quot; value=&quot;Left&quot;/&gt;
&lt;input type=&quot;button&quot; id=&quot;right&quot; value=&quot;Right&quot;/&gt;
&lt;div id=&quot;content&quot;&gt;Move&lt;/div&gt;
</pre>
<pre class="brush: jscript;">
$(&quot;#right&quot;).click(function() {
	$(&quot;#content&quot;).animate(
			{&quot;left&quot;: &quot;+=50px&quot;},
			&quot;slow&quot;);
});
$(&quot;#left&quot;).click(function() {
	$(&quot;#content&quot;).animate(
			{&quot;left&quot;: &quot;-=50px&quot;},
			&quot;slow&quot;);
});
</pre>
<p><strong>Demo 4:</strong><br />
<iframe src="http://viralpatel.net/blogs/demo/jquery/animate-demo/animate-move.html" width="100%" height="150px" frameborder="0"></iframe></p>
<h2>Callback Function</h2>
<p>Callback functions are very useful to perform certain activity when the animation is completed. Also note here when multiple elements are mapped with the animation and we have specified a callback function. Then the callback will get called for each of the element.</p>
<p>Let us see an example where we use callback function to display a message when animation is completed. </p>
<pre class="brush: jscript;">
$(&quot;#animate&quot;).click(function() {
	$(&quot;#content&quot;).animate(
			{&quot;height&quot;: &quot;100px&quot;, &quot;width&quot;: &quot;250px&quot;},
			&quot;slow&quot;, function(){
				$(this).html(&quot;Animation Completed&quot;);
			});
});</pre>
<p><strong>Demo 5:</strong><br />
<iframe src="http://viralpatel.net/blogs/demo/jquery/animate-demo/animate-callback.html" width="100%" height="150px" frameborder="0"></iframe></p>
<h2>Combine multiple animations</h2>
<p>You may want to combine multiple animations. Following are few demos will help you understanding this.</p>
<p><strong>Example 1</strong>: Animate both height and width at same time.<br />
This example is pretty straight forward. You can animate both height and width at same time by specifying it in animate function. For example: In below code we specified height and width value in animate function.</p>
<pre class="brush: jscript;">
$(&quot;#animate&quot;).click(function() {
	$(&quot;#content&quot;).animate(
			{&quot;height&quot;: &quot;100px&quot;, &quot;width&quot;: &quot;250px&quot;},
			&quot;slow&quot;, );
});</pre>
<p><strong>Example 2</strong>: Queuing the animations.</p>
<pre class="brush: jscript;">
$(&quot;#animate&quot;).click(function() {
	$(&quot;#content&quot;)
		.animate({&quot;height&quot;: &quot;100px&quot;}, 500)
		.animate({&quot;width&quot;: &quot;250px&quot;}, 500);
});
</pre>
<p><strong>Demo 6:</strong><br />
<iframe src="http://viralpatel.net/blogs/demo/jquery/animate-demo/animate-queue.html" width="100%" height="150px" frameborder="0"></iframe></p>
<h2>Queuing of Events</h2>
<p>In above demo (Demo 6) we saw that when we queued up the events with multiple .animate() method call, the animation is actually queued up. i.e. it completes the first animation and then proceed with next. Let see an example were we use <code>queue</code> parameter to disable queuing. In following example we have set parameter <code>queue</code> to <code>false</code>. The code is exactly same as demo 6, only change we added is queue = false. Also note that queue parameter is added with second argument.</p>
<pre class="brush: jscript;">
$(&quot;#animate&quot;).click(function() {
	$(&quot;#content&quot;)
		.animate({&quot;height&quot;: &quot;100px&quot;}, {&quot;queue&quot;: false, &quot;duration&quot;: 500})
		.animate({&quot;width&quot;: &quot;250px&quot;}, 500);
});
</pre>
<p><strong>Demo 7:</strong><br />
<iframe src="http://viralpatel.net/blogs/demo/jquery/animate-demo/animate-queue-false.html" width="100%" height="150px" frameborder="0"></iframe></p>
<div id="relatedpost" style="background-color:#FFF1A8; padding:3px;"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2009/10/jquery-bounce-effect-bounce-html-js.html" title="Fantastic Bouncy Effect using jQuery/JavaScript">Fantastic Bouncy Effect using jQuery/JavaScript</a></li><li><a href="http://viralpatel.net/blogs/2009/09/create-accordion-menu-jquery.html" title="Create Simplest Accordion Menu using jQuery">Create Simplest Accordion Menu using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2009/08/20-top-jquery-tips-tricks-for-jquery-programmers.html" title="20 Top jQuery tips &#038; tricks for jQuery programmers">20 Top jQuery tips &#038; tricks for jQuery programmers</a></li><li><a href="http://viralpatel.net/blogs/2009/07/delete-row-html-table-clicking-using-jquery.html" title="Delete Row from HTML Table by clicking it using jQuery">Delete Row from HTML Table by clicking it using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2009/03/how-to-apply-html-user-interface-effects-using-jquery.html" title="How to apply HTML User Interface Effects using jQuery.">How to apply HTML User Interface Effects using jQuery.</a></li><li><a href="http://viralpatel.net/blogs/2010/01/jquery-resizable-draggable-resize-drag-tutorial-example.html" title="jQuery Resizable and Draggable Tutorial with Example">jQuery Resizable and Draggable Tutorial with Example</a></li><li><a href="http://viralpatel.net/blogs/2009/12/jquery-live-events.html" title="jQuery Live Event">jQuery Live Event</a></li><li><a href="http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html" title="Changing Form Input (Textbox) Style on Focus using jQuery">Changing Form Input (Textbox) Style on Focus using jQuery</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html&amp;title=Understanding jQuery animate() function&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html&amp;title=Understanding jQuery animate() function" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html&amp;title=Understanding jQuery animate() function" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html&amp;title=Understanding jQuery animate() function" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>
<p><a href="http://feedads.g.doubleclick.net/~a/X_jxdv11L91Bk7yVUf4Duwb7zoo/0/da"><img src="http://feedads.g.doubleclick.net/~a/X_jxdv11L91Bk7yVUf4Duwb7zoo/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/X_jxdv11L91Bk7yVUf4Duwb7zoo/1/da"><img src="http://feedads.g.doubleclick.net/~a/X_jxdv11L91Bk7yVUf4Duwb7zoo/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=kfrWQMtveXA:-LElDkxDCCk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=kfrWQMtveXA:-LElDkxDCCk:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=kfrWQMtveXA:-LElDkxDCCk:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=kfrWQMtveXA:-LElDkxDCCk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=kfrWQMtveXA:-LElDkxDCCk:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=kfrWQMtveXA:-LElDkxDCCk:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=kfrWQMtveXA:-LElDkxDCCk:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=kfrWQMtveXA:-LElDkxDCCk:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=kfrWQMtveXA:-LElDkxDCCk:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html</feedburner:origLink></item>
		<item>
		<title>Eclipse Tip: Hide Closed Projects in Eclipse Project Explorer View</title>
		<link>http://feedproxy.google.com/~r/viralpatelnet/~3/H3gWX4sLyK8/hide-closed-projects-eclipse-project-explorer-view.html</link>
		<comments>http://viralpatel.net/blogs/2010/02/hide-closed-projects-eclipse-project-explorer-view.html#comments</comments>
		<pubDate>Fri, 19 Feb 2010 15:33:04 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[eclipse feature]]></category>
		<category><![CDATA[eclipse tricks]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2038</guid>
		<description><![CDATA[Ever wanted to hide all those closed projects in eclipse? Well, here is a simple trick that you may not know already. 
Imagine your Eclipse workspace is filled with many projects that you created in past just to test some small functionality. Now you are done with these projects and hence you have closed it. [...]]]></description>
			<content:encoded><![CDATA[<p>Ever wanted to hide all those closed projects in eclipse? Well, here is a simple trick that you may not know already. </p>
<p>Imagine your Eclipse workspace is filled with many projects that you created in past just to test some small functionality. Now you are done with these projects and hence you have closed it. Eclipse by default show all the closed projects in Project Explorer. Hence your project explorer may look like following where only two projects are open and rest competing for your attention although they are closed!<br />
<img src="http://img.viralpatel.net/2010/02/eclipse-close-project.png" alt="eclipse-close-project" title="eclipse-close-project" width="261" height="183" class="size-full wp-image-2039" /></p>
<p>Eclipse comes with a cool tiny feature that many of us not know. You may want to Hide all those closed projects from your workspace in Project Explorer tab. Simply follow following steps and do this is few seconds!</p>
<p><strong>Step 1: Click on right corner of Project Explorer tab and open context menu. Select Filters option from menu.</strong></p>
<p><img src="http://img.viralpatel.net/2010/02/eclipse-project-explorer-filter.png" alt="eclipse-project-explorer-filter" title="eclipse-project-explorer-filter" width="458" height="295" class="size-full wp-image-2040" /></p>
<p><strong>Step 2: Check Closed Projects option from Filter and press Ok</strong></p>
<p><img src="http://img.viralpatel.net/2010/02/eclipse-filter-close.png" alt="eclipse-filter-close" title="eclipse-filter-close" width="320" height="469" class="size-full wp-image-2043" /></p>
<p>Now check your project explorer tab, all the closed projects are gone! Doesn&#8217;t it looks more clean :)</p>
<p><img src="http://img.viralpatel.net/2010/02/eclipse-project-explorer-close-hide.png" alt="" title="eclipse-project-explorer-close-hide" width="252" height="238" class="size-full wp-image-2041" /></p>
<p>We used Filters option to remove closed projects from Project Explorer tab. Filters provides more options to select and remove from displaying it from explorer view.  </p>
<div id="relatedpost" style="background-color:#FFF1A8; padding:3px;"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2009/07/20-very-useful-eclipse-ide-shortcuts-for-developers.html" title="20 very useful Eclipse IDE Shortcuts for Developers">20 very useful Eclipse IDE Shortcuts for Developers</a></li><li><a href="http://viralpatel.net/blogs/2009/05/inspect-your-code-in-eclipse-using-eclipse-scrapbook-feature.html" title="Inspect your code in Eclipse using Eclipse Scrapbook feature">Inspect your code in Eclipse using Eclipse Scrapbook feature</a></li><li><a href="http://viralpatel.net/blogs/2009/10/eclipse-workspace-in-use-or-cannot-be-created-error.html" title="Eclipse: Workspace in use or cannot be created Error">Eclipse: Workspace in use or cannot be created Error</a></li><li><a href="http://viralpatel.net/blogs/2009/10/setting-tomcat-heap-size-jvm-heap-eclipse.html" title="Setting Tomcat Heap Size (JVM Heap) in Eclipse">Setting Tomcat Heap Size (JVM Heap) in Eclipse</a></li><li><a href="http://viralpatel.net/blogs/2009/09/database-connection-pooling-tomcat-eclipse-db.html" title="Database Connection Pooling in Tomcat using Eclipse">Database Connection Pooling in Tomcat using Eclipse</a></li><li><a href="http://viralpatel.net/blogs/2009/04/google-android-adt-sdk-and-eclipse-ide-integration-on-linux.html" title="Google Android ADT, SDK and Eclipse IDE integration on Linux ">Google Android ADT, SDK and Eclipse IDE integration on Linux </a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/02/hide-closed-projects-eclipse-project-explorer-view.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/02/hide-closed-projects-eclipse-project-explorer-view.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/02/hide-closed-projects-eclipse-project-explorer-view.html&amp;title=Eclipse Tip: Hide Closed Projects in Eclipse Project Explorer View&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/02/hide-closed-projects-eclipse-project-explorer-view.html&amp;title=Eclipse Tip: Hide Closed Projects in Eclipse Project Explorer View" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/02/hide-closed-projects-eclipse-project-explorer-view.html&amp;title=Eclipse Tip: Hide Closed Projects in Eclipse Project Explorer View" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/02/hide-closed-projects-eclipse-project-explorer-view.html&amp;title=Eclipse Tip: Hide Closed Projects in Eclipse Project Explorer View" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>
<p><a href="http://feedads.g.doubleclick.net/~a/SvQBC0oRcl6i-el3oD9rzvlTpYU/0/da"><img src="http://feedads.g.doubleclick.net/~a/SvQBC0oRcl6i-el3oD9rzvlTpYU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/SvQBC0oRcl6i-el3oD9rzvlTpYU/1/da"><img src="http://feedads.g.doubleclick.net/~a/SvQBC0oRcl6i-el3oD9rzvlTpYU/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=H3gWX4sLyK8:otabjZJQaPU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=H3gWX4sLyK8:otabjZJQaPU:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=H3gWX4sLyK8:otabjZJQaPU:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=H3gWX4sLyK8:otabjZJQaPU:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=H3gWX4sLyK8:otabjZJQaPU:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=H3gWX4sLyK8:otabjZJQaPU:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=H3gWX4sLyK8:otabjZJQaPU:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=H3gWX4sLyK8:otabjZJQaPU:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=H3gWX4sLyK8:otabjZJQaPU:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/02/hide-closed-projects-eclipse-project-explorer-view.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://viralpatel.net/blogs/2010/02/hide-closed-projects-eclipse-project-explorer-view.html</feedburner:origLink></item>
		<item>
		<title>Writing a URL Shortner in Java Struts2 &amp; Hibernate</title>
		<link>http://feedproxy.google.com/~r/viralpatelnet/~3/8pUHPRppV7s/create-url-shortner-in-java-struts2-hibernate.html</link>
		<comments>http://viralpatel.net/blogs/2010/02/create-url-shortner-in-java-struts2-hibernate.html#comments</comments>
		<pubDate>Wed, 17 Feb 2010 09:16:40 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[Struts 2]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Struts2]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2029</guid>
		<description><![CDATA[This is an attempt to create a simple URL shortner service in pure JEE with Struts2 and Hibernate. 

Creating Base Framework
I always have Basic framework ready which gives a kick start to the web app development. You don&#8217;t have to hassle about different configuration issues/jar file issues etc. Let us start with creating sample base [...]]]></description>
			<content:encoded><![CDATA[<p>This is an attempt to create a simple URL shortner service in pure JEE with Struts2 and Hibernate. </p>
<p><img src="http://img.viralpatel.net/2010/02/shorty-url-shortner-struts2-hibernate.png" alt="shorty-url-shortner-struts2-hibernate" title="shorty-url-shortner-struts2-hibernate" width="523" height="189" class="aligncenter size-full wp-image-2031" /></p>
<h2>Creating Base Framework</h2>
<p>I always have Basic framework ready which gives a kick start to the web app development. You don&#8217;t have to hassle about different configuration issues/jar file issues etc. Let us start with creating sample base framework for our project. We will use Struts2 and Hibernate for this implementation.<br />
First lets create a Dynamic web project in eclipse.<br />
<img alt="Dynamic web project" src="http://img.viralpatel.net/2008/12/eclipse-new-project-struts-example.png" title="Dynamic web project" class="aligncenter" width="369" height="365" /><br />
We will name our project <strong>Shorty</strong>.</p>
<p>Then, we will add all the required Jar files for our project. Following is the list of Jars that I have included in the <strong>WEB-INF/lib</strong> folder.<br />
<img src="http://img.viralpatel.net/2010/02/shorty-struts2-hibernate-jars.png" alt="shorty-struts2-hibernate-jars" title="shorty-struts2-hibernate-jars" width="232" height="375" class="aligncenter size-full wp-image-2033" /></p>
<p>You can download all of the above JARs from <a rel="nofollow" target="_blank" href="http://www.ibiblio.org/maven/">http://www.ibiblio.org/maven/</a></p>
<p>Now lets us change the web.xml file and add Struts filter. This will add Struts support in our base framework.<br />
Following will be the web.xml content.<br />
<strong>WEB-INF/web.xml</strong></p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;web-app id=&quot;WebApp_ID&quot; version=&quot;2.4&quot;
	xmlns=&quot;http://java.sun.com/xml/ns/j2ee&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd&quot;&gt;
	&lt;display-name&gt;Go&lt;/display-name&gt;
	&lt;welcome-file-list&gt;
		&lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
	&lt;/welcome-file-list&gt;
 	&lt;filter&gt;
		&lt;filter-name&gt;struts2&lt;/filter-name&gt;
		&lt;filter-class&gt;
			org.apache.struts2.dispatcher.FilterDispatcher
		&lt;/filter-class&gt;
	&lt;/filter&gt;
	&lt;filter-mapping&gt;
		&lt;filter-name&gt;struts2&lt;/filter-name&gt;
		&lt;url-pattern&gt;/*&lt;/url-pattern&gt;
	&lt;/filter-mapping&gt;

&lt;/web-app&gt;
</pre>
<p>Now create a source folder called <strong>resources</strong>. Right click on your project in Project explorer -> New -> Source Folder.</p>
<p>Create a file hibernate.cfg.xml in the resources folder. This will be the configuration file of Hibernate which contains database connection strings and other related data.</p>
<p><strong>resources/hibernate.cfg.xml</strong></p>
<pre class="brush: xml;">
&lt;?xml version='1.0' encoding='utf-8'?&gt;
&lt;!DOCTYPE hibernate-configuration PUBLIC
        &quot;-//Hibernate/Hibernate Configuration DTD 3.0//EN&quot;
        &quot;http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd&quot;&gt;

&lt;hibernate-configuration&gt;

	&lt;session-factory&gt;

		&lt;property name=&quot;connection.driver_class&quot;&gt;
			com.mysql.jdbc.Driver
		&lt;/property&gt;
		&lt;property name=&quot;connection.url&quot;&gt;
			jdbc:mysql://localhost:3306/shorty
		&lt;/property&gt;
		&lt;property name=&quot;connection.username&quot;&gt;username&lt;/property&gt;
		&lt;property name=&quot;connection.password&quot;&gt;password&lt;/property&gt;

		&lt;property name=&quot;connection.pool_size&quot;&gt;1&lt;/property&gt;
		&lt;property name=&quot;dialect&quot;&gt;
			org.hibernate.dialect.MySQLDialect
		&lt;/property&gt;
		&lt;property name=&quot;current_session_context_class&quot;&gt;thread&lt;/property&gt;
		&lt;property name=&quot;cache.provider_class&quot;&gt;
			org.hibernate.cache.NoCacheProvider
		&lt;/property&gt;
		&lt;property name=&quot;show_sql&quot;&gt;true&lt;/property&gt;
		&lt;property name=&quot;hbm2ddl.auto&quot;&gt;update&lt;/property&gt;

	&lt;/session-factory&gt;

&lt;/hibernate-configuration&gt;
</pre>
<p>Also lets create package structure for the source code in our base framework. We will create few packages in <strong>src</strong> folder.<br />
<img src="http://img.viralpatel.net/2010/02/url-shortner-base-framework-package.png" alt="url-shortner-base-framework-package" title="url-shortner-base-framework-package" width="203" height="84" class="aligncenter size-full wp-image-2035" /></p>
<p>Now we are ready with a basic framework that has Hibernate and Struts2 support. This can now be used to create any application using these two technologies.</p>
<p>Let us start with creating database design for our simplest URL shortner.</p>
<h2>Database Design for URL Shortner</h2>
<p>Our requirement is very simple. We will have a single table in database that holds the value for URLs and its shortcode. Following will be the DDL for LINKS table. Note that we will also track number of clicks on each URL. </p>
<pre class="brush: sql;">
CREATE TABLE LINKS
(
	id 		INT PRIMARY KEY AUTO_INCREMENT,
	shortcode 	VARCHAR(20),
	url 		VARCHAR(255),
	clicks		INT DEFAULT 0,
	created	TIMESTAMP DEFAULT NOW()
);
</pre>
<h2>Adding logic to create shortcode</h2>
<p>URL Shortner is all about creating short codes for a long url. The logic that we will use to create a short code is simple. We will add URL into database table with auto generating primary key. This primary key will be a unique number. Then we convert this number to a string representation of base48 with characters 0 to 9 a to z and A to Z. Following is the logic for this.</p>
<pre class="brush: java;">
	public static String base48Encode(Long no) {
		Double num = Double.valueOf(no);
		String charSet = &quot;23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ&quot;;
		Integer length = charSet.length();
		String encodeString = new String();
		while(num &gt; length) {
			encodeString = charSet.charAt(num.intValue() % length)+encodeString;
			 num = Math.ceil(new Double(num / length) - 1) ;
		}
		encodeString = charSet.charAt(num.intValue())+encodeString;

		return encodeString;
	}
</pre>
<p>In above method we have passed a long number (which will be auto generated primary key) and get string representation.</p>
<p>We will add this logic into a file ShortyUtil.java. Create ShortyUtil class under <em>net.viralpatel.shorty.util</em> package. </p>
<p><strong>net.viralpatel.shorty.util.ShortyUtil</strong></p>
<pre class="brush: java;">
package net.viralpatel.shorty.util;

public class ShortyUtil {
	public static String base48Encode(Long no) {
		Double num = Double.valueOf(no);
		String charSet = &quot;23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ&quot;;
		Integer length = charSet.length();
		String encodeString = new String();
		while(num &gt; length) {
			encodeString = charSet.charAt(num.intValue() % length)+encodeString;
			 num = Math.ceil(new Double(num / length) - 1) ;
		}
		encodeString = charSet.charAt(num.intValue())+encodeString;

		return encodeString;
	}

	public static String getShortCodeFromURL(String URL) {

		int index=0;
		for(index=URL.length()-1; index&gt;=0 &amp;&amp; URL.charAt(index)!= '/' ;index--);
		String shortCode = URL.substring(index+1);

		return shortCode;
	}
}
</pre>
<h2>Connecting to Database using Hibernate</h2>
<p>Adding Hibernate related code is easy. </p>
<p>First add <em>HibernateUtil</em> class in <em>net.viralpatel.shorty.util</em> that we will use to create SessionFactory object. </p>
<p><strong>net.viralpatel.shorty.util.HibernateUtil</strong></p>
<pre class="brush: java;">
package net.viralpatel.shorty.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtil {

	private static final SessionFactory sessionFactory = buildSessionFactory();

	private static SessionFactory buildSessionFactory() {
		try {
			// Create the SessionFactory from hibernate.cfg.xml
			return new AnnotationConfiguration().configure().buildSessionFactory();
		} catch (Throwable ex) {
			// Make sure you log the exception, as it might be swallowed
			System.err.println(&quot;Initial SessionFactory creation failed.&quot; + ex);
			throw new ExceptionInInitializerError(ex);
		}
	}

	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}

}
</pre>
<p>Now create an entity class that will map to LINKS table in database. Create Link.java class under <code>net.viralpatel.shorty.model</code> package.</p>
<p><strong>net.viralpatel.shorty.model.Link</strong></p>
<pre class="brush: java;">
package net.viralpatel.shorty.model;

import java.io.Serializable;
import java.sql.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name=&quot;LINKS&quot;)
public class Link implements Serializable{

	private static final long serialVersionUID = -8767337896773261247L;

	private Long id;
	private String shortCode;
	private String url;
	private Long clicks;
	private Date created;

	@Id
	@GeneratedValue
	@Column(name=&quot;id&quot;)
	public Long getId() {
		return id;
	}
	@Column(name = &quot;shortcode&quot;)
	public String getShortCode() {
		return shortCode;
	}
	@Column(name = &quot;created&quot;)
	public Date getCreated() {
		return created;
	}
	@Column(name = &quot;url&quot;)
	public String getUrl() {
		return url;
	}
	@Column(name = &quot;clicks&quot;)
	public Long getClicks() {
		return clicks;
	}
	public void setClicks(Long clicks) {
		this.clicks = clicks;
	}
	public void setShortCode(String shortCode) {
		this.shortCode = shortCode;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public void setCreated(Date created) {
		this.created = created;
	}
	public void setId(Long id) {
		this.id = id;
	}
}
</pre>
<p>Now add the mapping for above entity class Link.java in hibernate.cfg.xml file. Add following link in &gt;session-factory&lt; tag:</p>
<pre class="brush: java;">
&lt;mapping class=&quot;net.viralpatel.shorty.model.Link&quot; /&gt;
</pre>
<p>Also we will need a controller class that we invoke from Struts action class to do read/write in database. Create LinkController.java under net.viralpatel.shorty.controller package.</p>
<p><strong>net.viralpatel.shorty.controller.LinkController</strong></p>
<pre class="brush: java;">
package net.viralpatel.shorty.controller;

import org.hibernate.Query;
import org.hibernate.classic.Session;

import net.viralpatel.shorty.model.Link;
import net.viralpatel.shorty.util.HibernateUtil;
import net.viralpatel.shorty.util.ShortyUtil;

public class LinkController extends HibernateUtil {

	public Link get(String shortCode) {

		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();

		Query query = session.createQuery(&quot;from Link where shortcode = :shortcode&quot;);
		query.setString(&quot;shortcode&quot;, shortCode);
		Link link = (Link) query.uniqueResult();
		if(null != link) {
			link.setClicks(link.getClicks());
			session.save(link);
		}
		session.getTransaction().commit();

		return link;

	}

	public Link add(Link link) {

		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();

		Query query = session.createQuery(&quot;from Link where url = :url&quot;);
		query.setString(&quot;url&quot;, link.getUrl());
		Link oldLink = (Link) query.uniqueResult();
		if(null != oldLink)
			return oldLink;

		session.save(link);
		if(null == link.getShortCode()) {
			link.setShortCode(ShortyUtil.base48Encode(link.getId()));
			session.save(link);
		}
		session.getTransaction().commit();
		return link;
	}
}
</pre>
<h2>Adding Struts2 Support</h2>
<p>The UI for our URL shortner is very simple. We will have a index.jsp page which has a textbox for entering long URL and a small <em>Shorten</em> button. Also we will add a functionality where we can see some statistics/details of any short url. For example if shortcode <em>http://&lt;shorturl&gt;q1d</em> points to http://viralpatel.net then <em>http://&lt;shorturl&gt;q1d+</em> will show a page with details about url http://viralpatel.net.<br />
<strong>Related:</strong> <a target="_blank" href="http://viralpatel.net/blogs/2009/12/tutorial-create-struts-2-application-eclipse-example.html">Tutorial: Create Struts 2 Application in Eclipse</a></p>
<p>Lets starts with creating Action class. Create a class <code>LinkAction.java</code> under <code>net.viralpatel.shorty.view</code> package.</p>
<p><strong>LinkAction.java</strong></p>
<pre class="brush: java;">
package net.viralpatel.shorty.view;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;
import net.viralpatel.shorty.controller.LinkController;
import net.viralpatel.shorty.model.Link;
import net.viralpatel.shorty.util.ShortyUtil;

import com.opensymphony.xwork2.ActionSupport;

public class LinkAction extends ActionSupport implements ServletRequestAware {

	private static final long serialVersionUID = 1L;
	private final static String DETAIL = &quot;detail&quot;;
	private String url;
	private Link link;

	private LinkController linkController;

	private HttpServletRequest request;

	public LinkAction() {
		linkController = new LinkController();
	}
	public String add() {
		link = new Link();
		link.setUrl(this.url);
		link = linkController.add(link);

		return SUCCESS;
	}
	public String get() {

		String uri = request.getRequestURI();

		uri = ShortyUtil.getShortCodeFromURL(uri);

		if(uri.charAt(uri.length()-1) == '+') {
			uri = uri.substring(0, uri.length()-1);
			this.link = this.linkController.get(uri);
			return DETAIL;
		}

		this.link = this.linkController.get(uri);
		if(null == this.link) {
			addActionError(getText(&quot;error.url.unavailable&quot;));
			return INPUT;
		} else {

			setUrl(link.getUrl());
			return SUCCESS;
		}
	}
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public Link getLink() {
		return link;
	}

	public void setLink(Link link) {
		this.link = link;
	}
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}
}
</pre>
<p>Also create struts configuration file struts.xml under resources folder and copy following content into it.<br />
<strong>resources/struts.xml</strong></p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;
&lt;!DOCTYPE struts PUBLIC
    &quot;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&quot;
    &quot;http://struts.apache.org/dtds/struts-2.0.dtd&quot;&gt;

&lt;struts&gt;
	&lt;constant name=&quot;struts.enable.DynamicMethodInvocation&quot;
		value=&quot;false&quot; /&gt;
	&lt;constant name=&quot;struts.devMode&quot; value=&quot;false&quot; /&gt;
	&lt;constant name=&quot;struts.custom.i18n.resources&quot;
		value=&quot;MessageResources&quot; /&gt;

	&lt;package name=&quot;default&quot; extends=&quot;struts-default&quot; namespace=&quot;/&quot;&gt;
		&lt;action name=&quot;add&quot; class=&quot;net.viralpatel.shorty.view.LinkAction&quot;
			method=&quot;add&quot;&gt;
			&lt;result name=&quot;success&quot;&gt;index.jsp&lt;/result&gt;
		&lt;/action&gt;
		&lt;action name=&quot;*&quot; class=&quot;net.viralpatel.shorty.view.LinkAction&quot;
			method=&quot;get&quot;&gt;
			&lt;result name=&quot;success&quot; type=&quot;redirect&quot;&gt;${url}&lt;/result&gt;
			&lt;result name=&quot;input&quot;&gt;index.jsp&lt;/result&gt;
			&lt;result name=&quot;detail&quot;&gt;detail.jsp&lt;/result&gt;
		&lt;/action&gt;
	&lt;/package&gt;
&lt;/struts&gt;
</pre>
<p>Note that we have used wildcard mapping in Struts2 action class. This is to ensure we call LinkAction for any shortcode passed in url shortner service.</p>
<p>Create a resource bundle file MessageResources.properties which will hold value for domain name of our URL shortner and an error message.<br />
<strong>resources/MessageResources.properties</strong></p>
<pre class="brush: xml;">
shorty.base.url=http://shorty/
error.url.unavailable=Couldn't find the site's URL to redirect to.
</pre>
<p>You may want to change value of <em>key shorty.base.url</em> to your domain name.</p>
<p>Add following JSP files in WebContent folder.</p>
<p><strong>WebContent/index.jsp</strong></p>
<pre class="brush: xml;">
&lt;%@ taglib uri=&quot;/struts-tags&quot; prefix=&quot;s&quot;%&gt;
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;
&quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;
&lt;title&gt;Shorty - An Open Source URL Shortner in Struts2/Hibernate | ViralPatel.net&lt;/title&gt;
&lt;link href=&quot;css/style.css&quot; rel=&quot;stylesheet&quot;/&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1 class=&quot;title&quot;&gt;Shorty&lt;/h1&gt;
&lt;br&gt;
&lt;p&gt;A Simple URL Shortner in Struts2/Hibernate/MySQL&lt;/p&gt;
&lt;br&gt;&lt;br&gt;
&lt;div id=&quot;link-container&quot;&gt;

	&lt;s:form action=&quot;add&quot; method=&quot;post&quot;&gt;
		&lt;s:actionerror/&gt;
		&lt;s:textfield name=&quot;url&quot; cssClass=&quot;link&quot;/&gt;
		&lt;s:submit value=&quot;Shorten&quot;/&gt;
	&lt;/s:form&gt;
	&lt;s:if test=&quot;link.shortCode != null&quot;&gt;
			&lt;h3&gt;&lt;s:text name=&quot;shorty.base.url&quot;/&gt;&lt;s:property value=&quot;link.shortCode&quot;/&gt;&lt;/h3&gt;
	&lt;/s:if&gt;

&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>WebContent/detail.jsp</strong></p>
<pre class="brush: xml;">
&lt;%@ taglib uri=&quot;/struts-tags&quot; prefix=&quot;s&quot;%&gt;
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;
&quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;
&lt;title&gt;Shorty - An Open Source URL Shortner in Struts2/Hibernate | ViralPatel.net&lt;/title&gt;
&lt;link href=&quot;css/style.css&quot; rel=&quot;stylesheet&quot; /&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;h1 class=&quot;title&quot;&gt;Shorty&lt;/h1&gt;

	Short Code: &lt;s:property value=&quot;link.shortCode&quot; /&gt; &lt;br /&gt;
	Original URL: &lt;s:property value=&quot;link.url&quot; /&gt; &lt;br /&gt;
	Clicks: &lt;s:property value=&quot;link.clicks&quot; /&gt; &lt;br /&gt;
	Created On: &lt;s:property value=&quot;link.created&quot; /&gt; &lt;br /&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<h2>That&#8217;s all Folks</h2>
<p>Execute the web project in your favorite container like Tomcat, Glassfish etc.<br />
<img src="http://img.viralpatel.net/2010/02/shorty-url-shortner-struts2-hibernate.png" alt="shorty-url-shortner-struts2-hibernate" title="shorty-url-shortner-struts2-hibernate" width="523" height="189" class="aligncenter size-full wp-image-2031" /></p>
<h2>Download</h2>
<p><a href="http://viralpatel.net/blogs/download/struts/shorty/Shorty.war"><strong>Download WAR File with Source Code</strong></a></p>
<div id="relatedpost" style="background-color:#FFF1A8; padding:3px;"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2010/01/tutorial-struts2-hibernate-example-eclipse.html" title="Tutorial: Create Struts2 Hibernate Example in Eclipse">Tutorial: Create Struts2 Hibernate Example in Eclipse</a></li><li><a href="http://viralpatel.net/blogs/2010/01/struts-2-ajax-tutorial-example-drop-down.html" title="Struts 2 Ajax Tutorial with Example">Struts 2 Ajax Tutorial with Example</a></li><li><a href="http://viralpatel.net/blogs/2009/12/struts-2-file-upload-save-tutorial-with-example.html" title="Struts 2 File Upload and Save Tutorial with Example">Struts 2 File Upload and Save Tutorial with Example</a></li><li><a href="http://viralpatel.net/blogs/2009/12/struts2-interceptors-tutorial-with-example.html" title="Struts2 Interceptors Tutorial with Example">Struts2 Interceptors Tutorial with Example</a></li><li><a href="http://viralpatel.net/blogs/2009/12/struts-2-tiles-plugin-tutorial-with-example-in-eclipse.html" title="Struts 2 Tiles Plugin Tutorial with Example in Eclipse">Struts 2 Tiles Plugin Tutorial with Example in Eclipse</a></li><li><a href="http://viralpatel.net/blogs/2009/12/struts2-validation-framework-tutorial-example.html" title="Struts2 Validation Framework Tutorial with Example">Struts2 Validation Framework Tutorial with Example</a></li><li><a href="http://viralpatel.net/blogs/2009/12/tutorial-create-struts-2-application-eclipse-example.html" title="Tutorial: Create Struts 2 Application in Eclipse">Tutorial: Create Struts 2 Application in Eclipse</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/02/create-url-shortner-in-java-struts2-hibernate.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/02/create-url-shortner-in-java-struts2-hibernate.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/02/create-url-shortner-in-java-struts2-hibernate.html&amp;title=Writing a URL Shortner in Java Struts2 &#038; Hibernate&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/02/create-url-shortner-in-java-struts2-hibernate.html&amp;title=Writing a URL Shortner in Java Struts2 &#038; Hibernate" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/02/create-url-shortner-in-java-struts2-hibernate.html&amp;title=Writing a URL Shortner in Java Struts2 &#038; Hibernate" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/02/create-url-shortner-in-java-struts2-hibernate.html&amp;title=Writing a URL Shortner in Java Struts2 &#038; Hibernate" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>
<p><a href="http://feedads.g.doubleclick.net/~a/fIcuGVAKfw78CwVJJFqtcobckcA/0/da"><img src="http://feedads.g.doubleclick.net/~a/fIcuGVAKfw78CwVJJFqtcobckcA/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/fIcuGVAKfw78CwVJJFqtcobckcA/1/da"><img src="http://feedads.g.doubleclick.net/~a/fIcuGVAKfw78CwVJJFqtcobckcA/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=8pUHPRppV7s:VfTNe9uddmA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=8pUHPRppV7s:VfTNe9uddmA:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=8pUHPRppV7s:VfTNe9uddmA:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=8pUHPRppV7s:VfTNe9uddmA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=8pUHPRppV7s:VfTNe9uddmA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=8pUHPRppV7s:VfTNe9uddmA:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=8pUHPRppV7s:VfTNe9uddmA:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=8pUHPRppV7s:VfTNe9uddmA:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=8pUHPRppV7s:VfTNe9uddmA:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/02/create-url-shortner-in-java-struts2-hibernate.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://viralpatel.net/blogs/2010/02/create-url-shortner-in-java-struts2-hibernate.html</feedburner:origLink></item>
		<item>
		<title>Understanding Primary Key(PK) Constraint in Oracle</title>
		<link>http://feedproxy.google.com/~r/viralpatelnet/~3/ZyvLgWaXv08/understanding-primary-keypk-constraint-in-oracle.html</link>
		<comments>http://viralpatel.net/blogs/2010/02/understanding-primary-keypk-constraint-in-oracle.html#comments</comments>
		<pubDate>Tue, 16 Feb 2010 15:21:35 +0000</pubDate>
		<dc:creator>Anuj Parashar</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[database indexes]]></category>
		<category><![CDATA[oracle]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2032</guid>
		<description><![CDATA[
The Primary Key(PK) constraint is the most basic concept of any RDBMS (I am particularly interested in Oracle). Yet, I have noticed people getting confused when it comes to the practical usage and asking questions like:
- I have disabled PK and now oracle is doing full table scan.
- How PK constraints and indexes are related/different?
- [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.viralpatel.net/2010/02/primary-key.jpg" alt="primary-key" title="primary-key" width="343" height="183" class="aligncenter size-full wp-image-2034" /><br />
The Primary Key(PK) constraint is the most basic concept of any RDBMS (I am particularly interested in Oracle). Yet, I have noticed people getting confused when it comes to the practical usage and asking questions like:</p>
<p>- I have disabled PK and now oracle is doing full table scan.<br />
- How PK constraints and indexes are related/different?<br />
- How Oracle is using a non-unique index to enforce PK constraints?</p>
<p>Although these questions seem simple to the experienced users yet these can act as food for thought for the new developers. I have tried to consolidate few aspects about PK constraint which I found particularly confusing / worth knowing.</p>
<p><strong>1. Primary key(PK) constraint and unique index are different.</strong><br />
PK constraint is a rule that prohibits multiple rows from having the same value in the same column or combination of columns and prohibits values from being null.<br />
Index is a database object which is used for fast retrieval of data. It is created using DDL commands: &#8220;CREATE INDEX&#8221; or as part of a &#8220;CREATE TABLE&#8221; with PK/UK constraint or an &#8220;ALTER TABLE&#8221; command to add these constraints.</p>
<p><strong>2. An enabled PK constraint is always associated with an index.</strong><br />
The associated index can be unique or non-unique (discussed later). The corresponding index can be find by querying:</p>
<pre class="brush: sql;">
SELECT constraint_name, constraint_type, index_name
  FROM user_constraints
 WHERE table_name = '&lt;TABLE_NAME&gt;';
</pre>
<p>Also, if we have an enabled PK constraint, the corresponding column(s) will be &#8220;<strong>NOT NULL</strong>&#8220;. Now if you drop/disable the PK constriant, the column(s) will be changed to the state in which they were before adding the PK constraint.</p>
<pre class="brush: sql;">
-- Creating a table with two columns. One as NULL and other as NOT NULL
CREATE TABLE tbl_test ( col_1 NUMBER,
                                  col_2 NUMBER NOT NULL);

-- Querying to check the the column nullable status
SELECT table_name, column_name, nullable
  FROM user_tab_cols
 WHERE table_name = 'TBL_TEST';

-- TABLE_NAME | COLUMN_NAME | NULLABLE
-- TBL_TEST   | COL_1       | Y
-- TBL_TEST   | COL_2       | N

-- Adding the the PK constraint
ALTER TABLE tbl_test ADD CONSTRAINT tbl_test_pk PRIMARY KEY(col_1);

-- Querying to check the user constraints.
--Two entries, one for NOT NULL constraint and one for PK constraint
SELECT a.table_name, b.column_name, a.constraint_name,
           a.constraint_type, a.index_name
  FROM user_constraints a, user_cons_columns b
 WHERE a.table_name      = 'TBL_TEST'
   AND a.constraint_name = b.constraint_name;

-- TABLE_NAME | COLUMN_NAME | CONSTRAINT_NAME | CONSTRAINT_TYPE | INDEX_NAME
-- TBL_TEST   | COL_2       | SYS_C001231845  | C               |
-- TBL_TEST   | COL_1       | TBL_TEST_PK     | P               | TBL_TEST_PK

-- Rechecking the column nullable status. Both the columns are now NOT NULL
SELECT table_name, column_name, nullable
  FROM user_tab_cols
 WHERE table_name = 'TBL_TEST';

-- TABLE_NAME | COLUMN_NAME | NULLABLE
-- TBL_TEST   | COL_1       | N
-- TBL_TEST   | COL_2       | N

-- Disabling the PK constraint
ALTER TABLE tbl_test DISABLE PRIMARY KEY;
-- OR
-- ALTER TABLE tbl_test DISABLE CONSTRAINT tbl_test_pk;

-- The column status is changed back as it was before adding the PK.
SELECT table_name, column_name, nullable
  FROM user_tab_cols
 WHERE table_name = 'TBL_TEST';

-- TABLE_NAME | COLUMN_NAME | NULLABLE
-- TBL_TEST   | COL_1       | Y
-- TBL_TEST   | COL_2       | N</pre>
<p><strong>3. If the PK constraint is disabled, there will be no index associated with it.</strong><br />
The &#8220;index_name&#8221; in the above query would be blank. But the constraint name would still be there. So, PK constraint exists (with status as disabled) but there is no associated index.</p>
<pre class="brush: sql;">
DROP TABLE tbl_test;

CREATE TABLE tbl_test (col_1 NUMBER);

CREATE INDEX idx_col_1 ON tbl_test (col_1);

ALTER TABLE tbl_test ADD CONSTRAINT tbl_test_pk PRIMARY KEY(col_1);

SELECT constraint_name, constraint_type, index_name
  FROM user_constraints
 WHERE table_name = 'TBL_TEST';

-- CONSTRAINT_NAME | CONSTRAINT_TYPE | INDEX_NAME
-- TBL_TEST_PK     | P               | IDX_COL_1

ALTER TABLE tbl_test DISABLE PRIMARY KEY;
-- OR
-- ALTER TABLE tbl_test DISABLE CONSTRAINT tbl_test_pk;

-- Once the PK is disabled, the association with the index is gone
SELECT constraint_name, constraint_type, index_name, status
  FROM user_constraints
 WHERE table_name = 'TBL_TEST';

CONSTRAINT_NAME | CONSTRAINT_TYPE | INDEX_NAME | STATUS
TBL_TEST_PK     | P               |            | DISABLED
</pre>
<p><strong>4. Once PK constraint is disabled, the index left on that column can be dropped.</strong><br />
If the index was created by oracle with the creation of PK constraint, it will be dropped automatically. If some existing index was associated with the PK constraint, it will not be dropped by oracle(refer point 6 for details). But its now possible to drop that index manually.</p>
<pre class="brush: sql;">
-- With the primary key disabled, the index can now be dropped
DROP INDEX idx_col_1;

SELECT table_name, index_name
  FROM user_indexes
 WHERE table_name = 'TBL_TEST';

-- no rows returned.
</pre>
<p><strong>5. Enabling of the PK constraint requires association with index.</strong><br />
If we now try to enable the PK constraint again, it will pick up the first index it found on that column and will get associated with it. In case there is no index to get associated, oracle will create a new index with the name same as that of PK constraint.</p>
<pre class="brush: sql;">
ALTER TABLE tbl_test ENABLE PRIMARY KEY;
-- OR
-- ALTER TABLE  tbl_test ENABLE CONSTRAINT tbl_test_pk;

-- Oracle has created a new index with name &quot;TBL_TEST_PK&quot;
SELECT constraint_name, constraint_type, index_name
  FROM user_constraints
 WHERE table_name = 'TBL_TEST';

-- A new index &quot;TBL_TEST_PK&quot; is created and associated with the PK constraint
-- CONSTRAINT_NAME | CONSTRAINT_TYPE | INDEX_NAME
-- TBL_TEST_PK     | P               | TBL_TEST_PK

SELECT table_name, index_name
  FROM user_indexes
 WHERE table_name = 'TBL_TEST';

-- TABLE_NAME | INDEX_NAME
-- TBL_TEST   | TBL_TEST_PK
</pre>
<p><strong>6. Use &#8220;USING INDEX&#8221; clause to associated a particular index with the PK.</strong><br />
If there are more than one indexes on the column on which you want to add PK constraint, we can selectively choose the index to be assoicated with the PK using &#8220;<strong>USING INDEX</strong>&#8220;. This clause can be used while:<br />
a) Adding the PK constraint for the first time (using &#8220;ALTER TABLE&#8221; command).</p>
<pre class="brush: sql;">
DROP TABLE tbl_test;

CREATE TABLE tbl_test ( col_1 NUMBER,
                        col_2 NUMBER,
                        col_3 NUMBER);

CREATE INDEX idx_col_1_2 ON tbl_test(col_1, col_2);

CREATE INDEX idx_col_1_3 ON tbl_test(col_1, col_3);

CREATE UNIQUE INDEX idx_col_1 ON tbl_test(col_1);

-- Forcing oracle to use the unique index &quot;IDX_COL_1&quot;
ALTER TABLE tbl_test ADD CONSTRAINT tbl_test_pk PRIMARY KEY(col_1)
USING INDEX idx_col_1;

SELECT constraint_name, constraint_type, index_name
  FROM user_constraints
 WHERE table_name = 'TBL_TEST';

-- CONSTRAINT_NAME | CONSTRAINT_TYPE | INDEX_NAME
-- TBL_TEST_PK     | P               | IDX_COL_1
</pre>
<p>b) Enabling the PK constraint.</p>
<pre class="brush: sql;">
DROP TABLE tbl_test;

CREATE TABLE tbl_test ( col_1 NUMBER, col_2 NUMBER,
                        col_3 NUMBER);

CREATE INDEX idx_col_1_2 ON tbl_test(col_1, col_2);

CREATE INDEX idx_col_1_3 ON tbl_test(col_1, col_3);

CREATE UNIQUE INDEX idx_col_1 ON tbl_test(col_1);

ALTER TABLE tbl_test ADD CONSTRAINT tbl_test_pk PRIMARY KEY(col_1);

SELECT table_name, index_name, uniqueness
  FROM user_indexes
 WHERE table_name = 'TBL_TEST';

-- TABLE_NAME | INDEX_NAME  | UNIQUENESS
-- TBL_TEST   | IDX_COL_1_2 | NONUNIQUE
-- TBL_TEST   | IDX_COL_1_3 | NONUNIQUE
-- TBL_TEST   | IDX_COL_1   | UNIQUE

-- Although an unique index exists, oracle has picked up the first index
SELECT constraint_name, constraint_type, index_name
  FROM user_constraints
 WHERE table_name = 'TBL_TEST';

-- CONSTRAINT_NAME | CONSTRAINT_TYPE | INDEX_NAME
-- TBL_TEST_PK     | P               | IDX_COL_1_2

ALTER TABLE tbl_test DISABLE PRIMARY KEY;

-- Forcing oracle to use the unique index
ALTER TABLE  tbl_test ENABLE CONSTRAINT TBL_TEST_PK USING INDEX IDX_COL_1;

SELECT constraint_name, constraint_type, index_name
  FROM user_constraints
 WHERE table_name = 'TBL_TEST';

-- CONSTRAINT_NAME | CONSTRAINT_TYPE | INDEX_NAME
-- TBL_TEST_PK     | P               | IDX_COL_1
</pre>
<p>Manully associating PK constraint with already existing unique/non-unique index has the following advantages:<br />
a) The index remains available and valid when the constraint is disabled.<br />
b) Enabling the PK constraint doesn&#8217;t require rebuilding the unique/non-unique index associated with the constraint.<br />
c) The redundant indexes can be eliminated. PK constraint can be associated with a composite index too if the column is included as the prefix of the composite index. So, in the example above, it iss possible to remove the unique index (if not required) and the composite index can be used for PK enforcement.</p>
<p><strong>7. The index associated with the PK constraint needn&#8217;t be unique.</strong><br />
A non-unique index can also be be associated with the PK constraints. Now the question is <strong>how oracle allows PK constraint to be enforced using a non-unique index</strong>. Here is the explanation (as per best of my knowledge, might not be correct):</p>
<p>As described above, PK constraint is a rule to prohibit duplicate/null records for the PK column. Suppose, we already have 1 Million records in the table and inserting a new entry. So, to enforce the PK constraint, Oracle has to search through the already present records and this is where the index comes handy. If you have an index on that column, the search will be quite fast. The unique index will be the best but a non-unique index will also be a better option as compared to a full table scan. So, the basic purpose of associating index with PK constraints is to efficiently enforce the underlying rule. So, using index for PK constraint enforcement is a part of Oracle architecture (I assume its the same for all other RDBMS).</p>
<pre class="brush: sql;">
DROP TABLE tbl_test;

CREATE TABLE tbl_test ( col_1 NUMBER, col_2 NUMBER,
                        col_3 NUMBER);

CREATE INDEX idx_col_1_2 ON tbl_test(col_1, col_2);

-- Associating composite index with the PK constraint
ALTER TABLE tbl_test ADD CONSTRAINT tbl_test_pk PRIMARY KEY(col_1)
USING INDEX idx_col_1_2;

SELECT constraint_name, constraint_type, index_name
  FROM user_constraints
 WHERE table_name = 'TBL_TEST';

-- CONSTRAINT_NAME | CONSTRAINT_TYPE | INDEX_NAME
-- TBL_TEST_PK     | P               | IDX_COL_1_2

 SELECT table_name, index_name, uniqueness
  FROM user_indexes
 WHERE table_name = 'TBL_TEST';

-- TABLE_NAME | INDEX_NAME  | UNIQUENESS
-- TBL_TEST   | IDX_COL_1_2 | NONUNIQUE
</pre>
<p><strong>8. Merits of allowing non-unique index for enforcing PK constraints</strong>:<br />
a) The non-unique indexes facilitates the use of &#8220;<strong>INITIALLY DEFERRED</strong>&#8221; clause with the constraint until the transaction has been committed if the PK constraint has been defined as &#8220;<strong>DEFERRABLE</strong>&#8221; at the time of creating. The &#8220;<strong>DEFERRABLE</strong>&#8221; PK constraint can&#8217;t be associated with a unique index.</p>
<pre class="brush: sql;">
DROP TABLE tbl_test;

CREATE TABLE tbl_test ( col_1 NUMBER,
                        col_2 NUMBER);

ALTER TABLE tbl_test ADD CONSTRAINT tbl_test_pk PRIMARY KEY(col_1)
INITIALLY DEFERRED DEFERRABLE;

-- The resulting index created by oracle is non-unique
SELECT table_name, index_name, uniqueness
  FROM user_indexes
 WHERE table_name = 'TBL_TEST';

-- TABLE_NAME | INDEX_NAME  | UNIQUENESS
-- TBL_TEST   | TBL_TEST_PK | NONUNIQUE

-- Allowing duplicate records inspite of the presence of PK consraint
INSERT INTO tbl_test VALUES (1,2);
INSERT INTO tbl_test VALUES (1,2);
INSERT INTO tbl_test VALUES (1,2); 

-- Constraint checked at the time of transaction commit
COMMIT;
-- ORA-02091: transaction rolled back
-- ORA-00001: unique constraint (GC_ADMIN.TBL_TEST_PK) violated
</pre>
<p>b) The &#8220;<strong>NOVALIDATE</strong>&#8221; option can be used to exclude the enforcement of constraint on the already existing data.</p>
<pre class="brush: sql;">
DROP TABLE tbl_test purge;

CREATE TABLE tbl_test ( col_1 NUMBER);

INSERT INTO tbl_test VALUES (1);
INSERT INTO tbl_test VALUES (1);
INSERT INTO tbl_test VALUES (1);

ALTER TABLE tbl_test add constraint idx_col_1 PRIMARY KEY (col_1) NOVALIDATE;
-- ORA-02437: cannot validate (GC_ADMIN.IDX_COL_1) - primary key violated

ALTER TABLE tbl_test add constraint idx_col_1 PRIMARY KEY (col_1) DISABLE;

ALTER TABLE tbl_test ENABLE NOVALIDATE PRIMARY KEY;
-- ORA-02437: cannot validate (GC_ADMIN.IDX_COL_1) - primary key violated

-- This is because oracle tries to create unique index for the PK constraints.
-- The statement fails while checking the uniqueness for creating the unique index.
-- To fix this, create a non-unique index first. Then oracle will associate
-- the primary key constraint with this non-unique index.
CREATE INDEX idx_col_1 ON tbl_test(col_1);

ALTER TABLE tbl_test ENABLE NOVALIDATE PRIMARY KEY;
</pre>
<p><strong>9. Bitmap index can&#8217;t be associated with a PK constraint.</strong></p>
<pre class="brush: sql;">
DROP TABLE tbl_test;

CREATE TABLE tbl_test ( col_1 NUMBER,
                        col_2 NUMBER,
                        col_3 NUMBER);

CREATE BITMAP INDEX idx_col_1 ON tbl_test (col_1);

ALTER TABLE tbl_test ADD CONSTRAINT tbl_test_pk PRIMARY KEY(col_1) USING INDEX idx_col_1;
-- ORA-14196: Specified index cannot be used to enforce the constraint.
</pre>
<p><strong>10. Dropping the PK may or may not drop the associated index.</strong><br />
If you drop a PK constraint, the associated index may or may not be dropped depending on the association of PK constraint and index. Two scenario arises:<br />
a) The PK constraint is associated with an already present index (either by using &#8220;USING INDEX&#8221; clause or by default association if not specifically specified). In that case, the index will not be dropped with the dropping of PK constraint.</p>
<pre class="brush: sql;">
DROP TABLE tbl_test;

CREATE TABLE tbl_test ( col_1 NUMBER);

CREATE INDEX idx_col_1 ON tbl_test (col_1);

ALTER TABLE tbl_test ADD CONSTRAINT tbl_test_pk PRIMARY KEY(col_1)
USING INDEX idx_col_1;

ALTER TABLE tbl_test DROP PRIMARY KEY;

-- Primary Key dropped
SELECT constraint_name, constraint_type, index_name
  FROM user_constraints
 WHERE table_name = 'TBL_TEST';

-- no rows selected.
-- The index is still present
 SELECT table_name, index_name, uniqueness
  FROM user_indexes
 WHERE table_name = 'TBL_TEST';

-- TABLE_NAME | INDEX_NAME | UNIQUENESS
-- TBL_TEST   | IDX_COL_1  | NONUNIQUE
</pre>
<p>b) If the PK constraint is created while there is no index on PK column, oracle will create a new unique index with the same name as PK constraint. By default, this index will be dropped with the dropping of PK constraint. You can keep this index intact by using the &#8220;<strong>KEEP INDEX</strong>&#8221; clause.</p>
<pre class="brush: sql;">
DROP TABLE tbl_test;

CREATE TABLE tbl_test ( col_1 NUMBER);

ALTER TABLE tbl_test ADD CONSTRAINT tbl_test_pk PRIMARY KEY(col_1);

SELECT constraint_name, constraint_type, index_name
  FROM user_constraints
 WHERE table_name = 'TBL_TEST';

-- CONSTRAINT_NAME | CONSTRAINT_TYPE | INDEX_NAME
-- TBL_TEST_PK     | P               | TBL_TEST_PK

SELECT table_name, index_name, uniqueness
  FROM user_indexes
 WHERE table_name = 'TBL_TEST';

-- TABLE_NAME | INDEX_NAME  | UNIQUENESS
-- TBL_TEST   | TBL_TEST_PK | UNIQUE

ALTER TABLE tbl_test DROP PRIMARY KEY;

SELECT constraint_name, constraint_type, index_name
  FROM user_constraints
 WHERE table_name = 'TBL_TEST';

-- no rows selected.

 SELECT table_name, index_name, uniqueness
  FROM user_indexes
 WHERE table_name = 'TBL_TEST';

-- no rows selected.

ALTER TABLE tbl_test ADD CONSTRAINT tbl_test_pk PRIMARY KEY(col_1);

ALTER TABLE tbl_test DROP PRIMARY KEY KEEP INDEX;

-- The PK constraint is gone
SELECT constraint_name, constraint_type, index_name
  FROM user_constraints
 WHERE table_name = 'TBL_TEST';

-- no rows selected.
-- Yet the index created by oracle is still there
 SELECT table_name, index_name, uniqueness
  FROM user_indexes
 WHERE table_name = 'TBL_TEST';

-- TABLE_NAME | INDEX_NAME  | UNIQUENESS
-- TBL_TEST   | TBL_TEST_PK | UNIQUE
</pre>
<p>Please note that the above mentioned points are also more or less applicable for Unique key(UK) constraints. I haven&#8217;t tried to touch that subject to keep the content precise.<br />
All queries are tested and verified on Oracle 10.2.0.4 version. </p>
<p><em><strong>Disclaimer:</strong> All data and information provided on this article is for informational purposes only. Author makes no representations as to accuracy, completeness, suitability, or validity of any information on this article. All information is provided on an as-is basis.</em></p>
<div id="relatedpost" style="background-color:#FFF1A8; padding:3px;"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2009/05/fetch-random-rows-from-database-mysql-oracle-ms-sql-postgresql-example.html" title="Fetch Random rows from Database (MySQL, Oracle, MS SQL, PostgreSQL)">Fetch Random rows from Database (MySQL, Oracle, MS SQL, PostgreSQL)</a></li><li><a href="http://viralpatel.net/blogs/2009/04/full-text-search-using-mysql-full-text-search-capabilities.html" title="Full-Text Search using MySQL: Full-Text Search Capabilities">Full-Text Search using MySQL: Full-Text Search Capabilities</a></li><li><a href="http://viralpatel.net/blogs/2009/08/fast-data-copy-with-create-table-select-from-in-plsql.html" title="Fast data copy with &#8220;Create Table Select From&#8221; in PL/SQL">Fast data copy with &#8220;Create Table Select From&#8221; in PL/SQL</a></li><li><a href="http://viralpatel.net/blogs/2009/04/oracle-buying-sun-microsystems-mysql-future.html" title="Oracle buying Sun Microsystems: What will happen to MySQL!">Oracle buying Sun Microsystems: What will happen to MySQL!</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/02/understanding-primary-keypk-constraint-in-oracle.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/02/understanding-primary-keypk-constraint-in-oracle.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/02/understanding-primary-keypk-constraint-in-oracle.html&amp;title=Understanding Primary Key(PK) Constraint in Oracle&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/02/understanding-primary-keypk-constraint-in-oracle.html&amp;title=Understanding Primary Key(PK) Constraint in Oracle" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/02/understanding-primary-keypk-constraint-in-oracle.html&amp;title=Understanding Primary Key(PK) Constraint in Oracle" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/02/understanding-primary-keypk-constraint-in-oracle.html&amp;title=Understanding Primary Key(PK) Constraint in Oracle" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>
<p><a href="http://feedads.g.doubleclick.net/~a/uJ4SWmGmTj64uPkdRQA4bw4-EGA/0/da"><img src="http://feedads.g.doubleclick.net/~a/uJ4SWmGmTj64uPkdRQA4bw4-EGA/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/uJ4SWmGmTj64uPkdRQA4bw4-EGA/1/da"><img src="http://feedads.g.doubleclick.net/~a/uJ4SWmGmTj64uPkdRQA4bw4-EGA/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=ZyvLgWaXv08:zqojvq73_W0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=ZyvLgWaXv08:zqojvq73_W0:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=ZyvLgWaXv08:zqojvq73_W0:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=ZyvLgWaXv08:zqojvq73_W0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=ZyvLgWaXv08:zqojvq73_W0:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=ZyvLgWaXv08:zqojvq73_W0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=ZyvLgWaXv08:zqojvq73_W0:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=ZyvLgWaXv08:zqojvq73_W0:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=ZyvLgWaXv08:zqojvq73_W0:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/02/understanding-primary-keypk-constraint-in-oracle.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://viralpatel.net/blogs/2010/02/understanding-primary-keypk-constraint-in-oracle.html</feedburner:origLink></item>
		<item>
		<title>Generate Pie Chart/Bar Graph in PDF using iText &amp; JFreeChart</title>
		<link>http://feedproxy.google.com/~r/viralpatelnet/~3/6bcnK5ZnOjU/generate-pie-chart-bar-graph-in-pdf-using-itext-jfreechart.html</link>
		<comments>http://viralpatel.net/blogs/2010/02/generate-pie-chart-bar-graph-in-pdf-using-itext-jfreechart.html#comments</comments>
		<pubDate>Mon, 15 Feb 2010 06:00:34 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[iText]]></category>
		<category><![CDATA[jFreeChart]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[PDF in Java]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2025</guid>
		<description><![CDATA[iText is a wonderful library if you want to generate PDFs in Java. It comes with a huge set of API to create/manage a PDF file. We already saw in our previous tutorial how to generate a pdf file in itext and also how to merge two pdf files using itext.
In this tutorial we will [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.viralpatel.net/2010/02/generate-charts-graph-pdf-itext.jpg" alt="generate pie chart graph in java pdf itext jfreechart" title="generate-charts-graph-pdf-itext" width="150" height="182" class="alignright size-full wp-image-2026" />iText is a wonderful library if you want to generate PDFs in Java. It comes with a huge set of API to create/manage a PDF file. We already saw in our previous tutorial <a href="http://viralpatel.net/blogs/2009/04/generate-pdf-file-in-java-using-itext-jar.html">how to generate a pdf file</a> in itext and also <a href="http://viralpatel.net/blogs/2009/06/itext-tutorial-merge-split-pdf-files-using-itext-jar.html">how to merge two pdf</a> files using itext.</p>
<p>In this tutorial we will see how to generate Pie charts and Bar charts in Java using iText and jFreeChart library. First a brief note about jFreeChart.</p>
<p>JFreeChart is a free 100% Java chart library that makes it easy for developers to display professional quality charts in their applications. It gives a wide range of API to generate charts and graphs in Java.</p>
<h2>Step 1: Download required Jar files</h2>
<p>For this example we will need following jar files.</p>
<ul>
<li>iText-2.1.5.jar (<a href="http://prdownloads.sourceforge.net/itext/iText-2.1.5.jar">download</a>)</li>
<li>jcommon-1.0.16.jar</li>
<li>jfreechart-1.0.13.jar</li>
</ul>
<p>Download the jFreeChart jars from: <a rel="nofollow" target="_blank" href="http://sourceforge.net/projects/jfreechart/files/">http://sourceforge.net/projects/jfreechart/files/</a></p>
<h2>Step 2: Generating Pie Charts/Bar Graph using jFreeChart</h2>
<p>Next we will use jFreeChart library and generate the pie and bar charts. </p>
<pre class="brush: java;">
package net.viralpatel.itext.pdf;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;

public class PieChartDemo {
	public static void main(String[] args) {
		//TODO: Add code to generate PDFs with charts
	}

	public static JFreeChart generatePieChart() {
		DefaultPieDataset dataSet = new DefaultPieDataset();
		dataSet.setValue(&quot;China&quot;, 19.64);
		dataSet.setValue(&quot;India&quot;, 17.3);
		dataSet.setValue(&quot;United States&quot;, 4.54);
		dataSet.setValue(&quot;Indonesia&quot;, 3.4);
		dataSet.setValue(&quot;Brazil&quot;, 2.83);
		dataSet.setValue(&quot;Pakistan&quot;, 2.48);
		dataSet.setValue(&quot;Bangladesh&quot;, 2.38);

		JFreeChart chart = ChartFactory.createPieChart(
				&quot;World Population by countries&quot;, dataSet, true, true, false);

		return chart;
	}

	public static JFreeChart generateBarChart() {
		DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
		dataSet.setValue(791, &quot;Population&quot;, &quot;1750 AD&quot;);
		dataSet.setValue(978, &quot;Population&quot;, &quot;1800 AD&quot;);
		dataSet.setValue(1262, &quot;Population&quot;, &quot;1850 AD&quot;);
		dataSet.setValue(1650, &quot;Population&quot;, &quot;1900 AD&quot;);
		dataSet.setValue(2519, &quot;Population&quot;, &quot;1950 AD&quot;);
		dataSet.setValue(6070, &quot;Population&quot;, &quot;2000 AD&quot;);

		JFreeChart chart = ChartFactory.createBarChart(
				&quot;World Population growth&quot;, &quot;Year&quot;, &quot;Population in millions&quot;,
				dataSet, PlotOrientation.VERTICAL, false, true, false);

		return chart;
	}
}
</pre>
<p>In above code, we have created two methods that returns JFreeChart object. These methods creates charts using jFreeChart API. Note that we have used dummy data. In real example these values must be dynamically fetched from database or other data source.</p>
<p>Also note that the main method is still empty. We haven&#8217;t added yet the code to generate actual PDF file using iText API. </p>
<h2>Step 3: Generate PDF with Charts/Graphs in Java using iText</h2>
<p>Now its time to generate the actual PDF files. For this we will use iText library and pass it the graphs generated by jFreeChart library. Add following code in your java class.</p>
<pre class="brush: java;">
	public static void main(String[] args) {
		writeChartToPDF(generateBarChart(), 500, 400, &quot;C://barchart.pdf&quot;);
		writeChartToPDF(generatePieChart(), 500, 400, &quot;C://piechart.pdf&quot;);
	}
	public static void writeChartToPDF(JFreeChart chart, int width, int height, String fileName) {
		PdfWriter writer = null;

		Document document = new Document();

		try {
			writer = PdfWriter.getInstance(document, new FileOutputStream(
					fileName));
			document.open();
			PdfContentByte contentByte = writer.getDirectContent();
			PdfTemplate template = contentByte.createTemplate(width, height);
			Graphics2D graphics2d = template.createGraphics(width, height,
					new DefaultFontMapper());
			Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width,
					height);

			chart.draw(graphics2d, rectangle2d);

			graphics2d.dispose();
			contentByte.addTemplate(template, 0, 0);

		} catch (Exception e) {
			e.printStackTrace();
		}
		document.close();
	}
</pre>
<p>In above code we have created a method writeChartToPDF() which take few arguments like jFreeChart object, width, height and filename and write a PDF files in that file.</p>
<p><img src="http://img.viralpatel.net/2010/02/java-bar-chart-pdf.png" alt="java-bar-chart-pdf" title="java-bar-chart-pdf" width="387" height="318" class="aligncenter size-full wp-image-2027" /><br />
<img src="http://img.viralpatel.net/2010/02/java-pdf-pie-chart.png" alt="java-pdf-pie-chart" title="java-pdf-pie-chart" width="452" height="361" class="aligncenter size-full wp-image-2028" /></p>
<p>This is ofcourse very preliminary example of adding pie charts in PDF using Java iText/jFreeChart. But atleast it gives basic idea of how to achieve this. Feel free to modify the above code and play around to generate different charts/graphs in PDF.</p>
<div id="relatedpost" style="background-color:#FFF1A8; padding:3px;"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2009/06/itext-tutorial-merge-split-pdf-files-using-itext-jar.html" title="iText tutorial: Merge &#038; Split PDF files using iText JAR">iText tutorial: Merge &#038; Split PDF files using iText JAR</a></li><li><a href="http://viralpatel.net/blogs/2009/04/generate-pdf-file-in-java-using-itext-jar.html" title="PDF Generation in Java using iText JAR">PDF Generation in Java using iText JAR</a></li><li><a href="http://viralpatel.net/blogs/2010/02/most-useful-java-best-practice-quotes-java-developers.html" title="10 Most Useful Java Best Practice Quotes for Java Developers">10 Most Useful Java Best Practice Quotes for Java Developers</a></li><li><a href="http://viralpatel.net/blogs/2010/01/r-i-p-sun-james-gosling-paying-respects.html" title="R.I.P Sun: James Gosling paying Respects">R.I.P Sun: James Gosling paying Respects</a></li><li><a href="http://viralpatel.net/blogs/2009/12/struts2-validation-framework-tutorial-example.html" title="Struts2 Validation Framework Tutorial with Example">Struts2 Validation Framework Tutorial with Example</a></li><li><a href="http://viralpatel.net/blogs/2009/12/tutorial-create-struts-2-application-eclipse-example.html" title="Tutorial: Create Struts 2 Application in Eclipse">Tutorial: Create Struts 2 Application in Eclipse</a></li><li><a href="http://viralpatel.net/blogs/2009/12/introduction-to-struts-2-framework.html" title="Introduction to Struts 2 Framework">Introduction to Struts 2 Framework</a></li><li><a href="http://viralpatel.net/blogs/2009/12/advanced-messaging-queuing-protocol-amqp.html" title="Advanced Messaging Queuing Protocol: A Short Note">Advanced Messaging Queuing Protocol: A Short Note</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/02/generate-pie-chart-bar-graph-in-pdf-using-itext-jfreechart.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/02/generate-pie-chart-bar-graph-in-pdf-using-itext-jfreechart.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/02/generate-pie-chart-bar-graph-in-pdf-using-itext-jfreechart.html&amp;title=Generate Pie Chart/Bar Graph in PDF using iText &#038; JFreeChart&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/02/generate-pie-chart-bar-graph-in-pdf-using-itext-jfreechart.html&amp;title=Generate Pie Chart/Bar Graph in PDF using iText &#038; JFreeChart" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/02/generate-pie-chart-bar-graph-in-pdf-using-itext-jfreechart.html&amp;title=Generate Pie Chart/Bar Graph in PDF using iText &#038; JFreeChart" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/02/generate-pie-chart-bar-graph-in-pdf-using-itext-jfreechart.html&amp;title=Generate Pie Chart/Bar Graph in PDF using iText &#038; JFreeChart" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>
<p><a href="http://feedads.g.doubleclick.net/~a/V-raB7_BdOOc29bfP3OqSECzB7Y/0/da"><img src="http://feedads.g.doubleclick.net/~a/V-raB7_BdOOc29bfP3OqSECzB7Y/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/V-raB7_BdOOc29bfP3OqSECzB7Y/1/da"><img src="http://feedads.g.doubleclick.net/~a/V-raB7_BdOOc29bfP3OqSECzB7Y/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=6bcnK5ZnOjU:R1QHL2EtmCo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=6bcnK5ZnOjU:R1QHL2EtmCo:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=6bcnK5ZnOjU:R1QHL2EtmCo:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=6bcnK5ZnOjU:R1QHL2EtmCo:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=6bcnK5ZnOjU:R1QHL2EtmCo:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=6bcnK5ZnOjU:R1QHL2EtmCo:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=6bcnK5ZnOjU:R1QHL2EtmCo:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=6bcnK5ZnOjU:R1QHL2EtmCo:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=6bcnK5ZnOjU:R1QHL2EtmCo:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/02/generate-pie-chart-bar-graph-in-pdf-using-itext-jfreechart.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://viralpatel.net/blogs/2010/02/generate-pie-chart-bar-graph-in-pdf-using-itext-jfreechart.html</feedburner:origLink></item>
		<item>
		<title>10 Most Useful Java Best Practice Quotes for Java Developers</title>
		<link>http://feedproxy.google.com/~r/viralpatelnet/~3/p5yPgzCJ59E/most-useful-java-best-practice-quotes-java-developers.html</link>
		<comments>http://viralpatel.net/blogs/2010/02/most-useful-java-best-practice-quotes-java-developers.html#comments</comments>
		<pubDate>Wed, 10 Feb 2010 10:12:54 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[java class file]]></category>
		<category><![CDATA[Java design pattern]]></category>
		<category><![CDATA[JVM]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2021</guid>
		<description><![CDATA[
Quote 1: Avoid creating unnecessary objects and always prefer to do Lazy Initialization 
Object creation in Java is one of the most expensive operation in terms of memory utilization and performance impact. It is thus advisable to create or initialize an object only when it is required in the code. 

public class Countries {

	private List [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.viralpatel.net/2010/02/star-trek-spock-java-best-practice-quotes.png" alt="star-trek-spock-java-best-practice-quotes" title="star-trek-spock-java-best-practice-quotes" width="355" height="218" class="aligncenter size-full wp-image-2022" /></p>
<h3>Quote 1: Avoid creating unnecessary objects and always prefer to do Lazy Initialization </h3>
<p>Object creation in Java is one of the most expensive operation in terms of memory utilization and performance impact. It is thus advisable to create or initialize an object only when it is required in the code. </p>
<pre class="brush: java;">
public class Countries {

	private List countries;

	public List getCountries() {

		//initialize only when required
		if(null == countries) {
			countries = new ArrayList();
		}
		return countries;
	}
}
</pre>
<h3>Quote 2: Never make an instance fields of class public</h3>
<p>Making a class field public can cause lot of issues in a program. For instance you may have a class called MyCalender. This class contains an array of String weekdays. You may have assume that this array will always contain 7 names of weekdays. But as this array is public, it may be accessed by anyone. Someone by mistake also may change the value and insert a bug!</p>
<pre class="brush: java;">
public class MyCalender {

	public String[] weekdays =
		{&quot;Sun&quot;, &quot;Mon&quot;, &quot;Tue&quot;, &quot;Thu&quot;, &quot;Fri&quot;, &quot;Sat&quot;, &quot;Sun&quot;};

	//some code	

}
</pre>
<p>Best approach as many of you already know is to always make the field private and add a getter method to access the elements. </p>
<pre class="brush: java;">
	private String[] weekdays =
		{&quot;Sun&quot;, &quot;Mon&quot;, &quot;Tue&quot;, &quot;Thu&quot;, &quot;Fri&quot;, &quot;Sat&quot;, &quot;Sun&quot;};

	public String[] getWeekdays() {
		return weekdays;
	}
</pre>
<p>But writing getter method does not exactly solve our problem. The array is still accessible. Best way to make it unmodifiable is to return a clone of array instead of array itself. Thus the getter method will be changed to.</p>
<pre class="brush: java;">
	public String[] getWeekdays() {
		return weekdays.clone();
	}
</pre>
<h3>Quote 3: Always try to minimize Mutability of a class</h3>
<p>Making a class immutable is to make it unmodifiable. The information the class preserve will stay as it is through out the lifetime of the class. Immutable classes are simple, they are easy to manage. They are thread safe. They makes great building blocks for other objects. </p>
<p>However creating immutable objects can hit performance of an app. So always choose wisely if you want your class to be immutable or not. Always try to make a small class with less fields immutable. </p>
<p>To make a class immutable you can define its all constructors private and then create a public static method<br />
to initialize and object and return it.</p>
<pre class="brush: java;">
public class Employee {

	private String firstName;
	private String lastName;

	//private default constructor
	private Employee(String firstName, String lastName) {
		this.firstName = firstName;
		this.lastName = lastName;
	}

	public static Employee valueOf (String firstName, String lastName) {
		return new Employee(firstName, lastName);
	}
}
</pre>
<h3>Quote 4: Try to prefer Interfaces instead of Abstract classes</h3>
<p>First you can not inherit multiple classes in Java but you can definitely implements multiple interfaces. Its very easy to change the implementation of an existing class and add implementation of one more interface rather then changing full hierarchy of class.</p>
<p>Again if you are 100% sure what methods an interface will have, then only start coding that interface. As it is very difficult to add a new method in an existing interface without breaking the code that has already implemented it. On contrary a new method can be easily added in Abstract class without breaking existing functionality.</p>
<h3>Quote 5: Always try to limit the scope of Local variable</h3>
<p>Local variables are great. But sometimes we may insert some bugs due to copy paste of old code. Minimizing the scope of a local variable makes code more readable, less error prone and also improves the maintainability of the code.</p>
<p>Thus, declare a variable only when needed just before its use.</p>
<p>Always initialize a local variable upon its declaration. If not possible at least make the local instance assigned <code>null</code> value.</p>
<h3>Quote 6: Try to use standard library instead of writing your own from scratch</h3>
<p>Writing code is fun. But &#8220;do not reinvent the wheel&#8221;. It is very advisable to use an existing standard library which is already tested, debugged and used by others. This not only improves the efficiency of programmer but also reduces chances of adding new bugs in your code. Also using a standard library makes code readable and maintainable. </p>
<p>For instance Google has just released a new library <a rel="nofollow" target="_blank" href="http://code.google.com/p/google-collections/">Google Collections</a> that can be used if you want to add advance collection functionality in your code.</p>
<h3>Quote 7: Wherever possible try to use Primitive types instead of Wrapper classes</h3>
<p>Wrapper classes are great. But at same time they are slow. Primitive types are just values, whereas Wrapper classes are stores information about complete class. </p>
<p>Sometimes a programmer may add bug in the code by using wrapper due to oversight. For example, in below example:</p>
<pre class="brush: java;">
int x = 10;
int y = 10;

Integer x1 = new Integer(10);
Integer y1 = new Integer(10);

System.out.println(x == y);
System.out.println(x1 == y1);
</pre>
<p>The first sop will print true whereas the second one will print false. The problem is when comparing two wrapper class objects we cant use == operator. It will compare the reference of object and not its actual value. </p>
<p>Also if you are using a wrapper class object then never forget to initialize it to a default value. As by default all wrapper class objects are initialized to <code>null</code>. </p>
<pre class="brush: java;">
Boolean flag;

if(flag == true) {
	System.out.println(&quot;Flag is set&quot;);
} else {
	System.out.println(&quot;Flag is not set&quot;);
}
</pre>
<p>The above code will give a <code>NullPointerException</code> as it tries to box the values before comparing with true and as its null.</p>
<h3>Quote 8: Use Strings with utmost care.</h3>
<p>Always carefully use Strings in your code. A simple concatenation of strings can reduce performance of program. For example if we concatenate strings using + operator in a for loop then everytime + is used, it creates a new String object. This will affect both memory usage and performance time.</p>
<p>Also whenever you want to instantiate a String object, never use its constructor but always instantiate it directly. For example:</p>
<pre class="brush: java;">
//slow instantiation
String slow = new String(&quot;Yet another string object&quot;);

//fast instantiation
String fast = &quot;Yet another string object&quot;;
</pre>
<h3>Quote 9: Always return empty Collections and Arrays instead of null</h3>
<p>Whenever your method is returning a collection element or an array, always make sure you return <strong>empty</strong> array/collection and not <strong>null</strong>. This will save a lot of if else testing for null elements. For instance in below example we have a getter method that returns employee name. If the name is null it simply return blank string &#8220;&#8221;.</p>
<pre class="brush: java;">
public String getEmployeeName() {
	return (null==employeeName ? &quot;&quot;: employeeName);
}
</pre>
<h3>Quote 10: Defensive copies are savior</h3>
<p>Defensive copies are the clone objects created to avoid mutation of an object. For example in below code we have defined a Student class which has a private field birth date that is initialized when the object is constructed.</p>
<pre class="brush: java;">
public class Student {
	private Date birthDate;

	public Student(birthDate) {
		this.birthDate = birthDate;
	}

	public Date getBirthDate() {
		return this.birthDate;
	}
}
</pre>
<p>Now we may have some other code that uses the Student object.</p>
<pre class="brush: java;">
public static void main(String []arg) {

	Date birthDate = new Date();
	Student student = new Student(birthDate);

	birthDate.setYear(2019);

	System.out.println(student.getBirthDate());
}
</pre>
<p>In above code we just created a Student object with some default birthdate. But then we changed the value of year of the birthdate. Thus when we print the birth date, its year was changed to 2019!</p>
<p>To avoid such cases, we can use Defensive copies mechanism. Change the constructor of Student class to following.</p>
<pre class="brush: java;">
public Student(birthDate) {
	this.birthDate = new Date(birthDate);
}
</pre>
<p>This ensure we have another copy of birthdate that we use in Student class.</p>
<h2>Two bonus quotes</h2>
<p>Here are two bonus Java best practice quotes for you. </p>
<h4>Quote 11: Never let exception come out of finally block</h4>
<p>Finally blocks should never have code that throws exception. Always make sure finally clause does not throw exception. If you have some code in finally block that does throw exception, then log the exception properly and never let it come out :)</p>
<h4>Quote 12: Never throw &#8220;Exception&#8221; </h4>
<p>Never throw java.lang.Exception directly. It defeats the purpose of using checked Exceptions. Also there is no useful information getting conveyed in caller method.</p>
<h2>More Quotes from Java Developers</h2>
<p>Do you have a quote that is not included in above list? Well, feel free to add your Java best practice quote using comment below. Write your quote and explain it in 2-3 lines. I will add all those user generated quotes in this section.</p>
<h3>Quote #13: Avoid floating point numbers</h3>
<p>It is a bad idea to use floating point to try to represent exact quantities like monetary amounts. Using floating point for dollars-and-cents calculations is a recipe for disaster. Floating point numbers are best reserved for values such as measurements, whose values are fundamentally inexact to begin with. For calculations of monetary amounts it is better to use BigDecimal.</p>
<div id="relatedpost" style="background-color:#FFF1A8; padding:3px;"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2009/08/java-garbage-collection-simplified.html" title="Java Garbage Collection Simplified">Java Garbage Collection Simplified</a></li><li><a href="http://viralpatel.net/blogs/2009/07/protect-java-code-decompilation-using-java-obfuscator.html" title="Protect Java code from decompilation using Java Obfuscator">Protect Java code from decompilation using Java Obfuscator</a></li><li><a href="http://viralpatel.net/blogs/2009/05/getting-jvm-heap-size-used-memory-total-memory-using-java-runtime.html" title="Getting JVM heap size, used memory, total memory using Java Runtime">Getting JVM heap size, used memory, total memory using Java Runtime</a></li><li><a href="http://viralpatel.net/blogs/2009/01/decompile-class-file-java-decompiler-class-java-class.html" title="Decompile Java Class file using decompilers.">Decompile Java Class file using decompilers.</a></li><li><a href="http://viralpatel.net/blogs/2009/01/java-singleton-design-pattern-tutorial-example-singleton-j2ee-design-pattern.html" title="Java Singleton design pattern tutorial.">Java Singleton design pattern tutorial.</a></li><li><a href="http://viralpatel.net/blogs/2009/01/jvm-java-increase-heap-size-setting-heap-size-jvm-heap.html" title="Playing with JVM / Java Heap Size.">Playing with JVM / Java Heap Size.</a></li><li><a href="http://viralpatel.net/blogs/2009/01/tutorial-java-class-file-format-revealed.html" title="Tutorial: Java Class file format, revealed&#8230;">Tutorial: Java Class file format, revealed&#8230;</a></li><li><a href="http://viralpatel.net/blogs/2008/12/java-virtual-machine-an-inside-story.html" title="Java Virtual Machine, An inside story!!">Java Virtual Machine, An inside story!!</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/02/most-useful-java-best-practice-quotes-java-developers.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/02/most-useful-java-best-practice-quotes-java-developers.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/02/most-useful-java-best-practice-quotes-java-developers.html&amp;title=10 Most Useful Java Best Practice Quotes for Java Developers&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/02/most-useful-java-best-practice-quotes-java-developers.html&amp;title=10 Most Useful Java Best Practice Quotes for Java Developers" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/02/most-useful-java-best-practice-quotes-java-developers.html&amp;title=10 Most Useful Java Best Practice Quotes for Java Developers" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/02/most-useful-java-best-practice-quotes-java-developers.html&amp;title=10 Most Useful Java Best Practice Quotes for Java Developers" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>
<p><a href="http://feedads.g.doubleclick.net/~a/vDeYZWtDVUhq54fIsAWZtJQFS0w/0/da"><img src="http://feedads.g.doubleclick.net/~a/vDeYZWtDVUhq54fIsAWZtJQFS0w/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/vDeYZWtDVUhq54fIsAWZtJQFS0w/1/da"><img src="http://feedads.g.doubleclick.net/~a/vDeYZWtDVUhq54fIsAWZtJQFS0w/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=p5yPgzCJ59E:WUZdRbG9pew:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=p5yPgzCJ59E:WUZdRbG9pew:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=p5yPgzCJ59E:WUZdRbG9pew:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=p5yPgzCJ59E:WUZdRbG9pew:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=p5yPgzCJ59E:WUZdRbG9pew:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=p5yPgzCJ59E:WUZdRbG9pew:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=p5yPgzCJ59E:WUZdRbG9pew:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=p5yPgzCJ59E:WUZdRbG9pew:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=p5yPgzCJ59E:WUZdRbG9pew:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/02/most-useful-java-best-practice-quotes-java-developers.html/feed</wfw:commentRss>
		<slash:comments>22</slash:comments>
		<feedburner:origLink>http://viralpatel.net/blogs/2010/02/most-useful-java-best-practice-quotes-java-developers.html</feedburner:origLink></item>
		<item>
		<title>Some Useful Unix File Finding Commands</title>
		<link>http://feedproxy.google.com/~r/viralpatelnet/~3/7xOpVvAMKmI/some-useful-unix-file-finding-commands.html</link>
		<comments>http://viralpatel.net/blogs/2010/02/some-useful-unix-file-finding-commands.html#comments</comments>
		<pubDate>Thu, 04 Feb 2010 08:36:18 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[Unix Shell Script]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2010</guid>
		<description><![CDATA[Following are some bunch of commands that might be useful if you want to find files in unix/linux. 
Large Files
Find files larger than 10MB in the current directory downwards&#8230;

find . -size +10000000c -ls

Find files larger than 100MB&#8230;

find . -size +100000000c -ls

Old Files
Find files last modified over 30days ago&#8230;

find . -type f -mtime 30 -ls

Find files [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.viralpatel.net/2010/02/magnifying-glass-find-files-unix.jpg" alt="magnifying-glass-find-files-unix" title="magnifying-glass-find-files-unix" width="206" height="112" class="alignright size-full wp-image-2020" />Following are some bunch of commands that might be useful if you want to find files in unix/linux. </p>
<h2>Large Files</h2>
<p>Find files larger than 10MB in the current directory downwards&#8230;</p>
<pre class="brush: bash;">
find . -size +10000000c -ls
</pre>
<p>Find files larger than 100MB&#8230;</p>
<pre class="brush: bash;">
find . -size +100000000c -ls
</pre>
<h2>Old Files</h2>
<p>Find files last modified over 30days ago&#8230;</p>
<pre class="brush: bash;">
find . -type f -mtime 30 -ls
</pre>
<p>Find files last modified over 365days ago&#8230;</p>
<pre class="brush: bash;">
find . -type f -mtime 365 -ls
</pre>
<p>Find files last accessed over 30days ago&#8230;</p>
<pre class="brush: bash;">
find . -type f -atime 30 -ls
</pre>
<p>Find files last accessed over 365days ago&#8230;</p>
<pre class="brush: bash;">
find . -type f -atime 365 -ls
</pre>
<h2>Find Recently Updated Files</h2>
<p>There have been instances where a runaway process is seemingly using  up any and all space left on a partition. Finding the culprit file is  always useful.</p>
<p>If the file is being updated at the current time  then we can use find to find files modified in the last day&#8230;</p>
<pre class="brush: bash;">
find  . -type f -mtime -1 -ls
</pre>
<p>Better still, if we know a file is being  written to now, we can touch a file and ask the find command to list  any files updated after the timestamp of that file, which will logically  then list the rogue file in question.</p>
<pre class="brush: bash;">
touch testfile
find .  -type f -newer testfile -ls
</pre>
<h2>Finding tar Files</h2>
<p>A clean up of redundant tar (backup) files, after completing a piece of work say, is sometimes forgotten. Conversely, if tar files are needed, they can be identified and duly compressed (using compress or gzip) if not already done so, to help save space. Either way, the following lists all tar files for review.</p>
<pre class="brush: bash;">
find . -type f -name &quot;*.tar&quot; -ls
find . -type f -name &quot;*.tar.Z&quot; -ls
</pre>
<h2>Large Directories</h2>
<p>List, in order, the largest sub-directories (units are in Kb)&#8230;</p>
<pre class="brush: bash;">
du -sk * | sort -n
</pre>
<p>Sometimes it is useful to then cd into that suspect directory and re-run the du command until the large files are found.</p>
<h2>Removing Files using Find</h2>
<p>The above find commands can be edited to remove the files found rather than list them. The &#8220;-ls&#8221; switch can be changed for &#8220;-exec rm {}\;&#8221;=.</p>
<p>e.g.</p>
<pre class="brush: bash;">
find . -type f -mtime 365 -exec rm {} \;
</pre>
<p>Running the command with the &#8220;-ls&#8221; switch first, is always prudent to see what will be removed.</p>
<p>The &#8220;-ls&#8221; switch prints out summary information about the file (like owner and permissions). If just the filename is required then swap &#8220;-ls&#8221; switch for &#8220;-print&#8221;.</p>
<p>Are you using different commands to find a file? Please share it using below comment form. :)</p>
<div id="relatedpost" style="background-color:#FFF1A8; padding:3px;"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2010/01/unix-shell-script-line-ending-executable-issue-subversion.html" title="Unix Shell Script Line Ending &#038; Executable Issue with Subversion">Unix Shell Script Line Ending &#038; Executable Issue with Subversion</a></li><li><a href="http://viralpatel.net/blogs/2009/11/shell-script-replace-text-variables-multiple-files-unix.html" title="Replace Text in Variables &#038; Single/Multiple-Files in UNIX">Replace Text in Variables &#038; Single/Multiple-Files in UNIX</a></li><li><a href="http://viralpatel.net/blogs/2009/08/shell-script-rename-moving-files-unix.html" title="Shell Script to Rename &#038; Move files in Unix">Shell Script to Rename &#038; Move files in Unix</a></li><li><a href="http://viralpatel.net/blogs/2009/08/generate-random-number-unix-shell-script.html" title="Generate Random Number in UNIX Shell Script">Generate Random Number in UNIX Shell Script</a></li><li><a href="http://viralpatel.net/blogs/2009/07/writing-functions-in-shell-script.html" title="Writing Functions in Shell Script">Writing Functions in Shell Script</a></li><li><a href="http://viralpatel.net/blogs/2009/05/how-to-execute-command-prompt-command-view-output-java.html" title="How to execute a command prompt command &#038; view output in Java">How to execute a command prompt command &#038; view output in Java</a></li><li><a href="http://viralpatel.net/blogs/2008/12/how-to-reset-mysql-root-password.html" title="How to: Reset MySQL root password">How to: Reset MySQL root password</a></li><li><a href="http://viralpatel.net/blogs/2008/11/conversion-of-text-file-in-pdf-and-vice-versa-in-unix.html" title="Conversion of text file in PDF and vice versa in UNIX">Conversion of text file in PDF and vice versa in UNIX</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/02/some-useful-unix-file-finding-commands.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/02/some-useful-unix-file-finding-commands.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/02/some-useful-unix-file-finding-commands.html&amp;title=Some Useful Unix File Finding Commands&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/02/some-useful-unix-file-finding-commands.html&amp;title=Some Useful Unix File Finding Commands" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/02/some-useful-unix-file-finding-commands.html&amp;title=Some Useful Unix File Finding Commands" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/02/some-useful-unix-file-finding-commands.html&amp;title=Some Useful Unix File Finding Commands" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>
<p><a href="http://feedads.g.doubleclick.net/~a/I04JI1pyUTcqt-Vl2MwvjIUHAJM/0/da"><img src="http://feedads.g.doubleclick.net/~a/I04JI1pyUTcqt-Vl2MwvjIUHAJM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/I04JI1pyUTcqt-Vl2MwvjIUHAJM/1/da"><img src="http://feedads.g.doubleclick.net/~a/I04JI1pyUTcqt-Vl2MwvjIUHAJM/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=7xOpVvAMKmI:anVtsRDO3dc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=7xOpVvAMKmI:anVtsRDO3dc:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=7xOpVvAMKmI:anVtsRDO3dc:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=7xOpVvAMKmI:anVtsRDO3dc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=7xOpVvAMKmI:anVtsRDO3dc:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=7xOpVvAMKmI:anVtsRDO3dc:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=7xOpVvAMKmI:anVtsRDO3dc:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=7xOpVvAMKmI:anVtsRDO3dc:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=7xOpVvAMKmI:anVtsRDO3dc:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/02/some-useful-unix-file-finding-commands.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://viralpatel.net/blogs/2010/02/some-useful-unix-file-finding-commands.html</feedburner:origLink></item>
		<item>
		<title>Step by step Guide to Crack WinRAR</title>
		<link>http://feedproxy.google.com/~r/viralpatelnet/~3/DEAVOr4FLiw/step-by-step-guide-to-crack-winrar.html</link>
		<comments>http://viralpatel.net/blogs/2010/02/step-by-step-guide-to-crack-winrar.html#comments</comments>
		<pubDate>Wed, 03 Feb 2010 11:25:43 +0000</pubDate>
		<dc:creator>Rishabh Dangwal</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[cracking]]></category>
		<category><![CDATA[hacked]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2018</guid>
		<description><![CDATA[Hi folks, its been a long time since I have posted some thing technical, so I will be writing about the challenge I got at NIT KU, where I cracked WinRAR 3.80 using a disassembler and will tell you the same here. You can crack any version of WinRAR using this method and need not [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.viralpatel.net/2010/02/image001.jpg" alt="" title="image001" class="alignright size-full wp-image-2019" />Hi folks, its been a long time since I have posted some thing technical, so I will be writing about the challenge I got at NIT KU, where I cracked WinRAR 3.80 using a disassembler and will tell you the same here. You can crack any version of WinRAR using this method and need not to pay for the registration fee and you can do this all by your self, easily. Furthermore, major software are cracked using the same way,but just get a bit complex in the methodology. This tutorial is intended for those who are new to cracking and disassembling.</p>
<p><em><strong>Disclaimer – By Reading this tutorial You agree that this tutorial is intended for educational purposes only and the author can not be held liable for any kind of damages done whatsoever to your machine, or damages caused by some other, creative application of this tutorial.</p>
<p>In any case you disagree with the above statement, stop here.<br />
</strong></em></p>
<h2>The Tools</h2>
<p>To perform this hack you will be needing -</p>
<ol>
<li>Any De-assembler (I use Hackers Disassembler and Hview ) </li>
<li>Resource Hacker </li>
<li>A patch Creator ( Use Universal Patch Creator or Code fusion) </li>
</ol>
<p>You will be able to get them by <a rel="nofollow" href="http://rdhacker.blogspot.com/search/label/Google">googling</a> or you can download my set of tools provided.</p>
<h2>How to Crack ?</h2>
<p>You need to have a bit knowledge of assembly language,and in case you don&#8217;t have it,just cram the steps and it will work anytime,every time. Download the latest version of WinRAR from their website and install it.<br />
I will be cracking Winrar 3.80 here (cuz I already have it:P ). This is basically a 2 step process ( 4 step ,if you want to do things with a professional touch,period) .</p>
<p><img src="http://img.viralpatel.net/2010/02/image002.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>Now copy the WinRAR.exe file to desktop. Make a copy of it there. </p>
<h3>Step 1 – Hunting for Memory Address</h3>
<p>Now load Hackers Disasembler and load the copy in it.<br />
<img src="http://img.viralpatel.net/2010/02/image003.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>The Disassembler will disassemble the executable in assembly code. Now you need to search for strings that are used in WinRAR program. Press Ctrl + F and type “evaluation” without quotes and search in the assembly code. Hit enter&#8230;<br />
<img src="http://img.viralpatel.net/2010/02/image004.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>After you have reached this block of code by searching, just look at the block of code above it. There you will find that some assembly values are being compared and then code is jumped to some other function. Now see carefully, the “evaluation copy” function must be invoked after some specific condition is met. We need to look for it at the code and the make certain changes to the condition so that the program doesn&#8217;t checks for the condition.<br />
<img src="http://img.viralpatel.net/2010/02/image006.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>In the above code you can see this code -</p>
<pre>
00444B6A: 803DF4B84B0000 cmp byte ptr [004BB8F4], 00
00444B71: 0F859B000000 JNE 00444C12
</pre>
<p>This is the code responsible for validating you as a legal user :) . Just note down the memory address that leads to jump (JNE) at some memory location. In this case, note down 00444B71.</p>
<p>Note : For any WinRAR version, this code and memory address might be different,but the JNE will be same. Just note down the respective memory address that checks.</p>
<p>Now you need to search for the code that brings that ugly nag screen “Please purchase WinRAR license” after your trial period of 40 days is over. For this,look over your toolbar and click on “D” which stands for looking for Dialog references.</p>
<p><img src="http://img.viralpatel.net/2010/02/image007.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>Now in the dialog box that opens,search for “please” and you will get the reference as -<br />
ID-REMINDER, “Please purchase WinRAR license”<br />
<img src="http://img.viralpatel.net/2010/02/image008.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>Double click on it and you will reach the subsequent code.<br />
<img src="http://img.viralpatel.net/2010/02/image009.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>The code will be something like</p>
<pre>
* String: “REMINDER”
0048731A: 68EB5E4B00 push 004B5EEB
</pre>
<p>Just note the memory address that invokes the REMINDER dialog. In this case its 0048731A. Note it down.<br />
<em>Note : For any WinRAR version, this code and memory address might be different.But the Reminder Memory address code will always PUSH something. Just note down the respective memory address that PUSH ‘s.</em></p>
<h3>Step 2 – Fixing and Patching</h3>
<p>Now in this step we will be patching up values of memory addresses we noted earlier. I will be doing this using HVIEW.<br />
Now load the copy you disassembled in Hacker’s Disassembler in Hview.<br />
<img src="http://img.viralpatel.net/2010/02/image010.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>After you have loaded it, you will see the code is unreadable. Its just like opening an EXE file in notepad. You need to decode it. To do that, just press F4 and yoiu will get an option to decode it. Hit DECODE and you will be able to see code in the form of assembly code and memory addresses.<br />
<img src="http://img.viralpatel.net/2010/02/image011.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>After you have done that, you need to search for memory addresses you noted down earlier. Just hit F5 and a search box will be there. Now you need to enter the memory address. To do that, enter a “.” and the type memory address neglecting the earlier “00” . The “.” will suffice for “00”. ie -<br />
Type .444B71 in place of 00444B71<br />
<img src="http://img.viralpatel.net/2010/02/image012.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>and search in the code.<br />
<img src="http://img.viralpatel.net/2010/02/image013.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>After you have reached the respective code, you need to make changes to it. Press F3 and you will be able to edit the code.Now make the following changes &#8211;<br />
<img src="http://img.viralpatel.net/2010/02/image014.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>After you have done it, save it by pressing F9.<br />
Now search for next memory location by pressing F5 and entering it. Reach there and make the following changes by pressing F3 -<br />
<img src="http://img.viralpatel.net/2010/02/image015.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>Save the changes by pressing F9 and exit HVIEW by pressing F10.<br />
Congrats&#8230;You have cracked WinRAR :) Replace the original WinRAR.exe with this copyofwinrar.exe by renaming it. It will work 100% fine :P</p>
<h3>Step 3 – Spicing up the EXE</h3>
<p>Now U have a 100% working version of EXE, you might want to change your registration information in WinRAR. TO do this, you can use Resource hacker.<br />
<img src="http://img.viralpatel.net/2010/02/image016.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>Launch Resource Hacker, load the copyofwinrar.exe in it<br />
<img src="http://img.viralpatel.net/2010/02/image017.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>Now go to DIALOG –> Expand tree –> ABOUTRARDLG and click it. Now Find Trial copy line and replace it with your favorite one :P<br />
<img src="http://img.viralpatel.net/2010/02/image018.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>and click on Compile Script button.<br />
<img src="http://img.viralpatel.net/2010/02/image019.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>Now save the file with any name on your desktop or any location what so ever.<br />
<img src="http://img.viralpatel.net/2010/02/image020.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>Now you have a fully patched WinRAR.exe file :)) you can either use it, or also can distribute it like a real cracker. If you want to learn that, move on to next step.</p>
<h3>Step 4 – Creating a working Patch (or giving Professional touch :P )</h3>
<p>I will be using diablo2oo2&#8217;s Universal Patcher (UPE) for creating the patch. The patch will work like any authentic one for that WinRAR version. Just like the one U downloaded at anytime of your life from any Crack and Keygen website.<br />
Launch Patch Creator and click on add new project. Enter project Information and click on save.<br />
<img src="http://img.viralpatel.net/2010/02/image021.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>Click on Add – > Offset patch<br />
<img src="http://img.viralpatel.net/2010/02/image022.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>After you have done that, double click on offset patch and then </p>
<ol>
<li>Give path of original winrar.exe </li>
<li>Give path of unmodified Winrar.exe (again) </li>
<li>Give path for fully patched Winrar.exe (ie Cracked Winrar.exe in this case) </li>
<li>Click on compare and it will show difference between both files </li>
<li>Click on save. </li>
</ol>
<p><img src="http://img.viralpatel.net/2010/02/image023.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>Now in the next window, click on Create Patch and save it. The Patch will be created. Now copy it in WinRAR installation directory and hit on patch, it WILL<br />
<img src="http://img.viralpatel.net/2010/02/image024.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>Congrats you have created a patch of your own and have learned to crack WinRAR :)<br />
<img src="http://img.viralpatel.net/2010/02/image025.jpg" alt="" title="image001" class="aligncenter size-full wp-image-2019" /></p>
<p>You can crack other software in the same way…just practice, debug and disassemble and you will get the way :)</p>
<p><em>[PS: The above is the long way to do it, I will be telling you the shortest way to crack WinRAR in just 1 step, the main aim of this tutorial was to introduce you to disassemblers and tools, and do some dirty work with your hand. ]<br />
</em></p>
<p>Cheers</p>
<style type="text/css">
#author-info{font-family:Helvetica,Arial,Helvetica,sans-serif; width:650px; height:130px; background-color:#f4f4f4; border:1px solid #eee}
#author-info #a-pic{width:90px; height:75%; display:inline; float:left; padding:15px}
#author-info #a-pic #a-avatar{border-bottom:1px solid #999; border-right:1px solid #999; padding:2px; background-color:white; height:80px; width:80px}
#author-info #a-pic #a-avatar img{border:0px solid; padding:0px}
#author-info #a-details{width:520px; height:75%; display:inline; float:right; padding:15px 10px 0px 0px}
#author-info #a-details #a-about{color:#0C3FC4; font-size:1.13em; font-weight:bold; margin-bottom:3px}
#author-info #a-details #a-det{font-size:14px}
</style>
<div id="author-info">
<div id="a-pic">
<div id="a-avatar">
	<img src="http://img.viralpatel.net/author/rishabh-dangwal.jpg" />
	</div>
</div>
<div id="a-details">
<div id="a-about">
		About the Author
	</div>
<div id="a-det">
	<a href="http://www.prohack.in" rel="nofollow" target="_blank">Rishabh Dangwal</a> is a freelance security consultant, technoblogger and a student pursuing engineering. His tastes include fiddling with every possible piece of computers and technology he could get his hands on and sharing them to the world.
	</div>
</div>
</div>
<div id="relatedpost" style="background-color:#FFF1A8; padding:3px;"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2010/01/google-takes-china-stop-censoring.html" title="Google Takes on China; Will Stop Censoring Results">Google Takes on China; Will Stop Censoring Results</a></li><li><a href="http://viralpatel.net/blogs/2010/01/simplest-virus-fork-bomb.html" title="Simplest Virus – Fork Bomb">Simplest Virus – Fork Bomb</a></li><li><a href="http://viralpatel.net/blogs/2010/01/hacking-wifi-network-using-backtrack.html" title="Hacking Wifi Network Using BackTrack">Hacking Wifi Network Using BackTrack</a></li><li><a href="http://viralpatel.net/blogs/2009/09/how-to-create-ie-specific-css-stylesheet.html" title="How To: Create an IE Specific Stylesheet">How To: Create an IE Specific Stylesheet</a></li><li><a href="http://viralpatel.net/blogs/2009/04/omg-salma-hayek-apple-mobileme-account-hacked.html" title="OMG: Salma Hayek&#8217;s Apple MobileMe account Hacked!!">OMG: Salma Hayek&#8217;s Apple MobileMe account Hacked!!</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/02/step-by-step-guide-to-crack-winrar.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/02/step-by-step-guide-to-crack-winrar.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/02/step-by-step-guide-to-crack-winrar.html&amp;title=Step by step Guide to Crack WinRAR&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/02/step-by-step-guide-to-crack-winrar.html&amp;title=Step by step Guide to Crack WinRAR" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/02/step-by-step-guide-to-crack-winrar.html&amp;title=Step by step Guide to Crack WinRAR" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/02/step-by-step-guide-to-crack-winrar.html&amp;title=Step by step Guide to Crack WinRAR" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>
<p><a href="http://feedads.g.doubleclick.net/~a/j5Vg_zes36eBsbRhwVTf8eJ3f_g/0/da"><img src="http://feedads.g.doubleclick.net/~a/j5Vg_zes36eBsbRhwVTf8eJ3f_g/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/j5Vg_zes36eBsbRhwVTf8eJ3f_g/1/da"><img src="http://feedads.g.doubleclick.net/~a/j5Vg_zes36eBsbRhwVTf8eJ3f_g/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=DEAVOr4FLiw:ET5kX7bAkYg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=DEAVOr4FLiw:ET5kX7bAkYg:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=DEAVOr4FLiw:ET5kX7bAkYg:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=DEAVOr4FLiw:ET5kX7bAkYg:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=DEAVOr4FLiw:ET5kX7bAkYg:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=DEAVOr4FLiw:ET5kX7bAkYg:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=DEAVOr4FLiw:ET5kX7bAkYg:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=DEAVOr4FLiw:ET5kX7bAkYg:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=DEAVOr4FLiw:ET5kX7bAkYg:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/02/step-by-step-guide-to-crack-winrar.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://viralpatel.net/blogs/2010/02/step-by-step-guide-to-crack-winrar.html</feedburner:origLink></item>
		<item>
		<title>Did Twitter Forget to Update its Copyright Year?</title>
		<link>http://feedproxy.google.com/~r/viralpatelnet/~3/OEK_Zo81H1A/did-twitter-forget-to-update-copyright-year.html</link>
		<comments>http://viralpatel.net/blogs/2010/02/did-twitter-forget-to-update-copyright-year.html#comments</comments>
		<pubDate>Sun, 31 Jan 2010 21:50:55 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[tech stories]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2014</guid>
		<description><![CDATA[I noticed a strange thing today on Twitter&#8217;s homepage. Its already end of the first month of 2010 and Twitter&#8217;s homepage is still showing Copyright year 2009!! I don&#8217;t know if they have done this purposefully or just forgot to update the year. See the below screenshot.

I am not an expert in Copyright matters, but [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.viralpatel.net/twitter-logo.png" alt="twitter logo" title="twitter-logo" width="201" height="63" class="alignleft size-full wp-image-579" />I noticed a strange thing today on Twitter&#8217;s <a href="http://twitter.com">homepage</a>. Its already end of the first month of 2010 and Twitter&#8217;s homepage is still showing Copyright year 2009!! I don&#8217;t know if they have done this purposefully or just forgot to update the year. See the below screenshot.</p>
<p><a href="http://img.viralpatel.net/2010/02/twitter-copyright.png" target="_blank"><img src="http://img.viralpatel.net/2010/02/twitter-copyright-thumb.png" alt="twitter-copyright" title="twitter-copyright" width="512" height="308" class="aligncenter size-full wp-image-2015" /></a></p>
<p>I am not an expert in Copyright matters, but we know that every website <a target="_blank" rel="nofollow" href="http://www.seomoz.org/ugc/update-the-copyright-year-on-your-website">should change</a> its Copyright year when a new year is started. Also it is <a rel="nofollow" target="_blank" href="http://www.lunametrics.com/aboutus/archives/WebsiteCopyrightDate.php">not a compulsory</a> thing to do so, but it is always advisable when your homepage is not just a static page showing some static tag, but showing realtime Trends. Like in the screenshot you will notice the Twitter’s homepage is showing latest trends such as <strong>Haiti</strong>, <strong>iPad</strong>, <strong>Serena Williams</strong> etc.</p>
<p>Just to make sure this is not just a case with me, I tried to view Twitter’s homepage using a web proxy. I wanted to try new IP and see if this is same with everyone. I tried 2-3 web proxies and it all gave me same result. The copyright year on Twitter’s homepage is 2009 for everyone.</p>
<p>As expected I couldn’t find &copy; 2009 on a single popular social network/online websites. I tried Facebook, Google, Linkedin, Myspace, Orkut, AOL, Microsoft.com, Yahoo, Friendfeed etc but all of them have updated the copyright year to 2010. Surprisingly the Mixer Labs Geo API service <a rel="nofollow" target="_blank" href="http://www.geoapi.com/">Geo API</a> which Twitter <a rel="nofollow" target="_blank" href=” http://www.techcrunch.com/2009/12/23/twitter-acquires-mixer-labs/”>recently acquired</a> also have copyright year 2009!!! </p>
<p>Well in case Twitter has really missed to update its Copyright year, here is simple PHP script they must use to update their copyright automatically ;)</p>
<pre class="brush: php;">
&amp;copy; &lt;?php echo date(’Y'); ?&gt; Twitter
</pre>
<p>I couldn’t find a single reason to think that Twitter has deliberately left Copyright year to 2009.</p>
<p>What do you guys have to say about this? Does Twitter has deliberately left copyright year to 2009 or did they just forget it?</p>
<div id="relatedpost" style="background-color:#FFF1A8; padding:3px;"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2009/08/pillows-try-social-media-pillow.html" title="Pillows for you: Try these Social Media Pillow">Pillows for you: Try these Social Media Pillow</a></li><li><a href="http://viralpatel.net/blogs/2009/04/breaking-news-twitter-hit-by-stalkdaily-virus.html" title="Breaking News: Twitter hit by StalkDaily Virus">Breaking News: Twitter hit by StalkDaily Virus</a></li><li><a href="http://viralpatel.net/blogs/2010/01/apple-tablet-ipad-video.html" title="Finally Apple Unveiled its Tablet, The iPad (Video)">Finally Apple Unveiled its Tablet, The iPad (Video)</a></li><li><a href="http://viralpatel.net/blogs/2009/11/go-google-programming-language.html" title="GO: Google Launches its own Programming Language">GO: Google Launches its own Programming Language</a></li><li><a href="http://viralpatel.net/blogs/2009/11/following-viralpatelnet.html" title="Following @viralpatelnet">Following @viralpatelnet</a></li><li><a href="http://viralpatel.net/blogs/2009/11/google-wave-fail-whale.html" title="Google Wave has its own Fail Whale">Google Wave has its own Fail Whale</a></li><li><a href="http://viralpatel.net/blogs/2009/08/display-twitter-user-image-on-your-blogwebsite-in-2-minutes.html" title="Display Twitter User Image on your Blog/Website in 2 Minutes">Display Twitter User Image on your Blog/Website in 2 Minutes</a></li><li><a href="http://viralpatel.net/blogs/2009/08/if-twitter-consisted-of-100-people.html" title="If Twitter Consisted of 100 People!">If Twitter Consisted of 100 People!</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/02/did-twitter-forget-to-update-copyright-year.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/02/did-twitter-forget-to-update-copyright-year.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/02/did-twitter-forget-to-update-copyright-year.html&amp;title=Did Twitter Forget to Update its Copyright Year?&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/02/did-twitter-forget-to-update-copyright-year.html&amp;title=Did Twitter Forget to Update its Copyright Year?" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/02/did-twitter-forget-to-update-copyright-year.html&amp;title=Did Twitter Forget to Update its Copyright Year?" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/02/did-twitter-forget-to-update-copyright-year.html&amp;title=Did Twitter Forget to Update its Copyright Year?" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>
<p><a href="http://feedads.g.doubleclick.net/~a/-pZ4mXoJaxtN39sQlCC4ZnC6v7g/0/da"><img src="http://feedads.g.doubleclick.net/~a/-pZ4mXoJaxtN39sQlCC4ZnC6v7g/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/-pZ4mXoJaxtN39sQlCC4ZnC6v7g/1/da"><img src="http://feedads.g.doubleclick.net/~a/-pZ4mXoJaxtN39sQlCC4ZnC6v7g/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=OEK_Zo81H1A:0Ww-kp08NqM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=OEK_Zo81H1A:0Ww-kp08NqM:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=OEK_Zo81H1A:0Ww-kp08NqM:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=OEK_Zo81H1A:0Ww-kp08NqM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=OEK_Zo81H1A:0Ww-kp08NqM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=OEK_Zo81H1A:0Ww-kp08NqM:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=OEK_Zo81H1A:0Ww-kp08NqM:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=OEK_Zo81H1A:0Ww-kp08NqM:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=OEK_Zo81H1A:0Ww-kp08NqM:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/02/did-twitter-forget-to-update-copyright-year.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://viralpatel.net/blogs/2010/02/did-twitter-forget-to-update-copyright-year.html</feedburner:origLink></item>
		<item>
		<title>Finally Apple Unveiled its Tablet, The iPad (Video)</title>
		<link>http://feedproxy.google.com/~r/viralpatelnet/~3/-PJFfuylKQc/apple-tablet-ipad-video.html</link>
		<comments>http://viralpatel.net/blogs/2010/01/apple-tablet-ipad-video.html#comments</comments>
		<pubDate>Wed, 27 Jan 2010 22:46:54 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[tech stories]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2009</guid>
		<description><![CDATA[
After months of speculations and rumors its finally here. Apple has added another weapon in its arsenal, the iPad. 
In a grand Apple press conference at the Yerba Buena Center for the Arts in San Francisco today, Apple&#8217;s very own Steve Jobs unveiled the iPad. It features multi-touch interaction with multimedia formats including newspapers, magazines, [...]]]></description>
			<content:encoded><![CDATA[<p><img alt="" src="http://cdn.mashable.com/wp-content/uploads/2010/01/ipad-website-top.jpg" class="alignright" width="260" height="190" /><br />
After months of speculations and rumors its finally here. Apple has added another weapon in its arsenal, the <a rel="nofollow" href="http://www.apple.com/ipad/">iPad</a>. </p>
<p>In a grand Apple press conference at the Yerba Buena Center for the Arts in San Francisco today, Apple&#8217;s very own Steve Jobs unveiled the iPad. It features multi-touch interaction with multimedia formats including newspapers, magazines, ebooks, textbooks, photos, videos, music, word processing documents, spreadsheets, video games, all existing iPhone OS apps, and internet browsing. The device incorporates an LED-backlit 9.7-inch (25 cm) multi-touch in-plane switching display running at XGA resolution made by Innolux, a subsidiary of Foxconn. Pricing for models in the United States ranges from US$499 to $829 depending on the amount of memory and inclusion of 3G access.</p>
<p>The iPad is slated to be available for sale in the United States at the end of March (WiFi version) and end of April (Wifi and 3G version) 2010. International 3G prices are to be announced summer 2010.</p>
<p>Following are some features of iPad.</p>
<ul>
<li>1GHz Apple A4 processor (custom)</li>
<li>0.5″ thick</li>
<li>1.5 pounds</li>
<li>9.7″ Capacitive touchscreen (1024×768)</li>
<li>16-64GB of SSD storage</li>
<li>3G available but not in all iPads</li>
<li>$14.99 for 250MB, $29.99 for unlimited data on AT&#038;T (no contract)</li>
<li>3G iPads are unlocked, have GSM micro SIMs</li>
<li>Accelerometer, Compass</li>
<li>802.11n and Bluetooth 2.1</li>
<li>Runs iPhone apps in window or pixel doubling</li>
<li>Hardware-accelerated OpenGL graphics</li>
<li>SDK out today</li>
<li>$499 for 16GB base model, $830 for all maxed out</li>
<li>Dock with hard keyboard available</li>
</ul>
<p>Following is the Apple&#8217;s official iPad commercial.</p>
<p><embed src="http://v.wordpress.com/wp-content/plugins/video/flvplayer.swf?ver=1.15" type="application/x-shockwave-flash" width="640" height="362" allowscriptaccess="always" allowfullscreen="true" flashvars="guid=DnLiyQ9N&amp;width=640&amp;height=362&amp;qc_publisherId=p-18-mFEk4J448M" title=""></embed></p>
<div id="relatedpost" style="background-color:#FFF1A8; padding:3px;"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2009/04/omg-salma-hayek-apple-mobileme-account-hacked.html" title="OMG: Salma Hayek&#8217;s Apple MobileMe account Hacked!!">OMG: Salma Hayek&#8217;s Apple MobileMe account Hacked!!</a></li><li><a href="http://viralpatel.net/blogs/2010/02/did-twitter-forget-to-update-copyright-year.html" title="Did Twitter Forget to Update its Copyright Year?">Did Twitter Forget to Update its Copyright Year?</a></li><li><a href="http://viralpatel.net/blogs/2009/11/go-google-programming-language.html" title="GO: Google Launches its own Programming Language">GO: Google Launches its own Programming Language</a></li><li><a href="http://viralpatel.net/blogs/2009/11/google-wave-fail-whale.html" title="Google Wave has its own Fail Whale">Google Wave has its own Fail Whale</a></li><li><a href="http://viralpatel.net/blogs/2009/08/pillows-try-social-media-pillow.html" title="Pillows for you: Try these Social Media Pillow">Pillows for you: Try these Social Media Pillow</a></li><li><a href="http://viralpatel.net/blogs/2009/07/vanish-this-message-self-destruct-vanish-protocol.html" title="This Message will Self-Destruct: Vanish, Self-Destruct digital data">This Message will Self-Destruct: Vanish, Self-Destruct digital data</a></li><li><a href="http://viralpatel.net/blogs/2009/07/youtube-experimenting-3d-videos.html" title="YouTube Experimenting with 3D videos!">YouTube Experimenting with 3D videos!</a></li><li><a href="http://viralpatel.net/blogs/2009/07/precrime-minority-report-real-facebook-england.html" title="Pre-crime &#038; Minority Report turns real through Facebook in England">Pre-crime &#038; Minority Report turns real through Facebook in England</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/01/apple-tablet-ipad-video.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/01/apple-tablet-ipad-video.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/01/apple-tablet-ipad-video.html&amp;title=Finally Apple Unveiled its Tablet, The iPad (Video)&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/01/apple-tablet-ipad-video.html&amp;title=Finally Apple Unveiled its Tablet, The iPad (Video)" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/01/apple-tablet-ipad-video.html&amp;title=Finally Apple Unveiled its Tablet, The iPad (Video)" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/01/apple-tablet-ipad-video.html&amp;title=Finally Apple Unveiled its Tablet, The iPad (Video)" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>
<p><a href="http://feedads.g.doubleclick.net/~a/qCCakdvNa-XpPCQbFxMWzLcpLMI/0/da"><img src="http://feedads.g.doubleclick.net/~a/qCCakdvNa-XpPCQbFxMWzLcpLMI/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/qCCakdvNa-XpPCQbFxMWzLcpLMI/1/da"><img src="http://feedads.g.doubleclick.net/~a/qCCakdvNa-XpPCQbFxMWzLcpLMI/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=-PJFfuylKQc:Cl3JuWY2EXE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=-PJFfuylKQc:Cl3JuWY2EXE:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=-PJFfuylKQc:Cl3JuWY2EXE:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=-PJFfuylKQc:Cl3JuWY2EXE:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=-PJFfuylKQc:Cl3JuWY2EXE:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=-PJFfuylKQc:Cl3JuWY2EXE:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=-PJFfuylKQc:Cl3JuWY2EXE:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=-PJFfuylKQc:Cl3JuWY2EXE:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=-PJFfuylKQc:Cl3JuWY2EXE:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/01/apple-tablet-ipad-video.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://viralpatel.net/blogs/2010/01/apple-tablet-ipad-video.html</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 0.436 seconds. --><!-- Cached page generated by WP-Super-Cache on 2010-03-14 22:43:04 -->
