<?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>Gigu's blog &#187; java</title>
	<atom:link href="http://blog.gigoo.org/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.gigoo.org</link>
	<description>wEBbLOG</description>
	<lastBuildDate>Thu, 01 Jul 2010 22:59:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A same cup of Java &#8230;</title>
		<link>http://blog.gigoo.org/2010/07/01/a-same-cup-of-java/</link>
		<comments>http://blog.gigoo.org/2010/07/01/a-same-cup-of-java/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 22:59:21 +0000</pubDate>
		<dc:creator>Greg Gigon</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[stuff]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[languages]]></category>

		<guid isPermaLink="false">http://blog.gigoo.org/2010/07/01/a-same-cup-of-java/</guid>
		<description><![CDATA[… at IKEA.
&#160;
Recently I changed the job. After three years (longest I ever worked for a single company) I left ThoughtWorks. Majority of my consultant career oscillated in .NET space. It was almost three years since last I was doing Java. New job … is Java (packed full of Java technologies). 
I had to do [...]]]></description>
			<content:encoded><![CDATA[<p>… at IKEA.</p>
<p>&#160;</p>
<p><img style="border-right-width: 0px; margin: 0px 10px 0px 0px; display: inline; float: left; border-top-width: 0px; border-left-width: 0px" border="0" align="left" src="http://stacyprowell.com/blog/wp-content/uploads/2009/04/java_logo_21.png" width="123" height="163" />Recently I changed the job. After three years (longest I ever worked for a single company) I left ThoughtWorks. Majority of my consultant career oscillated in .NET space. It was almost three years since last I was doing Java. New job … is Java (packed full of Java technologies). </p>
<p>I had to do some IKEA shopping one late afternoon after work (something for the house). As my journey turned out to be a waste of time (items out of stock) I was sitting in front of the IKEA building consuming a horrible £1.40 Hot Dog Menu 2. Watching the sun set I had a little epiphany! I started new job, I got dropped into source code and I was able to work without relearning Java, libraries and tools. </p>
<p>Then I realised that through three years of work at TW, C# and .NET changed it’s shape a lot. In a mean time Java did nothing,well … almost nothing. C# introduced new language syntax, features, influenced by dynamic and functional languages. Java had got annotations and generics (somehow weird generics).</p>
<p>Is that a bed thing? It gives stable platform, and more consistent syntax in legacy code. On the other hand it lacks cool features, and I do have to admit, I like new features. It’s like every time when Apple releases new iPhone instead of all cool new things on it all you get is better performance and stability <img src='http://blog.gigoo.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>There is also the explosion of languages that run on JVM. I like <a href="http://groovy.codehaus.org/" onclick="javascript:pageTracker._trackPageview('/outbound/article/groovy.codehaus.org');" target="_blank">Groovy</a> and <a href="http://jruby.org/" onclick="javascript:pageTracker._trackPageview('/outbound/article/jruby.org');" target="_blank">JRuby</a>, I need to check out <a href="http://clojure.org/" onclick="javascript:pageTracker._trackPageview('/outbound/article/clojure.org');" target="_blank">Clojure</a> and <a href="http://www.scala-lang.org/" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.scala-lang.org');" target="_blank">Scala</a>. </p>
<p>There was a lot of fear when Oracle purchased Sun. Next new release of Java will have closures. If it is caused by Oracle’s influence I hope for more to come.</p>
<p>It is about time for Java to make some tuff decisions and stop being 100% backwards compatible.</p>
<p>What you think? Comment me your thoughts.</p>
<p>Cheers, Greg</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gigoo.org/2010/07/01/a-same-cup-of-java/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to deal with nulls</title>
		<link>http://blog.gigoo.org/2010/03/18/how-to-deal-with-nulls/</link>
		<comments>http://blog.gigoo.org/2010/03/18/how-to-deal-with-nulls/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 07:30:08 +0000</pubDate>
		<dc:creator>Greg Gigon</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[stuff]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[null]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[patterns]]></category>

		<guid isPermaLink="false">http://blog.gigoo.org/?p=4912</guid>
		<description><![CDATA[This week I’ve been refactoring and improving some code in a .Net world. In last few weeks I also had some close encounters with Java as well. When looking at the code in both environments I realized that there is a lot of checking for null values on in a code. Where it is not [...]]]></description>
			<content:encoded><![CDATA[<p>This week I’ve been refactoring and improving some code in a <strong>.Net</strong> world. In last few weeks I also had some close encounters with <strong>Java</strong> as well. When looking at the code in both environments I realized that there is a lot of checking for <strong>null</strong> values on in a code. Where it is not a bad practice to check for null it actually presents another problem.</p>
<p>For someone like me when I was new to a code I couldn’t guess, what is the goal of that check. When you dealing with <strong>null</strong> the very important thing is to know where they came from and why it happened that null values occurred. When dealing with integration points it is even more important.</p>
<p>As you can guess code:</p>
<pre>if (serverResponse == null)
{
    DoSomeStuff();
}</pre>
<p>is not very descriptive. What actually happend when I got null, does it mean that there was a communication problem, error occurred or perhaps a null means that the operation was successful.</p>
<p>I think the best approach will be to avoid nulls if it is possible at all. Ways we could try to avoid it:<br />
•   <strong> use Maybe pattern<br />
•   create Empty object values<br />
•   use Null Object pattern</strong></p>
<h3>Maybe pattern</h3>
<p>I’m not sure if that is it’s appropriate name but I’ve used it on few projects and it seems like people are referring to it this way.</p>
<p>Have a Maybe interface and return it instead of the object itself.</p>
<pre>interface Maybe&lt;T&gt;
{
    bool Hasvalue;
    T Value;
}</pre>
<p>Also have two implementation of the interface:</p>
<pre class="csharp">public class Something&lt;T&gt;
{
    private readonly T _value;
    public Something(T value)
    {
        _value = value;
    }

    bool HasValue { get { return true; }  }
    T Value { get { return value; } }
}

public class Nothing&lt;T&gt;
{
    bool HasValue { get { return false; } }
    T Value { get { throw new InvalidOperationException(); } }
}</pre>
<p>When returning value from an object return Maybe. Collaborator that consumes value can check if it is Something or Nothing or just ask if it has value.</p>
<h3>Empty Object value</h3>
<p>Just like string.Empty you can implement Empty or something similar as predefined value on your type. For example:</p>
<pre>class Hen
{
    Egg LayEgg()
    {
        // doing stuff
        return Egg.Empty;
    }
}

class Egg
{
    public static Egg Empty = new Egg(“nothing in it”);
}</pre>
<p>You can always check before the execution if the egg is empty.</p>
<h3>Null object pattern</h3>
<p>Object with no default behavior. For example:</p>
<pre>interface TV
{
void ShowMovie();
}

class LCD : TV
{
    void ShowMovie()
    {
        // showing movie
    }
}

class Plasma : TV
{
    void ShowMovie()
    {
        // showing movie
    }
}

class NullTV : TV
{
    void ShowMovie()
    {
        // do nothing
    }
}</pre>
<p>If something is not working well and we don’t have any of the TVs available we could return NullTV and nothing will happen.<br />
Using the patter we can validate by type if the returned TV is a valid object and act accordingly.</p>
<p>I’m interested what other approaches people are heaving. Also what are the approaches in dynamic languages like Python or Ruby.</p>
<p><span style="text-decoration: underline;"><strong>Please add your comment <img src='http://blog.gigoo.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </strong></span></p>
<p>Greg</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gigoo.org/2010/03/18/how-to-deal-with-nulls/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Percent encoding in Groovy</title>
		<link>http://blog.gigoo.org/2010/02/01/percent-encoding-in-groovy/</link>
		<comments>http://blog.gigoo.org/2010/02/01/percent-encoding-in-groovy/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 23:35:46 +0000</pubDate>
		<dc:creator>Greg Gigon</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[encoding]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.gigoo.org/?p=4860</guid>
		<description><![CDATA[I was writing some helpers for OAuth Twitter authorization. One of the problem I got was the encoding. OAuth is using UTF-8 and percent encoding (special style of URL ecoding).
I couldn&#8217;t find anything build-in in Java or Groovy so I wrote a very short little method that does it.
 def encodeString(def stringToEncode){
 def reservedCaracters = [...]]]></description>
			<content:encoded><![CDATA[<p>I was writing some helpers for OAuth Twitter authorization. One of the problem I got was the encoding. OAuth is using UTF-8 and <a title="Percent encoding" href="http://en.wikipedia.org/wiki/Percent-encoding" onclick="javascript:pageTracker._trackPageview('/outbound/article/en.wikipedia.org');" target="_blank">percent encoding</a> (special style of URL ecoding).</p>
<p>I couldn&#8217;t find anything build-in in Java or Groovy so I wrote a very short little method that does it.</p>
<p><span> </span><em><strong>def encodeString(def stringToEncode){</strong></em></p>
<p><span><em><strong> </strong></em></span><em><strong>def reservedCaracters = [32:1, 33:1, 42:1, 34:1, 39:1, 40:1, 41:1, 59:1, 58:1, 64:1, 38:1, 61:1, 43:1, 36:1, 33:1, 47:1, 63:1, 37:1, 91:1, 93:1, 35:1]</strong></em></p>
<p><span><em><strong> </strong></em></span><em><strong>def encoded =  stringToEncode.collect { letter -&gt;<br />
reservedCaracters[(int)letter] ? &#8220;%&#8221; +Integer.toHexString((int)letter).toString().toUpperCase() : letter<br />
}<br />
return encoded.join(&#8220;&#8221;)<br />
}</strong></em></p>
<p>If you ever need something similar, use it <img src='http://blog.gigoo.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Greg</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gigoo.org/2010/02/01/percent-encoding-in-groovy/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>F1 Dashboard released</title>
		<link>http://blog.gigoo.org/2009/08/17/f1-dashboard-released/</link>
		<comments>http://blog.gigoo.org/2009/08/17/f1-dashboard-released/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 22:31:35 +0000</pubDate>
		<dc:creator>Greg Gigon</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[stuff]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[gae]]></category>
		<category><![CDATA[google app engine]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.gigoo.org/?p=4815</guid>
		<description><![CDATA[In last few months I was working on a little personal project. When Google App Engine team announced that preview of Java version is available I decided to give it a try. When I was looking for a subject of my application, one of the ideas started to emerge more that others. I was looking [...]]]></description>
			<content:encoded><![CDATA[<p>In last few months I was working on a little personal project. When Google App Engine team announced that preview of Java version is available I decided to give it a try. When I was looking for a subject of my application, one of the ideas started to emerge more that others. I was looking for a web site that could aggregate all the information about Formula 1 racing. Because there was none available (or my Google search ended on first few results that were not satisfactory) I decided to make one.</p>
<p>Few weeks and cups of coffee latter <a title="F1 Dashboard.com" href="http://www.f1dashboard.com" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.f1dashboard.com');" target="_blank">F1Dashboard.com</a> is released.</p>
<p style="text-align: center;">
<div id="attachment_4820" class="wp-caption alignnone" style="width: 489px"><img class="size-full wp-image-4820" title="F1 Dashboard screen shot" src="http://blog.gigoo.org/wp-content/uploads/2009/08/f1-dashboard.jpg" alt="F1 Dashboard screen shot" width="479" height="207" /><p class="wp-caption-text">F1 Dashboard screen shot</p></div>
<h3>Generalities</h3>
<p>So, in few words, F1 Dashboard is agregator of news, and media feeds from world of Formula 1. I decided not to collect content, just store information where to find it and short description.</p>
<p>News are harvested from a number of web sites. Twitter updates serves as another source of news.</p>
<p>Images are comming from Flickr, videos from YouTube.</p>
<p>All updates  are happening every few minutes and are 100% automated.</p>
<h3>Technicalities</h3>
<p>GAE supports Groovy as one of JVM programming languages. I decided to give it a try. I love Groovy, it is somewhere in between a friendly and known Java API and Ruby programming language.</p>
<p>It took me a moment to use to BigTable type of DataStore. It restrictes a way I used to work with databases normaly. Google provide entire environment for local development, whitch means I don&#8217;t have to upload to a cloud to see working result.</p>
<p>I created a little homegrown Model Views Presenter/Controller framework and used StringTemplate as rendering engine.</p>
<p>jQuery is the library of choice to handle all JavaScript.</p>
<p>Page styling was done by a friendly and kind designer from <a title="Circa82" href="http://www.circa82.co.uk" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.circa82.co.uk');" target="_blank">Circa82</a> Michael Austin (thanks buddy).</p>
<p>Come on guys, give it a try and tell me what you think <img src='http://blog.gigoo.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Feedback greatlly appriciated. <a title="http://www.f1dashboard.com" href="http://www.f1dashboard.com" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.f1dashboard.com');" target="_blank">http://www.f1dashboard.com</a></p>
<p>Cheerios, Greg</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gigoo.org/2009/08/17/f1-dashboard-released/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Groovy with JDO on Google App Engine, enhancing with DataNucleus</title>
		<link>http://blog.gigoo.org/2009/04/27/groovy-with-jdo-on-google-app-engine-enhancing-with-datanucleus/</link>
		<comments>http://blog.gigoo.org/2009/04/27/groovy-with-jdo-on-google-app-engine-enhancing-with-datanucleus/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 01:52:25 +0000</pubDate>
		<dc:creator>Greg Gigon</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[datanucleus]]></category>
		<category><![CDATA[gae]]></category>
		<category><![CDATA[google app engine]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jdo]]></category>

		<guid isPermaLink="false">http://blog.gigoo.org/2009/04/27/groovy-with-jdo-on-google-app-engine-enhancing-with-datanucleus/</guid>
		<description><![CDATA[ I have some time this days and I’m trying to fly some clouds with Google App Engine (GAE), Now when they have released Java support I can try to use Groovy. Today I tried to implement some simple storage using JDO. GAE team supports some of its features via&#160; DataNucleus. DataNucleus is using a [...]]]></description>
			<content:encoded><![CDATA[<p><img style="display: inline; margin: 0px 10px 0px 0px" src="http://code.google.com/appengine/images/appengine_lowres.jpg" align="left" /> I have some time this days and I’m trying to fly some clouds with <a href="http://code.google.com/appengine/" onclick="javascript:pageTracker._trackPageview('/outbound/article/code.google.com');" target="_blank">Google App Engine</a> (GAE), Now when they have released Java support I can try to use <a href="http://groovy.codehaus.org/" onclick="javascript:pageTracker._trackPageview('/outbound/article/groovy.codehaus.org');" target="_blank">Groovy</a>. Today I tried to implement some simple storage using JDO. GAE team supports some of its features via&#160; <a href="http://www.datanucleus.org/" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.datanucleus.org');" target="_blank">DataNucleus</a>. DataNucleus is using a post compilation hook to enhance any persistable classes. </p>
<p>Having Groovy in a <strong>lib</strong> folder of your <strong>war </strong>(GAE runs your application from this folder) I need to put <strong>asm </strong>library as well. Latest version of Groovy (1.6.1) has a dependency on <strong>asm </strong>library in version <strong>2.2.3. </strong>On the other hand DataNucleus enhancer has dependency on <strong>asm </strong>library in version <strong>3.1</strong>. </p>
<p>GAE Java SDK is shipped with <strong>Ant</strong> task for enhancing persistable classes. It also contains <strong>Ant </strong>macro definition file that makes it simple for usage. Unfortunately this macro includes all libraries from application <strong>lib </strong>folder. This is causing Enhancer to use <strong>asm</strong> library in a version that causes it to fail massively. </p>
<blockquote><p><strong><em>[enhance] SEVERE: An error occured for ClassEnhancer &quot;ASM&quot; when trying to call the method &quot;org.datanucleus.enhancer.as          <br />m.ASMClassEnhancer&quot; on class &quot;getClassNameForFileName&quot; : org.objectweb.asm.ClassReader.accept(Lorg/objectweb/asm/ClassVi           <br />sitor;I)V</em></strong></p>
</blockquote>
<p>Number of this error messages is as big as the number of classes in my application.</p>
<p>Solution is to exclude <strong>asm </strong>library from the macro that Google shipped. Easiest way is to edit, or copy to your local application folder and use it there. The line problematic line of code is in <strong>classpath </strong>element.</p>
<blockquote><p><em>&lt;classpath&gt;        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;pathelement path=&quot;${appengine.tools.classpath}&quot;/&gt;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;pathelement path=&quot;@{war}/WEB-INF/classes&quot;/&gt;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;fileset dir=&quot;@{war}/WEB-INF/lib&quot; includes=&quot;*.jar&quot;&gt;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/fileset&gt;         <br />&lt;/classpath&gt;</em></p>
</blockquote>
<p>The easiest way to fix it is to exclude <strong>asm </strong>library in <strong>fileset </strong>element, just like this:</p>
<blockquote><p><em>&lt;classpath&gt;        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;pathelement path=&quot;${appengine.tools.classpath}&quot;/&gt;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;pathelement path=&quot;@{war}/WEB-INF/classes&quot;/&gt;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;fileset dir=&quot;@{war}/WEB-INF/lib&quot; includes=&quot;*.jar&quot; <strong>excludes=&quot;asm*.jar&quot;&gt;</strong>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/fileset&gt;         <br />&lt;/classpath&gt;</em></p>
<p>Hope that helps anyone with similar problem.</p>
<p>Cheers, Greg</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.gigoo.org/2009/04/27/groovy-with-jdo-on-google-app-engine-enhancing-with-datanucleus/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
