<?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>Upthrust &#187; Java</title>
	<atom:link href="http://blog.mpathirage.com/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mpathirage.com</link>
	<description>This is the weblog of Milinda Pathirage</description>
	<lastBuildDate>Mon, 29 Aug 2011 02:00:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Configure JDK Documentation in IntelliJ IDEA on Mac OS X 10.6.x</title>
		<link>http://blog.mpathirage.com/2011/02/16/configure-jdk-documentation-in-intellij-idea-on-mac-os-x-10-6-x/</link>
		<comments>http://blog.mpathirage.com/2011/02/16/configure-jdk-documentation-in-intellij-idea-on-mac-os-x-10-6-x/#comments</comments>
		<pubDate>Wed, 16 Feb 2011 11:25:55 +0000</pubDate>
		<dc:creator>Milinda Lakmal</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[IntelliJ IDEA]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Mac OS]]></category>

		<guid isPermaLink="false">http://blog.mpathirage.com/?p=761</guid>
		<description><![CDATA[I began to use Macbook Pro as my personal laptop couple months ago and most of the work I am doing involve Java. I am using IntelliJ IDEA as my Java IDE and I had a issue with documentation popups that shown during code completion for JDK classes. I only saw compiled signatures and I [...]]]></description>
			<content:encoded><![CDATA[<p>I began to use Macbook Pro as my personal laptop couple months ago and most of the work I am doing involve Java. I am using IntelliJ IDEA as my Java IDE and I had a issue with documentation popups that shown during code completion for JDK classes. I only saw compiled signatures and I couldn&#8217;t see any documentation, as it shown in the days I used Linux. I thought of fixing this issue today and start googling and found <a href="http://stackoverflow.com/questions/4145734/jdk-documentation-in-intellij-idea-on-mac-os-x" target="_blank">this post</a> in stackoverflow.com. Above post shows the solution for this documentation popup issue and also it shows how you can attach JDK source to IntelliJ IDEA. Following are the steps to fix the above mentioned issue:</p>
<ol>
<li>Sign in to <a rel="nofollow" href="http://connect.apple.com/">Apple&#8217;s Developer Downloads</a> using you Apple Developer account.</li>
<li>Select &#8220;Downloads&#8221; under &#8220;Browse&#8221; and then &#8220;Java&#8221; under &#8220;Downloads&#8221;.</li>
<li>Download and install &#8220;Java for Mac OS X 10.6 Update 3 Developer Package&#8221;. (There is  a newer developer preview available, but didn&#8217;t tried that. According to it you need to have Update 3 anyway.)</li>
<li>Open the &#8220;Project Structure&#8221; dialog through &#8220;File&#8221; menu or through tool bar.</li>
<li>Click on &#8220;SDKs&#8221; under &#8220;Platform Settings&#8221; and look at the &#8220;Documentation Paths&#8221; tab.</li>
<li>Add the following paths (the path may be different based on which JDK you&#8217;re using):
<ul>
<li>/Library/Java/JavaVirtualMachines/1.6.0_22-b04-307.jdk/Contents/Home/docs.jar!/docs/api</li>
<li>/Library/Java/JavaVirtualMachines/1.6.0_22-b04-307.jdk/Contents/Home/appledocs.jar!/appledoc/api</li>
</ul>
</li>
<li>Add the following path under the Sourcepath tab:
<ul>
<li>/Library/Java/JavaVirtualMachines/1.6.0_22-b04-307.jdk/Contents/Home/src.jar!/src</li>
</ul>
</li>
</ol>
<p>Thanks <a href="http://stackoverflow.com/users/26535/chris-williams" target="_blank">Chris Williams</a> for the tip.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mpathirage.com/2011/02/16/configure-jdk-documentation-in-intellij-idea-on-mac-os-x-10-6-x/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Java Puzzlers: Phantom Reference Menace, Attack Of The Clone, &amp; Revenge Of The Shift</title>
		<link>http://blog.mpathirage.com/2010/06/27/java-puzzlers-phantom-reference-menace-attack-of-the-clone-revenge-of-the-shift/</link>
		<comments>http://blog.mpathirage.com/2010/06/27/java-puzzlers-phantom-reference-menace-attack-of-the-clone-revenge-of-the-shift/#comments</comments>
		<pubDate>Sun, 27 Jun 2010 05:35:11 +0000</pubDate>
		<dc:creator>Milinda Lakmal</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[java puzzlers]]></category>

		<guid isPermaLink="false">http://blog.mpathirage.com/?p=473</guid>
		<description><![CDATA[In this presentation, Joshua Bloch and  William Pugh describes eight short Java programs with curious behavior. Things discussed in this presentation will help you a lot, if you are a Java developer. Following is the list of problems and summary of things you can learn from studying those problems. 1. The Joy Of Sets What is [...]]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="340" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/wDN_EYUvUq0&amp;hl=en_US&amp;fs=1&amp;rel=0" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="340" src="http://www.youtube.com/v/wDN_EYUvUq0&amp;hl=en_US&amp;fs=1&amp;rel=0" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>In this presentation, <a href="http://en.wikipedia.org/wiki/Joshua_Bloch" target="_blank">Joshua Bloch</a> and  <a href="http://en.wikipedia.org/wiki/William_Pugh" target="_blank">William Pugh</a> describes eight short Java programs with curious behavior. Things discussed in this presentation will help you a lot, if you are a Java developer.</p>
<p>Following is the list of problems and summary of things you can learn from studying those problems.</p>
<p><strong><em>1. The Joy Of Sets</em></strong></p>
<p>What is the out put of following program.</p>
<p><script src="http://gist.github.com/449898.js?file=gistfile1.pde"></script> Moral of the above problem:</p>
<ul>
<li><strong><em>Collection&lt;E&gt;.remove</em></strong> takes <strong><em>Object</em></strong>, not <strong><em>E</em></strong></li>
<li>Integral arithmetic always results in <strong><em>int</em></strong> or <strong><em>long</em></strong></li>
<li>Avoid mixing types</li>
<li>Avoid <strong><em>short</em></strong>; prefer <strong><em>int</em></strong> and <strong><em>long</em></strong></li>
</ul>
<p><strong><em> 2. More Joy of Sets </em></strong> <strong><em><script src="http://gist.github.com/450066.js?file=gistfile1.pde"></script></em></strong></p>
<p>Out put of the above program will depends on the whether you are connected to internet or not. This happens because URL&#8217;s <strong>equals</strong> and <strong>hashCode</strong> are broken.</p>
<p>Things we can learn from above problem:</p>
<ul>
<li>Do not use <strong><em>URL</em></strong> as a <strong><em>Set</em></strong> element or <strong><em>Map</em></strong> key
<ul>
<li><strong><em>equals</em></strong> and <strong><em>hashCode</em></strong> aren&#8217;t well defined</li>
<li>They do not obey their general contracts</li>
</ul>
</li>
<li>Use <strong><em>URI</em></strong> instead of <strong><em>URL </em></strong>
<ul>
<li>Make <strong><em>URL</em></strong> from <strong><em>URI</em></strong> as neccessary</li>
</ul>
</li>
<li><strong><em>equals</em></strong> should not depends on the environment</li>
</ul>
<p>3. <strong><em>Racy Little Number</em></strong></p>
<p>How often does the following test pass.</p>
<p><script src="http://gist.github.com/450127.js?file=gistfile1.pde"></script> Moral of the problem:</p>
<ul>
<li>JUnit does not support concurrency</li>
<li>You must provide your own way of handling concurrency
<ul>
<li>If you don&#8217;t you will get a false sense of security</li>
</ul>
</li>
</ul>
<p>4. <strong><em>Elvis Lives Again</em></strong></p>
<p>What does following program print?<br />
 <script src="http://gist.github.com/454658.js?file=gistfile1.pde"></script></p>
<p>Moral of the problem:</p>
<ul>
<li>Wrapped primitives aren&#8217;t primitives
<ul>
<li>Prefer primitives to wrapped primitives</li>
</ul>
</li>
<li>Auto-unboxing can occur when you leas expect it
<ul>
<li>It can cause NullPointerException</li>
</ul>
</li>
<li>Never use <strong><em>Boolean</em></strong> as a three-valued return type
<ul>
<li>Almost guarantees <strong><em>NullPointerException</em></strong></li>
</ul>
</li>
<li>Watch out for circularities in class initialization
<ul>
<li>Construct instance at end of class initialization</li>
</ul>
</li>
</ul>
<p><em><strong>5. Mind The Gap</strong></em></p>
<p>What does following program prints?<br />
<script src="http://gist.github.com/454668.js?file=gistfile1.pde"></script></p>
<p>Moral of the problem:</p>
<ul>
<li>The <strong><em>skip</em></strong> method is hard to use and error prone.</li>
<li>Use your <strong><em>skipFully</em></strong>(you will learn about it during the presentation) instead of skip</li>
<li>More generally, if an API is broken, wrap it</li>
<li>For API designers
<ul>
<li>Don&#8217;t violate the principle of last astonishment</li>
<li>Make is easy to do simple things</li>
</ul>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.mpathirage.com/2010/06/27/java-puzzlers-phantom-reference-menace-attack-of-the-clone-revenge-of-the-shift/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JPA Implementation Patterns</title>
		<link>http://blog.mpathirage.com/2010/01/30/jpa-implementation-patterns/</link>
		<comments>http://blog.mpathirage.com/2010/01/30/jpa-implementation-patterns/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 11:28:57 +0000</pubDate>
		<dc:creator>Milinda Lakmal</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[DAO]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[Persistence]]></category>

		<guid isPermaLink="false">http://blog.mpathirage.com/?p=273</guid>
		<description><![CDATA[These days I am working on Human Task implementation for WSO2 Carbon platform, and decided to use JPA based persistence mechanism. While working on &#8216;Task Engine&#8217; implementation, I found out that JPA is not just about implementing set of entities and persisting them using &#8216;Entity Manager&#8217;. I found out that, there are small but very [...]]]></description>
			<content:encoded><![CDATA[<p>These days I am working on Human Task implementation for WSO2 Carbon platform, and decided to use JPA based persistence mechanism. While working on &#8216;Task Engine&#8217; implementation, I found out that JPA is not just about implementing set of entities and persisting them using &#8216;Entity Manager&#8217;. I found out that, there are small but very important things that anyone should know to make their JPA based implementations successful. Without those you&#8217;ll stuck in the middle of some thing, deciding what is the best option. While googling I found series of articles from <a title="Posts by Vincent Partington" href="http://blog.xebia.com/author/vpartington/" target="_blank">Vincent Partington</a> on JPA implementation patterns which are very useful for anyone who new to JPA. In this post I am going to summarize each and every post from &#8216;<a rel="nofollow" href="http://blog.xebia.com/2009/07/13/jpa-implementation-patterns-wrap-up/" target="_blank">JPA Implementation Patterns</a>&#8216; article series.</p>
<p><a rel="nofollow" href="http://blog.xebia.com/2009/03/09/jpa-implementation-patterns-data-access-objects/" target="_blank"><strong>Data Access Objects</strong></a></p>
<p>This post starts with the background information about JPA and JPA implementations. After that Vincent tells us that there are more things than data access object and domain objects, like transaction handling, lazy loading and detach objects.</p>
<p>Then he comes to the main topic and first describes why we need DAOs(<a rel="nofollow" href="http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html" target="_blank">Data Access Objects</a>) and how DAO layer which resides on top JPA can help you. After that he provides us with the information about type-safe generic DAO pattern, how to use DAO and advantages of type-safe generic DAO pattern.</p>
<p>In think this post is a must read for anyone who try to get started with JPA and this post help me a lot to understand issues in my JPA based implementation.</p>
<p><a rel="nofollow" href="http://blog.xebia.com/2009/03/16/jpa-implementation-patterns-bidirectional-assocations/" target="_blank"><strong>Bidirectional Associations</strong></a></p>
<p>This post is about association between JPA entities. And it mainly describes a bidirectional association pattern used by developers who use JPA. Vincent start this post with a sample and then describes how bidirectional association can make developers life easier. After that he describes problems associated with bidirectional association and provide reader with a patter that can use to solve the issues. At last he describes the variations to the patter the introduced and what user must consider before using this pattern.</p>
<p><strong><a rel="nofollow" href="http://blog.xebia.com/2009/03/23/jpa-implementation-patterns-saving-detached-entities/" target="_blank">Saving (detached) Entities</a></strong></p>
<p>This post talks about saving detached entities or merging changes done to the detached entities. First Vincent talked about how entities become detached and what  will happen when try to persist detached entity.</p>
<p>Then he describes about differences between Hibernate&#8217;s saveOrUpdate and JPA Entity Manager merge method.</p>
<p>In the last part of this post Vincent describes the problems with JPA merge and a pattern which every one can use to solve issues described with merge method.</p>
<p><strong><a rel="nofollow" href="http://blog.xebia.com/2009/04/03/jpa-implementation-patterns-retrieving-entities/" target="_blank">Retrieving Entities</a></strong></p>
<p>This post talks about two ways of retrieving an entity. One is using <a href="http://java.sun.com/javaee/5/docs/api/javax/persistence/EntityManager.html#find(java.lang.Class,%20java.lang.Object)">EntityManager.find</a> and other is using JPQL queries. This post contains three example ways of retrieving entities by using EntityManager.find and JPQL queries.</p>
<p><strong><a rel="nofollow" href="http://blog.xebia.com/2009/04/09/jpa-implementation-patterns-removing-entities/" target="_blank">Removing Entities</a></strong></p>
<p>This post mainly focused on removing entities with bi-directional relationships. And Vincent has described pattern to overcome issue with removing entities when there are bi-directional associations.</p>
<p><a rel="nofollow" href="http://blog.xebia.com/2009/05/11/jpa-implementation-patterns-service-facades-and-data-transfers-objects/" target="_blank"><strong>Service Facades and Data Transfer Objects</strong></a></p>
<p>This post is mainly about applying old school enterprise application architecture patterns to your JPA base implementations. First Vincent describes why we must bother about DAO&#8217;s DTO&#8217;s and Service Facades. Then he describes pros and cons of Data Transfer Objects(DTO) and pros and cons of Service Facades in JPA space. Finally he explain to you implications to your JPA architecture when you use DTO&#8217;s and Service Facades.</p>
<p><a rel="nofollow" href="http://blog.xebia.com/2009/04/27/jpa-implementation-patterns-lazy-loading/" target="_blank"><strong>Lazy Loading</strong></a></p>
<p>To use JPA to its full potential you must understand &#8216;Lazy Loading&#8217; and how it works. Understanding lazy loading will allow you to utilize computing resources effectively and help you to design you entities and their relationships in way that it increase the efficiency.</p>
<p>First part of the post is about lazy loading and when lazy  loading occur. Then post has some information about lazy loading implementation mechanisms. After that the post describes &#8220;Runtime proxy based lazy loading&#8221; in hibernate and &#8220;Runtime bytecode instrumentation&#8221; in OpenJPA. Then there is a seperate section on differences between Hibernate and OpenJPA. Finally post contains a patter which help us to effectively use lazy loading.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mpathirage.com/2010/01/30/jpa-implementation-patterns/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

