<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>JavaWorld's Daily Brew</title>
  <subtitle>Starting conversations in the Java developer community</subtitle>
  <link rel="alternate" type="text/html" href="http://www.javaworld.com/community"/>
  <link rel="self" type="application/atom+xml" href="http://www.javaworld.com/community/atom/feed"/>
  <id>http://www.javaworld.com/community/atom/feed</id>
  <updated>2009-11-07T18:55:35-05:00</updated>
  <entry>
    <title>Closures Coming to Java 7</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/3719" />
    <id>http://www.javaworld.com/community/node/3719</id>
    <published>2009-11-20T19:05:00-05:00</published>
    <updated>2009-11-21T08:56:13-05:00</updated>
    <author>
      <name>dmarx</name>
    </author>
    <category term="Dustin" />
    <category term="Java SE 7" />
    <summary type="html"><![CDATA[<!--paging_filter--><p><strong>The Big Announcement: Closures in JDK 7!</strong></p>
    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p><strong>The Big Announcement: Closures in JDK 7!</strong></p>
<p>The biggest current news in the <a href="http://java.sun.com/">Java</a> <a href="http://www.javaworld.com/">world</a> is the apparent reconsideration by <a href="http://www.sun.com/">Sun</a> regarding the addition of <a href="http://twitpic.com/pz3hn">closures</a> to <a href="http://java.sun.com/features/jdk/7/">JDK 7</a>.  <a href="http://blogs.sun.com/mr/">Mark Reinhold</a>'s <a href="http://www.devoxx.com/">Devoxx</a> announcement has led to many posts on the subject including <a href="http://www.jroller.com/scolebourne/">Stephen Colebourne</a>'s <a href="http://www.jroller.com/scolebourne/entry/closures_in_jdk_7">Closures in JDK 7</a>, <a href="http://tech.puredanger.com/about">Alex Miller</a>'s <a href="http://puredanger.com/tech/2009/11/18/closures-after-all/">Closures After All?</a>, <a href="http://blogs.tedneward.com/">Ted Neward</a>'s <a href="http://blogs.tedneward.com/2009/11/19/Closures+Are+Back+Again.aspx">Closures Are Back Again</a>, <a href="http://www.java.net/blogs/cayhorstmann/">Cay Horstmann</a>'s <a href="http://weblogs.java.net/blog/cayhorstmann/archive/2009/11/18/closures-java-7">Closures? In Java 7???</a>, <a href="http://java.dzone.com/users/mitch-pronschinske">Mitch Pronschinske</a>'s <a href="http://java.dzone.com/news/closures-coming-java-7">Closures Coming to Java 7</a>, <a href="http://java.dzone.com/users/geertjan">Geertjan Wielenga</a>'s <a href="http://java.dzone.com/news/devoxx-day-3-conference-day-1">Devoxx Day 3: Conference Day 1</a>, and a summary of some of these posts in the Java.net editorial <a href="http://weblogs.java.net/blog/editor/archive/2009/11/19/devoxx-surprise-out-nowhere-closures-jdk-7">DEVOXX Surprise: Out of Nowhere: Closures in JDK 7!</a></p>
<p>The collective excitement, concern, confusion, and questioning attitudes represented by these posts is likely indicative of the general Java community's feelings regarding this announcement.  I have <a href="http://marxsoftware.blogspot.com/2008/12/most-missed-java-se-7-features.html">blogged before</a> regarding closures being (at that time we thought based on last year's Devoxx announcement) one of the most-missed features to not be included in Java 7.  <a href="http://www.infoq.com/author/Dionysios-G.-Synodinos">Dionysios G. Synodinos</a> summarized, in <a href="http://www.infoq.com/news/2009/01/java7-updated">Java 7 Roadmap Updated: Reactions</a>, several online reactions (including mine) to the 2008 Devoxx announcement that closures were being omitted from JDK 7.  The <a href="http://java.net/">Java.net</a> poll on <a href="http://java.net/pub/pq/240">most-missed Java 7 features</a> showed closures being the most voted for "missed feature" with nearly half the votes.  Even <a href="http://blogs.sun.com/jag/">James Gosling</a> has weighed in with his <a href="http://blogs.sun.com/jag/entry/closures">favoring of closures in Java</a>.  The <a href="http://www.javac.info/consensus-closures-jsr.html">JSR Proposal for Closures in Java</a> also lists individuals and organizations particularly interested in Java closures.  Closures are clearly popular with Java developers who read and write regularly in the blogosphere.</p>
<p><strong>What Are Closures?</strong></p>
<p>For those who are not familiar with closures, <a href="http://martinfowler.com/">Martin Fowler</a>'s post <a href="http://martinfowler.com/bliki/Closure.html">Closure</a> is perhaps the definitive explanation of what constitutes a closure.  Fowler states about closures: "Essentially a closure is a block of code that can be passed as an argument to a function call."  Fowler compares and contrasts closures with anonymous classes and highlights closures as syntactically simpler than anonymous classes and able to see variables available at time of closure definition.</p>
<p>Besides Fowler's <a href="http://martinfowler.com/bliki/Closure.html">Closure</a> post, other useful introductions to closures can be found in the <a href="http://groovy.codehaus.org/User+Guide">Groovy User Guide</a> section on <a href="http://groovy.codehaus.org/Closures">Closures</a> (defines closures as "A Groovy Closure is like a 'code block' or a method pointer.") and in the <a href="http://en.wikipedia.org/wiki/Main_Page">Wikipedia</a> entry on <a href="http://en.wikipedia.org/wiki/Closure_(computer_science)">closures</a>.</p>
<p><strong>What Are the Java Closure Proposals?</strong></p>
<p>The <a href="http://www.javaworld.com/">JavaWorld</a> article <a href="http://www.javaworld.com/javaworld/jw-06-2008/jw-06-closures.html">Understanding the Closures Debate</a> lays out the three most popular proposed alternatives for closures in Java.  The three primary proposals for Java closures are BGGA, CICE, and FCM.</p>
<p>The <a href="http://www.javac.info/closures-v05.html">BGGA proposal</a> is <a href="http://blogs.sun.com/jrose/entry/closures_without_function_types">named</a> after the first letter in the last names of each of its original authors: <a href="http://bracha.org/Site/Home.html">Gilad Bracha</a>, <a href="http://gafter.blogspot.com/">Neal Gafter</a>, <a href="http://en.wikipedia.org/wiki/James_Gosling">James Gosling</a>, and Peter von der Ahe.  It is often referred to as the "full closures" proposal and was by far the most popular of the three options voted on in <a href="http://www.java.net/pub/pq/196">this Java.net poll</a>.</p>
<p>The <a href="http://www.jroller.com/scolebourne/entry/first_class_methods_java_style">FCM</a> (<a href="http://docs.google.com/Doc?id=ddhp95vd_0f7mcns">First Class Methods</a>) closure proposal is the one closest to the example syntax Mark Reinhold <a href="http://java.dzone.com/news/closures-coming-java-7">reportedly wrote on the airplane ride</a> to Devoxx and it sounds like <a href="http://docs.google.com/Doc?id=ddhp95vd_6hg3qhc">FCM 0.5</a> is considered the starting point for Java 7 treatment of closures.  It currently sounds like the Java 7 implementation would exclude inclusion of the <a href="http://docs.google.com/View?docid=ddhp95vd_8f8zkn3">Java Control Abstraction</a> (JCA) features.</p>
<p>A third Java closures proposal is the <a href="http://docs.google.com/Doc.aspx?id=k73_1ggr36h">Concise Instance Creation Expressions</a> (CICE) proposal by <a href="http://www.theserverside.com/news/thread.tss?thread_id=27163">Josh Bloch</a>, <a href="http://g.oswego.edu/">Doug Lea</a>, and <a href="http://crazybob.org/">Bob Lee</a> proposes "a more concise syntax to instantiate anonymous classes."  <a href="http://crazybob.org/2006/10/java-closure-spectrum.html">Bob Lee's introduction of CICE</a> closure proposal compares it to the <a href="http://www.javac.info/closures-v05.html">BGGA proposal</a>.  <a href="http://www.elharo.com/">Elliotte Rusty Harold</a> has posted <a href="http://cafe.elharo.com/java/cice-not-so-nice/">his complaints</a> about the CICE proposal.</p>
<p>The blog post <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=202004">Comparing Inner Class/Closure Proposals</a> compares the three above proposals and throws the <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=182412">Clear, Consistent, and Concise (C3S) for Java</a> proposal into the comparison.</p>
<p><strong>Additional Resources</strong></p>
<p>Another good resource regarding Java and closures is <a href="http://www.briangoetz.com/">Brian Goetz</a>'s <a href="http://www.ibm.com/developerworks/java/library/j-jtp04247.html">The Closures Debate</a>.  The <a href="http://wiki.java.net/bin/view/JDK/ClosuresSyntaxInJava7">Closures Syntax in Java 7</a> Twiki page and <a href="http://tech.puredanger.com/java7#closures">Alex Miller's Java 7 page</a> have numerous links to additional information on closures in Java.</p>
    ]]></content>
  </entry>
  <entry>
    <title>Java: Too big to fail?</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/3713" />
    <id>http://www.javaworld.com/community/node/3713</id>
    <published>2009-11-19T23:14:03-05:00</published>
    <updated>2009-11-19T23:15:12-05:00</updated>
    <author>
      <name>Josh Fruhlinger</name>
    </author>
    <category term="future of Java" />
    <category term="java" />
    <summary type="html"><![CDATA[<!--paging_filter--><p>If you're worked up over the post-merger future of the Java platform, you owe it to yourself to read <a href="http://www.javaworld.com/javaworld/jw-11-2009/091909-java-future.html" target="_blank">Peter Wayner's longish piece</a> on this very Web site!  It is quite soothing, and you can imagine it being read aloud in the calm, ration voice of a public radio announcer.    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>If you're worked up over the post-merger future of the Java platform, you owe it to yourself to read <a href="http://www.javaworld.com/javaworld/jw-11-2009/091909-java-future.html" target="_blank">Peter Wayner's longish piece</a> on this very Web site!  It is quite soothing, and you can imagine it being read aloud in the calm, ration voice of a public radio announcer.  The thesis goes something like this: Java <em>could</em> be wrecked by Oracle heavy-handedness driving wedges between it and other big companies with big Java stakes, and it <em>could</em> be supplanted by other, hotter and noisier, languages.  But it probably won't, because of inertia!  Well, OK, "inertia" sounds bad; let's say because of a huge pool of happy Java developers, and a huge number of installed JVMs, which are really doing just fine for most things people use them for.  I quibble with some of his details -- I particularly doubt that even the biggest, most lumbering company would pay "$100, $200, or even $1 million per CPU to avoid recoding their Java EE applications" -- but in general I think he's right: Java is here to stay because you can't just turn it off, and if it gets screwed up everyone would suffer.</p>

<p>This is not exactly the stuff of enthusiasm building!  I got my very first real job in 1999 as a copy editor for the group that was putting <em>JavaWorld</em> out in those days, and the technology had <em>buzz</em> then -- certainly more than some of our other publications, like <em>SunWorld</em> (which focused on Solaris) and <em>Windows TechEdge</em> (which was for NT admins, whee!).  Java was innovative, weird, and was going to take over the world, maybe.  Now it's everywhere, like everyone dreamed.  If there are no more worlds left to conquer, well, it's big enough that it won't go away any time soon, either.</p>

<p>And who says you can't teach an old dog new tricks?  The much-desired advent of closures in Java 7 <a href="http://weblogs.java.net/blog/cayhorstmann/archive/2009/11/18/closures-java-7" target="_blank">may be on the horizon</a>!  So, despite the grumpiness that often comes to the fore in this blog, I do believe that Java has a steady future, that may even feature some excitement now and then.</p>


    ]]></content>
  </entry>
  <entry>
    <title>CouchDB is so Groovy</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/3712" />
    <id>http://www.javaworld.com/community/node/3712</id>
    <published>2009-11-19T11:46:25-05:00</published>
    <updated>2009-11-20T08:55:41-05:00</updated>
    <author>
      <name>Andrew Glover</name>
    </author>
    <category term="amazon" />
    <category term="Andy" />
    <category term="Articles" />
    <category term="cloud" />
    <category term="couchdb" />
    <category term="development" />
    <category term="development 2.0" />
    <category term="ec2" />
    <category term="groovy" />
    <category term="open source" />
    <category term="programming" />
    <category term="rest" />
    <category term="software as a service" />
    <summary type="html"><![CDATA[<!--paging_filter--><p>Without a doubt, the burst of innovation occurring in the open source world over the last few years has led to an increase in developer productivity, baby. Freely available tools, frameworks, and solutions address once-common time sinks. Apache&#8217;s <a href="http://couchdb.apache.org/">CouchDB</a> is no exception. It&#8217;s amazingly easy to get going with CouchDB <a href="http://thediscoblog.com/2009/11/10/couchdb-on-ec2-in-3-12-minutes/">once you have it up and running</a>.</p>
    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>Without a doubt, the burst of innovation occurring in the open source world over the last few years has led to an increase in developer productivity, baby. Freely available tools, frameworks, and solutions address once-common time sinks. Apache&#8217;s <a href="http://couchdb.apache.org/">CouchDB</a> is no exception. It&#8217;s amazingly easy to get going with CouchDB <a href="http://thediscoblog.com/2009/11/10/couchdb-on-ec2-in-3-12-minutes/">once you have it up and running</a>. And all you need to work with it is an HTTP connection; no JDBC driver is required, nor do you need a third-party administrative-management platform. </p>
<p>In this article published by <a href="http://www.ibm.com/developerworks/">IBM DeveloperWorks</a> entitled &#8220;<a href="http://www.ibm.com/developerworks/java/library/j-javadev2-5/">REST up with CouchDB and Groovy&#8217;s RESTClient</a>&#8220;, you&#8217;ll meet CouchDB and see how you can rapidly get up to speed with using it. For ease of installation, you&#8217;ll take advantage of <a href="http://aws.amazon.com/ec2/">Amazon&#8217;s EC2 platfor</a>m and you&#8217;ll <a href="http://thediscoblog.com/2008/07/22/restful-services-without-the-sweat/">RESTfully communicate</a> with CouchDB via a handy Groovy module dubbed <a href="http://groovy.codehaus.org/modules/http-builder/">HttpBuilder</a>. If you ask me, it can&#8217;t get any cooler, man! </p>
<p>If you enjoy these kind of technologies, then have a look at some other related articles like:</p>
<ul>
<li><a href="http://thediscoblog.com/2009/11/02/ec2-is-easier-than-you-think/">Easy EC2</a> (November 2009)</li>
<li><a href="http://thediscoblog.com/2009/10/01/you-can-borrow-ec2-too/">You can borrow EC2 too</a> (October 2009)</li>
<li><a href="http://thediscoblog.com/2009/08/20/hello-google-app-engine/">Hello Google App Engine</a> (August 2009)</li>
</ul>
<p>So what are you waiting for? Read on! </p>
<p>Looking to spin up Continuous Integration <em>quickly</em>? Check out <a href="http://www.ciinabox.com">www.ciinabox.com</a>.</p>
    ]]></content>
  </entry>
  <entry>
    <title>Closures are back again!</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/3710" />
    <id>http://www.javaworld.com/community/node/3710</id>
    <published>2009-11-19T03:10:11-05:00</published>
    <updated>2009-11-20T18:55:45-05:00</updated>
    <author>
      <name>Ted Neward</name>
    </author>
    <summary type="html"><![CDATA[<!--paging_filter--><p>
Those of you who've seen me speak on Java 7 at various conferences have heard me lament<br />
(in a small way) the fact that Sun decided last year (Dec 2008) to forgo the idea<br />
of including closures in the Java language. Imagine my surprise, then, to check my<br />
Twitter feed and discover that, to everyone's surprise, closures <a href="http://puredanger.com/tech/2009/11/18/closures-after-all/" target="_blank">are<br />
back in as a consideration for the Java7 release</a>.
</p>
<p>
Several thoughts come to mind:
</p>
    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>
Those of you who've seen me speak on Java 7 at various conferences have heard me lament<br />
(in a small way) the fact that Sun decided last year (Dec 2008) to forgo the idea<br />
of including closures in the Java language. Imagine my surprise, then, to check my<br />
Twitter feed and discover that, to everyone's surprise, closures <a href="http://puredanger.com/tech/2009/11/18/closures-after-all/" target="_blank">are<br />
back in as a consideration for the Java7 release</a>.
</p>
<p>
Several thoughts come to mind:
</p>
<ul>
<li>
<strong><em>&quot;WTF?!?!? This is a community effort?&quot;</em></strong> Originally,<br />
when Sun created the Java Community Process, the tradeoff for a committee-based development<br />
process was against the open and fair inclusion of ideas from outside of Sun. But<br />
with the Java7 release still lacking a JSR (as of a few weeks ago, anyway; I haven't<br />
checked today to see if it was opened), and both the Modules facility and language<br />
extensions deferred to &quot;Projects&quot; (not JSRs), it seems Sun is now abandoning<br />
the JCP in favor of a Sun-dominant process that is certainly solicitous of the community<br />
at large, but not constrained or defined by it. And for the life of me, I can't tell<br />
if this is a good thing or a bad thing. It's good in that now we don't have to garner<br />
a critical mass of community momentum to get something included into the platform<br />
or language, but it's bad in that Sun has historically been the bigger drag on innovation<br />
there, not the community.
</li>
<li>
<strong><em>&quot;Can we please stop calling them closures?&quot;</em></strong> This<br />
is a nit, but technically what we're talking about adding here are either lambda expressions<br />
or anonymous methods, depending on whose glossary you're using when you're talking.<br />
A true closure is one that will compute all referenced variables from the enclosing<br />
scope and automatically include them in the generated code, which (so far as I can<br />
tell) none of the Java anonymous method or lambda expression proposals currently include.<br />
But it's a nit, so I'll say it this once and then drop it.
</li>
<li>
<strong><em>&quot;Will Groovy, Scala, Clojure and all other JVM languages please report<br />
to the refactoring room?&quot;</em></strong> People look at me quizzically when I<br />
say I'd like to see Java have closures in the language, because in general my take<br />
on language features in Java is that the Java language is more or less dead, and I<br />
could care less what happens to it; I'd vastly prefer to code in Groovy or Scala or<br />
Clojure or JRuby before writing something in Java. My rationale for wanting closures<br />
in Java, however, is this: by defining a common <em>implementation</em> for closures<br />
in Java, all of the above languages can refactor their implementations of anonymous<br />
methods/lambda expressions/etc into something that uses Java's closure implementation,<br />
and that'll make calling Groovy anonymous methods from Scala much much easier.
</li>
<li>
<strong><em>&quot;Why there, now?&quot;</em></strong> Devoxx is apparently turning<br />
into JavaOne Winter, because Sun's been making a lot of pretty big announcements at<br />
that show, including last year's &quot;no closures, no built-in XML support, ...&quot;<br />
announcement about Java7, and now this year's &quot;well, we lied, we're thinking<br />
about closures again&quot;. Fortunately I think the Devoxx folks have much better<br />
skills at keeping their conference relevant to the Java community than JavaOne's organizers<br />
did. And I say that <em>despite</em> the fact (or perhaps because of the fact) that<br />
I didn't speak there this year. ;-)
</li>
<li>
<strong><em>&quot;When is this all supposed to ship again?&quot;</em></strong> Originally,<br />
my understanding was that JDK7 was slated to ship in the early part of 2010, but now<br />
rumor has it slipping to this time next year (2010). That is a huge postponement,<br />
and gives Microsoft a bit of an edge, since Visual Studio 2010 and .NET 4.0 are (again,<br />
according to rumor) supposed to ship somewhere around the end of 1Q2010. If Sun/Oracle<br />
keeps this up, we could very well be seeing a 2-.NET-releases-to-1-Java-release pattern,<br />
and that's disturbing in its own right. (Anybody else remember the days when Sun withdrew<br />
Java from ECMA, ISO and ANSI standardization consideration because they wanted to<br />
&quot;innovate on the platform faster&quot;?)
</li>
<li>
<strong><em>&quot;We really have no clue what we're talking about.&quot;</em></strong> Aside<br />
from rumors and hearsay (including the one that says that Mark Reinhold, who made<br />
the announcement, made up the syntax on the flight from the US to Belgium), we really<br />
don't have much by way of Sun-blessed <em>official</em> discussions of what this will<br />
look like or act like, at least none so far as I've been able to find, so any sort<br />
of supposition on whether it will be good or suck like an inverted hurricane is a<br />
tad premature. Trust me, I want to see where this goes, too, so I'll be keeping an<br />
eye out.
</li>
</ul>
<p>
In the meantime, if you want to keep on top of the Java space, maybe it's time to <a href="http://www.devoxx.com" target="_blank">consider<br />
a trip to Antwerp</a> this time next year, since, if the new ship date rumors are<br />
to be believed,&#160; it looks like Sun (once again) is planning to use Devoxx as<br />
the platform from which to make a large announcement, this time the release Java7<br />
itself.
</p>
<p>
<strong>Update:</strong> <a href="http://olabini.com" target="_blank">Ola Bini</a> noted<br />
that...
</p>
<p>
Two things:
</p>
<ul>
<li>
They are definitely closures. Calling them anonymous functions are incorrect,<br />
since they aren't really functions. Lambda expression is an OK name, but it has connotations<br />
that aren't really correct for a language like Java. A closure is defined as an anonymous<br />
piece of code that closes over at least one free variable, which in the case of this<br />
proposal will definitely happen. In fact, all of these will be closures, since they<br />
will be closing over the this at least.
</li>
<li>
This is mostly on the level of compiler, syntax and type checking, and will NOT have<br />
any real implications for runtime. This means there will be no real sharing of implementation<br />
- at most JRuby, Groovy and Scala blocks will implement another interface (but all<br />
of them already implement Runnable and Callable so it's a limited win).
</li>
</ul>
<p>
which prompted me to respond thusly:
</p>
<p>
First off, I actually never used the term &quot;anonymous function&quot;; instead,<br />
I said &quot;anonymous method&quot;, which, as I understand it, is how the underlying<br />
implementation of these proposals will work: the syntax &quot;#() return 42&quot;<br />
will create an anonymous inner class instance of an interface defined by the library<br />
(in its &quot;SimpleClosure&quot; example, the BGGA compiler uses the interface &quot;javax.lang.function.I&quot;,<br />
which has one method on it, &quot;invoke()&quot;), which, thus, makes this an anonymous<br />
method. We can't call them &quot;anonymous functions&quot; because Java has no function<br />
type, and probably never will. (And yes, it may seem like we're splitting hairs somewhat<br />
to differentiate between functions and methods,but once you've explored ML, Haskell,<br />
Scala, or F#, you really begin to see a huge difference in those terms, so it's important<br />
to be precise with our terminology, or else the conversation becomes almost entirely<br />
meaningless.)
</p>
<p>
Neal Gafter uses the definition &quot;A closure is a function that captures the bindings<br />
of free variables in its lexical context.&quot; (<a href="http://gafter.blogspot.com/2007/01/definition-of-closures.html)">http://gafter.blogspot.com/2007/01/definition-of-closures.html)</a> Given<br />
that said same post also claims that Java has no function type (and therefore, by<br />
his definition, can't really have a closure), I suppose we could split the hairs even<br />
further and suggest that Java will never have closures until it has true function<br />
types. Personally, I'm happy to say that we can swap in &quot;methods&quot; for &quot;functions&quot;<br />
in this particular discussion, but my understanding is that capturing free variables<br />
also implies capturing variables referenced in the enclosing lexical context, which<br />
the current &quot;closures&quot; proposal (as reported by Alex Miller's closures page)<br />
will not do. (Non-final enclosing parameters will not be accessible, only those passed<br />
in formally as parameters. <a href="http://www.jroller.com/scolebourne/entry/closures_in_jdk_7" target="_blank">Stephen<br />
Colebourne</a> reports as much: &quot;[Mark Reinhold] also indicated that access to<br />
non-final variables was unlikely.&quot;)
</p>
<p>
Given that the current proposal suggests the new #() syntax will essentially generate<br />
an anonymous inner class with a method of the appropriate signature (though I do believe<br />
that method handles are targeted for use at some point, based on what I've been hearing<br />
through the rumor mill), to me it feels like the &quot;closures&quot; implementation<br />
is generating an anonymous method of an anonymous class with a few other restrictions<br />
included--hence my commentary above.
</p>
<p>
(Having said all that, the <a href="http://docs.google.com/View?docid=ddhp95vd_6hg3qhc" target="_blank">FCM<br />
proposal</a> does provide complete capture of all referenced variables in enclosing<br />
scope, but Mark's keynote hasn't officially endorsed either the BGGA proposal or the<br />
FCM proposal, and if Sun keeps to their habits, they won't. They'll build something<br />
that's an amalgamation of all of them. Right now the current consensus seems to be<br />
to adopt the BGGA implementation behind the FCM syntax, which jives with Neal's 0.6a<br />
specification proposal.)
</p>
<p>
On top of that, the comment &quot;all of these will be closures, since they will be<br />
closing over the this at least&quot; is not, I don't think, entirely true. The details<br />
of the closures proposal aren't clear, but the &quot;outer this&quot; (which I believe<br />
is the &quot;this&quot; Ola refers to above) hasn't been explicitly mentioned in any<br />
of the closures proposals I've seen, nor have I seen any text suggesting that they<br />
will honor it, so I don't know that this is true. Of course, in absence of a specification<br />
or real working bits, all we can do is just speculate. However, having said that,<br />
playing around a bit with the BGGA prototype compiler (which, admittedly, is still<br />
one minor rev back from Neal's revised proposal), I saw no generated &quot;outer this&quot;<br />
in the generated code for the generated inner class implementation of the closure.<br />
If the comment above is meant to refer to the &quot;this&quot; of the inner class<br />
instance, then that would make all methods of an object-oriented language that provided<br />
an implicit &quot;this&quot; a closure, and somehow I doubt that's what Ola means,<br />
though I could, as always, be wrong.
</p>
<p>
As for the runtime implementation, as I said earlier I believe the plan is to use<br />
method handles (already on the table for JDK 7), which do have some runtime implications<br />
(generally good ones, from what I can tell so far), but not beyond what was already<br />
on the table for 7.
</p>
<p></p>
<p>Enterprise consulting, mentoring or instruction. Java, C++, .NET or XML services.<br />
1-day or multi-day workshops available. <a href="mailto:ted@tedneward.com">Contact<br />
me for details</a>.</p>
    ]]></content>
  </entry>
  <entry>
    <title>Android just reproducing Java ME&#039;s problems, now</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/3704" />
    <id>http://www.javaworld.com/community/node/3704</id>
    <published>2009-11-17T12:03:18-05:00</published>
    <updated>2009-11-17T17:16:14-05:00</updated>
    <author>
      <name>Josh Fruhlinger</name>
    </author>
    <category term="Android" />
    <category term="Java ME" />
    <summary type="html"><![CDATA[<!--paging_filter--><p>Is Android a Java platform?  It's certainly Java-esque, in the sense that for the most part you write apps for it in Java code.  But it's not blessed by Sun or tested for compatibility -- in fact, it's incompatible with standard Java in several specified ways; its VM isn't an official JVM; and, to make things wackier, the Java it's based on is Java SE, not Java ME.  This drives folks like <a href="http://blogs.sun.com/hinkmond/entry/google_s_android_no_match" target="_blank">Hinkmond Wong, Sun's Java ME blogger</a>, crazy.    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>Is Android a Java platform?  It's certainly Java-esque, in the sense that for the most part you write apps for it in Java code.  But it's not blessed by Sun or tested for compatibility -- in fact, it's incompatible with standard Java in several specified ways; its VM isn't an official JVM; and, to make things wackier, the Java it's based on is Java SE, not Java ME.  This drives folks like <a href="http://blogs.sun.com/hinkmond/entry/google_s_android_no_match" target="_blank">Hinkmond Wong, Sun's Java ME blogger</a>, crazy.  But you can make a decent argument that the sorry, fragmented state of Java ME brought made Android inevitable. With its crazy quilt of different implementations on various handsets and OSes, Java ME was never going to be the platform for the next generation of desktop-quality apps; a new platform was necessary to help Java code take over the mobile world.</p>

<p>Except!  It turns out that Android is hitting <a href="http://www.wired.com/gadgetlab/2009/11/android-fragmentation/" target="_blank">all the same fragmentation problems as Java ME, and in record time</a>!  Not only are there three different versions of the Android OS out in the wild at the moment, but different handset manufacturers customize the platform and add their own specialized ROMs, with the result that code that runs on one phone completely borks out on another.</p>

<p>You can say a lot of negative stuff about how Apple handles the iPhone -- their arbitrary rejection of apps based on content is particularly egregious.  But I think that their basic model, in which they tightly control the both the OS and the hardware, is boon for developers.  It may be that the only way to have a platform that is truly standardized is to have one company in charge of it.  Microsoft was essentially able to impose a more-or-less standard x86 platform spec on PC manufacturers by the sheer power of its monopoly, but nobody has ever managed to do the same for cell phones.  Android was supposed to be developers' great hope, but it may be another sign that a truly interoperable platform can't be built by multiple companies with competing agendas.  And that's something that ought to interest Java developers, whether they care about cell phones or not.</p>     ]]></content>
  </entry>
  <entry>
    <title>Groovy Console: Graphical Groovy Shell</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/3703" />
    <id>http://www.javaworld.com/community/node/3703</id>
    <published>2009-11-16T23:15:00-05:00</published>
    <updated>2009-11-21T08:56:13-05:00</updated>
    <author>
      <name>dmarx</name>
    </author>
    <category term="Dustin" />
    <category term="groovy" />
    <summary type="html"><![CDATA[<!--paging_filter--><p>I wrote about <a href="http://groovy.codehaus.org/Groovy+Shell">Groovy Shell</a> in my <a href="http://marxsoftware.blogspot.com/2009/11/groovy-shell-gentle-introduction-to.html">last blog post</a>.  As I wrote in that post, Groovy Shell is a highly useful command line based method for experimenting with <a href="http://groovy.codehaus.org/">Groovy</a> code.  For those who prefer a graphical interface over the command line interface, <a href="http://groovy.codehaus.org/Groovy+Console">Groovy Console</a> provides a nice alternative and that is the subject of this blog post.</p>
    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>I wrote about <a href="http://groovy.codehaus.org/Groovy+Shell">Groovy Shell</a> in my <a href="http://marxsoftware.blogspot.com/2009/11/groovy-shell-gentle-introduction-to.html">last blog post</a>.  As I wrote in that post, Groovy Shell is a highly useful command line based method for experimenting with <a href="http://groovy.codehaus.org/">Groovy</a> code.  For those who prefer a graphical interface over the command line interface, <a href="http://groovy.codehaus.org/Groovy+Console">Groovy Console</a> provides a nice alternative and that is the subject of this blog post.</p>
<p>Assuming Groovy is <a href="http://groovy.codehaus.org/Installing+Groovy">appropriately installed</a> on one's system with <code>GROOVY_HOME</code> defined correctly, it is easy to run the Groovy Console by simply typing <code>groovyConsole</code> at the command line.  The next screen snapshot shows the running of Groovy Console along with the output from selecting Help-&gt;About.</p>
<p><a href="http://3.bp.blogspot.com/_sDOe5HxTdMk/SwInoibM5yI/AAAAAAAABZs/YFYfYSKPiNg/s1600/groovyConsoleStartUpHelpAbout.png"></a></p>
<p>It is easy to enter Groovy code and execute it (by clicking on the icon on the far right with the green arrow pointing right).  The next two screen snapshots show entering Groovy code in the top pane and then the results of clicking on that "Execute Groovy Script" button in the bottom pane.  Color coding helps make the scripts and the output more readable.</p>
<p><a href="http://3.bp.blogspot.com/_sDOe5HxTdMk/SwIqqndUeYI/AAAAAAAABZ0/CX7a9GcerJU/s1600/groovyConsoleCurentDateTimeScript.png"></a></p>
<p><a href="http://1.bp.blogspot.com/_sDOe5HxTdMk/SwIq316hMxI/AAAAAAAABZ8/l0sW4OZ6Hf0/s1600/groovyConsoleCurrentDateTimeOutput.png"></a></p>
<p>The Groovy Console supports larger fonts.  The next screen image shows the results of selecting View -&gt; Larger Font multiple times.</p>
<p><a href="http://2.bp.blogspot.com/_sDOe5HxTdMk/SwItylnDlQI/AAAAAAAABaE/HsSe1mMjIhI/s1600/groovyConsoleMultipleLargerFontCalendarProperties.png"></a></p>
<p>This image also shows a simple script for getting the date/time from <a href="http://java.sun.com/javase/6/docs/api/java/util/Calendar.html">Calendar</a> using Groovy's property access syntax.  Instead of needing to call <a href="http://java.sun.com/javase/6/docs/api/java/util/Calendar.html#getInstance()">getInstance()</a> on <code>Calendar</code> and <a href="http://java.sun.com/javase/6/docs/api/java/util/Calendar.html#getTime()">getTime()</a> on the returned <code>Calendar</code> instance, I was able to access those directly with <code>.instance.time</code>.</p>
<p>Groovy Console allows one to select whether shortened or full stack traces should be displayed.  The following two screen snapshots demonstrate the difference between the normal (shortened) stack traces and full stack traces.  To turn on full stack traces, one selects View -&gt; Show Full Stack Traces.</p>
<p><a href="http://3.bp.blogspot.com/_sDOe5HxTdMk/SwIxvxGrpEI/AAAAAAAABaM/t2tUaBHXPbA/s1600/groovyConsoleNoColorClassException.png"></a></p>
<p><a href="http://4.bp.blogspot.com/_sDOe5HxTdMk/SwIx3RnavgI/AAAAAAAABaU/BiqsE1oXvMY/s1600/groovyConsoleNoColorClassExceptionFullStackTrace.png"></a></p>
<p>In this case, it is easy to deal with the stack trace.  All that needs to be done is to import the <a href="http://java.sun.com/javase/6/docs/api/java/awt/Color.html">Color</a> class as shown in the next screen snapshot (classes in <a href="http://java.sun.com/javase/6/docs/api/java/awt/package-summary.html">java.awt</a> package are not automatically imported in Groovy).</p>
<p><a href="http://1.bp.blogspot.com/_sDOe5HxTdMk/SwIyPD5MPvI/AAAAAAAABac/FOoCDXOCl4w/s1600/groovyConsoleColorClassImported.png"></a></p>
<p>Groovy Console supports numerous other useful features.  Scripts can be saved to disk once they do what the developer wants.  JAR files and directories can be added to the Groovy Console classpath for custom Java classes used by Groovy scripts.  The <a href="http://groovy.codehaus.org/Groovy+Console">Groovy Console page</a> lists many more useful features of Groovy Console such as the ability to host Groovy Console as an applet and the ability to embed Groovy Console in <a href="http://java.sun.com/docs/books/tutorial/uiswing/">Swing</a>-based applications.</p>
<p>Another useful graphical approach to playing with Groovy code is the <a href="http://groovyconsole.appspot.com/">Groovy web console</a> deployed on <a href="http://code.google.com/appengine/">Google App Engine</a>.</p>
    ]]></content>
  </entry>
  <entry>
    <title>Comparing Scala and Groovy via ScalaTest and easyb</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/3702" />
    <id>http://www.javaworld.com/community/node/3702</id>
    <published>2009-11-16T16:40:25-05:00</published>
    <updated>2009-11-20T08:55:42-05:00</updated>
    <author>
      <name>Andrew Glover</name>
    </author>
    <category term="agile" />
    <category term="Andy" />
    <category term="bdd" />
    <category term="concurrency" />
    <category term="Developer Testing" />
    <category term="development 2.0" />
    <category term="dsl" />
    <category term="easyb" />
    <category term="functional language" />
    <category term="functional programming" />
    <category term="groovy" />
    <category term="java" />
    <category term="JUnit" />
    <category term="JVM" />
    <category term="multicore" />
    <category term="open source" />
    <category term="programming" />
    <category term="scala" />
    <category term="Software Development" />
    <category term="TDD" />
    <category term="testing" />
    <category term="unit testing" />
    <category term="xunit" />
    <summary type="html"><![CDATA[<!--paging_filter--><p>Because it&#8217;s my bag, I&#8217;ve recently taken to learning <a href="http://www.scala-lang.org/">Scala</a>.</p>
    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>Because it&#8217;s my bag, I&#8217;ve recently taken to learning <a href="http://www.scala-lang.org/">Scala</a>. In particular, I&#8217;ve run across some situations where I&#8217;ve known instinctively that a more <a href="http://en.wikipedia.org/wiki/Functional_language">functional language</a> (i.e. one that avoids state and mutability) would have perhaps made the task at hand a bit easier or at least safer to code (think situations involving threads (i.e. <a href="http://thediscoblog.com/2008/10/19/book-review-programming-erlang/">concurrency</a>), for instance). And while I&#8217;ve thus far handled those situations with various libraries and frameworks on the JVM (either straight Java or via <a href="http://gpars.codehaus.org/">Groovy</a>), <a href="http://thediscoblog.com/2008/10/19/poll-which-language-is-better-suited-for-jvm-concurrency/">Scala</a> has always held my interest in that the language is <em><a href="http://thediscoblog.com/2008/10/31/is-scala-or-clojure-poised-for-stardom/">functional by nature</a></em> &#8212; that is, functional aspects are intrinsically present as opposed to added in or forced via additional libraries, etc. </p>
<p>One of my favorite techniques for learning a new language is to leverage it <a href="http://www.ibm.com/developerworks/java/library/j-pg11094/index.html">via a testing framework</a> &#8212; that way, you get to learn the syntax while also learning about how the language behaves. For instance, because <a href="http://thediscoblog.com/2007/09/21/stacking-it-up-with-bdd-baby/">BDD is my bag</a>, I thought I&#8217;d start things off by writing a few behaviors with <a href="http://www.scalatest.org/">ScalaTest</a>. Briefly, ScalaTest is </p>
<p>
an open source test framework [written in Scala] for the Java platform designed to increase your productivity by letting you write fewer lines of test code that more clearly reveal your intent.
</p>
<p>Interestingly, they team behind ScalaTest has even trademarked the slogan</p>
<p>
Less code, more clarity
</p>
<p>Of course, I&#8217;m all about less code and more clarity &#8212; <a href="http://easyb.org/">I&#8217;m all about easy, baby</a>! So I thought it would be fun while learning about Scala to also compare and contrast Scala and ScalaTest to <a href="http://www.amazon.com/gp/product/1932394842?ie=UTF8&amp;tag=thdibl-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1932394842">Groovy</a> and <a href="http://easyb.org/">easyb</a>. Before I go any further, please allow me to state, for the record, that I&#8217;m much for familiar with <a href="http://thediscoblog.com/category/dynamic-languages/groovy/">Groovy</a> than Scala and that I&#8217;m almost certainly <a href="http://thediscoblog.com/index.php?s=easyb&amp;submit=Search">biased towards easyb</a> no matter how hard I might try to admit otherwise. Nevertheless, I do believe I can be objective in this situation as I am intent on leveraging Scala where appropriate. </p>
<p>The ScalaTest team has done a wonderful job of documenting the various options available for testing; in fact, they&#8217;ve got an entire section dedicated to BDD-style testing; in particular, they have an <a href="http://rspec.info/">RSpec</a> inspired syntax that is obviously similar to <a href="http://easyb.org/howtobb.html">easyb&#8217;s specification syntax</a> (which was also inspired by RSpec). Thus, with ScalaTest&#8217;s <code>Spec</code> trait, you can leverage an <code>it</code>-style syntax for behavior verification; plus, via Scala&#8217;s <a href="http://www.scala-lang.org/node/117">mix-ins feature</a>, you can also leverage a more natural <code>should</code>-style of verification, which definitely leads to a more readable specification. </p>
<p>Using the <a href="http://www.scalatest.org/getting_started_with_bdd">ScalaTest documentation</a>, you can create a specification that describes a stack like so:</p>
<p>import org.scalatest.Spec</p>
<p>class ExampleSpec extends Spec {<br />
 describe(&quot;A Stack&quot;) {<br />
  it(&quot;should pop values in last-in-first-out order&quot;) (pending)<br />
  it(&quot;should throw NoSuchElementException if an empty stack is popped&quot;) (pending)<br />
 }<br />
}</p>
<p>This is, of course, runnable and yields a report that states that there are two pending tests (or behaviors). Note, with ScalaTest, you must indicate a specification is pending by appending a <code>(pending)</code> clause. </p>
<p>Conversely, with easyb, the same specification can be written like so:</p>
<p>description &quot;this specification describes a stack&quot;</p>
<p>it &quot;should pop values in last-in-first-out order&quot;<br />
it &quot;should throw NoSuchElementException if an empty stack is popped&quot;</p>
<p>What&#8217;s noticeably lacking from easyb&#8217;s syntax is the <code>describe</code> clause (which, in many ways, is just like a scenario); however, easyb doesn&#8217;t force you do declare that a particular behavior is pending &#8212; it&#8217;ll figure that out by itself. What&#8217;s more, you aren&#8217;t forced to create a class structure to contain your specification. You don&#8217;t have to import anything either. </p>
<p>Next, when you decide to code your behavior, in ScalaTest, you implement the <code>it</code>&#8217;s method body like so:</p>
<p>import org.scalatest.Spec<br />
import org.scalatest.matchers.ShouldMatchers<br />
import scala.collection.mutable.Stack</p>
<p>class ExampleSpec extends Spec with ShouldMatchers {</p>
<p> describe(&quot;A Stack&quot;) {<br />
  it(&quot;should pop values in last-in-first-out order&quot;) {<br />
   val stack = new Stack[Int]<br />
   stack.push(1)<br />
   stack.push(2)<br />
   stack.pop() should be === 2<br />
   stack.pop() should be === 1<br />
  }<br />
  it(&quot;should throw NoSuchElementException if an empty stack is popped&quot;) {<br />
   val emptyStack = new Stack[String]<br />
   evaluating { emptyStack.pop() } should produce [NoSuchElementException]<br />
  }<br />
 }<br />
}</p>
<p>As you can see from the code above, this behavior is validating a simple <code>Stack</code> object&#8211; in this case, its Scala&#8217;s own stack implementation; suffice to say, it behaves, for the most part, just like a normal stack. First and foremost, ScalaTest&#8217;s <code>ShouldMatchers</code> mixin is slick! Note how you can literally write <code>should be</code> and then pass in a condition. I think this syntax reads nicely (except for the fact that ScalaTest is using 3 <code>=</code>&#8217;s). Moreover, exception verification is quite nice too &#8212; the <code>evaluating</code>  line is quite elegant and the keyword <code>produce</code> is hip! I take it the <code>produce</code> clause takes a collection of exceptions, so it would be nice if, in the case of only one exception, you could drop the <code>[]</code> syntax though. </p>
<p>ScalaTest also has another mixin type dubbed <code>MustMatchers</code>, which replaces <code>should</code> with <code>must</code> should you want to use that word instead. </p>
<p>The same verification process in easyb looks like so (note, in the code below, I&#8217;m going to use Java&#8217;s <code>Stack</code>):</p>
<p>description &quot;this specification describes a stack&quot;</p>
<p>it &quot;should pop values in last-in-first-out order&quot;, {<br />
	stack = new Stack&lt;Integer&gt;()<br />
	stack.push 1<br />
    stack.push 2<br />
    stack.pop().shouldBe 2<br />
    stack.pop().shouldBe 1<br />
}<br />
it &quot;should throw EmptyStackException if an empty stack is popped&quot;, {<br />
	emptyStack = new Stack&lt;String&gt;()<br />
	ensureThrows(EmptyStackException){<br />
		emptyStack.pop()<br />
	}<br />
}</p>
<p>In easyb&#8217;s case, the actual assertion-like clause is <code>shouldBe</code> (or its cousins like <code>shouldEqual</code>, etc); what&#8217;s more, you must &#8220;attach&#8221; the clause to the desired object (as opposed to ScalaTest&#8217;s more <em>removed</em> syntax, which allows you to drop .&#8217;s). Nevertheless, the <code>shouldBe</code> call doesn&#8217;t insert an additional operator either (i.e. there isn&#8217;t the <code>===</code>). easyb&#8217;s exception verification is certainly not as nice as ScalaTest&#8217;s though &#8212; I suppose I could write the <code>ensureThrows</code> clause as one line but it doesn&#8217;t read as nicely as <code>evaluating { blah } should produce [Exception]</code> &#8212; I really like that syntax in ScalaTest. </p>
<p>As you can see from these two simple examples, the spirit of BDD is there &#8212; each framework takes a slightly different approach in terms of syntax, but that&#8217;s probably due to the underlying nature of the languages themselves. Scala is certainly less verbose than normal Java, but it seems to me that Groovy is less verbose than Scala (but I concede that this might just be a result of each framework&#8217;s syntax) . I find that easyb yields more clarity but I do find that ScalaTest&#8217;s matchers syntax to read quite nicely. </p>
<p>Scala is definitely an interesting language that exposes some interesting features. Like every other major player on the JVM, it has its spot &#8212; for me, the strict nature of its typing and functional-ness makes it applicable in concurrency situations; however, its syntax, while less verbose than that of Java, isn&#8217;t necessarily as flexible as <a href="http://www.amazon.com/gp/product/0978739299?ie=UTF8&amp;tag=thdibl-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0978739299">Groovy</a>, for instance (although dropping the dot (&#8221;.&#8221;) on method calls makes successive method calls read copasetically (i.e. <code>should be</code>)). </p>
<p>ScalaTest is well documented and offers quite a few neat options (via Scala traits &#038; mixins) that make testing a lot more interesting and certainly clearer than plain Jane JUnits; however, for me, I still find easyb&#8217;s syntax to be much more clarifying (and of course, much less code). Nevertheless, for Scala code that I do write, I&#8217;ll be leveraging ScalaTest &#8212; it&#8217;s already taught me a few things! Can you dig it, man? </p>
<p>Looking to spin up Continuous Integration <em>quickly</em>? Check out <a href="http://www.ciinabox.com">www.ciinabox.com</a>.</p>
    ]]></content>
  </entry>
  <entry>
    <title>Groovy Shell: A Gentle Introduction to Groovy</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/3699" />
    <id>http://www.javaworld.com/community/node/3699</id>
    <published>2009-11-16T10:44:00-05:00</published>
    <updated>2009-11-21T08:56:13-05:00</updated>
    <author>
      <name>dmarx</name>
    </author>
    <category term="Dustin" />
    <category term="groovy" />
    <summary type="html"><![CDATA[<!--paging_filter--><p><a href="http://groovy.codehaus.org/Groovy+Shell">Groovy Shell</a> brings to <a href="http://groovy.codehaus.org/">Groovy</a> what <a href="http://ruby.activeventure.com/programmingruby/book/irb.html">irb</a> (<a href="http://www.rubyinside.com/irb-lets-bone-up-on-the-interactive-ruby-shell-1771.html">Interactive Ruby</a>) and <a href="http://wiki.netbeans.org/FaqJRubyAndIRB">jirb</a> (<a href="http://docs.codehaus.org/display/JRUBY/The+JRuby+Tutorial+Part+1.5+-+Using+JIRB+to+Check+Java+Behaviour">Interactive JRuby</a>) bring to <a href="http://www.ruby-lang.org/">Ruby</a> and <a /></p>
    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p><a href="http://groovy.codehaus.org/Groovy+Shell">Groovy Shell</a> brings to <a href="http://groovy.codehaus.org/">Groovy</a> what <a href="http://ruby.activeventure.com/programmingruby/book/irb.html">irb</a> (<a href="http://www.rubyinside.com/irb-lets-bone-up-on-the-interactive-ruby-shell-1771.html">Interactive Ruby</a>) and <a href="http://wiki.netbeans.org/FaqJRubyAndIRB">jirb</a> (<a href="http://docs.codehaus.org/display/JRUBY/The+JRuby+Tutorial+Part+1.5+-+Using+JIRB+to+Check+Java+Behaviour">Interactive JRuby</a>) bring to <a href="http://www.ruby-lang.org/">Ruby</a> and <a href="http://jruby.org/">JRuby</a> respectively.  I have written about both <a href="http://www.oracle.com/technology/pub/articles/marx-ruby.html">IRB</a> and <a href="http://marxsoftware.blogspot.com/2009/04/jirb-gentle-introduction-to-jruby.html">JIRB</a> and in this blog post I look more closely at <a href="http://www.vogella.de/articles/Groovy/article.html#commandline_groovyshell">Groovy Shell</a>.</p>
<p>As IRB and JIRB do for Ruby and JRuby, Groovy Shell provides an easy, command line based interactive tool for experimenting with Groovy syntax. This can be easier to use for experimenting with Groovy than writing files to be run in a separate step or trying to pass multiple commands to the Groovy interpreter with the <code>-e</code> option.</p>
<p>Assuming that Groovy has been <a href="http://groovy.codehaus.org/Installing+Groovy">appropriately installed</a>, it is easy to run Groovy Shell with the <code>groovysh</code> command.  Doing so leads to the output shown in the next screen snapshot.</p>
<p><a href="http://4.bp.blogspot.com/_sDOe5HxTdMk/SwDu5QHsUtI/AAAAAAAABZE/lQGXLhmJdy8/s1600/groovyShStart.png"></a></p>
<p>Entering "help" at the Groovy Shell prompt brings up usage information as demonstrated in the next screen snapshot.</p>
<p><a href="http://1.bp.blogspot.com/_sDOe5HxTdMk/SwDvgNzGdbI/AAAAAAAABZM/Ncv09rXgFmg/s1600/groovyShUsage.png"></a></p>
<p>At this point, I'll demonstrate via Groovy Shell capabilities that Groovy applies similar to capabilities I demonstrated previously for Ruby and JRuby using IRB and JIRB.  The next screen snapshot demonstrates some Groovy math operations in Groovy Shell.</p>
<p><a href="http://3.bp.blogspot.com/_sDOe5HxTdMk/SwDzrLvosrI/AAAAAAAABZU/DBlLJCpALsY/s1600/groovyShellMathOperators.png"></a></p>
<p>Groovy provides many String operations one might not expect in a language as tied to Java as Groovy is.  However, the next screen snapshot proves some of Groovy's string operations that behave similarly to those demonstrated for Ruby and JRuby in my previous writings on IRB and JIRB.</p>
<p><a href="http://1.bp.blogspot.com/_sDOe5HxTdMk/SwD2KYkpOqI/AAAAAAAABZc/1w0L3BwFyeo/s1600/groovyShellStringOperations.png"></a></p>
<p>The 2004 JavaOne conference presentation <a href="http://codehaus.org/~jstrachan/GroovyJavaOne-2004.ppt">The Groovy Programming Language: Let's Get Groovy</a> includes a nice tip related to use of Groovy Shell.  In one of that presentation's slides, Rod Cope and James Strachan demonstrated using Groovy Shell to easily determine the methods available on a particular class.  They specifically looked at the <a href="http://java.sun.com/javase/6/docs/api/java/io/File.html">File</a> class, but it could be used on any class as shown in the next screen snapshot with <a href="http://java.sun.com/javase/6/docs/api/java/io/File.html">File</a> and <a href="http://java.sun.com/javase/6/docs/api/java/lang/String.html">String</a>.</p>
<p><a href="http://2.bp.blogspot.com/_sDOe5HxTdMk/SwD-FiqB04I/AAAAAAAABZk/0wtSlEStfY4/s1600/groovyShMethodsOnFileAndString.png"></a></p>
<p>There is much more that can be done with the Groovy Shell and more information is available in the online <a href="http://groovy.codehaus.org/User+Guide">Groovy User Guide</a> section <a href="http://groovy.codehaus.org/Groovy+Shell">Groovy Shell</a>.  Some problems previously encountered with Groovy Shell are covered in the <a href="http://groovy.codehaus.org/Groovy+Shell#GroovyShell-Troubleshooting">Troubleshooting section</a>.</p>
<p>For those who prefer a graphical tool similar to Groovy Shell, the <a href="http://java.sun.com/docs/books/tutorial/uiswing/">Swing</a>-based <a href="http://groovy.codehaus.org/Groovy+Console">Groovy Console</a> or <a href="http://code.google.com/appengine/">Google App Engine</a> powered browser-based <a href="http://groovyconsole.appspot.com/">Groovy Web Console</a> is likely to be of great interest.</p>
    ]]></content>
  </entry>
  <entry>
    <title>How Many People Should You Interview With?</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/3697" />
    <id>http://www.javaworld.com/community/node/3697</id>
    <published>2009-11-14T20:41:50-05:00</published>
    <updated>2009-11-14T20:58:12-05:00</updated>
    <author>
      <name>Esther Schindler</name>
    </author>
    <category term="career" />
    <category term="interview" />
    <category term="job" />
    <summary type="html"><![CDATA[<p>When a software developer &mdash; or anyone, really &mdash; is looking for a new job, it's expected that you'll talk with the person to whom you report. Your new boss knows what she's looking for in the new hire (including technical skills and "team fit"), and since you're going to report to her she certainly will want to choose someone that'll make her happy. But how many <em>other</em> people should you expect to talk with?</p>
    ]]></summary>
    <content type="html"><![CDATA[<p>When a software developer &mdash; or anyone, really &mdash; is looking for a new job, it's expected that you'll talk with the person to whom you report. Your new boss knows what she's looking for in the new hire (including technical skills and "team fit"), and since you're going to report to her she certainly will want to choose someone that'll make her happy. But how many <em>other</em> people should you expect to talk with?</p>
<script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script><p>From the job-hunter's viewpoint, this is simply a matter of avoiding exhaustion. Even the thought of talking to five people in a single day of interviews makes me shudder. Plus, it might seem as though your chances of getting the job decrease with every additional person with whom you interview, because everyone will have his own expectations. Who can possibly meet everyone's idea of "the person who'd be <em>perfect</em> for this job"?</p>
<p>I've seen and experienced just about every variation on this theme, from the Hire decision coming after a ten-minute phone interview with the manager to a grueling day in which everyone in the company had to ask a really tough question. Or, too often, a really stupid one.</p>
<p>Over the years, I've come to lean towards the "more interviews are better" side of the issue. From the job-hunter's point of view, every discussion you have with someone who works at the company gives you another opportunity to <a href="http://www.javaworld.com/community/node/3292">judge the corporate culture</a>, particularly if you speak with folks at different levels. Your prospective boss might tell you how important it is for developers to grow their skills, for instance, but if you ask three people you'd be working with <a href="http://www.javaworld.com/community/node/2836">when they last got developer training</a> you'll find out if the company puts its money where its mouth is. The more people you talk with, and <a href="http://www.javaworld.com/community/node/2745">the more questions you ask (rather than answer)</a> the better you can triangulate on the department's goals; is everybody heading in the same direction or do departments have differing priorities? </p>
<p><script type="text/javascript" charset="utf-8" src="http://static.polldaddy.com/p/2255786.js"></script><p><noscript><br />
<a href="http://answers.polldaddy.com/poll/2255786/">The last time I interviewed for a full-time position, I spoke with:</a><span style="font-size:9px;">(<a href="http://www.polldaddy.com">polls</a>)</span><br />
</noscript></p>
<p>But I'm a little more interested in the question from the company's point of view... or rather, the point of view of the team who's going to bring on the new developer. As I wrote about several months ago, in <a href="http://www.javaworld.com/community/node/2500">Interviewing Your Next Boss: Putting the Programming Lead on the Hot Seat</a>, dire and terrible things can happen when the people above the manager have a different idea of what's needed than the people who will report to him. (Read the comments, if you don't believe me.)</p>
<p>But the same rule applies to the people you'll work <em>with</em>. I don't know why "team fit" is so often considered by Management and by HR&nbsp;departments (the same HR departments who <a href="http://www.javaworld.com/community/node/3383">dump your r&eacute;sum&eacute;</a> because you lack a current tech buzzword or because they didn't accept <a href="http://www.itworld.com/open-source/80513/what-include-your-open-source-resume">your expertise gained in an open source project</a>) but they think that team members don't recognize the need for "fit," too. Who do they think will be spending all the time with the new developer?!</p>
<p>A long time ago, I worked for a very small company &mdash; it employed 12 people &mdash; at which every new hire spoke with everyone on staff, from Carolyn the bookkeeper to the guy who owned the firm. (You didn't formally interview with Sam, the owner's dog, but I can't imagine that anyone who Sam objected to would be offered a position.) Anyone could veto a new hire. Anyone. An explanation wasn't required, though the company culture was such that it'd be expected. The result was that we had an incredibly strong, diverse team of people who truly loved one another, learned from each other, and were immensely productive. (I'm still in touch with half my coworkers, and I live on the other side of the country, now.)</p>
<p>However, one reason I'm even more in favor of "have more interviews, not fewer" is on Agile grounds. If the developer is going to work with people in other departments (whether IT or line-of-business), those users have to be comfortable with her, too. A candidate may be able to speak brilliantly to other programmers, but have terrible listening skills when it comes to learning what the users need. In the real-world scenario that inspired this blog post (a hiring anecdote imparted by a friend), the developer got along fine with the tech staff. But when he interviewed with the project manager, she gave him a thumbs-down; according to the non-technical project manager, the guy didn't understand the business processes required.
</p>
<p>What's your experience been?&nbsp;I created a poll so we could judge what "normal" is (I'm sure you're as curious as I am). But I'm sure there's arguments for-and-against the "many interviews" options. Tell me what's worked for you.</p>
<p><em>You probably should <a href="http://www.twitter.com/estherschindler">follow me on Twitter</a>. Because, y'know, you just should.</em></p>
    ]]></content>
  </entry>
  <entry>
    <title>Spam</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/3696" />
    <id>http://www.javaworld.com/community/node/3696</id>
    <published>2009-11-14T13:10:18-05:00</published>
    <updated>2009-11-14T18:49:17-05:00</updated>
    <author>
      <name>Oleg Mikheev</name>
    </author>
    <category term="spam" />
    <summary type="html"><![CDATA[<!--paging_filter--><p>Ugg shoes, tiffani wathes, gucci glasses... JavaWorld became a good source of information about all those useful and luxury commodities lately. Spam messages flooded this site.</p>
<p>Last week I took some time and liberty to filter out hundreds of spam messages, block dozens of users, and change some policies.</p>
    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>Ugg shoes, tiffani wathes, gucci glasses... JavaWorld became a good source of information about all those useful and luxury commodities lately. Spam messages flooded this site.</p>
<p>Last week I took some time and liberty to filter out hundreds of spam messages, block dozens of users, and change some policies.</p>
<p>Until things stabilize (or until I get bored with this voluntary duty) messages like <a href="http://www.javaworld.com/community/node/774#comment-8394">this</a> will be deleted, messages like <a href="http://www.javaworld.com/community/node/774#comment-11621">this</a> will get spam links stripped.</p>
<p>Message signatures are disabled as most of times they contain spam links. Reply preview is mandatory.</p>
<p>If that's too strict or you have any other suggestions - don't hesitate to reply right here ;-)</p>
<p>The only open question (imo) is whether a message which content makes sense signed smth like <em>super.com dev</em> should be considered spam, should we filter out the link etc.</p>
    ]]></content>
  </entry>
  <entry>
    <title>SAP CTO tries to liberate Java with hilariously self-aggrandizing blog post</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/3689" />
    <id>http://www.javaworld.com/community/node/3689</id>
    <published>2009-11-12T16:04:56-05:00</published>
    <updated>2009-11-12T21:44:55-05:00</updated>
    <author>
      <name>Josh Fruhlinger</name>
    </author>
    <category term="EU" />
    <category term="merger" />
    <category term="Oracle" />
    <category term="SAP" />
    <summary type="html"><![CDATA[<!--paging_filter--><p>Oh, I'm sorry, have you been bored by the Sun-Oracle merger drama because it's been all about MySQL and Java has been reduced to a baffled bystander?  Well, get ready for some ancillary Java-related corporate drama that has the added benefit of being pretty hysterical!</p>    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>Oh, I'm sorry, have you been bored by the Sun-Oracle merger drama because it's been all about MySQL and Java has been reduced to a baffled bystander?  Well, get ready for some ancillary Java-related corporate drama that has the added benefit of being pretty hysterical!</p>

<p>It seems that the <em>Wall Street Journal</em> in a recent editorial noted that SAP had sent a letter to Oracle proposing some sort of meet-up between the companies' leaders; the <em>WSJ</em> speculated that this was in essence an offer on the part of SAP (which is based in Germany) to intervene with EU regulators on behalf of the troubled Sun-Oracle merger.  Well, that certainly came as surprise to SAP!  According to the company, the letter was actually a <a href="http://www.pcworld.com/businesscenter/article/181978/sap_outreach_to_oracle_about_java_not_help_with_sun_deal.html" target="_blank">request that Oracle keep Java open, or perhaps even open it further</a>; Oracle never actually replied to the missive, but did leak an out-of-context paragraph from it to the <em>Journal</em> to make it look like SAP was trying to help the merger along.</p>

<p>No doubt partly in response to all this, SAP CTO Vishal Sikka put up <a href="http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/16648" target="_blank">a blog post covering what I assume is the same ground covered in SAP's letter to Oracle</a>.  The opening paragraphs hit points that I think many people, particularly those not affiliated with Sun or Oracle, would agree with: Java ought to be more open, the JVM ought to be open source, and the Java Community Process ought to be under the control of an outside foundation, like Eclipse is.  For extra burn, he even finds a 2007 quote from Oracle's representative on the JCP to this effect.</p>

<p>But then his next quote is from Mikhail Gorbachev.  Because he finishes up the blog post memorializing the fall of the Berlin Wall 20 years ago, and claims that in making his triumphant call for Java liberty, he is the moral equivalent of Ronald Reagan demanding that Gorbachev tear down the Wall.  This is, to put it mildly, overstating things.  Still, it's nice to know that Java can elicit such <em>passion,</em> you know?</p>    ]]></content>
  </entry>
  <entry>
    <title>The EU objects</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/3686" />
    <id>http://www.javaworld.com/community/node/3686</id>
    <published>2009-11-10T20:29:36-05:00</published>
    <updated>2009-11-10T20:35:30-05:00</updated>
    <author>
      <name>Josh Fruhlinger</name>
    </author>
    <category term="EU" />
    <category term="java" />
    <category term="merger" />
    <category term="mysql" />
    <summary type="html"><![CDATA[<!--paging_filter--><p>As predicted by everybody, the EU has issued a <a href="http://www.nytimes.com/2009/11/11/technology/companies/11oracle.html" target="_blank">formal objection</a> to the Oracle-Sun merger.  In particular, the European Commission worries that Oracle will hold back on MySQL development, presumably to prevent the open source database from becoming a rival to Oracle's much pricier high-end offerings.    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>As predicted by everybody, the EU has issued a <a href="http://www.nytimes.com/2009/11/11/technology/companies/11oracle.html" target="_blank">formal objection</a> to the Oracle-Sun merger.  In particular, the European Commission worries that Oracle will hold back on MySQL development, presumably to prevent the open source database from becoming a rival to Oracle's much pricier high-end offerings.  While you may have a knee-jerk reaction to this to the effect that "Oh, MySQL is open source, if Oracle doesn't advance it someone else will," note that almost all MySQL development comes <a href="http://news.cnet.com/8301-13505_3-10394478-16.html" target="_blank">in-house</a>, not from outside developers.</p>

<p>Of relevance is that the same can and has been said for Java; thus, it's relevant that, according to the <em>New York Times</em> article I linked to above, the EU's antitrust attention was originally focused on how Oracle's acquisition would affect Java.  And to be sure one might speculate on ways Oracle could direct Java to aid its own projects and irritate its competitors; still, the potential clash in the database market is obviously easier to get one's mind around.</p>

<p>EU regulators apparently have a much keener interest in open source than their American counterparts, so it's not too crazy that they're sniffing around these specific areas.  (Also relevant, of course, is that MySQL is in origin a European project.)  The upshot of the EU's focus on MySQL is that, if the merger passes (and the smart money <a href="http://blogs.wsj.com/deals/2009/11/10/the-case-for-why-oracle-will-win-in-europe/" target="_blank">still thinks it will</a>), then Oracle's intentions for Java will <em>not</em> have gotten strong regulatory scrutiny, and won't necessarily be the subject of any promises from Oracle.</p>    ]]></content>
  </entry>
  <entry>
    <title>CouchDB on EC2 in 3 1/2 minutes</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/3685" />
    <id>http://www.javaworld.com/community/node/3685</id>
    <published>2009-11-10T18:35:29-05:00</published>
    <updated>2009-11-20T08:55:42-05:00</updated>
    <author>
      <name>Andrew Glover</name>
    </author>
    <category term="amazon" />
    <category term="amazon web services" />
    <category term="Andy" />
    <category term="couchdb" />
    <category term="development 2.0" />
    <category term="ec2" />
    <category term="open source" />
    <category term="rest" />
    <category term="saas" />
    <category term="software as a service" />
    <category term="Software Development" />
    <category term="Ubuntu" />
    <summary type="html"><![CDATA[<!--paging_filter--><p><a href="http://couchdb.apache.org/">CouchDB</a> is an open source <em>document oriented database</em> <a href="http://thediscoblog.com/2008/10/19/book-review-programming-erlang/">written in Erlang</a> that allows you to model domains in a flexible manner  as a self-contained document that contains no schema but, instead, a roughly similar blueprint to other documents.  </p>
    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p><a href="http://couchdb.apache.org/">CouchDB</a> is an open source <em>document oriented database</em> <a href="http://thediscoblog.com/2008/10/19/book-review-programming-erlang/">written in Erlang</a> that allows you to model domains in a flexible manner  as a self-contained document that contains no schema but, instead, a roughly similar blueprint to other documents.  </p>
<p>Provisioning a CouchDB instance in the cloud is easier than you think, baby! In fact, you can watch it done in 3 and a half minutes. In this video, an instance of CouchDB is provisioned (via <code>aptitude</code>) on an ubuntu 9.04 instance running on Amazon&#8217;s EC2. </p>
<p></p>
<p>As you can see, in many ways, this video and, of course, CouchDB embodies the <a href="http://thediscoblog.com/2009/05/10/development-20/">core aspects of Development 2.0</a>: </p>
<ul>
<li>capitalizing on open source technologies
<ul>
<li> that is, fully leveraging open source technologies across the board from application servers, databases, and core frameworks of a solution</li>
</ul>
</li>
<li>borrowing infrastructures
<ul>
<li>that is, renting (or borrowing) all levels of applications required for managing and running software applications</li>
</ul>
</li>
</ul>
<p>Looking to spin up Continuous Integration <em>quickly</em>? Check out <a href="http://www.ciinabox.com">www.ciinabox.com</a>.</p>
    ]]></content>
  </entry>
  <entry>
    <title>Ajax-like J2EE security login</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/3675" />
    <id>http://www.javaworld.com/community/node/3675</id>
    <published>2009-11-08T06:57:50-05:00</published>
    <updated>2009-11-15T08:57:12-05:00</updated>
    <author>
      <name>Oleg Mikheev</name>
    </author>
    <category term="ajax" />
    <category term="form-based" />
    <category term="J2EE" />
    <category term="J2EE security" />
    <category term="login" />
    <summary type="html"><![CDATA[<!--paging_filter--><p>J2EE Web security is based on the separation of content into two web contexts - protected and public. But there are lots of cases (in my experience majority of cases) when you provide the same content (e.g. a web page) but with different information displayed for different types of users. For non-authenticated (non logged-in) users you hide some sensitive info from your content, and for authenticated (logged-in) users you may choose to hide of display some data depending on their authorization (the user role).</p>
    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>J2EE Web security is based on the separation of content into two web contexts - protected and public. But there are lots of cases (in my experience majority of cases) when you provide the same content (e.g. a web page) but with different information displayed for different types of users. For non-authenticated (non logged-in) users you hide some sensitive info from your content, and for authenticated (logged-in) users you may choose to hide of display some data depending on their authorization (the user role).</p>
<p>The form-based J2EE security automatically protects the 'secure' part of the web application. Which in reality means that J2EE container automatically asks for user credentials when the user tries to access the protected context. Context here means a folder on the server (something like 'secure'), which is accessible by a URL path (something like 'http://server.com/secure').</p>
<p>But what if you just have a page or two (or a dozen) that render themselves differently depending on the user type? In this case you don't have anything that could be considered a secure context, as you can't physically separate you content into two, unless you want to copy all your pages to a 'secure' folder.</p>
<p>The bitter truth is that the only way J2EE container authenticates (logs-in) a user is by intercepting user's access to the protected context. You just can't manually ask J2EE container to log your users in, and to present a form to enter their credentials. This situation is a long-lived problem for all J2EE devlopers.</p>
<p>Under the hood the J2EE form-based security has three entities: the log-in page (where the user enters his login/password) which pops-up when user tries to access the protected content, the error page (the one that shows up if login/password entered was incorrect), and the /j_security_check URL which is built-into any J2EE container. The latter is capable of receiving login/password info from the login page, validating them, and upon successfull validation redirecting to the page that was originally requested, or, in case of validation failure, redirect the user to the error page (to give him another try).</p>
<p>The tricky part is that /j_security_check URL cannont be used manually. You can't just send user/password to it, J2EE container requires that this URL be called automatically. Wouldn't it be wonderful if it was possible to make an AJAX call and pass login/password to /j_security_check?</p>
<p>The solution that I've come to for situations with no physical separation between protected and public content is based on an &lt;iframe&gt;.
</p>
<p>
So, lets suppose that we have configured a form-based secured web-application, in web.xml it looks something like:<br />
<div class="codeblock"><code>&lt;security-constraint&gt;<br />	&lt;web-resource-collection&gt;<br />		&lt;web-resource-name&gt;secured&lt;/web-resource-name&gt;<br />		&lt;url-pattern&gt;/secure/*&lt;/url-pattern&gt;<br />		&lt;http-method&gt;POST&lt;/http-method&gt;<br />		&lt;http-method&gt;GET&lt;/http-method&gt;<br />	&lt;/web-resource-collection&gt;<br />	&lt;auth-constraint&gt;<br />		&lt;role-name&gt;admin&lt;/role-name&gt;<br />	&lt;/auth-constraint&gt;<br />&lt;/security-constraint&gt;<br />&lt;security-role&gt;<br />	&lt;role-name&gt;admin&lt;/role-name&gt;<br />&lt;/security-role&gt;</code></div></p>
<p>We will need two pages - login.jsp and parentReload.jsp. The first one goes to J2EE login-config config in web.xml, so that it would show up if a request is made to a secure context:<br />
<div class="codeblock"><code>&lt;login-config&gt;<br />	&lt;auth-method&gt;FORM&lt;/auth-method&gt;<br />	&lt;form-login-config&gt;<br />		&lt;form-login-page&gt;/login.jsp&lt;/form-login-page&gt;<br />		&lt;form-error-page&gt;/login.jsp?invalid=true&lt;/form-error-page&gt;<br />	&lt;/form-login-config&gt;<br />&lt;/login-config&gt;</code></div></p>
<p>The login.jsp itself should look something like this:<br />
<div class="codeblock"><code>&lt;%@ page contentType=&quot;text/html;charset=UTF-8&quot; language=&quot;java&quot; %&gt;<br />&lt;html&gt;<br />&lt;body&gt;<br />&lt;%<br />	if (request.getParameter(&quot;invalid&quot;)!=null) {<br />%&gt;<br />Incorrect login/password, try again:<br />&lt;%<br />	}<br />%&gt;<br />&lt;form action=&quot;j_security_check&quot; method=&quot;post&quot;&gt;<br />	user name: &lt;input type=&quot;text&quot; name=&quot;j_username&quot;/&gt;&lt;br/&gt;<br />	password: &lt;input type=&quot;password&quot; name=&quot;j_password&quot;/&gt;&lt;br&gt;<br />	&lt;input type=&quot;submit&quot;&gt;<br />&lt;/form&gt;<br />&lt;/body&gt;<br />&lt;/html&gt;</code></div></p>
<p>The parentReload.jsp goes to the /secure folder, probably becoming its the only inhibitant. The JSP content is pretty simple, can you guess what it does?<br />
<div class="codeblock"><code>&lt;%@ page contentType=&quot;text/html;charset=UTF-8&quot; language=&quot;java&quot; %&gt;<br />&lt;html&gt;<br />&lt;head&gt;<br />	&lt;script type=&quot;text/javascript&quot;&gt;<br />		parent.location.reload();<br />	&lt;/script&gt;<br />&lt;/head&gt;</code></div><br />
Yes, it reloads the parent window!</p>
<p>Now, on each page that is supposed to be rendered differently for different types of users you can put this nice code on the top of page:<br />
<div class="codeblock"><code>&lt;%<br />final java.security.Principal userPrincipal = request.getUserPrincipal();<br />if(userPrincipal==null) {<br />%&gt;<br />&lt;iframe src=&quot;secure/parentReload.jsp&quot; frameborder=&quot;0&quot;&gt;&lt;/iframe&gt;<br />&lt;%<br />}<br />%&gt;</code></div></p>
<p>This is how it works, if you haven't guessed it by now: if the current user is not authenticated yet an iframe is rendered on the page. This iframe's src 'secure/parentReload.jsp' is located in the protected area, so, instead of displaying the original parentReload.jsp J2EE container intercepts this request and renders the login.jsp page inside the frame, which results in a little user/password widget on the top of each page, which is pretty neat. Once the user decides to login the iframe form is submitted without reloading the main page. If user credentials were valid J2EE container renders the parentReload.jsp in the iframe. Once rendered inside the iframe it will cause the parent window (the main page) to reload. Upon reload it will no longer try to render the iframe anymore, and you are free to render the protected content.</p>
<p>This has been tested and workd great on Tomcat, and supposed to work with any J2EE container. Enjoy.</p>
    ]]></content>
  </entry>
  <entry>
    <title>Don&#039;t trust Cookie setMaxAge</title>
    <link rel="alternate" type="text/html" href="http://www.javaworld.com/community/node/3673" />
    <id>http://www.javaworld.com/community/node/3673</id>
    <published>2009-11-07T11:10:06-05:00</published>
    <updated>2009-11-07T18:55:35-05:00</updated>
    <author>
      <name>Oleg Mikheev</name>
    </author>
    <category term="cookie" />
    <category term="cookie expiration" />
    <summary type="html"><![CDATA[<!--paging_filter--><p>I've just run into the issue with misleading, or at least incomplete documentation related to HTTP Cookie representation in J2EE. Cookie class JavaDoc states that <a href="http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/Cookie.html#setMaxAge(int)" title="Cookie.setMaxAge(int)">Cookie.setMaxAge(int)</a> method "<em>Sets the maximum age of the cookie in seconds.</em>"<br />
That's not true, unfortunately. Cookies, as we know, don't hold info about their max age. They hold the date/time value of their expected expiration.</p>
    ]]></summary>
    <content type="html"><![CDATA[<!--paging_filter--><p>I've just run into the issue with misleading, or at least incomplete documentation related to HTTP Cookie representation in J2EE. Cookie class JavaDoc states that <a href="http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/Cookie.html#setMaxAge(int)" title="Cookie.setMaxAge(int)">Cookie.setMaxAge(int)</a> method "<em>Sets the maximum age of the cookie in seconds.</em>"<br />
That's not true, unfortunately. Cookies, as we know, don't hold info about their max age. They hold the date/time value of their expected expiration.</p>
<p>So, instead of setting the max age for a cookie, this setMaxAge method adds the int parameter seconds to the current <strong>SERVER</strong> date/time and puts this new date/time value to a cookie as its expiration time. Later, when this cookie is sent to the browser, this expiration date is compared to the <strong>CLIENT</strong> date/time, and cookie gets expired if its expiration date is in past.</p>
<p>All this means that setMaxAge method description is valid in just one case: all clients are run on the same machine with the server, or at least have their system time synchronized with the server. Rather idealistic, isn't it. There are lots of computers with system time that is in the past.</p>
<p>If you'd really like to rely on a cookie expiring after a defied period then a different approach should be taken, the brand new System and Method for Defining a Cookie Max Age :-)</p>
<p>So, if you'd like your cookie to expire in definite time you will need another cookies to hold the cookie 'meta-information'. To make sure that cookie 'cookie1' having value 'someValue' will expire in, say, 20 seconds, in your servlet or servlet filter you could do:<br />
<div class="codeblock"><code>	response.addCookie(new Cookie(&quot;cookie1Name&quot;,&quot;cookie1&quot;));<br />	response.addCookie(new Cookie(&quot;cookie1Value&quot;,&quot;someValue&quot;));<br />	response.addCookie(new Cookie(&quot;cookie1Timeout&quot;,&quot;20&quot;));</code></div></p>
<p>Then, add the next JavaScript on the page that the servlet produces:</p>
<p><div class="codeblock"><code>&lt;script type=&quot;text/javascript&quot;&gt;<br />	// Original JavaScript code by Chirp Internet: <a href="http://www.chirp.com.au<br />" title="www.chirp.com.au<br />">www.chirp.com.au<br /></a>	// Please acknowledge use of this code by including this header.<br />	function getCookie(name) {<br />		var re = new RegExp(name + &quot;=([^;]+)&quot;);<br />		var value = re.exec(document.cookie);<br />		return (value != null) ? unescape(value[1]) : null;<br />	}<br /><br />	function setCookie(name, value, expiry) {<br />		document.cookie = name + &quot;=&quot; + escape(value) + &quot;; expires=&quot; + expiry.toGMTString() + &quot;; path=/&quot;;<br />	}<br />	<br />	var cookie1Name = getCookie(&#039;cookie1Name&#039;);<br />	var cookie1Value = getCookie(&#039;cookie1Value&#039;);<br />	var cookie1Timeout = Math.abs(getCookie(&#039;cookie1Timeout&#039;)) * 1000; // converting to milliseconds<br />	setCookie(cookie1Name, cookie1Value, new Date((new Date()).getTime()+cookie1Timeout));<br />&lt;/script&gt;</code></div></p>
<p>This will result in a cookie1 to expire in 20 seconds. </p>
<p>Awkward, but it works.</p>
<p>Unfortunately this approach will not work for Cookies that are set during AJAX calls, as there will be no possibility to run a custom JavaScript in this case.</p>
    ]]></content>
  </entry>
</feed>
