<?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>Grayger &#187; Java</title>
	<atom:link href="http://www.grayger.com/category/java-eng/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.grayger.com</link>
	<description>In the pursuit of effectiveness</description>
	<lastBuildDate>Sat, 02 Jul 2011 16:38:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Hidden Features of Java</title>
		<link>http://www.grayger.com/java-eng/hidden-features-of-java/</link>
		<comments>http://www.grayger.com/java-eng/hidden-features-of-java/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 15:58:31 +0000</pubDate>
		<dc:creator>grayger</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.grayger.com/wp/?p=51</guid>
		<description><![CDATA[A few days ago, I registered stackoverflow.com and found an interesting post: what are hidden features of Java?
The stuffs that I didn&#8217;t know before are

Double brace initialization


	Map map=new HashMap&#60;String,String&#62;() {
		{
			put(&#34;key1&#34;,&#34;value1&#34;);
			put(&#34;key2&#34;,&#34;value2&#34;);
		}
	};

Instance initializer


public class Initializer {
	static {
		System.out.println(&#34;static&#34;);
	}
	{
		System.out.println(&#34;instance&#34;);
	}
	public Initializer() {
		System.out.println(&#34;constructor&#34;);
	}
}

Covariant return type


	abstract class Base {
		abstract List getList();
	}

	class Sub extends Base {
		@Override
		ArrayList getList() {
			return null;
		}
	}


Double brace initialization uses instance [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago, I registered stackoverflow.com and found an interesting post: <a href="http://stackoverflow.com/questions/15496/hidden-features-of-java">what are hidden features of Java?</a></p>
<p>The stuffs that I didn&#8217;t know before are</p>
<ul>
<li>Double brace initialization</li>
<pre class="brush: java; ">

	Map map=new HashMap&lt;String,String&gt;() {
		{
			put(&quot;key1&quot;,&quot;value1&quot;);
			put(&quot;key2&quot;,&quot;value2&quot;);
		}
	};
</pre>
<li>Instance initializer</li>
<pre class="brush: java; ">

public class Initializer {
	static {
		System.out.println(&quot;static&quot;);
	}
	{
		System.out.println(&quot;instance&quot;);
	}
	public Initializer() {
		System.out.println(&quot;constructor&quot;);
	}
}
</pre>
<li>Covariant return type</li>
<pre class="brush: java; ">

	abstract class Base {
		abstract List getList();
	}

	class Sub extends Base {
		@Override
		ArrayList getList() {
			return null;
		}
	}
</pre>
</ul>
<p>Double brace initialization uses instance initializer because first brace is for declairing annomymous inner class and second brace is for instance initializer block.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.grayger.com/java-eng/hidden-features-of-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java VM Optimization</title>
		<link>http://www.grayger.com/java-eng/32/</link>
		<comments>http://www.grayger.com/java-eng/32/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 14:36:54 +0000</pubDate>
		<dc:creator>grayger</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.grayger.com/wp/?p=32</guid>
		<description><![CDATA[I saw a presentation on Java VM optimization via InfoQ. Java is originally slow, but HotSpot compiler is getting smarter enough to free Java from the shame.
http://www.infoq.com/presentations/pampuch-vm-optimizations-language-designers
]]></description>
			<content:encoded><![CDATA[<p>I saw a presentation on Java VM optimization via InfoQ. Java is originally slow, but HotSpot compiler is getting smarter enough to free Java from the shame.</p>
<p><a href="http://www.infoq.com/presentations/pampuch-vm-optimizations-language-designers">http://www.infoq.com/presentations/pampuch-vm-optimizations-language-designers</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.grayger.com/java-eng/32/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java deadlock detection</title>
		<link>http://www.grayger.com/java-eng/java-deadlock-detection/</link>
		<comments>http://www.grayger.com/java-eng/java-deadlock-detection/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 16:27:44 +0000</pubDate>
		<dc:creator>grayger</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Deadlock]]></category>
		<category><![CDATA[Profiler]]></category>

		<guid isPermaLink="false">http://www.grayger.com/wp/?p=23</guid>
		<description><![CDATA[Detecting deadlock is one of common features of Java profiling tools but I haven&#8217;t experienced the situation where those tools detect deadlock from code I wrote. In fact, deadlock is hazardous because it is difficult to predict and reproduce.
I wondered under what conditions do profilers detect deadlock and then report it, so I wrote code [...]]]></description>
			<content:encoded><![CDATA[<p>Detecting deadlock is one of common features of Java profiling tools but I haven&#8217;t experienced the situation where those tools detect deadlock from code I wrote. In fact, deadlock is hazardous because it is difficult to predict and reproduce.</p>
<p>I wondered under what conditions do profilers detect deadlock and then report it, so I wrote code that reaches deadlock.</p>
<pre class="brush: java; ">

package com.grayger.deadlock;

public class SimpleDeadlocker {
	private final static Object OBJ1=new Object();
	private final static Object OBJ2=new Object();

	private final static int LOOP=100;

	public void obj1First() {
		synchronized(OBJ1) {
			printInfo(&quot;Hold OBJ1&quot;);
			synchronized(OBJ2) {
				printInfo(&quot;Hole OBJ2&quot;);
			}
			printInfo(&quot;Release OBJ2&quot;);
		}
		printInfo(&quot;Release OBJ1&quot;);
	}

	public void obj2First() {
		synchronized(OBJ2) {
			printInfo(&quot;Hold OBJ2&quot;);
			synchronized(OBJ1) {
				printInfo(&quot;Hole OBJ1&quot;);
			}
			printInfo(&quot;Release OBJ1&quot;);
		}
		printInfo(&quot;Release OBJ2&quot;);
	}

	private void printInfo(String info) {
		System.out.println(Thread.currentThread().getName()+&quot; &quot;+info);
	}

	public static void main(String args[]) {
		final SimpleDeadlocker d=new SimpleDeadlocker();
		Thread t1=new Thread(new Runnable() {
			public void run() {
				for(int i=0;i&lt;loop;i++)&gt;
					d.obj1First();
				}
				d.printInfo(&quot;Terminated&quot;);
			}
		}, &quot;OBJ1_First&quot;);

		Thread t2=new Thread(new Runnable() {
			public void run() {
				for(int i=0;i&lt;loop;i++)&gt;
					d.obj2First();
				}
				d.printInfo(&quot;Terminated&quot;);
			}
		}, &quot;OBJ2_First&quot;);

		t1.start();
		t2.start();
	}
}
</pre>
<p>Above example can be refactored as follows:</p>
<pre class="brush: java; ">

package com.grayger.deadlock;

public class Deadlocker {
	private final static int LOOP=100;

	static class Deadlock1 {
		private final static Object OBJ1=new Object();
		private final static Object OBJ2=new Object();		

		public void obj1First() {
			synchronized(OBJ1) {
				printInfo(&quot;Hold OBJ1&quot;);
				synchronized(OBJ2) {
					printInfo(&quot;Hole OBJ2&quot;);
				}
				printInfo(&quot;Release OBJ2&quot;);
			}
			printInfo(&quot;Release OBJ1&quot;);
		}
	}

	static class Deadlock2 {
		private final static Object OBJ1=new Object();
		private final static Object OBJ2=new Object();

		public void obj2First() {
			synchronized(OBJ2) {
				printInfo(&quot;Hold OBJ2&quot;);
				synchronized(OBJ1) {
					printInfo(&quot;Hole OBJ1&quot;);
				}
				printInfo(&quot;Release OBJ1&quot;);
			}
			printInfo(&quot;Release OBJ2&quot;);
		}
	}

	public static void printInfo(String info) {
		System.out.println(Thread.currentThread().getName()+&quot; &quot;+info);
	}

	public static void main(String args[]) {
		final Deadlock1 d1=new Deadlock1();
		final Deadlock2 d2=new Deadlock2();
		Thread t1=new Thread(new Runnable() {
			public void run() {
				for(int i=0;i&lt;loop;i++)&gt;
					d1.obj1First();
				}
				Deadlocker.printInfo(&quot;Terminated&quot;);
			}
		}, &quot;OBJ1_First&quot;);

		Thread t2=new Thread(new Runnable() {
			public void run() {
				for(int i=0;i&lt;loop;i++)&gt;
					d2.obj2First();
				}
				Deadlocker.printInfo(&quot;Terminated&quot;);
			}
		}, &quot;OBJ2_First&quot;);

		t1.start();
		t2.start();
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.grayger.com/java-eng/java-deadlock-detection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>@Override annotation in Java6</title>
		<link>http://www.grayger.com/java-eng/override-annotation-in-java6/</link>
		<comments>http://www.grayger.com/java-eng/override-annotation-in-java6/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 16:10:32 +0000</pubDate>
		<dc:creator>grayger</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Annotation]]></category>

		<guid isPermaLink="false">http://www.grayger.com/wp/?p=31</guid>
		<description><![CDATA[The @Override annotation added in Java5 is very useful. Recently I found out the annotation of Java6 differs from that of Java5. Java6 allows annotating a method that implements a method declared in interface with @Override whereas Java5 doesn&#8217;t allow it.
Unfortunately I couldn&#8217;t find any document on the change from java.sun.com site. Missing this issue [...]]]></description>
			<content:encoded><![CDATA[<p>The @Override annotation added in Java5 is very useful. Recently I found out the annotation of Java6 differs from that of Java5. Java6 allows annotating a method that implements a method declared in interface with @Override whereas Java5 doesn&#8217;t allow it.</p>
<p>Unfortunately I couldn&#8217;t find any document on the change from java.sun.com site. Missing this issue from the release note of Java6 seems to be a mistake as <a title="http://blogs.sun.com/ahe/entry/override_snafu" href="http://blogs.sun.com/ahe/entry/override_snafu">http://blogs.sun.com/ahe/entry/override_snafu</a> says.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.grayger.com/java-eng/override-annotation-in-java6/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Implementation patterns</title>
		<link>http://www.grayger.com/java-eng/implementation-patterns/</link>
		<comments>http://www.grayger.com/java-eng/implementation-patterns/#comments</comments>
		<pubDate>Fri, 22 Feb 2008 13:26:00 +0000</pubDate>
		<dc:creator>grayger</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Design pattern]]></category>
		<category><![CDATA[Implementation patterns]]></category>

		<guid isPermaLink="false">http://www.grayger.com/wp/?p=28</guid>
		<description><![CDATA[Kent Beck&#8217;s &#8220;Implementation patterns&#8221; is the first book that I bought in this year. Its main concern is how to write better code that is readable and understandable, and it also touchs fundamentals of software design especially OOP. One of the book&#8217;s keywords is &#8220;intention&#8221;. Its strengths lie in being well-structured, easy to understand and [...]]]></description>
			<content:encoded><![CDATA[<p>Kent Beck&#8217;s &#8220;Implementation patterns&#8221; is the first book that I bought in this year. Its main concern is how to write better code that is readable and understandable, and it also touchs fundamentals of software design especially OOP. One of the book&#8217;s keywords is &#8220;intention&#8221;. Its strengths lie in being well-structured, easy to understand and thin.</p>
<p>However it is not a pioneeering book like DP of GoF; it doesn&#8217;t address something really new. That makes me a little disppointed because I have expected it would tell me lots of stuffs that I didn&#8217;t realize before. It is like a well-documented wikipedia in that sense.</p>
<p>The title of book need to be changed to &#8220;Implementation patterns in Java&#8221;. It is not just because example code of the book is written in Java but because some topics are very specific to Java so that these topics are not concerns of Non-Java developers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.grayger.com/java-eng/implementation-patterns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Annotation in Swing</title>
		<link>http://www.grayger.com/uncategorized/annotation-in-swing/</link>
		<comments>http://www.grayger.com/uncategorized/annotation-in-swing/#comments</comments>
		<pubDate>Fri, 19 Oct 2007 02:27:00 +0000</pubDate>
		<dc:creator>grayger</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Annotation]]></category>
		<category><![CDATA[JUnit4]]></category>
		<category><![CDATA[Swing]]></category>

		<guid isPermaLink="false">http://grayger.hosting.paran.com/wordpress/?p=13</guid>
		<description><![CDATA[The annotation, already a must in Junit4, is adopted by Swing (JSR 296).
http://java.sun.com/developer/technicalArticles/javase/swingappfr/
It is becoming a trend.
]]></description>
			<content:encoded><![CDATA[<p>The annotation, already a must in Junit4, is adopted by Swing (JSR 296).<br />
<a href="http://java.sun.com/developer/technicalArticles/javase/swingappfr/">http://java.sun.com/developer/technicalArticles/javase/swingappfr/</a></p>
<p>It is becoming a trend.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.grayger.com/uncategorized/annotation-in-swing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PMD rules from Effective Java</title>
		<link>http://www.grayger.com/uncategorized/pmd-rules-from-effective-java/</link>
		<comments>http://www.grayger.com/uncategorized/pmd-rules-from-effective-java/#comments</comments>
		<pubDate>Wed, 31 Jan 2007 06:06:00 +0000</pubDate>
		<dc:creator>grayger</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Effective Java]]></category>
		<category><![CDATA[PMD]]></category>

		<guid isPermaLink="false">http://grayger.hosting.paran.com/wordpress/?p=10</guid>
		<description><![CDATA[When I installed PMD plugin to my Eclipse and tested the plugin, I found that following rules appear in &#8220;Effective Java&#8221; by Joshua.
* OverrideBothEqualsAndHashcode
* FinalizeDoesNotCallSuperFinalize
* ConstructorCallsOverridableMethod
* ProperCloneImplementation
* CloneThrowsCloneNotSupportedException
* CloneMethodMustImplementCloneable
* ReplaceVectorWithList
* ReplaceHashtableWithMap
* UseArrayListInsteadOfVector
* ReturnFromFinallyBlock
* EmptyCatchBlock
* ExceptionAsFlowControl
]]></description>
			<content:encoded><![CDATA[<p>When I installed PMD plugin to my Eclipse and tested the plugin, I found that following rules appear in &#8220;Effective Java&#8221; by Joshua.</p>
<p>* OverrideBothEqualsAndHashcode<br />
* FinalizeDoesNotCallSuperFinalize<br />
* ConstructorCallsOverridableMethod<br />
* ProperCloneImplementation<br />
* CloneThrowsCloneNotSupportedException<br />
* CloneMethodMustImplementCloneable<br />
* ReplaceVectorWithList<br />
* ReplaceHashtableWithMap<br />
* UseArrayListInsteadOfVector<br />
* ReturnFromFinallyBlock<br />
* EmptyCatchBlock<br />
* ExceptionAsFlowControl</p>
]]></content:encoded>
			<wfw:commentRss>http://www.grayger.com/uncategorized/pmd-rules-from-effective-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

