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

<channel>
	<title>Juggling Eggs &#187; Java</title>
	<atom:link href="http://sonnygill.net/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://sonnygill.net</link>
	<description>Priceless eggs, variable gravity</description>
	<lastBuildDate>Sun, 06 May 2012 19:47:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using Struts 2&#8242;s native dependency injection support</title>
		<link>http://sonnygill.net/java/struts2-dependency-injection/</link>
		<comments>http://sonnygill.net/java/struts2-dependency-injection/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 13:35:23 +0000</pubDate>
		<dc:creator>sonnygill</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Struts]]></category>

		<guid isPermaLink="false">http://sonnygill.wordpress.com/?p=88</guid>
		<description><![CDATA[Since I knew that Struts 2 used Guice internally, I was curious if the native DI support in S2 could be used in a simple application. A little bit of digging and fiddling around showed what is possible. struts.xml MyServiceImpl.java &#8230; <a href="http://sonnygill.net/java/struts2-dependency-injection/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Since I knew that Struts 2 used Guice internally, I was curious if the native DI support in S2 could be used in a simple application. A little bit of digging and fiddling around showed what is possible.</p>
<p>struts.xml</p>
<pre class="brush: xml; title: ; notranslate">
...
 &lt;constant name=&quot;myVal&quot; value=&quot;9&quot; /&gt;
 &lt;bean name=&quot;myService&quot; type=&quot;prac.MyService&quot; class=&quot;prac.MyServiceImpl&quot; /&gt;
...
</pre>
<p>MyServiceImpl.java</p>
<pre class="brush: java; title: ; notranslate">
...
 @Inject(&quot;myVal&quot;)
 public void setMyVal(String myVal) {
 this.myVal = Integer.parseInt(myVal);
 }
...
</pre>
<p>MyAction.java</p>
<pre class="brush: java; title: ; notranslate">
...
 @Inject(&quot;myService&quot;)
 public void setMyService(MyService myService) {
 this.myService = myService;
 }
...
</pre>
<p>This will create a single instance of MyService with myVal injected into it.<br />
And on every invocation of MyAction, that MyService instance will be injected into it.<br />
Sweet!</p>
<p>Of course, this is part of Struts internals, so these can change at any time. It is probably not a good idea to use it on a real world system.</p>
]]></content:encoded>
			<wfw:commentRss>http://sonnygill.net/java/struts2-dependency-injection/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Object equality in Java</title>
		<link>http://sonnygill.net/java/java-object-equality/</link>
		<comments>http://sonnygill.net/java/java-object-equality/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 03:37:26 +0000</pubDate>
		<dc:creator>sonnygill</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://sonnygill.wordpress.com/?p=82</guid>
		<description><![CDATA[The first time I paid attention to the equals() method was when preparing for SCJP exam, where you have to know what the output of some lines of code will be. That was simple enough &#8211; follow the logic of &#8230; <a href="http://sonnygill.net/java/java-object-equality/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The first time I paid attention to the equals() method was when preparing for SCJP exam, where you have to know what the output of some lines of code will be. That was simple enough &#8211; follow the logic of the code, and make sure that you are not accidentally overloading equals instead of overriding it.</p>
<p>A few years later, I revisited equals() ( and hashcode() ) when reading Joshua Bloch&#8217;s Effective Java. <a href="http://developer.java.sun.com/developer/Books/effectivejava/Chapter3.pdf">Chapter 3, &#8220;Methods Common to All Objects&#8221; </a> shows how to, and why you should, properly  implement equals() method. This must be required reading for every Java programmer, even if you ever only write CRUD applications in Struts, and are never going to use any of it.</p>
<p>Recently, I read <a href="http://www.angelikalanger.com">Angelika Langer</a>&#8216;s article on this subject. If, like me, you have read the Effective Java book, and think that you know all that you need to about Object equality, think again!</p>
<p>Angelika Langer and Klaus Kreft disect various approaches to implementing equals() &#8211; <a href="http://www.angelikalanger.com/Articles/JavaSolutions/SecretsOfEquals/Equals.html">Secrets of equals()</a>.</p>
<p>The gist of it is that although implementing equals() for a final class, or a class with a final equals() method is reasonably straightforward, there is no one correct way of doing that with mixed-type comparisons allowed between objects of different types in the same class hierarchy.<br />
The second thing to keep in mind is that if you are overriding a class that implements equals(), and you override the equals() method you have to pay particular attention to whether the superclass&#8217;s equals() method allows mixed-type comparisons or not -</p>
<blockquote><p>If the designer of such a non-final class decides in favor of implementing equals() using instanceof , then no subclass can ever add fields and override equals() without violating the transitivity requirement of the equals() contract.<br />
If the designer decides in favor of implementing equals() using getClass() , then no subclass object will ever be comparable to a superclass object and trivial extensions may not make a lot of sense.</p></blockquote>
<p>There is a follow up article showing one way of <a href="http://www.angelikalanger.com/Articles/JavaSolutions/SecretsOfEquals/Equals-2.html">Implementing equals() To Allow Mixed-Type Comparison</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://sonnygill.net/java/java-object-equality/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

