Skip to main content

Feeling Groovy

Posted by daniel on August 16, 2004 at 10:02 AM PDT

Gotta parse the XML fast

I'm not sure why Groovy seems to be taking hold so fast. For instance, Ruby seems to provide much of the benefits of Groovy and it has not caught on as much as we might have expected. Martin Fowler write about transforming XML with Ruby in Moving Away From XSLT. Groovy does have the advantage of being easily integrated into a Java application.

Jack Herrington shows a nice example of this in Getting Groovy with XML. He provides an example that takes information from an XML data file and totals transactions in several accounts. In the first take, he uses DOM and his Java program is the typical long-winded code we are used to when dealing with DOM. By the next to last iteration, the Groovy code looks like this:

calculateAmounts = { doc |
    accountValues = [:];
    accountNodes = doc.xpath( "/transactions/account" );
    for( accountNode in accountNodes )
        amount = 0;
        amountNodes = accountNode.xpath( "transaction/@amount" );
        for( amountNode in amountNodes )
            amount +=
                Integer.valueOf( amountNode.getValue() ).intValue();
        accountValues.put(, amount );
    return accountValues;

He takes one more pass at the code to make it more object oriented, but it is nice to see how much boiler plate code can be replaced by Groovy. Hmmm, maybe that's why it's taking hold so fast.

In today's Weblogs, Navaneeth Krishnan offers A brief History of Portals. He looks at the evolution of his understanding of portals from his Diablo playing days to now when "The portal I am familiar with today is a content/service aggregation and delivery system which front-ends a variety of other systems."

Malcolm Davis has taken another look at netbeans 3.6

. He is not very impressed with the performance or the feature set. His post has generated a lively discussion.

Also in Java Today
, playing MP3's in Java is a reality, thanks in part to the JavaZOOM Team, which has been supporting MP3 in Java libraries and players for a while now. In Extend JavaSound to play MP3, Ogg Vorbis, and More, they show how the JavaSound API, part of core Java since J2SE 1.3, "provides a flexible plugin architecture allowing any third-party vendor to add custom audio format support through the JavaSound Service Provider Interfaces (SPIs)."

Dana Nourie has written a article on what Java newbies can get from You probably know most of what is covered in the article, but it is nice to see us getting coverage in A Community for Everyone.

Checked vs. Runtime exceptions is a big topic in
today's Forums. Yishai has written a well received and lengthy post that begins, "An overly simplistic way of thinking about checked exceptions is that if given the exact same input parameters, the method could sometimes throw an exception, and sometimes not, then that exception should be a checked exception. It tells the user of the API that this is an error condition that they cannot account for ahead of time, prior to calling the method."

The rules about String concatenation may no longer apply once we use Tiger. Kunitz writes "This rule must be modified for Java 5.0. Java 5.0 introduces a StringBuilder class. This class will be somewhat faster than StringBuffer because it doesn't synchronize. So everywhere where you would have been used StringBuffer locally in a single thread, you should use StringBuilder with Java 5.0."

Rabreuc writes "I believe in using local variables just when you need them. Its nonsense declaring a variable at the top lines and using them 3000 lines after. Also a resources cost, even if its not that "much"."

In Projects and Communities, the JSR invites you to a live chat with the JCP's Onno Kluyt, JCP Chair and Aaron Williams, spec lead for JSR 215 which defines JCP 2.6. Join in August 17, 2004 at 11:00 A.M. PDT/6:00 PM GMT.

Linux on a Mac? Follow this Linux community link to an early look at 64-bit Linux on a PowerPC 970 platform in the developerWorks article Yellow Dog Linux on Power Mac G5.

In today's News Headlines

Registered users can submit news items for the href=""> News Page using
our news submission
. All submissions go through an editorial review before being posted to the site. You can also subscribe to
News RSS feed

Current and upcoming
Java Events

Registered users can submit event listings for the href=""> Events Page using our href=""> events submission
form. All submissions go through an editorial review before being
posted to the site.

Archives and Subscriptions: This blog is delivered weekdays as the
Today RSS feed
. Also, once this page
is no longer featured as the front page of
it will be archived along with other past issues in the href=""> Archive.