<?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>non-random ramble &#187; java</title>
	<atom:link href="http://jimbarritt.com/non-random/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://jimbarritt.com/non-random</link>
	<description>adventures in code</description>
	<lastBuildDate>Tue, 20 Sep 2011 13:16:52 +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>Oracle Jdbc Driver 10.2.0.2.0 fails to render Euro (€) when db is set to WE8MSWIN1252 encoding</title>
		<link>http://jimbarritt.com/non-random/2010/11/08/oracle-jdbc-driver-10-2-0-2-0-fails-to-render-euro-e-when-db-is-set-to-we8mswin1252-encoding/</link>
		<comments>http://jimbarritt.com/non-random/2010/11/08/oracle-jdbc-driver-10-2-0-2-0-fails-to-render-euro-e-when-db-is-set-to-we8mswin1252-encoding/#comments</comments>
		<pubDate>Mon, 08 Nov 2010 16:46:41 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[databases]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[random]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/?p=741</guid>
		<description><![CDATA[We just spent a few glorious hours or so trawling the internet and writing old skool jdbc code, to discover this little beauty. Simply upgrade to 10.2.0.5 of the jdbc driver and it goes away. Thanks to this post http://efreedom.com/Question/1-377745/Oracle-JDBC-Euro-Character we discovered our problem. For the full details on the euro&#8230;. http://www.fileformat.info/info/unicode/char/20ac/index.htm And if your [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jimbarritt.com/non-random/wp-content/uploads/2010/11/euro_sign.png" rel="lightbox[741]"><img src="http://jimbarritt.com/non-random/wp-content/uploads/2010/11/euro_sign.png" alt="" title="euro_sign" width="100" height="100" class="aligncenter size-full wp-image-743" /></a></p>
<p>We just spent a few glorious hours or so trawling the internet and writing old skool jdbc code, to discover this little beauty. Simply upgrade to 10.2.0.5 of the jdbc driver and it goes away.</p>
<p>Thanks to this post http://efreedom.com/Question/1-377745/Oracle-JDBC-Euro-Character we discovered our problem.</p>
<p>For the full details on the euro&#8230;. </p>
<p>http://www.fileformat.info/info/unicode/char/20ac/index.htm</p>
<p>And if your really bored:</p>
<p>http://www.fileformat.info/info/unicode/char/1f47e/index.htm</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2010%2F11%2F08%2Foracle-jdbc-driver-10-2-0-2-0-fails-to-render-euro-e-when-db-is-set-to-we8mswin1252-encoding%2F&amp;title=Oracle%20Jdbc%20Driver%2010.2.0.2.0%20fails%20to%20render%20Euro%20%28%E2%82%AC%29%20when%20db%20is%20set%20to%20WE8MSWIN1252%20encoding"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2010/11/08/oracle-jdbc-driver-10-2-0-2-0-fails-to-render-euro-e-when-db-is-set-to-we8mswin1252-encoding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing JRuby with Intellij (OS X)</title>
		<link>http://jimbarritt.com/non-random/2010/07/03/installing-jruby-with-intellij-os-x/</link>
		<comments>http://jimbarritt.com/non-random/2010/07/03/installing-jruby-with-intellij-os-x/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 09:14:25 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[build]]></category>
		<category><![CDATA[intellij]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[thoughtblog]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/?p=573</guid>
		<description><![CDATA[GET it from http://jruby.org/ There is a download page, download and exract the tar file somehwere. I put it in /System/Library/Frameworks/JRuby.framework/jruby-1.5.1 I then created a symbolic link to jruby_current And then simply add it to my ~/.bash_profile Now you can add the JRuby SDK to your Java Module in Intellij: Now you can have ruby [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jimbarritt.com/non-random/wp-content/uploads/2010/07/jruby.png" rel="lightbox[573]"><img src="http://jimbarritt.com/non-random/wp-content/uploads/2010/07/jruby.png" alt="" title="jruby" width="235" height="232" class="aligncenter size-full wp-image-574" /></a></p>
<p>GET it from <a href="http://jruby.org/#2">http://jruby.org/</a></p>
<p>There is a download page, download and exract the tar file somehwere.</p>
<p>I put it in <code>/System/Library/Frameworks/JRuby.framework/jruby-1.5.1</code></p>
<p>I then created a symbolic link to <code>jruby_current</code><br />
<pre name='code' class='java:nogutter:nocontrols'>
ln -s jruby-1.5.1/ jruby_current
</pre></p>
<p>And then simply add it to my <code>~/.bash_profile</code></p>
<pre name='code' class='java:nogutter:nocontrols'>
$vi ~/.bash_profile
export PATH=/System/Library/Frameworks/JRuby.framework/jruby_current/bin:$PATH
#Reload the profile&#8230;
$. ~/.bash_profile
#Try out jruby&#8230;
$jruby -v
jruby 1.5.1 (ruby 1.8.7 patchlevel 249) (2010-06-06 f3a3480) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_17) [x86_64-java]
</pre>
<p>Now you can add the JRuby SDK to your Java Module in Intellij:</p>
<p><a href="http://jimbarritt.com/non-random/wp-content/uploads/2010/07/jruby_sdk.png" rel="lightbox[573]"><img src="http://jimbarritt.com/non-random/wp-content/uploads/2010/07/jruby_sdk.png" alt="" title="jruby_sdk" width="600" /></a></p>
<p>Now you can have ruby and Java in the same project. Awesome.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2010%2F07%2F03%2Finstalling-jruby-with-intellij-os-x%2F&amp;title=Installing%20JRuby%20with%20Intellij%20%28OS%20X%29"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2010/07/03/installing-jruby-with-intellij-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Link from log console output to a line of code in IntelliJ</title>
		<link>http://jimbarritt.com/non-random/2010/05/16/link-from-log-console-output-to-a-line-of-code-in-intellij/</link>
		<comments>http://jimbarritt.com/non-random/2010/05/16/link-from-log-console-output-to-a-line-of-code-in-intellij/#comments</comments>
		<pubDate>Sun, 16 May 2010 13:47:55 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ides]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[thoughtblog]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/?p=480</guid>
		<description><![CDATA[Whilst playing around with some code analysis I thought it would be useful to be able to output a hyperlink back to a line of code in the IDE console. As it happens, you can &#8220;Trick&#8221; IntelliJ to do this with the following log statement: The pattern it seems to match is something like at [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jimbarritt.com/non-random/wp-content/uploads/2010/05/clickfromconsole.gif" rel="lightbox[480]"><img src="http://jimbarritt.com/non-random/wp-content/uploads/2010/05/clickfromconsole.gif" alt="" title="clickfromconsole" width="800"  class="aligncenter size-full wp-image-481" /></a></p>
<p>Whilst playing around with some code analysis I thought it would be useful to be able to output a hyperlink back to a line of code in the IDE console. As it happens, you can &#8220;Trick&#8221; IntelliJ to do this with the following log statement:</p>
<pre name='code' class='java:nogutter:nocontrols'>
    @Test
    public void canClickOnAFileInTheConsoleAndGoToTheLineOfCode() {
        log.info(String.format(&#8220;Check it at %s. (%s.java:%d)&#8221;,
            getClass().getName(), getClass().getSimpleName(), 15));
    }
</pre>
<p>The pattern it seems to match is something like <code>at {classFullName}.{identifier}({classSimpleName}.java)</code></p>
<p><code>classFullName</code> has to be a valid class name.<br />
<code>identifier</code> is usually used for the method name, but it can be anything. The full stop is nescessary. So in the example above, I put a space in there and so it reads like a sentance.</p>
<p>Anyone know a another way to do this?</p>
<p>UPDATE: </p>
<p>Actually it seems that you can get something similar if you output a full path name, e.g.:</p>
<pre name='code' class='java:nogutter:nocontrols'>
    File f = new File(&#8220;./src/test/resource/testfiles/level_01/level_01_01/file_01_01_A.txt&#8221;);
    log.info(f.getAbsolutePath() + &#8220;:&#8221; + 34);
</pre>
<p>This will create a link in the output window to the line of the file. Nice.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2010%2F05%2F16%2Flink-from-log-console-output-to-a-line-of-code-in-intellij%2F&amp;title=Link%20from%20log%20console%20output%20to%20a%20line%20of%20code%20in%20IntelliJ"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2010/05/16/link-from-log-console-output-to-a-line-of-code-in-intellij/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XStream collections: when is an ArrayList not an ArrayList ?</title>
		<link>http://jimbarritt.com/non-random/2009/11/25/xstream-collections-when-is-an-arraylist-not-an-arraylist/</link>
		<comments>http://jimbarritt.com/non-random/2009/11/25/xstream-collections-when-is-an-arraylist-not-an-arraylist/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 15:29:44 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jdk]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/?p=315</guid>
		<description><![CDATA[I was just getting the following output from XStream when trying to serialize an object which has a collection property: &#60;addresses class="java.util.Arrays$ArrayList"> &#60;a class="address-array"> &#60;address> It had to step through the code to see what was going on. The key is in the subtlety of the type of the list that I was putting in [...]]]></description>
			<content:encoded><![CDATA[<p>I was just getting the following output from XStream when trying to serialize an object which has a collection property:</p>
<pre>
&lt;addresses class="java.util.Arrays$ArrayList">
&lt;a class="address-array">
&lt;address>
</pre>
<p>It had to step through the code to see what was going on.</p>
<p>The key is in the subtlety of the type of the list that I was putting in there. Notice that actually its not an <code>java.util.ArrayList</code> its actually an inner class of the <code>Arrays</code>, called, happily <code>$ArrayList</code>, so I had been staring at it the whole time and not noticed.</p>
<p>When XStream serializes its doing the following:</p>
<pre name='code' class='java:nogutter:nocontrols'>
        Class actualType = newObj.getClass();
        Class defaultType = mapper.defaultImplementationOf(fieldType);
        if (!actualType.equals(defaultType)) {
            String serializedClassName = mapper.serializedClass(actualType);
            if (!serializedClassName.equals(mapper.serializedClass(defaultType))) {
                String attributeName = mapper.aliasForSystemAttribute(&#8220;class&#8221;);
                if (attributeName != null) {
                    writer.addAttribute(attributeName, serializedClassName);
                 }
            }
        }
</pre>
<p>From version 1.3.1 &#8211; <code>AbstractReflectionConverter:127</code></p>
<p>So its asking the mapper what the default implementation of the type is. The type in this case was <code>java.util.List</code> and the default implementation is of course <code>java.util.ArrayList</code>. It is not seeing <code>java.util.Arrays$ArrayList</code> as the same thing and so thinks it needs to specify it.</p>
<p>Now you might be asking, how come I have a strange inner class version of <code>ArrayList</code> ? Well the thing is, I thought I was being clever in the set up of my test data and im using:</p>
<pre name='code' class='java:nogutter:nocontrols'>
       addresses = Arrays.asList(
                new AddressBuilder().addressType(&#8220;home&#8221;).streetAddress(&#8220;1 The street&#8221;).build(),
                new AddressBuilder().addressType(&#8220;work&#8221;).streetAddress(&#8220;2 The street&#8221;).build(),
                new AddressBuilder().addressType(&#8220;holiday&#8221;).streetAddress(&#8220;3 The street&#8221;).build()
        );
</pre>
<p>To set up my test data. <code>asList</code> does this:</p>
<pre name='code' class='java:nogutter:nocontrols'>
 public static  List asList(T&#8230; a) {
	return new ArrayList(a);
    }
    private static class ArrayList extends AbstractList
	implements RandomAccess, java.io.Serializable
    {
        private static final long serialVersionUID = -2764017481108945198L;
	private Object[] a;
</pre>
<p>Where it uses its own implementation of ArrayList.</p>
<p>Phew, another fun couple of hours spent there.</p>
<p></e></t></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2009%2F11%2F25%2Fxstream-collections-when-is-an-arraylist-not-an-arraylist%2F&amp;title=XStream%20collections%3A%20when%20is%20an%20ArrayList%20not%20an%20ArrayList%20%3F"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2009/11/25/xstream-collections-when-is-an-arraylist-not-an-arraylist/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MacWidgets &#8211; Java Swing looking native on OS X</title>
		<link>http://jimbarritt.com/non-random/2009/11/15/macwidgets-java-swing-looking-native-on-os-x/</link>
		<comments>http://jimbarritt.com/non-random/2009/11/15/macwidgets-java-swing-looking-native-on-os-x/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 22:33:15 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[swing]]></category>
		<category><![CDATA[thoughtblog]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/?p=241</guid>
		<description><![CDATA[I just discovered Exploding Pixels&#8217; MacWidgets. Its a beautiful library. Literally just pasted a couple of lines of code into my Java app and now it looks right at home on the os x desktop. I&#8217;m running JDK 1.6 on Leopard. Here is is in action: And here is the code (its been edited slightly [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://exploding-pixels.com/google_code/graphics/UnifiedToolBar.png" /></p>
<p>I just discovered <a href="http://explodingpixels.wordpress.com/">Exploding Pixels&#8217;</a> <a href="http://code.google.com/p/macwidgets/">MacWidgets</a>. Its a beautiful library. Literally just pasted a couple of lines of code into my Java app and now it looks right at home on the os x desktop. I&#8217;m running JDK 1.6 on Leopard. </p>
<p>Here is is in action:</p>
<p><img src="http://jimbarritt.com/non-random/wp-content/uploads/2009/11/macwidgets-demo.jpg" alt="macwidgets-demo" title="macwidgets-demo" width="730" height="535" class="alignnone size-full wp-image-268" /></p>
<p>And here is the code (its been edited slightly so may not copy and paste, but you get the idea) &#8230;</p>
<pre name='code' class='java:nogutter:nocontrols'>
&nbsp;
        MacUtils.makeWindowLeopardStyle(getRootPane());
&nbsp;
        UnifiedToolBar toolBar = new UnifiedToolBar();
&nbsp;
        JButton button = new JButton(&#8220;My Button&#8221;);
        button.putClientProperty(&#8220;JButton.buttonType&#8221;, &#8220;textured&#8221;);
        toolBar.addComponentToLeft(button);
&nbsp;
        getContentPane().add(toolBar.getComponent(), BorderLayout.NORTH);
&nbsp;
        BottomBar bottomBar = new BottomBar(BottomBarSize.SMALL);
        bottomBar.addComponentToLeft(MacWidgetFactory.createEmphasizedLabel(&#8221; Status&#8221;));
&nbsp;
        getContentPane().add(bottomBar.getComponent(), BorderLayout.SOUTH);
&nbsp;
</pre>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2009%2F11%2F15%2Fmacwidgets-java-swing-looking-native-on-os-x%2F&amp;title=MacWidgets%20%26%238211%3B%20Java%20Swing%20looking%20native%20on%20OS%20X"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2009/11/15/macwidgets-java-swing-looking-native-on-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java UTC Date formatting</title>
		<link>http://jimbarritt.com/non-random/2009/08/14/java-utc-date-formatting/</link>
		<comments>http://jimbarritt.com/non-random/2009/08/14/java-utc-date-formatting/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 11:30:45 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/2009/08/14/java-utc-date-formatting/</guid>
		<description><![CDATA[I was trying to fix a test that is expecting a date to come back in UTC format. It was using the XStream ISO8601DateConverter. It worked fine if you were in the UK timezone, but not in a different timezone. It hurt my head, so I wrote a test to demonstrate how to make it [...]]]></description>
			<content:encoded><![CDATA[<p>I was trying to fix a test that is expecting a date to come back in UTC format.</p>
<p>It was using the XStream ISO8601DateConverter.</p>
<p>It worked fine if you were in the UK timezone, but not in a different timezone.</p>
<p>It hurt my head, so I wrote a test to demonstrate how to make it work.</p>
<p>Which is <a href="http://jimbarritt.com/non-random/wp-content/uploads/2009/08/dateformattingtestjava.txt">DateFormattingTest.java</a> here.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2009%2F08%2F14%2Fjava-utc-date-formatting%2F&amp;title=Java%20UTC%20Date%20formatting"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2009/08/14/java-utc-date-formatting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java array initialisation&#8230;</title>
		<link>http://jimbarritt.com/non-random/2008/12/04/java-array-initialisation/</link>
		<comments>http://jimbarritt.com/non-random/2008/12/04/java-array-initialisation/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 17:51:44 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/2008/12/04/java-array-initialisation/</guid>
		<description><![CDATA[I didn&#8217;t realise i can do this: final String[] stringArray = {"string0", "string1", "string2"};]]></description>
			<content:encoded><![CDATA[<p>I didn&#8217;t realise i can do this:</p>
<pre name="code" class="java">
final String[] stringArray = {"string0", "string1", "string2"};
</pre>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2008%2F12%2F04%2Fjava-array-initialisation%2F&amp;title=Java%20array%20initialisation%26%238230%3B"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2008/12/04/java-array-initialisation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Initialisation inline or in Constructor ?</title>
		<link>http://jimbarritt.com/non-random/2008/12/03/initialisation-inline-or-in-constructor/</link>
		<comments>http://jimbarritt.com/non-random/2008/12/03/initialisation-inline-or-in-constructor/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 12:00:31 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[anecdotes]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/2008/12/03/initialisation-inline-or-in-constructor/</guid>
		<description><![CDATA[private Map&#60;String, String&#62; nodeValueMap = new HashMap&#60;String, String&#62;(); private Map&#60;String, NodeHandler&#62; nodeHandlers = new HashMap&#60;String, NodeHandler&#62;(); Or public MyClass() { this.nodeValueMap = new HashMap&#60;String, String&#62;(); this.nodeHandlers = new HashMap&#60;String, NodeHandler&#62;(); } Well, I think I might have a rule of thumb&#8230; If you don&#8217;t actually have a constructor, then you should use inline instantiation. As [...]]]></description>
			<content:encoded><![CDATA[<pre name="code" class="java:nogutter:nocontrols">
private Map&lt;String, String&gt; nodeValueMap = new HashMap&lt;String, String&gt;();
private Map&lt;String, NodeHandler&gt; nodeHandlers = new HashMap&lt;String, NodeHandler&gt;();
</pre>
<p>Or</p>
<pre name="code" class="java:nogutter:nocontrols">
public MyClass() {
    this.nodeValueMap = new HashMap&lt;String, String&gt;();
    this.nodeHandlers = new HashMap&lt;String, NodeHandler&gt;();
}
</pre>
<p>Well, I think I might have a rule of thumb&#8230; If you don&#8217;t actually have a constructor, then you should use inline instantiation. As soon as you need to do some more complex logic in the constructor (in the case above I might want to initialise the map with some objects) then move <strong>all</strong> the initialisers into the constructor ? </p>
<p>i.e. don&#8217;t have multiple patterns going on.</p>
<p>As an aside, a quick discussion with Alistair (of <a href='http://www.howbigismypotato.com/'>how big is my potato</a> fame) reminded me of the fact that you can actually do an instance initialisation like:</p>
<pre name="code" class ="java:nogutter:nocontrols">
{
    this.nodeValueMap = new HashMap&lt;String, String&gt;();
    this.nodeHandlers = new HashMap&lt;String, NodeHandler&gt;();
}
</pre>
<p>Although what the case for doing so is im not sure, might be nice if you are making a STRUCT kind of object.</p>
<p>Also I didn&#8217;t realise that you can declare a class inside a method:</p>
<pre name="code" class ="java:nogutter:nocontrols">
public void doSomething() {
    public class InnerClasss{
        public void sayHello() { System.out.println("hello");}
    }

    InnerClass inst = new InnerClass();
    inst.sayHello();
}
</pre>
<p>Alistair had used this for testing some reflection code, when he needed some test classes to work with. </p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2008%2F12%2F03%2Finitialisation-inline-or-in-constructor%2F&amp;title=Initialisation%20inline%20or%20in%20Constructor%20%3F"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2008/12/03/initialisation-inline-or-in-constructor/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Goto in Java</title>
		<link>http://jimbarritt.com/non-random/2008/10/21/goto-in-java/</link>
		<comments>http://jimbarritt.com/non-random/2008/10/21/goto-in-java/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 11:18:08 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/2008/10/21/goto-in-java/</guid>
		<description><![CDATA[So there is no GOTO in java, although I believe it is a reserved keyword. However, you can do this &#8230; while ( ... ) { level1: for ( ... ) { for( ... ) { break level1; } } } It allows you to break out of a set of nested loops back to [...]]]></description>
			<content:encoded><![CDATA[<p>So there is no GOTO in java, although I believe it is a reserved keyword.</p>
<p>However, you can do this &#8230;</p>
<pre>
<code>
    while ( ... ) {
         level1:
         for ( ... ) {
              for( ... ) {
                   break level1;
              }
         }
    }
</code>
</pre>
<p>It allows you to break out of a set of nested loops back to whichever level you like.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2008%2F10%2F21%2Fgoto-in-java%2F&amp;title=Goto%20in%20Java"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2008/10/21/goto-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

