<?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>722 &#187; Java</title>
	<atom:link href="http://722.kalaari.net/b/lang/en/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://722.kalaari.net/b</link>
	<description>f 722 t 722 p 722 oxygen 722 722 722</description>
	<lastBuildDate>Sat, 24 Dec 2011 11:56:50 +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>jsr107 javax.cache annotations with Google Guice</title>
		<link>http://722.kalaari.net/b/lang/en/2011/12/23/jsr107-javax-cache-annotations-with-google-guice</link>
		<comments>http://722.kalaari.net/b/lang/en/2011/12/23/jsr107-javax-cache-annotations-with-google-guice#comments</comments>
		<pubDate>Fri, 23 Dec 2011 21:00:41 +0000</pubDate>
		<dc:creator>Christophe Furmaniak</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[guice]]></category>
		<category><![CDATA[jsr107]]></category>
		<category><![CDATA[lombok]]></category>

		<guid isPermaLink="false">http://722.kalaari.net/b/?p=108</guid>
		<description><![CDATA[<a href="http://722.kalaari.net/b/lang/en/2011/12/23/jsr107-javax-cache-annotations-with-google-guice" title="jsr107 javax.cache annotations with Google Guice"></a>I&#8217;m using Google Guice as my Dependency Injection framework. I wanted to use the javax.cache api aka JSR107 (with EHcache as implementation). If you want to learn more about this famous JSR107, it could be a good idea to go &#8230;<p class="read-more"><a href="http://722.kalaari.net/b/lang/en/2011/12/23/jsr107-javax-cache-annotations-with-google-guice">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://722.kalaari.net/b/lang/en/2011/12/23/jsr107-javax-cache-annotations-with-google-guice" title="jsr107 javax.cache annotations with Google Guice"></a><p>I&#8217;m using <a title="Google Guice" href="http://code.google.com/p/google-guice/wiki/Motivation?tm=6" target="_blank">Google Guice</a> as my Dependency Injection framework. I wanted to use the javax.cache api aka <a title="JSR107" href="http://jcp.org/en/jsr/detail?id=107" target="_blank">JSR107</a> (with <a href="http://ehcache.org/" target="_blank">EHcache</a> as implementation). If you want to learn more about this famous JSR107, it could be a good idea to go to <a href="http://gregluck.com/blog/archives/category/jsr107/">Greg Luck blog</a> to get some more infos about it.</p>
<p>In my case, I wanted to use the annotations part of the JSR107 because I find them to be more elegant than a pure code solution (understand, you can put cache in your app without changing the logic, you just annotate your business methods, and <em>woosh</em>, you have cache set up).</p>
<p>But the JSR107 annotations implementations are DI framework dependant. And untill some days ago, only Spring and CDI implementation were provided.</p>
<p>I <a href="https://twitter.com/#!/cfurmaniak/status/147052796154359808" target="_blank">twitted</a> to search any volunteers that might be interested in contributing (with or without me) to a Guice implementation.</p>
<p>Some hours laters, some commits from Michael Stachel were <a href="https://github.com/jsr107/RI/tree/master/cache-annotations-ri/cache-annotations-ri-guice" target="_blank">pushed by Alex Snaps to the github repo</a> and here they are, the JSR 107 annotations for Guice were available.</p>
<p>I&#8217;d like to show you how you can use them.</p>
<p>The full source code is available <a href="https://bitbucket.org/looztra/guicyjsr107app/src">here</a> as a <a href="http://mercurial.selenic.com/">Mercurial</a> repository on <a href="http://bitbucket.org/">Bitbucket</a>.</p>
<p>I&#8217;m using <a href="http://maven.apache.org/">Maven</a>, so here is the dependency part of the pom</p>
<pre class="brush:xml">
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>${guice.version}</version>
        </dependency>
        <!-- cache jsr107 stuff -->
        <dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache-jcache</artifactId>
            <version>1.4.0-beta1</version>
        </dependency>
        <dependency>
            <groupId>javax.cache.implementation</groupId>
            <artifactId>cache-annotations-ri-guice</artifactId>
            <version>0.5-SNAPSHOT</version>
        </dependency>
</pre>
<p>You can see here that I&#8217;m using the latest snapshot of the <strong>cache-annotations-ri-guice</strong> artifact (<em>0.5-SNAPSHOT</em> as I&#8217;m writing this post). I don&#8217;t know if the snapshots are available somewhere, so I just cloned the corresponding <a href="https://github.com/jsr107">git repositories</a> and installed the snapshots locally. To be more precise, you will need to clone the <a href="https://github.com/jsr107/jsr107spec">jsr107-spec</a> repo to build and install locally the jsr107 api artifacts that are needed by the <a href="https://github.com/jsr107/RI">jsr107 Reference Implementation</a> artifacts, among which you&#8217;ll find the <strong>cache-annotations-ri-guice</strong> artifact.</p>
<p>Now, let&#8217;s write a basic <em>UserService</em> interface (ok, you don&#8217;t need an interface actually):</p>
<pre class="brush:java">package net.awl.ismp.guice.jsr107;

import java.util.List;

/**
 *
 * @author looztra
 */
public interface UserService {
    public User getUserById(int id, int callId);
    public List&#60;User&#62; getUserByLastName(String name, int callId);
    public boolean calledBy(int callId);
}</pre>
<p>The <em>UserService</em> makes reference to a <em>User</em> class:</p>
<pre class="brush:java">package net.awl.ismp.guice.jsr107;

import java.io.Serializable;
import lombok.Data;

/**
 *
 * @author looztra
 */
@Data
public class User implements Serializable {
    private int id;
    private String firstName;
    private String lastName;
    private int age;
}</pre>
<p>People that follow may have spotted that I was too lazy to write the accessors and that I chose to use the <a href="http://projectlombok.org/">Lombok</a> <strong>@Data</strong> annotation instead.</p>
<p>Here is the main part of a simple implementation of the basic UserService:</p>
<pre class="brush:java">package net.awl.ismp.guice.jsr107;

import java.util.*;
import javax.cache.annotation.CacheKeyParam;
import javax.cache.annotation.CacheResult;
import lombok.extern.slf4j.Slf4j;

/**
 *
 * @author looztra
 */
@Slf4j
public class SimpleUserService implements UserService {

    private Map&#60;Integer, User&#62; users = new HashMap&#60;Integer, User&#62;();
    private List&#60;Integer&#62; callers = new ArrayList&#60;Integer&#62;();

    public SimpleUserService() {
        initContent();
    }

    @Override
    @CacheResult(cacheName = "getUserById")
    public User getUserById(@CacheKeyParam int id, int callId) {
        log.info("getUserById(): business method called for id (" + id + ") and callId (" + callId + ")");
        registerCaller(callId);
        if (id &#62;= 0 &#38;&#38; id &#60; 100) {
            return users.get(id);
        } else {
            return null;
        }
    }

    @Override
    @CacheResult(cacheName = "getUserByLastName")
    public List&#60;User&#62; getUserByLastName(@CacheKeyParam String name, int callId) {
        log.info("getUserByLastName(): business method called for name &#60;" + name + "&#62; and callId &#60;" + callId + "&#62;");
        registerCaller(callId);
        List&#60;User&#62; matches = new ArrayList&#60;User&#62;();
        for (Map.Entry&#60;Integer, User&#62; entry : users.entrySet()) {
            User potentialMatch = entry.getValue();
            if (potentialMatch.getLastName().contains(name)) {
                matches.add(potentialMatch);
            }
        }
        return matches;
    }
...
}</pre>
<p>The initContent() an the registerCaller() method are only utilities methods (full source code available <a href="https://bitbucket.org/looztra/guicyjsr107app/src/54a8fd3cd8be/src/main/java/net/awl/ismp/guice/jsr107/SimpleUserService.java">here</a>).</p>
<p>The interesting parts are the two annotations <a href="https://github.com/jsr107/jsr107spec/blob/master/src/main/java/javax/cache/annotation/CacheResult.java">@CacheResult</a> and <a href="https://github.com/jsr107/jsr107spec/blob/master/src/main/java/javax/cache/annotation/CacheKeyParam.java">@CacheKeyParam</a>.</p>
<p>Straight from the javadoc: <span style="color: #ff6600;">When a method annotated with <em>@CacheResult</em> is invoked a CacheKey will be generated and javax.cache.Cache#get(Object) is called before the invoked method actually executes. If a value is found in the cache it is returned and the annotated method is never actually executed. If no value is found the annotated method is invoked and the returned value is stored in the cache with the generated key.</span></p>
<p>The @CacheResult is then a very simple way to set up a <a href="http://ehcache.org/documentation/user-guide/concepts#read-through">Read-Through cache</a>.</p>
<p>The <em>@CacheKeyParam</em> is used to specify which subset of the method params are to be used as part of the CacheKey (by default, all the method params are used).</p>
<p>Those 2 annotations are not the only one existing of course. You could use @CachePut to implement a Write-Through cache for instance.</p>
<p>Before it can work as expected, don&#8217;t forget to register the <a href="https://github.com/jsr107/RI/blob/master/cache-annotations-ri/cache-annotations-ri-guice/src/main/java/javax/cache/annotation/impl/guice/module/CacheAnnotationsModule.java">CacheAnnotationsModule</a> so that Guice injector can use the jsr107 annotations.</p>
<pre class="brush:java">...
@BeforeClass
    public void setUp() {
        Injector injector = Guice.createInjector(new MyModule(),new CacheAnnotationsModule());
        service = injector.getInstance(UserService.class);
    }
...</pre>
<p><em>MyModule</em> being a very simple Guice module matching my simple needs:</p>
<pre class="brush:java">package net.awl.ismp.guice.jsr107;

import com.google.inject.AbstractModule;

/**
 *
 * @author looztra
 */
public class MyModule extends AbstractModule {

    @Override
    protected void configure() {
        bind(UserService.class).to(SimpleUserService.class);
    }

}</pre>
<p>A simple unit test to see it in action</p>
<pre class="brush:java">
    @Test
    public void testGetIdTwice() {
        Assert.assertNotNull(service);
        int callId = getCallerId();
        log.info("testGetIdTwice(): calling the service the first time with callerId &#60;" + callId + "&#62;");
        User found = service.getUserById(testGetIdTwice_SEARCHED_ID, callId);
        Assert.assertNotNull(found);
        log.info("testGetIdTwice(): found user &#60;" + found + "&#62;");
        // check that we went through the business method the time
        Assert.assertTrue(service.calledBy(callId));
        //
        int callId2 = getCallerId();
        log.info("testGetIdTwice(): calling the service the second time with callerId &#60;" + callId2 + "&#62;");
        User found2 = service.getUserById(testGetIdTwice_SEARCHED_ID, callId2);
        Assert.assertNotNull(found2);
        // check that we did not go through the business method this time
        Assert.assertFalse(service.calledBy(callId2));

    }
</pre>
<p>Feel free to get the full source code that is available <a href="https://bitbucket.org/looztra/guicyjsr107app/src">here</a> as a <a href="http://mercurial.selenic.com/">Mercurial</a> repository on <a href="http://bitbucket.org/">Bitbucket</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://722.kalaari.net/b/lang/en/2011/12/23/jsr107-javax-cache-annotations-with-google-guice/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jrrd TODO List</title>
		<link>http://722.kalaari.net/b/lang/en/2009/06/20/jrrd-todo-list</link>
		<comments>http://722.kalaari.net/b/lang/en/2009/06/20/jrrd-todo-list#comments</comments>
		<pubDate>Sat, 20 Jun 2009 20:12:00 +0000</pubDate>
		<dc:creator>Christophe Furmaniak</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[jrrd]]></category>

		<guid isPermaLink="false">http://722.kalaari.net/b/?p=33</guid>
		<description><![CDATA[<a href="http://722.kalaari.net/b/lang/en/2009/06/20/jrrd-todo-list" title="jrrd TODO List"></a>update website release 0.2 use maven and SVN explain the differences with other java rrd tools (jrobin, rrd4j, see https://wiki.man.poznan.pl/perfsonar-mdm/index.php/RRD_Java_libraries)]]></description>
			<content:encoded><![CDATA[<a href="http://722.kalaari.net/b/lang/en/2009/06/20/jrrd-todo-list" title="jrrd TODO List"></a><ul>
<li><span lang="en">update website <img src='http://722.kalaari.net/b/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></li>
<li><span lang="en">release 0.2</span></li>
<li><span lang="en">use maven and <span style="text-decoration: line-through;">SVN</span></span></li>
<li><span lang="en">explain the differences with other java rrd tools (jrobin, rrd4j, see https://wiki.man.poznan.pl/perfsonar-mdm/index.php/RRD_Java_libraries)</span></li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://722.kalaari.net/b/lang/en/2009/06/20/jrrd-todo-list/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java: auto-initialisation des variables d&#8217;instance&#8230;ou pas</title>
		<link>http://722.kalaari.net/b/lang/en/2009/06/11/java-auto-initialisation-des-variables-dinstance-ou-pas</link>
		<comments>http://722.kalaari.net/b/lang/en/2009/06/11/java-auto-initialisation-des-variables-dinstance-ou-pas#comments</comments>
		<pubDate>Thu, 11 Jun 2009 08:42:46 +0000</pubDate>
		<dc:creator>Christophe Furmaniak</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[java initialisation variable]]></category>

		<guid isPermaLink="false">http://722.kalaari.net/b/?p=28</guid>
		<description><![CDATA[<a href="http://722.kalaari.net/b/lang/en/2009/06/11/java-auto-initialisation-des-variables-dinstance-ou-pas" title="Java: auto-initialisation des variables d&#039;instance...ou pas"></a>A chaque fois que je crée une nouvelle classe, je me demande si je dois forcer la valeur par défaut des variables d&#8217;instance. La plupart du temps je me dis &#8220;je ne veux pas dépendre d&#8217;un comportement par défaut, je &#8230;<p class="read-more"><a href="http://722.kalaari.net/b/lang/en/2009/06/11/java-auto-initialisation-des-variables-dinstance-ou-pas">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://722.kalaari.net/b/lang/en/2009/06/11/java-auto-initialisation-des-variables-dinstance-ou-pas" title="Java: auto-initialisation des variables d&#039;instance...ou pas"></a><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr">A chaque fois que je crée une nouvelle classe, je me demande si je dois forcer la valeur par défaut des variables d&#8217;instance. La plupart du temps je me dis &#8220;je ne veux pas dépendre d&#8217;un comportement par défaut, je vais forcer explicitement la valeur par défaut de la variable d&#8217;instance, ce sera plus lisible&#8221;. C&#8217;est peut-être discutable mais je n&#8217;ai jamais eu l&#8217;occasion d&#8217;en discuter avec des java-gurus, ni d&#8217;ailleurs de réellement me poser des questions sur le bien-fondé et la justesse de ce choix.</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr">Jusqu&#8217;à ce jour. Je viens de découvrir (shame on me?) qu&#8217;il est parfois nécessaire de ne pas explicitement forcer la valeur par défaut.</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span id="more-28"></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr">1er cas:</span></p>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr"><span style="margin: 0px; padding: 0px; font-family: arial;">public class MotherClass {</span></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr"><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">public MotherClass(String&#8230; args) {<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">System.out.println(&#8220;MotherClass(): [BERORE CALL TO PREPARE] this:&#8221; + this);<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">prepare(args);<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">System.out.println(&#8220;MotherClass(): [AFTER CALL TO PREPARE] this:&#8221; + this);<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">}</span></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"><br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">public void prepare(String&#8230; args) {</span></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr"><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">this.member0_1 = args[0];<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">this.member0_2 = args[1];<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">System.out.println(&#8220;MotherClass.prepare(): this:&#8221; + this);<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">}<br style="padding: 0px; margin: 0px;" /><br style="padding: 0px; margin: 0px;" /><br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">public String toString() {<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">return &#8221;MotherClass &lt;member0_1=&#8221; + member0_1 + &#8221;, member0_2=&#8221; + member0_2 + &#8221;&gt;&#8221;;<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">}<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr"><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">protected String member0_1;<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">protected String member0_2 = &#8221;initialized&#8221;;<br style="padding: 0px; margin: 0px;" /><br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">public static void main(String[] args) {<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">MotherClass mc = new MotherClass(new String[] { &#8221;first&#8221;, &#8221;second&#8221; });<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">System.out.println(&#8220;main(): mc:&#8221; + mc);<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">}<br style="padding: 0px; margin: 0px;" />}</span></span></p>
</blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">Si on lance le <em>main</em>, ça donne:</span></span></p>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">MotherClass(): [BERORE CALL TO PREPARE] this:MotherClass &lt;member0_1=null, member0_2=initialized&gt;<br style="padding: 0px; margin: 0px;" />MotherClass.prepare(): this:MotherClass &lt;<span style="margin: 0px; padding: 0px; background-color: #57ff00;">member0_1=first, member0_2=second</span>&gt;<br style="padding: 0px; margin: 0px;" />MotherClass(): [AFTER CALL TO PREPARE] this:MotherClass &lt;member0_1=first, member0_2=second&gt;<br style="padding: 0px; margin: 0px;" />main(): mc:MotherClass &lt;<span style="margin: 0px; padding: 0px; background-color: #02ff00;">member0_1=first, member0_2=second</span>&gt;</span></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;">
</blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">Dans ce cas, rien de particulier, la classe se comporte comme on peut s&#8217;y attendre, que la variable d&#8217;instance ait été initialisée (<span style="margin: 0px; padding: 0px; font-family: 'courier new'; font-size: 13px; font-style: italic;">member0_2)<span style="margin: 0px; padding: 0px; font-family: 'Times New Roman'; font-size: 16px; font-style: normal;"> ou pas (<span style="margin: 0px; padding: 0px; font-family: 'courier new'; font-size: 13px; font-style: italic;">member0_1</span>).</span></span></span></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;">
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr">Etendons maintenant cette classe:</span></p>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">public class ClassThatExtends extends MotherClass {<br style="padding: 0px; margin: 0px;" /><br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">public ClassThatExtends(String&#8230; args) {<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">super(args);<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">System.out.println(&#8220;ClassThatExtends(): [AFTER super()] this:&#8221; + this);<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">}<br style="padding: 0px; margin: 0px;" /><br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">public void prepare(String&#8230; args) {<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">if (args.length == 4) {<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">this.member0_1 = args[0];<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">this.member0_2 = args[1];<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">this.member1_1 = args[2];<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">this.member1_2 = args[3];<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">}<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">System.out.println(&#8220;ClassThatExtends.prepare(): this:&#8221; + this);<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">}<br style="padding: 0px; margin: 0px;" /><br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">public String toString() {<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">return &#8221;ClassThatExtends &lt;member0_1=&#8221; + member0_1 + &#8221;, member0_2=&#8221; + member0_2<br style="padding: 0px; margin: 0px;" /> </span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">+ &#8221;, member1_1=&#8221; + member1_1 + &#8221;, member1_2=&#8221; + member1_2 + &#8221;&gt;&#8221;;<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">}<br style="padding: 0px; margin: 0px;" /><br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">private String member1_1;<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">private String member1_2 = &#8221;initialized&#8221;;<br style="padding: 0px; margin: 0px;" /></span></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr"><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">public static void main(String[] args) {<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">ClassThatExtends cte = new ClassThatExtends(new String[] { &#8221;first&#8221;, &#8221;second&#8221;, &#8221;third&#8221;,<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">&#8220;fourth&#8221; });<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">System.out.println(&#8220;main(): cte:&#8221; + cte);<br style="padding: 0px; margin: 0px;" /></span><span style="margin: 0px; padding: 0px; white-space: pre;"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"> </span></span><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;">}<br style="padding: 0px; margin: 0px;" />}</span></span></p>
</blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr">Si on lance le <em>main</em>:</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;">
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr"><em>MotherClass(): [BERORE CALL TO PREPARE] this:ClassThatExtends &lt;member0_1=null, member0_2=initialized, member1_1=null, member1_2=null&gt;</em></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr"><em>ClassThatExtends.prepare(): this:ClassThatExtends &lt;member0_1=first, member0_2=second, member1_1=third, member1_2=fourth&gt;</em></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr"><em>MotherClass(): [AFTER CALL TO PREPARE] this:ClassThatExtends &lt;member0_1=first, member0_2=second,<strong><span style="margin: 0px; padding: 0px; background-color: #00ff54;">member1_1=third</span></strong>, <strong><span style="margin: 0px; padding: 0px; background-color: #00ff54;">member1_2=fourth</span></strong>&gt;</em></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr"><em>ClassThatExtends(): [<strong>AFTER super()</strong>] this:ClassThatExtends &lt;member0_1=first, member0_2=second,<span style="margin: 0px; padding: 0px; background-color: #00ff54;"><strong>member1_1=third</strong></span>, <span style="margin: 0px; padding: 0px; background-color: #ffaa00;"><strong>member1_2=initialized</strong></span>&gt;</em></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr"><em>main(): cte:ClassThatExtends &lt;member0_1=first, member0_2=second, member1_1=third, member1_2=initialized&gt;</em></span></p>
</blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr"><span style="margin: 0px; padding: 0px; font-family: arial,helvetica,sans-serif;"><br />
</span></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr"><em>WTF</em>? member1_1 qui n&#8217;a pas été explicitement initialisée dans la classe fille a gardé la valeur fixée lors de l&#8217;appel du constructeur, par contre, member1_2 qui a été explicitement initialisée a été écrasée après avoir été valorisée dans le constructeur!</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr">Les variables d&#8217;instance d&#8217;une classe &#8220;fille&#8221; sont donc initialisées <strong><em>APRES</em></strong> la chaîne des appels des constructeurs.</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr">Dans le cas où la variable n&#8217;est pas explicitement initialisée lors de sa déclaration et que la variable est valorisée dans le constructeur, la valeur de la variable d&#8217;instance sera conservée. Dans le cas où la variable d&#8217;instance est explicitement initialisée lors de sa déclaration et qu&#8217;elle est valorisée dans le constructeur, la valeur est écrasée par la valeur d&#8217;initialisation spécifiée!</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: justify; line-height: 1.52em; padding: 0px;"><span lang="fr">Fichtre! En voila donc un comportement pas forcément trivial&#8230; Si quelqu&#8217;un arrive à me trouver le bout de doc chez Java (ou ailleurs) que j&#8217;ai du louper, je suis preneur.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://722.kalaari.net/b/lang/en/2009/06/11/java-auto-initialisation-des-variables-dinstance-ou-pas/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Soap vs Rest</title>
		<link>http://722.kalaari.net/b/lang/en/2009/05/19/soap-vs-rest</link>
		<comments>http://722.kalaari.net/b/lang/en/2009/05/19/soap-vs-rest#comments</comments>
		<pubDate>Tue, 19 May 2009 15:24:36 +0000</pubDate>
		<dc:creator>Christophe Furmaniak</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[soap rest serviceweb]]></category>

		<guid isPermaLink="false">http://722.kalaari.net/b/?p=22</guid>
		<description><![CDATA[<a href="http://722.kalaari.net/b/lang/en/2009/05/19/soap-vs-rest" title="Soap vs Rest"></a>Rest est &#8220;tendance&#8221; en ce moment. Mais est-ce toujours le bon choix? Elements de réponse par ici sur CleverAge.]]></description>
			<content:encoded><![CDATA[<a href="http://722.kalaari.net/b/lang/en/2009/05/19/soap-vs-rest" title="Soap vs Rest"></a><p>Rest est &#8220;tendance&#8221; en ce moment. Mais est-ce toujours le bon choix? Elements de réponse par <a href="http://www.clever-age.com/veille/clever-link/soap-vs.-rest-choisir-la-bonne-architecture-web-services.html" target="_blank">ici</a> sur <a href="http://www.clever-age.com" target="_blank">CleverAge</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://722.kalaari.net/b/lang/en/2009/05/19/soap-vs-rest/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TODO: scruter la Boîte A Outils du Developpeur Java</title>
		<link>http://722.kalaari.net/b/lang/en/2009/05/18/todo-scruter-la-boite-a-outils-du-developpeur-java</link>
		<comments>http://722.kalaari.net/b/lang/en/2009/05/18/todo-scruter-la-boite-a-outils-du-developpeur-java#comments</comments>
		<pubDate>Mon, 18 May 2009 12:10:12 +0000</pubDate>
		<dc:creator>Christophe Furmaniak</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[java outils]]></category>

		<guid isPermaLink="false">http://722.kalaari.net/b/?p=17</guid>
		<description><![CDATA[<a href="http://722.kalaari.net/b/lang/en/2009/05/18/todo-scruter-la-boite-a-outils-du-developpeur-java" title="TODO: scruter la Boîte A Outils du Developpeur Java"></a>Par ici =&#62; http://java.developpez.com/outils/developpeur/]]></description>
			<content:encoded><![CDATA[<a href="http://722.kalaari.net/b/lang/en/2009/05/18/todo-scruter-la-boite-a-outils-du-developpeur-java" title="TODO: scruter la Boîte A Outils du Developpeur Java"></a><p>Par ici =&#62; <a class="wp-caption" href="http://java.developpez.com/outils/developpeur/" target="_blank">http://java.developpez.com/outils/developpeur/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://722.kalaari.net/b/lang/en/2009/05/18/todo-scruter-la-boite-a-outils-du-developpeur-java/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Common Java Cookbook</title>
		<link>http://722.kalaari.net/b/lang/en/2009/05/18/common-java-cookbook</link>
		<comments>http://722.kalaari.net/b/lang/en/2009/05/18/common-java-cookbook#comments</comments>
		<pubDate>Mon, 18 May 2009 07:51:05 +0000</pubDate>
		<dc:creator>Christophe Furmaniak</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[java commons jakarta]]></category>

		<guid isPermaLink="false">http://722.kalaari.net/b/?p=13</guid>
		<description><![CDATA[<a href="http://722.kalaari.net/b/lang/en/2009/05/18/common-java-cookbook" title="Common Java Cookbook"></a>En voilà un lien qu&#8217;il est bien =&#62; http://www.discursive.com/books/cjcook/reference/book.html Ce cookbook contient pas mal d&#8217;exemple d&#8217;utilisation des outils Apache Commons , Apache * &#38; autres, pour se faciliter la vie et ne pas réinventer le fil à couper le beurre (ou le &#8230;<p class="read-more"><a href="http://722.kalaari.net/b/lang/en/2009/05/18/common-java-cookbook">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://722.kalaari.net/b/lang/en/2009/05/18/common-java-cookbook" title="Common Java Cookbook"></a><p>En voilà un lien qu&#8217;il est bien =&#62; <a href="http://www.discursive.com/books/cjcook/reference/book.html">http://www.discursive.com/books/cjcook/reference/book.html</a></p>
<p>Ce cookbook contient pas mal d&#8217;exemple d&#8217;utilisation des outils Apache Commons , Apache * &#38; autres, pour se faciliter la vie et ne pas réinventer le fil à couper le beurre (ou le GregorianCalendar)</p>
]]></content:encoded>
			<wfw:commentRss>http://722.kalaari.net/b/lang/en/2009/05/18/common-java-cookbook/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

