<?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>Foognostic blogs &#187; java</title>
	<atom:link href="http://blogs.foognostic.net/topics/code/java-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.foognostic.net</link>
	<description>Seeking knowledge of foo</description>
	<lastBuildDate>Fri, 23 Apr 2010 12:45:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>introducing jawarepl</title>
		<link>http://blogs.foognostic.net/2009/01/introducing-jawarepl/</link>
		<comments>http://blogs.foognostic.net/2009/01/introducing-jawarepl/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 19:57:16 +0000</pubDate>
		<dc:creator>Seth Schroeder</dc:creator>
				<category><![CDATA[GPLv3]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[bitbucket]]></category>
		<category><![CDATA[jawarepl]]></category>

		<guid isPermaLink="false">http://blogs.foognostic.net/?p=66</guid>
		<description><![CDATA[JAWAREPL is a JAva Web Application Read Eval Print Loop. It loads a Spring-based Java .war file into groovysh, and then makes its fully actived Spring beans easy to use. Here's a quick example. It uses 'petclinic', one of the sample apps included with Spring: $ groovysh . /Users/moi/Documents/code/jawarepl/jawarepl.groovy inst = new JAWAREPL(); Here's how [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://bitbucket.org/seths/jawarepl/overview/">JAWAREPL</a> is a JAva Web Application Read Eval Print Loop. It loads a <a href="http://www.springsource.org/">Spring</a>-based Java .war file into <a href="http://groovy.codehaus.org/Groovy+Shell">groovysh</a>, and then makes its fully actived Spring beans easy to use.</p>

<p>Here's a quick example. It uses 'petclinic', one of the sample apps included with Spring:</p>

<p><pre>
$ groovysh
. /Users/moi/Documents/code/jawarepl/jawarepl.groovy
inst = new JAWAREPL();
</pre></p>

<p>Here's how you configure it:</p>

<p><pre>
inst.war_path = "/path/to/petclinic/dist/petclinic.war";
inst.context_paths = [ "WEB-INF/applicationContext-hibernate.xml" ];
ctx = inst.context;
</pre></p>

<p>After that, the sky's the limit! Start grabbing beans out and call all the methods you want. Put this into groovysh:</p>

<p><pre>
clinic = ctx.getBean("clinic");
clinic.vets.each {
   println "vet = ${it.lastName}, ${it.firstName}";
   it.specialties.each {
       println "    $it";
   }
}
</pre></p>

<p>And this should come out:</p>

<p><pre>
vet = Carter, James
vet = Douglas, Linda
    dentistry
    surgery
vet = Jenkins, Sharon
vet = Leary, Helen
    radiology
vet = Ortega, Rafael
    surgery
vet = Stevens, Henry
    radiology
</pre></p>

<p>Just to demonstrate that it's not only for reading data, here is another sample where it adds a visit to the petclinic.</p>

<p><pre>
owner = clinic.findOwners("Schroeder")[0];
owner.pets.visits.each { println "$it.date, $it.description" }
[2009-01-24, 2009-01-24], [JAWAREPL test, JAWAREPL test]
visit = new org.springframework.samples.petclinic.Visit();
visit.date = new Date();
visit.pet = pets[0];
visit.description = "JAWAREPL test2";
clinic.storeVisit(visit);
...
Hibernate: insert into visits (visit_date, description, pet_id) values (?, ?, ?)
owner = clinic.findOwners("Schroeder")[0];
owner.pets.visits.each { println "$it.date, $it.description" }
[2009-01-24, 2009-01-24, 2009-01-24], [JAWAREPL test,
JAWAREPL test2, JAWAREPL test]
</pre></p>

<p>More detailed instructions are available on <a href="http://bitbucket.org/seths/jawarepl/src/123872d5dc2f/samples.txt">bitbucket</a>.</p>

<p>JAWAREPL has been tested on three of the sample Spring apps and a basic Grails app. Those are pretty trivial samples and even so, it was a minor task to make them all work; the Grails war had none of the GORM mojo stitched in so it was really not very useful (patches anyone?) That being said, I would <b>not</b> expect a complex war file to load smoothly. I seem to recall some sort of mock/mini JNDI provider in Spring if that what goes wrong. I will try to look at any <a href="http://bitbucket.org/seths/jawarepl/issues/">bug reports</a>, or much better yet <a href="http://bitbucket.org/seths/jawarepl/src/">patches</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.foognostic.net/2009/01/introducing-jawarepl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ versus Java, or references to references versus values of references.</title>
		<link>http://blogs.foognostic.net/2008/12/cpp-versus-java-or-references-to-references-versus-values-of-references/</link>
		<comments>http://blogs.foognostic.net/2008/12/cpp-versus-java-or-references-to-references-versus-values-of-references/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 02:36:21 +0000</pubDate>
		<dc:creator>Seth Schroeder</dc:creator>
				<category><![CDATA[c++]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[c]]></category>

		<guid isPermaLink="false">http://blogs.foognostic.net/?p=24</guid>
		<description><![CDATA[C++ has a more useful family of reference types than Java.]]></description>
			<content:encoded><![CDATA[<p>A few years of Java really make it hard to write C++ again. Quick, which language is this?</p>

<p>

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;stuff.yodel();</div></div>

</p>

<p>That works in Java and C++ but for different reasons. It's usually safer in C++.</p>

<p>In Java that code is less safe because it hasn't been tested for null. That is, one of the following already happened:
      <ol type="A">
        <li>

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Stuff stuff = null;</div></div>

</li>
        <li>

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Stuff stuff = new Stuff();</div></div>

</li>
        <li>

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Stuff stuff = Stuff.class.newInstance();</div></div>

</li>
      </ol>
      The guarantee is that each reference will have an intentional value, which <b>is</b> more than C++ promises for pointer values.
</p>

<p>C++ gives you stronger references. For that same line of code, one of these already happened:
      <ol type="A">
        <li>

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Stuff stuff;</div></div>

</li>
        <li>

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Stuff *stuff_p = new Stuff(), &amp;amp;stuff = *stuff_p;</div></div>

</li>
        <li>

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Stuff&amp;amp; f2() { Stuff stuff; return stuff; }</div></div>

</li>
      </ol>
      Which means...
      <ol type="A">
        <li>This

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">stuff</div></div>

refers to an object allocated on the stack. It's there, baby -- as much as any

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">int</div></div>

or

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">float</div></div>

. 
        <li>This

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">stuff</div></div>

refers to an object successfully allocated in the heap.
        <li><b>Very bad.</b>

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">f2</div></div>

destructed the stuff before giving it to you. Just keep compiler warnings on and it will bark &quot;warning: reference to local variable 'stuff' returned&quot;
      </ol>
</p>

<p>What wasn't shown for C++ was

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">stuff-&amp;gt;yodel()</div></div>

. That followed one of:
      <ol type="A">
        <li>

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Stuff *stuff;</div></div>

</li>
        <li>

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Stuff *stuff = null;</div></div>

</li>
        <li>

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Stuff *stuff = new Stuff();</div></div>

</li>
        <li>

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">std::auto_ptr&amp;lt;Stuff&amp;gt; stuff(new Stuff());</div></div>

</li>
      </ol>
      Which means...
      <ol type="A">
        <li>Uninitialized pointer, a.k.a. <i>Runtime Russian Roulette</i>. Unfortunately I couldn't get g++ to whine about this even with

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">-Wall -Wpedantic -Wextra</div></div>

.</li>
        <li>Null pointer, a.k.a. the minimum guarantee of Java.
        <li>Hmm, I don't <i>see</i> a delete any where around here... uh-oh...
        <li>There you go. You've got a smart pointer on the stack to prevent memory leaks, while preserving the expected

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">-&amp;gt;</div></div>

syntax.
      </ol>
</p>

<h2>So WHAT? Really now!</h2>

<p>Java guarantees that a reference will be initialized, and that it must always be tested for null. C++ warms the hearts of bearded old curmudgeons with more types of references. Each type is useful alone and in sometimes in conjunction (e.g. non-const references to pointers for output parameters). This is useful and important information to know. Draping Object everywhere and automating garbage collection is a lowbrow kludge.</p>

<p><b>Footnote 1</b>: Groovy's <a href="http://groovy.codehaus.org/Operators#Operators-SafeNavigationOperator%28%3F.%29">safe navigation operator</a> helps test for null by GOTOing the next safe expression. An interesting idea, and hopefully self-preventative. If I saw code with lots of '?' it would be up for a rewrite sooner rather than later.
</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.foognostic.net/2008/12/cpp-versus-java-or-references-to-references-versus-values-of-references/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
