<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Suhas&#039;s Java Blog</title>
	<atom:link href="http://suhasjavablog.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://suhasjavablog.wordpress.com</link>
	<description>I&#039;d explain it to you, but your brain would explode.</description>
	<lastBuildDate>Sun, 01 Jan 2012 03:22:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='suhasjavablog.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/dd9e25cdf053787ea34d00aa5544e92f?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Suhas&#039;s Java Blog</title>
		<link>http://suhasjavablog.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://suhasjavablog.wordpress.com/osd.xml" title="Suhas&#039;s Java Blog" />
	<atom:link rel='hub' href='http://suhasjavablog.wordpress.com/?pushpress=hub'/>
		<item>
		<title>2011 in review</title>
		<link>http://suhasjavablog.wordpress.com/2012/01/01/2011-in-review/</link>
		<comments>http://suhasjavablog.wordpress.com/2012/01/01/2011-in-review/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 03:22:34 +0000</pubDate>
		<dc:creator>ShamanOfJava</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://suhasjavablog.wordpress.com/?p=496</guid>
		<description><![CDATA[The WordPress.com stats helper monkeys prepared a 2011 annual report for this blog. Here&#8217;s an excerpt: A San Francisco cable car holds 60 people. This blog was viewed about 2,800 times in 2011. If it were a cable car, it would take about 47 trips to carry that many people. Click here to see the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=suhasjavablog.wordpress.com&amp;blog=8252942&amp;post=496&amp;subd=suhasjavablog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The WordPress.com stats helper monkeys prepared a 2011 annual report for this blog.</p>
<div style="background:url('/wp-content/mu-plugins/annual-reports/img/emailteaser.jpg') no-repeat center center;height:300px;"></div>
<p>Here&#8217;s an excerpt:</p>
<blockquote><p>A San Francisco cable car holds 60 people. This blog was viewed about <strong>2,800</strong> times in 2011. If it were a cable car, it would take about 47 trips to carry that many people.</p></blockquote>
<p><a href="/2011/annual-report/">Click here to see the complete report.</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/suhasjavablog.wordpress.com/496/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/suhasjavablog.wordpress.com/496/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/suhasjavablog.wordpress.com/496/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/suhasjavablog.wordpress.com/496/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/suhasjavablog.wordpress.com/496/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/suhasjavablog.wordpress.com/496/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/suhasjavablog.wordpress.com/496/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/suhasjavablog.wordpress.com/496/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/suhasjavablog.wordpress.com/496/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/suhasjavablog.wordpress.com/496/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/suhasjavablog.wordpress.com/496/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/suhasjavablog.wordpress.com/496/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/suhasjavablog.wordpress.com/496/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/suhasjavablog.wordpress.com/496/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=suhasjavablog.wordpress.com&amp;blog=8252942&amp;post=496&amp;subd=suhasjavablog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://suhasjavablog.wordpress.com/2012/01/01/2011-in-review/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0c9df61121797c71b3de813e8e55fee6?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">ShamanOfJava</media:title>
		</media:content>
	</item>
		<item>
		<title>How to deal with multiple spring configuration files?</title>
		<link>http://suhasjavablog.wordpress.com/2011/12/09/how-to-deal-with-multiple-spring-configuration-files/</link>
		<comments>http://suhasjavablog.wordpress.com/2011/12/09/how-to-deal-with-multiple-spring-configuration-files/#comments</comments>
		<pubDate>Fri, 09 Dec 2011 06:54:01 +0000</pubDate>
		<dc:creator>ShamanOfJava</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://suhasjavablog.wordpress.com/?p=482</guid>
		<description><![CDATA[We often use a separate spring config file for each layer in our project &#8211; say springConfig-delegate.xml for the delegate layer, springConfig-service.xml for the service layer and springConfig-dao.xml for the dao layer. Normally, people load them like ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {&#8220;springConfig-delegate.xml&#8221;,&#8221;springConfig-service.xml&#8221;,&#8221;springConfig-dao.xml&#8221;}); This is not a good practice when we have the provision [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=suhasjavablog.wordpress.com&amp;blog=8252942&amp;post=482&amp;subd=suhasjavablog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We often use a separate spring config file for each layer in our project &#8211; say springConfig-delegate.xml for the delegate layer, springConfig-service.xml for the service layer and springConfig-dao.xml for the dao layer.</p>
<p>Normally, people load them like</p>
<p><em>ApplicationContext context =</em><br />
<em> new ClassPathXmlApplicationContext(new String[] {&#8220;springConfig-delegate.xml&#8221;,&#8221;springConfig-service.xml&#8221;,&#8221;springConfig-dao.xml&#8221;});</em></p>
<p>This is not a good practice when we have the provision to organize all our spring configuration files into a single XML file &amp; load it.</p>
<p>Create a single spring config file names &#8220;springConfig.xml&#8221;</p>
<div>
<div>
<pre>&lt;beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"&gt;

	&lt;import resource="common/Spring-Common.xml"/&gt;
        &lt;import resource="connection/Spring-Connection.xml"/&gt;
        &lt;import resource="moduleA/Spring-ModuleA.xml"/&gt;

&lt;/beans&gt;</pre>
</div>
</div>
<p>and then load it like</p>
<blockquote><p>ApplicationContext context =<br />
new ClassPathXmlApplicationContext(springConfig.xml);</p></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/suhasjavablog.wordpress.com/482/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/suhasjavablog.wordpress.com/482/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/suhasjavablog.wordpress.com/482/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/suhasjavablog.wordpress.com/482/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/suhasjavablog.wordpress.com/482/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/suhasjavablog.wordpress.com/482/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/suhasjavablog.wordpress.com/482/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/suhasjavablog.wordpress.com/482/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/suhasjavablog.wordpress.com/482/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/suhasjavablog.wordpress.com/482/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/suhasjavablog.wordpress.com/482/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/suhasjavablog.wordpress.com/482/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/suhasjavablog.wordpress.com/482/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/suhasjavablog.wordpress.com/482/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=suhasjavablog.wordpress.com&amp;blog=8252942&amp;post=482&amp;subd=suhasjavablog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://suhasjavablog.wordpress.com/2011/12/09/how-to-deal-with-multiple-spring-configuration-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0c9df61121797c71b3de813e8e55fee6?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">ShamanOfJava</media:title>
		</media:content>
	</item>
		<item>
		<title>Auto-wiring in Spring</title>
		<link>http://suhasjavablog.wordpress.com/2011/12/09/auto-wiring-in-spring/</link>
		<comments>http://suhasjavablog.wordpress.com/2011/12/09/auto-wiring-in-spring/#comments</comments>
		<pubDate>Fri, 09 Dec 2011 06:30:27 +0000</pubDate>
		<dc:creator>ShamanOfJava</dc:creator>
				<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://suhasjavablog.wordpress.com/?p=477</guid>
		<description><![CDATA[In Spring framework, you can wire beans automatically with auto-wiring feature. To enable it, just define the “autowire” attribute in &#60;bean&#62;. There are 5 auto-wiring modes in spring no – Default, no auto wiring, set it manually via “ref” attribute byName – Auto wiring by property name. If the name of a bean is same [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=suhasjavablog.wordpress.com&amp;blog=8252942&amp;post=477&amp;subd=suhasjavablog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In Spring framework, you can wire beans automatically with auto-wiring feature. To enable it, just define the “<strong>autowire</strong>” attribute in &lt;bean&gt;.</p>
<p>There are 5 auto-wiring modes in spring</p>
<ol>
<li><strong>no</strong> – Default, no auto wiring, set it manually via “ref” attribute</li>
<li><strong>byName</strong> – Auto wiring by property name. If the name of a bean is same as the name of other bean property, auto wire it.</li>
<li><strong>byType</strong> – Auto wiring by property data type. If data type of a bean is compatible with the data type of other bean property, auto wire it.</li>
<li><strong>constructor</strong> – byType mode in constructor argument.</li>
<li><strong>autodetect</strong> – If a default constructor is found, use “autowired by constructor”; Otherwise, use “autowire by type”.</li>
</ol>
<p>Hope the following examples will help you understand auto-wiring much better</p>
<p>Consider the following classes &#8211; Customer.java and Person.java</p>
<blockquote><pre>
public class Customer {
        private Person person;

        public Customer(Person person) {
            this.person = person;
        }

        public void setPerson(Person person) {
            this.person = person;
        }
    }

    public class Person {
        // some code..
    }</span></pre>
</blockquote>
<p>1. <strong>NO</strong></p>
<p><strong></strong>This is the default mode. We have to use &lt;ref&gt; tag here</p>
<div>
<blockquote>
<pre>&lt;bean id="customer" class="de.suhas.Customer"&gt;
          &lt;property name="person" ref="person" /&gt;
&lt;/bean&gt;

&lt;bean id="person" class="de.suhas.Person" /&gt;</pre>
</blockquote>
<p>2. <strong>byName</strong></p>
<p><strong></strong>Auto-wire a bean by property name.</p>
<p>In this case, since the name of “person” bean is same with the name of the “customer” bean’s property (“person”), so, Spring will auto wired it via setter method – “<code>setPerson(Person person)</code>“.</p>
<blockquote>
<pre>&lt;bean id="customer" class="de.suhas.Customer" autowire="byName" /&gt;
&lt;bean id="person" class="de.suhas.Person" /&gt;</pre>
</blockquote>
<p>3. <strong>byType</strong></p>
<p>Auto-wire a bean by property data type. In this case, since the data type of “person” bean is same as the data type of the “customer” bean’s property. so, Spring will auto wired it via setter method – “setPerson(Person person)“.</p>
<blockquote><p>
&lt;bean id=&#8221;customer&#8221; class=&#8221;de.suhas.Customer&#8221; autowire=&#8221;byType&#8221; /&gt;<br />
&lt;bean id=&#8221;person&#8221; class=&#8221;de.suhas.Person&#8221; /&gt;</p></blockquote>
<p>4. <strong>constructor</strong></p>
<p>Auto-wire a bean by property data type in constructor argument.<br />
This is used when we go for constructor based dependency injection.<br />
In this case, since the data type of “person” bean is same as the constructor argument data type in “customer” bean’s property (Person object)<br />
So, Spring auto wired it via constructor method – “<code>public Customer(Person person)</code>“.</p>
</div>
<blockquote>
<div>&lt;bean id=&#8221;customer&#8221; class=&#8221;de.suhas.Customer&#8221; autowire=&#8221;constructor&#8221; /&gt;</div>
<div>&lt;bean id=&#8221;person&#8221; class=&#8221;de.suhas.Person&#8221; /&gt;</div>
</blockquote>
<p>5. <strong>autodetect</strong></p>
</div>
<div>If a default constructor is found, uses “constructor”, otherwise, uses “byType”.</div>
<div>
<blockquote>
<pre>&lt;bean id="customer" class="de.suhas.common.Customer" autowire="autodetect" /&gt;
&lt;bean id="person" class="de.suhas.Person" /&gt;</pre>
</blockquote>
</div>
<pre><strong>Tip</strong> : It’s always good to combine both ‘auto-wire’ and ‘dependency-check’ together, to make sure the property is always auto-wire successfully.
</pre>
<blockquote>
<pre>&lt;bean id="customer" class="de.suhas.Customer"
			autowire="autodetect" <strong>dependency-check="objects</strong> /&gt;
&lt;bean id="person" class="de.suhas.Person" /&gt;
</pre>
</blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/suhasjavablog.wordpress.com/477/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/suhasjavablog.wordpress.com/477/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/suhasjavablog.wordpress.com/477/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/suhasjavablog.wordpress.com/477/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/suhasjavablog.wordpress.com/477/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/suhasjavablog.wordpress.com/477/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/suhasjavablog.wordpress.com/477/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/suhasjavablog.wordpress.com/477/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/suhasjavablog.wordpress.com/477/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/suhasjavablog.wordpress.com/477/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/suhasjavablog.wordpress.com/477/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/suhasjavablog.wordpress.com/477/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/suhasjavablog.wordpress.com/477/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/suhasjavablog.wordpress.com/477/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=suhasjavablog.wordpress.com&amp;blog=8252942&amp;post=477&amp;subd=suhasjavablog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://suhasjavablog.wordpress.com/2011/12/09/auto-wiring-in-spring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0c9df61121797c71b3de813e8e55fee6?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">ShamanOfJava</media:title>
		</media:content>
	</item>
		<item>
		<title>Static binding and Dynamic Binding in Java</title>
		<link>http://suhasjavablog.wordpress.com/2011/12/08/static-binding-and-dynamic-binding-in-java/</link>
		<comments>http://suhasjavablog.wordpress.com/2011/12/08/static-binding-and-dynamic-binding-in-java/#comments</comments>
		<pubDate>Thu, 08 Dec 2011 12:39:03 +0000</pubDate>
		<dc:creator>ShamanOfJava</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://suhasjavablog.wordpress.com/?p=472</guid>
		<description><![CDATA[Static Binding and Dynamic Binding are related to Polymorphism In order to explain them, let us consider a simple example - public class Shape { int x= 10; void draw() { System.out.println(&#8220;Shape&#8221;); } } and public class Circle extends Shape{ int x=5; void draw(){ System.out.println(&#8220;Circle&#8221;); } } You might have noticed that class Circle is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=suhasjavablog.wordpress.com&amp;blog=8252942&amp;post=472&amp;subd=suhasjavablog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Static Binding and Dynamic Binding are related to Polymorphism</p>
<p>In order to explain them, let us consider a simple example -</p>
<p>public class <strong>Shape</strong> {</p>
<p>int x= 10;</p>
<p>void draw() {<br />
System.out.println(&#8220;Shape&#8221;);<br />
}<br />
}</p>
<p>and</p>
<p>public class Circle extends Shape{</p>
<p>int x=5;</p>
<p>void draw(){<br />
System.out.println(&#8220;Circle&#8221;);<br />
}<br />
}</p>
<p>You might have noticed that class Circle is inheriting the class Shape and both classes have the same member variable and the method draw() is overridden in class Circle.</p>
<p><strong>Dynamic Binding / Run Time Polymorphism / Late Binding<br />
</strong></p>
<p>Consider the following Test class</p>
<p>public class Test{</p>
<p>public static void main(String[] args) {<br />
Shape shape = new Circle();<br />
shape.draw(); // <strong>DYNAMIC BINDING</strong><br />
System.out.println(shape.x); //<strong> STATIC BINDING</strong><br />
}<br />
}</p>
<p><strong>Shape shape = new Circle()</strong></p>
<p>This is alright as Shape is the parent class of Circle.</p>
<p>Now if we call <strong><strong>shape </strong>.draw();</strong> then it the draw method in circle will be executed.<strong> <em></em></strong></p>
<p><strong><em>Note: The type of the object that is assigned to the Animal variable determines the method that is called.</em></strong></p>
<p>But when the compiler sees this draw() command, it knows that shape object is of type Shape, but the compiler also knows that shape object can be a reference to any class derived from Shape. Therefore, the compiler doesn’t know what version of draw() that statement is calling. It will only know it upon reaching the execution of that statement at runtime.</p>
<p><strong>Static binding/ Compile time polymorphism / early binding</strong></p>
<p>In some cases, the compiler can readily determine the correct version of something during compile time.</p>
<p>In Java, member variables have static binding because Java does not allow for polymorphic behavior with member variables. That means if both the Shape class and the Circle class have a member variable with the same name, it’s the base class version that is used.</p>
<p>In the above test class,    System.out.println(shape.x);  will print the value of x in class Shape.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/suhasjavablog.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/suhasjavablog.wordpress.com/472/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/suhasjavablog.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/suhasjavablog.wordpress.com/472/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/suhasjavablog.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/suhasjavablog.wordpress.com/472/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/suhasjavablog.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/suhasjavablog.wordpress.com/472/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/suhasjavablog.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/suhasjavablog.wordpress.com/472/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/suhasjavablog.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/suhasjavablog.wordpress.com/472/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/suhasjavablog.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/suhasjavablog.wordpress.com/472/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=suhasjavablog.wordpress.com&amp;blog=8252942&amp;post=472&amp;subd=suhasjavablog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://suhasjavablog.wordpress.com/2011/12/08/static-binding-and-dynamic-binding-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0c9df61121797c71b3de813e8e55fee6?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">ShamanOfJava</media:title>
		</media:content>
	</item>
		<item>
		<title>EasyMock</title>
		<link>http://suhasjavablog.wordpress.com/2011/12/01/easymock/</link>
		<comments>http://suhasjavablog.wordpress.com/2011/12/01/easymock/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 09:39:48 +0000</pubDate>
		<dc:creator>ShamanOfJava</dc:creator>
				<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://suhasjavablog.wordpress.com/?p=468</guid>
		<description><![CDATA[Before proceeding any further, let me plain unit testing in terms of its phases Test Setup : Define and Create all the Data and Objects you need for the tests Expectations : Say what methods and parameters you expect to be executed during the test Test : The actual behavior/method call you want to test [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=suhasjavablog.wordpress.com&amp;blog=8252942&amp;post=468&amp;subd=suhasjavablog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Before proceeding any further, let me plain unit testing in terms of its phases</p>
<p>Test Setup : Define and Create all the Data and Objects you need for the tests<br />
Expectations : Say what methods and parameters you expect to be executed during the test<br />
Test : The actual behavior/method call you want to test<br />
Assertions : Statements that make sure the outcome of the test were successful<br />
Test Tear down : Destroy any side effects that occurred during the test</p>
<p>jUnit is a Unit Testing Framework and provides all but the Expectations phase of testing.</p>
<p>The concept of mocking is what added the new phase of Expectations, and since jUnit saw most of it&#8217;s major development prior to the mocking movement, those features were not incorporated into the core, and a set of tools to fill that gap in the java space have opened up. Those libraries include</p>
<p>EasyMock<br />
jMock<br />
jMockIt</p>
<p>All of these libraries are compliments to any of the above Unit Testing frameworks I listed, including jUnit. They add the ability to define mock objects. Mock objects get &#8220;expectations&#8221; assigned to them, which are then asserted in the Assertions phase. Each Mock library accomplishes this slightly differently, but the major models are</p>
<p>Record Replay &#8211; EasyMock<br />
Expectations &#8211; jMock, jMockIt</p>
<p><strong>Sample EASYMOCK Program to calculate employee salary and bonus</strong></p>
<p>Salary class has to find out the employee salary and bonus but the business logic resides in FinanceDepartment.java</p>
<p>public interface <strong>IFinanceDepartment</strong> {</p>
<p>public long calculateSalary(long days);</p>
<p>public long calculateBonus(long employeeRating);</p>
<p>}</p>
<p>public class <strong>FinanceDepartment</strong> implements <strong>IFinanceDepartment</strong> {</p>
<p>@Override<br />
public long calculateBonus(long employeeRating) {<br />
return employeeRating * 5000;<br />
}</p>
<p>@Override<br />
public long calculateSalary(long days) {<br />
return days * 45;<br />
}</p>
<p>}</p>
<p>public class  <strong>Salary</strong> {</p>
<p>private IFinanceDepartment financeDepartment;</p>
<p>public IFinanceDepartment getFinanceDepartment() {<br />
return financeDepartment;<br />
}</p>
<p>public void setFinanceDepartment(IFinanceDepartment financeDepartment) {<br />
this.financeDepartment = financeDepartment;<br />
}</p>
<p>public Long calculateSalary(Long days) {<br />
return financeDepartment.calculateSalary(days);<br />
}</p>
<p>public Long calculateBonus(Long employeeRating) {<br />
return financeDepartment.calculateBonus(employeeRating);<br />
}</p>
<p>}</p>
<p>Now let&#8217;s write a EasyMock Test Case</p>
<p>import junit.framework.TestCase;</p>
<p>import org.easymock.EasyMock;<br />
import org.junit.BeforeClass;<br />
import org.junit.Test;</p>
<p>public class <strong>SalaryEasyMockTest</strong> extends TestCase {</p>
<p>private IFinanceDepartment financeDepartment;</p>
<p>private Salary salary;</p>
<p>@BeforeClass<br />
public void setUp() throws Exception {<br />
financeDepartment = EasyMock.createMock(IFinanceDepartment.class);<br />
salary = new Salary();<br />
salary.setFinanceDepartment(financeDepartment);<br />
}</p>
<p><strong>Limitations of EasyMock</strong></p>
<ul>
<li>Cannot mock static methods</li>
</ul>
<ul>
<li>Cannot mock private methods</li>
</ul>
<ul>
<li>Cannot mock final methods</li>
</ul>
<ul>
<li>Cannot mock concrete classes</li>
</ul>
<ul>
<li>Cannot mock Constructors</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/suhasjavablog.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/suhasjavablog.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/suhasjavablog.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/suhasjavablog.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/suhasjavablog.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/suhasjavablog.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/suhasjavablog.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/suhasjavablog.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/suhasjavablog.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/suhasjavablog.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/suhasjavablog.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/suhasjavablog.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/suhasjavablog.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/suhasjavablog.wordpress.com/468/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=suhasjavablog.wordpress.com&amp;blog=8252942&amp;post=468&amp;subd=suhasjavablog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://suhasjavablog.wordpress.com/2011/12/01/easymock/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0c9df61121797c71b3de813e8e55fee6?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">ShamanOfJava</media:title>
		</media:content>
	</item>
		<item>
		<title>Jasper Reports Tutorial</title>
		<link>http://suhasjavablog.wordpress.com/2011/11/23/jasper-reports-tutorial/</link>
		<comments>http://suhasjavablog.wordpress.com/2011/11/23/jasper-reports-tutorial/#comments</comments>
		<pubDate>Wed, 23 Nov 2011 10:32:18 +0000</pubDate>
		<dc:creator>ShamanOfJava</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://suhasjavablog.wordpress.com/?p=462</guid>
		<description><![CDATA[Jasper Reports is one of the most popular and most used open source reporting engine in the industry today. Its completely written in Java and can use data coming from any &#8216;datasource&#8217;  and generate reports in PDF, EXCEL and HTML. Prerequisites for this tutorial Download and install iReports from http://jasperforge.org/projects/ireport           [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=suhasjavablog.wordpress.com&amp;blog=8252942&amp;post=462&amp;subd=suhasjavablog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Jasper Reports is one of the most popular and most used open source reporting engine in the industry today. Its completely written in Java and can use data coming from any &#8216;datasource&#8217;  and generate reports in PDF, EXCEL and HTML.</p>
<p><strong><em>Prerequisites for this tutorial</em></strong></p>
<ol>
<li>Download and install iReports from http://jasperforge.org/projects/ireport                      (We use this to create the report template/layout) and this website will give you a  very very clear idea on how to design a report template. Trust me, its easy. It&#8217;s easy to understand it from their own website rather me trying to explain it in words.</li>
<li>Download and install MySQL</li>
<li>Have the following jar files in your classpath</li>
</ol>
<blockquote><p>commons-beanutils-1.7.jar</p>
<p>commons-collections-3.1.jar</p>
<p>commons-digester-1.8.jar</p>
<p>commons-lang-2.1.jar</p>
<p>commons-logging-1.1.jar</p>
<p>iText-2.1.1.jar</p>
<p>jasperreports-1.0.3.jar</p>
<p>mysql-connector-java-5.0.4-bin.jar</p></blockquote>
<p>Note: The template that we create using iReport tool will be saved with extension <strong>.jrxml</strong></p>
<p>Create a folder jrxml in your project and save/copy the template you designed here.</p>
<p>Create a folder report in your project and this is where your PDF/EXCEL report will be saved</p>
<p>Before we go further, we need to populate the data in the database so that we can fetch it and display it on the report. (Who would like to see a empty PDF report? In case, if you get a empty PDF report, then your must have forgotten to  add iText-2.1.1.jar to the classpath..provided your query works)</p>
<p>Execute the following scripts in MySQL Browser</p>
<blockquote><p>create table Employee(<br />
ID                 VARCHAR(4) NOT NULL,<br />
First_Name         VARCHAR(10),<br />
Last_Name          VARCHAR(10),<br />
Start_Date         DATE,<br />
End_Date           DATE,<br />
Salary             DECIMAL(8,2),<br />
City               VARCHAR(10),<br />
Description        VARCHAR(15)<br />
)</p>
<p>INSERT into Employee values<br />
(&#8217;06&#8242;,&#8217;Suhas&#8217;,'Saheer&#8217;,<br />
to_date(&#8217;20071213&#8242;,&#8217;YYYYMMDD&#8217;),<br />
to_date(&#8217;20701213&#8242;,&#8217;YYYYMMDD&#8217;),<br />
52500.56,<br />
&#8216;MUNICH&#8217;,<br />
&#8216;Programmer&#8217;)</p></blockquote>
<p>Since this is your first application, lets make it simple.<br />
We need to fetch the first_name and last_name from the employee table and show it on a PDF report named EmployeeReport.pdf</p>
<p>So the query for fetching the records to be displayed on the report is</p>
<blockquote><p>select First_Name, Last_Name from employee e</p></blockquote>
<p>Where to we need to provide this query?<br />
Either we can provide it in the .jrxml file we created or in our invoking method(java class)</p>
<p>In this tutorial, we are talking about the case where we mention the query in the .jrxml file itself</p>
<p><strong>EmployeeReport.jrxml</strong></p>
<blockquote><p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt;<br />
&lt;!DOCTYPE jasperReport PUBLIC &#8220;//JasperReports//DTD Report Design//EN&#8221;<br />
&#8220;http://jasperreports.sourceforge.net/dtds/jasperreport.dtd&#8221;&gt;<br />
&lt;jasperReport name=&#8221;EmployeeReport_SuhasJavaBlog&#8221;&gt;<br />
&lt;queryString&gt;<br />
&lt;![CDATA[select First_Name, Last_Name from employee e]]&gt;<br />
&lt;/queryString&gt;<br />
&lt;field name=&#8221;First_Name&#8221; /&gt;<br />
&lt;field name=&#8221;Last_Name&#8221; /&gt;<br />
&lt;title&gt;<br />
&lt;band height=&#8221;50&#8243;&gt;<br />
&lt;staticText&gt;<br />
&lt;reportElement x=&#8221;0&#8243; y=&#8221;0&#8243; width=&#8221;180&#8243; height=&#8221;15&#8243;/&gt;<br />
&lt;textElement/&gt;<br />
&lt;text&gt;&lt;![CDATA[Jasper Report - SuhasJavaBlog]]&gt;&lt;/text&gt;<br />
&lt;/staticText&gt;<br />
&lt;/band&gt;<br />
&lt;/title&gt;<br />
&lt;pageHeader&gt;<br />
&lt;band height=&#8221;30&#8243;&gt;<br />
&lt;staticText&gt;<br />
&lt;reportElement x=&#8221;0&#8243; y=&#8221;0&#8243; width=&#8221;69&#8243; height=&#8221;24&#8243; /&gt;<br />
&lt;textElement verticalAlignment=&#8221;Bottom&#8221; /&gt;<br />
&lt;text&gt;<br />
&lt;![CDATA[First Name: ]]&gt;<br />
&lt;/text&gt;<br />
&lt;/staticText&gt;<br />
&lt;staticText&gt;<br />
&lt;reportElement x=&#8221;140&#8243; y=&#8221;0&#8243; width=&#8221;79&#8243; height=&#8221;24&#8243; /&gt;<br />
&lt;text&gt;<br />
&lt;![CDATA[Last Name: ]]&gt;<br />
&lt;/text&gt;<br />
&lt;/staticText&gt;<br />
&lt;/band&gt;<br />
&lt;/pageHeader&gt;<br />
&lt;detail&gt;<br />
&lt;band height=&#8221;30&#8243;&gt;<br />
&lt;textField&gt;<br />
&lt;reportElement x=&#8221;0&#8243; y=&#8221;0&#8243; width=&#8221;69&#8243; height=&#8221;24&#8243; /&gt;<br />
&lt;textFieldExpression&gt;<br />
&lt;![CDATA[$F{First_Name}]]&gt;<br />
&lt;/textFieldExpression&gt;<br />
&lt;/textField&gt;<br />
&lt;textField&gt;<br />
&lt;reportElement x=&#8221;140&#8243; y=&#8221;0&#8243; width=&#8221;69&#8243; height=&#8221;24&#8243; /&gt;<br />
&lt;textFieldExpression&gt;<br />
&lt;![CDATA[$F{Last_Name}]]&gt;<br />
&lt;/textFieldExpression&gt;<br />
&lt;/textField&gt;<br />
&lt;/band&gt;<br />
&lt;/detail&gt;<br />
&lt;/jasperReport&gt;</p></blockquote>
<p>Note the highlighted text in the above template. (Thats our SQL query to fetch the records)</p>
<p>Now let&#8217;s take a look the Java code for generating the report. (We use Jasper API for this)</p>
<p>1. Establish a connection to the MySQL database :</p>
<blockquote><p>Class.forName(&#8220;com.mysql.jdbc.Driver&#8221;);<br />
conn = DriverManager.getConnection(&#8220;jdbc:mysql://localhost:3306/test?user=root&amp;password=root&#8221;);</p></blockquote>
<p>2. Read the .jrxml report template you have designed and create a JasperDesign Object which represent the report design :</p>
<blockquote><p>InputStream input = new FileInputStream(new File(&#8220;jrxml/BasicReport.jrxml&#8221;));<br />
JasperDesign jasperDesign = JRXmlLoader.load(input);</p></blockquote>
<p>3. Now compile the report design file to create a <code>JasperReport</code> object. The compilation of the report design file validates the JasperReports XML file (EmployeeReport.jrxml) with the <code>jaspereports.dtd</code> DTD and converts the report expressions into a ready-to-evaluate form :</p>
<blockquote><p>JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);</p></blockquote>
<p>4. To view this, generate a <code>JasperPrint</code> document, which may be viewed, printed or exported to other formats, from the compiled report design :</p>
<blockquote><p><del>JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);</del></p></blockquote>
<p>In this example,  we don&#8217;t have any parameters to pass.</p>
<p>Hence we re-write this as</p>
<blockquote><p>JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);</p></blockquote>
<p>5. A JasperReports report may be exported to a XML file, a PDF file, an HTML file, a CSV file, or an Excel XLS file; to export the JasperReports report we’ve just generated to a PDF file, use this:</p>
<blockquote><p> OutputStream output = new FileOutputStream(new File(&#8220;jrxml/EmployeeReport.pdf&#8221;));<br />
JasperExportManager.exportReportToPdfStream(jasperPrint, output);</p></blockquote>
<p>That&#8217;s it. You have done it. You just need to execute this method and you have your report ready under the &#8216;reports&#8217; folder in your project</p>
<p><strong>ReportGenerator.java</strong></p>
<blockquote><p>package de.suhas.jasper;</p>
<p>import java.io.File;<br />
import java.io.FileInputStream;<br />
import java.io.FileNotFoundException;<br />
import java.io.FileOutputStream;<br />
import java.io.InputStream;<br />
import java.io.OutputStream;<br />
import java.sql.Connection;<br />
import java.sql.DriverManager;<br />
import java.sql.ResultSet;<br />
import java.sql.SQLException;<br />
import java.sql.Statement;<br />
import java.util.HashMap;<br />
import java.util.Map;</p>
<p>import net.sf.jasperreports.engine.JRException;<br />
import net.sf.jasperreports.engine.JRResultSetDataSource;<br />
import net.sf.jasperreports.engine.JasperCompileManager;<br />
import net.sf.jasperreports.engine.JasperExportManager;<br />
import net.sf.jasperreports.engine.JasperFillManager;<br />
import net.sf.jasperreports.engine.JasperPrint;<br />
import net.sf.jasperreports.engine.JasperReport;<br />
import net.sf.jasperreports.engine.design.JasperDesign;<br />
import net.sf.jasperreports.engine.xml.JRXmlLoader;</p>
<p>public class ReportGenerator {</p>
<p>Connection conn;</p>
<p>public void generateReport() {</p>
<p>try {<br />
Class.forName(&#8220;com.mysql.jdbc.Driver&#8221;);<br />
conn = DriverManager.getConnection(&#8220;jdbc:mysql://localhost:3306/test?user=root&amp;password=root&#8221;);<br />
System.out.println(&#8220;Loading Report Designs&#8221;);<br />
InputStream input = new FileInputStream(new File(&#8220;jrxml/BasicReport.jrxml&#8221;));<br />
JasperDesign jasperDesign = JRXmlLoader.load(input);</p>
<p>System.out.println(&#8220;Compiling Report Designs&#8221;);<br />
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);</p>
<p>System.out.println(&#8220;Creating JasperPrint Object&#8221;);<br />
Map&lt;String, String&gt; parameters = new HashMap&lt;String, String&gt;();<br />
parameters.put(&#8220;ReportTitle&#8221;, &#8220;PDF JasperReport&#8221;);</p>
<p>System.out.println(&#8220;Filling Report to File&#8221;);<br />
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);</p>
<p>//Exporting the report<br />
OutputStream output = new FileOutputStream(new File(&#8220;jrxml/catalog.pdf&#8221;));<br />
JasperExportManager.exportReportToPdfStream(jasperPrint, output);</p>
<p>System.out.println(&#8220;Report Generation Complete&#8221;);<br />
conn.close();<br />
} catch (FileNotFoundException e) {<br />
e.printStackTrace();<br />
} catch (JRException e) {<br />
e.printStackTrace();<br />
} catch (ClassNotFoundException e) {<br />
e.printStackTrace();<br />
} catch (SQLException e) {<br />
e.printStackTrace();<br />
}<br />
}</p>
<p>public static void main(String[] args) {<br />
new ReportGenerator().generateReport();<br />
}<br />
}</p>
<p>Hope you guys have understood the art of creating reports using Jasper API and iReports.</p>
<p>Would love to hear from you guys if this was the slightest help to you.<br />
Also feel free to drop in a reply for any queries related to Jasper Reports</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/suhasjavablog.wordpress.com/462/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/suhasjavablog.wordpress.com/462/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/suhasjavablog.wordpress.com/462/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/suhasjavablog.wordpress.com/462/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/suhasjavablog.wordpress.com/462/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/suhasjavablog.wordpress.com/462/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/suhasjavablog.wordpress.com/462/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/suhasjavablog.wordpress.com/462/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/suhasjavablog.wordpress.com/462/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/suhasjavablog.wordpress.com/462/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/suhasjavablog.wordpress.com/462/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/suhasjavablog.wordpress.com/462/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/suhasjavablog.wordpress.com/462/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/suhasjavablog.wordpress.com/462/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=suhasjavablog.wordpress.com&amp;blog=8252942&amp;post=462&amp;subd=suhasjavablog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://suhasjavablog.wordpress.com/2011/11/23/jasper-reports-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0c9df61121797c71b3de813e8e55fee6?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">ShamanOfJava</media:title>
		</media:content>
	</item>
		<item>
		<title>LinkedList vs ArrayList</title>
		<link>http://suhasjavablog.wordpress.com/2011/11/20/linkedlist-vs-arraylist/</link>
		<comments>http://suhasjavablog.wordpress.com/2011/11/20/linkedlist-vs-arraylist/#comments</comments>
		<pubDate>Sun, 20 Nov 2011 05:31:43 +0000</pubDate>
		<dc:creator>ShamanOfJava</dc:creator>
				<category><![CDATA[Collection Framework]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[ArrayList]]></category>
		<category><![CDATA[LinkedList]]></category>

		<guid isPermaLink="false">http://suhasjavablog.wordpress.com/?p=453</guid>
		<description><![CDATA[Let&#8217;s first take a look at the interfaces which the ArrayList and LinkedList implement. public class ArrayList&#60;E&#62; extends AbstractList&#60;E&#62; implements List&#60;E&#62;, RandomAccess, Cloneable,Serializable public class LinkedList&#60;E&#62; extends AbstractSequentialList&#60;E&#62; implements List&#60;E&#62;, Queue&#60;E&#62; Cloneable, Serializable ArrayList Now for some implementation notes. The ArrayList is actually encapsulating an actualy Array, an Object[]. When you instanciate ArrayList, an array is created, and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=suhasjavablog.wordpress.com&amp;blog=8252942&amp;post=453&amp;subd=suhasjavablog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s first take a look at the interfaces which the ArrayList and LinkedList implement.</p>
<pre><code>public class ArrayList&lt;E&gt; extends AbstractList&lt;E&gt; implements List&lt;E&gt;, <strong>RandomAccess</strong>, Cloneable,Serializable</code>
public class LinkedList&lt;E&gt; extends AbstractSequentialList&lt;E&gt; implements List&lt;E&gt;, <strong>Queue&lt;E&gt;</strong> Cloneable, Serializable</pre>
<p><strong>ArrayList</strong></p>
<p>Now for some implementation notes. The <strong>ArrayList is actually encapsulating an actualy Array</strong>, an <code>Object[]</code>. When you instanciate ArrayList, an array is created, and when you add values into it, the array changes its size accordingly. This gives you strengths and weaknesses:</p>
<ul>
<li><strong>Fast Random Access</strong></li>
</ul>
<p>You can perform random access without fearing for performence. Calling <code>get(int)</code> will just access the underlying array</p>
<ul>
<li><strong>Adding values might be slow</strong> When you don’t know the amount of values the array will contain when you create it, a lot of shifting is going to be done in the memory space when the ArrayList manipulates its internal array.</li>
<li><strong>Slow manipulation</strong> When you’ll want to add a value randomly inside the array, between two already existing values, the array will have to start moving all the values one spot to the right in order to let that happen.</li>
</ul>
<p><strong>LinkedList</strong></p>
<p>The <strong>LinkedList is implemented using nodes linked to each other</strong>. Each node contains a<em>previous node</em> link, <em>next node</em> link, and <em>value</em>, which contains the actual data. When new data is inserted, a node is inserted and the links of the surrounding nodes are updated accordingly. When one is removed, the same happens – The surrounding nodes are changing their links and the deleted node is garbage collected. This, as well, gives strengths and weaknesses:</p>
<ul>
<li><strong>Fast manipulation</strong> As you’d expect, adding and removing new data <em>anywhere</em> in the list is instantanious. Change two links, and you have a new value anywhere you want it.</li>
<li><strong>No random access</strong> Even though the <code>get(int)</code> is still there, it now just iterates the list until it reaches the index you specified. It has some optimizations in order to do that, but that’s basically it.</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/suhasjavablog.wordpress.com/453/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/suhasjavablog.wordpress.com/453/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/suhasjavablog.wordpress.com/453/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/suhasjavablog.wordpress.com/453/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/suhasjavablog.wordpress.com/453/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/suhasjavablog.wordpress.com/453/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/suhasjavablog.wordpress.com/453/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/suhasjavablog.wordpress.com/453/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/suhasjavablog.wordpress.com/453/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/suhasjavablog.wordpress.com/453/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/suhasjavablog.wordpress.com/453/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/suhasjavablog.wordpress.com/453/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/suhasjavablog.wordpress.com/453/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/suhasjavablog.wordpress.com/453/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=suhasjavablog.wordpress.com&amp;blog=8252942&amp;post=453&amp;subd=suhasjavablog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://suhasjavablog.wordpress.com/2011/11/20/linkedlist-vs-arraylist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0c9df61121797c71b3de813e8e55fee6?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">ShamanOfJava</media:title>
		</media:content>
	</item>
		<item>
		<title>Abstraction vs Encapsulation</title>
		<link>http://suhasjavablog.wordpress.com/2011/11/18/abstraction-encapsulation/</link>
		<comments>http://suhasjavablog.wordpress.com/2011/11/18/abstraction-encapsulation/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 10:52:12 +0000</pubDate>
		<dc:creator>ShamanOfJava</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Abstraction]]></category>
		<category><![CDATA[Encapsulation]]></category>

		<guid isPermaLink="false">http://suhasjavablog.wordpress.com/?p=436</guid>
		<description><![CDATA[Abstraction is only giving essential details w/o any background information. This is achieved in java by 1) Abstract Class and Interface //We don&#8217;t know the function implementation of code until unless at run time or we have a information about the class which implementing this Interface or Extends this Abstract Class If we click on [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=suhasjavablog.wordpress.com&amp;blog=8252942&amp;post=436&amp;subd=suhasjavablog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Abstraction is only giving essential details w/o any background information.</p>
<p>This is achieved in java by<br />
1)<em> Abstract Class and Interface</em> //We don&#8217;t know the function implementation of code until unless at run time or we have a information about the class which implementing this Interface or Extends this Abstract Class If we click on this method it directly take us to Interface method not to Class which actually implementing this method.<br />
2) Hiding information by <em>access modifier </em>only give access to required<br />
3) <em>Object -</em> Nothing can be accessed by Object ref.</p>
<p>Encapsulation protects abstractions. Encapsulation is the bodyguard; abstraction is the VIP.</p>
<p>A real world example,</p>
<p>consider u have setup a big building(say a company), the details regarding materials used to built (glass, bricks), type of work, manager of the company, number of floors, design of the building, cost of the building etc. can be classified as ABSTRACTION.</p>
<p>Whereas, type of glass or bricks(grey one or red one) used, who all work for which all departments n how they work, cost of each and every element in the building etc. comes under Data ENCAPSULATION.</p>
<p>Another example can be of a VIP(Abstraction) and his assistant(Encapsulation).</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/suhasjavablog.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/suhasjavablog.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/suhasjavablog.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/suhasjavablog.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/suhasjavablog.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/suhasjavablog.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/suhasjavablog.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/suhasjavablog.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/suhasjavablog.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/suhasjavablog.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/suhasjavablog.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/suhasjavablog.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/suhasjavablog.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/suhasjavablog.wordpress.com/436/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=suhasjavablog.wordpress.com&amp;blog=8252942&amp;post=436&amp;subd=suhasjavablog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://suhasjavablog.wordpress.com/2011/11/18/abstraction-encapsulation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0c9df61121797c71b3de813e8e55fee6?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">ShamanOfJava</media:title>
		</media:content>
	</item>
		<item>
		<title>Difference between Iterator and Enumeration Interface</title>
		<link>http://suhasjavablog.wordpress.com/2011/11/18/difference-between-iterator-and-enumeration-interface/</link>
		<comments>http://suhasjavablog.wordpress.com/2011/11/18/difference-between-iterator-and-enumeration-interface/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 10:43:31 +0000</pubDate>
		<dc:creator>ShamanOfJava</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Enumeration]]></category>
		<category><![CDATA[Iterator]]></category>

		<guid isPermaLink="false">http://suhasjavablog.wordpress.com/?p=434</guid>
		<description><![CDATA[Both Iterator and Enumeration are used to traverse Collection objects, in a sequential fashion.  Enumeration can be applied to Vector and HashTable. Iterator can be used with most of the Collection objects. The main difference between the two is that Iterator is fail-safe. i.e,  If you are using an iterator to go through a collection [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=suhasjavablog.wordpress.com&amp;blog=8252942&amp;post=434&amp;subd=suhasjavablog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Both Iterator and Enumeration are used to traverse <em>Collection</em> objects, in a sequential fashion.  Enumeration can be applied to Vector and HashTable. Iterator can be used with most of the <em>Collection</em> objects.</p>
<p>The main difference between the two is that Iterator is fail-safe. i.e,  <span style="color:#000000;"> If you are using an iterator to go through a collection you can be sure of no concurrent modifications in the underlying collection which may</span> <span style="color:#000000;">happen in multi-threaded environments.</span></p>
<p>Enumeration is twice as fast as Iterator and uses very less memory.</p>
<blockquote><p>Vector &lt;String&gt; aVector = new Vector&lt;String&gt;();<br />
aVector.add(&#8220;I&#8221;);<br />
aVector.add(&#8220;am&#8221;);<br />
aVector.add(&#8220;really&#8221;);<br />
aVector.add(&#8220;good&#8221;);<br />
Enumeration&lt;String&gt; e = aVector.elements();<br />
while (e.hasMoreElements()) {<br />
System.out.println(e.nextElement());<br />
}</p></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/suhasjavablog.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/suhasjavablog.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/suhasjavablog.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/suhasjavablog.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/suhasjavablog.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/suhasjavablog.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/suhasjavablog.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/suhasjavablog.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/suhasjavablog.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/suhasjavablog.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/suhasjavablog.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/suhasjavablog.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/suhasjavablog.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/suhasjavablog.wordpress.com/434/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=suhasjavablog.wordpress.com&amp;blog=8252942&amp;post=434&amp;subd=suhasjavablog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://suhasjavablog.wordpress.com/2011/11/18/difference-between-iterator-and-enumeration-interface/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0c9df61121797c71b3de813e8e55fee6?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">ShamanOfJava</media:title>
		</media:content>
	</item>
		<item>
		<title>Few Tips for Constructor based Dependency Injection</title>
		<link>http://suhasjavablog.wordpress.com/2011/11/17/few-tips-for-constructor-based-dependency-injection/</link>
		<comments>http://suhasjavablog.wordpress.com/2011/11/17/few-tips-for-constructor-based-dependency-injection/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 09:06:47 +0000</pubDate>
		<dc:creator>ShamanOfJava</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Constructor Injection]]></category>
		<category><![CDATA[Dependency Injection]]></category>

		<guid isPermaLink="false">http://suhasjavablog.wordpress.com/?p=407</guid>
		<description><![CDATA[Why should one go for Constructor-based dependency Injection? Best to use for a bean with one or two properties. Less LOC as there are no setters, just one constructor method. Facilitates &#8216;immutable&#8217; property Prefer &#8216;type&#8217; over &#8216;index&#8217; while you go for constructor-based dependency injection Instead of: &#60;bean id="billingService"&#62; &#60;constructor-arg index="0" value="lizjason"/&#62; &#60;constructor-arg index="1" value="100"/&#62; &#60;/bean&#62; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=suhasjavablog.wordpress.com&amp;blog=8252942&amp;post=407&amp;subd=suhasjavablog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Why should one go for Constructor-based dependency Injection?</p>
<ol>
<li>Best to use for a bean with one or two properties.</li>
<li>Less LOC as there are no setters, just one constructor method.</li>
<li>Facilitates &#8216;immutable&#8217; property</li>
</ol>
<p>Prefer &#8216;type&#8217; over &#8216;index&#8217; while you go for constructor-based dependency injection</p>
<p>Instead of:</p>
<blockquote>
<pre>&lt;bean id="billingService"&gt;
&lt;constructor-arg index="0" value="lizjason"/&gt;
&lt;constructor-arg index="1" value="100"/&gt;
&lt;/bean&gt;</pre>
</blockquote>
<p>It is better to use the type attribute like this:</p>
<blockquote>
<pre>&lt;bean id="billingService"&gt;
&lt;constructor-arg type="java.lang.String" value="lizjason"/&gt;
&lt;constructor-arg type="int" value="100"/&gt;
&lt;/bean&gt;</pre>
</blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/suhasjavablog.wordpress.com/407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/suhasjavablog.wordpress.com/407/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/suhasjavablog.wordpress.com/407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/suhasjavablog.wordpress.com/407/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/suhasjavablog.wordpress.com/407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/suhasjavablog.wordpress.com/407/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/suhasjavablog.wordpress.com/407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/suhasjavablog.wordpress.com/407/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/suhasjavablog.wordpress.com/407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/suhasjavablog.wordpress.com/407/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/suhasjavablog.wordpress.com/407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/suhasjavablog.wordpress.com/407/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/suhasjavablog.wordpress.com/407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/suhasjavablog.wordpress.com/407/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=suhasjavablog.wordpress.com&amp;blog=8252942&amp;post=407&amp;subd=suhasjavablog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://suhasjavablog.wordpress.com/2011/11/17/few-tips-for-constructor-based-dependency-injection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0c9df61121797c71b3de813e8e55fee6?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">ShamanOfJava</media:title>
		</media:content>
	</item>
	</channel>
</rss>
