What I Learned Today

Inspired by this post.

A nice Groovy snippet:

def x = [a: 1, b: 2]
def y = [x: 'hi', y: 'there']
def z = [groovy: 'is', good: 'stuff']

def e = new Expando(*:x, *:y, *:z)

println e

Running within GroovyConsole produces:

groovy> def x = [a: 1, b: 2]
groovy> def y = [x: 'hi', y: 'there']
groovy> def z = [groovy: 'is', good: 'stuff']
groovy> def e = new Expando(*:x, *:y, *:z)
groovy> println e

{a=1, b=2, x=hi, y=there, groovy=is, good=stuff}

There are more good examples hidden away in the documentation on Groovy Maps.

And while I'm at it…I'll preserve this bit of List-y goodness (a Bob 'original') for posterity (otherwise it will get lost in the depths of my email, never to be seen again):

[-90.0F, 0.0F, (25.0F..45.0F).findAll { it % 5.0F == 0.0F }, 90.0F].flatten().each { deg ->
  println deg



I found an even simpler way:

[-90.0F, 0.0F, (25.0F..45.0F).step(5), 90.0F].flatten().each { deg ->
  println deg

It's a shame that step() only takes an integer parameter, but that is OK for this case.

Tags: Groovy, Programming

Examples and Tests for SVG Animation

A Useful Site For SVG-Heads.

Microsoft should be ashamed of Internet Explorer in regards to SVG. Truly.

Tags: Tools

Another Book Read

This time it's Ruby Phrasebook by James Clinton.

The price was right: AUD$19.95. I'll keep this beside me when I'm Ruby-ing, it's a useful memory-jogger to have.

I confess: I'm still trying to discover Ruby's "inner beauty." As a colleague says: in comparison with PHP or PERL, Ruby is a step forward. Apologies to any Ruby fanboy reading this, but It's got a lot of walking to do still, as far as I can see. This is Java, circa 1999…green threads, pissy networking, incomplete (and sometimes just plain wrong) class library, weird little GUI packages: the lot. Been there, done that!

Tags: Books

Room For Improvement?…Always!

Following on from my earlier posting: The Perils Of Being A Smarty-Pants!…

While doing the washing up, I spotted a couple of ways of making the code more idiomatically 'Groovy.' These just popped into my head. Unbidden, I swear!

Fancy a curry?

def fmt = String.&format.curry("%.3f")

public String toString() {
Weight(Pounds): ${fmt(getWeightPounds())}
Weight(Tons): ${fmt(getWeightTons())}"""

Notice the way that I am now no longer having to respecify the printf format…Good Stuff!

Also see how the & operator converts a method to a closure so that it can be passed around…More Good Stuff!

Not sure that it buys much in THIS case, but one could also do:

public String toString() {
  def s = new StringBuilder()
  s << "$m" << 'n'
  [ 'Pounds', 'Tons' ].each { prop ->
    s << /  Weight($prop): ${fmt("getWeight$prop"())}/ << 'n'

Sorry, no free set of stainless-steel steak knives, but there's also (I find this faintly ridiculous…or at least past the point of diminishing returns in terms of bang for buck for this situation):

public String toString() {
  def prefix = 'getWeight'
  def s = new StringBuilder()
  s << "$m" << 'n'
  this.class.declaredMethods.findAll {method ->
    method.name =~ prefix
  }.each {
    s << /  Weight(${it.name - prefix}): ${fmt("$it.name"())}/ << 'n' 

To quote the great philosopher, Homer (Simpson, that is): "Shut up brain, or I'll stab you with a Q-tip."

Worth preserving for posterity (read: I need to store this in external memory…my internal RAM has too many bad blocks these days).

Tags: Groovy, Programming

Another Book Read: Version Control With Git

Version Control With Git.

Mostly skimmed, rather than read, to be truthful…it's that sort of book: good to keep around for when you'll need it but not really a "fun read" (unless your soul has a special place for Version Control Systems).

I was inspired to know more after posting Productivity With Grails And Git, and so I had to find out more.

Git looks worthy, and the book is a worthy exposition of Git's capabilities.

Tags: Books, Grails, Programming

I Want One!


…it is the greatest gasoline-powered vehicle that has ever been, or will ever be, built. Seriously.

…Take a moment and consider what Bugatti has done: Because a handful of billionaires demanded that the fastest car in the world be available topless, the Volkswagen-owned ultra-luxury automaker essentially broke the laws of physics. Again.

The first Veyron is an engineering marvel. That's the one with the massively reinforced roof that helped keep the rest of the body from deforming into an amoebic tangle of graphite composite and exotic metal under the joint stresses of lateral acceleration, horsepower and wind. It stands as one of the greatest achievements of the petroleum age. It required the intellectual might of one of the largest and arguably smartest car companies in the world to birth a car that was not only faster than anything on the road, but easy enough to pilot that anyone could drive it. ("It killed my husband" is not the kind of country-club buzz that sells cars.)

…the Veyron's stats are legendary: 1,001 horsepower from a mid-mounted, 8.0-liter, 16-cylinder engine that gets air stuffed down its ravenous gullet by four massive turbochargers. All-wheel drive. A seven-speed, dual-clutch transmission that switches gears faster than a state staffer ducking questions about the Appalachian Trail. Depending on how you define "production car," it is the fastest in the world. In the quickest Lamborghini ever produced, the Murcielago LP640, you can hit 60 mph in 3.2 seconds. In the Grand Sport it takes a hair under 2.5. How does it feel to command that pace? Godlike.

…Bugatti offers seven different seat shapes, to accommodate the seven known varieties of billionaire: lust, gluttony, greed, sloth, wrath, envy and pride. Each is based around a carbon-fiber shell and available in whatever animal skin the laws of your kingdom permit.

…Other luxury touches include a stereo, we're told. The CD player is custom-designed by Burmeister to operate skip-free at 250 miles per hour. We never turned it on. With the carbon fiber and polycarbonate roof removed, you have the only soundtrack you need: the engine's growl (could be louder) and the roar of the twin air intakes, which suck air like a ??????? two rolls of quarters ?????????? quart of Sterno ??????? Las Vegas.

There's also a navigation system. It might be the finest example of passive aggression ever assembled; Bugatti's engineers clearly don't want you to use it. You can only program the system with a separate, 2005-vintage PDA. If you can stomach the Windows Mobile interface long enough to set your destination, you get to view your route guidance in a tiny screen in the rearview mirror.

…the last king of the gas-guzzlers, forever the greatest. All hail.

Somebody please give me a million or three so that I can afford it. Pretty please?


Al Gore would never forgive me!

As (himself newly [but much more modestly] reshod) Dr Paul King pointed out to me…here's the Video…phew!

The Perils Of Being A Smarty-Pants!

My friend and colleage Alex Garrett, just posted Groovy coding a pile of dirt.

Now, I thought his example could be improved, and came up with an example making use of Java's enums, which seemed a nice fit:

enum Material {
  CEMENT(131.0F, 20.0F),
  DRYSAND(90.0F, 35.0F),
  WETSAND(118.0F, 25.0F),
  CLEANGRAVEL(118.0F, 37.5F),
  SANDYGRAVEL(118.0F, 27.5F)

  Material(D, thetaDegrees) {
    this.D = D
    this.theta = Math.toRadians(thetaDegrees)

  final D
  final theta

class ConicalPile {
  private m
  private h

  def getWeightPounds() {
    (Math.PI * h ** 3 * m.D) / (3 * (Math.cos(m.theta) ** 2))

  def getWeightTons() {
    getWeightPounds() / 2000.0F

  public String toString() {
  Weight(pounds): ${String.format("%.3f", getWeightPounds())}
  Weight(tons): ${String.format("%.3f", getWeightTons())}"""

for (Material m : Material.values())
  println new ConicalPile(m: m, h: 10.0F)

Easy! Took 5 minutes. A nice easy diversion.

Not so fast there, cowboy…

That was the finished product…took me a bit of effort to get to it.

To see why, here's a simplified test application:

enum T {
  ALPHA(1, 2),
  BETA(3, 4),
  GAMMA(5, 6)

  def x
  def y

  public String toString() {
    "{x: $x, y: $y}"

println T.ALPHA

Didn't work! Imagine my surprise! Gives:

Caught: java.lang.ExceptionInInitializerError
        at Test.class$(Test.groovy)
        at Test.$get$$class$T(Test.groovy)
        at Test.run(Test.groovy:20)

So (on the assumption that enums are just specialised classes: The new enum declaration defines a full-fledged class (dubbed an enum type)) I tried a Groovy-style constructor with named parameters:

enum T {
  ALPHA(x: 1, y: 2),
  BETA(x: 3, y: 4),
  GAMMA(x: 5, y: 6)

  def x
  def y

  public String toString() {
    "{x: $x, y: $y}"

println T.ALPHA

Didn't work. One gets an almighty compiler error:

Information:Compilation completed with 1 error and 0 warnings
Information:1 error
Information:0 warnings
Error:BUG! exception in phase 'class generation' in source unit 'C:UsersBobDesktopAlexMaterialsrcTest.groovy' MapEntryExpression should not be visited here at

So much for guessing, which is essentially what I was doing.

So, back to a simpler, kinder Java-style, with a hand-crafted constructor (which I first tried as a pure Java class, and then 'mutated' back to Groovy):

enum T {
  ALPHA(1, 2),
  BETA(3, 4),
  GAMMA(5, 6)

  T(x, y) {
    this.x = x
    this.y = y

  def x
  def y

  public String toString() {
    "{x: $x, y: $y}"

println T.ALPHA

It flies! Viz:

{x: 1, y: 2}

Hence the example I lead with…

I'm assuming that I was being bitten by http://jira.codehaus … g/browse/GROOVY-3276, which is currently marked as Closed/Fixed. Hmmm.

##Hi ho. Hi ho. It's off to Jira I go…##

As has been pointed out to me:

Your surprise #1 does not make much sense to me because even with regular classes, that convenience is not there.

class T {
        def x
        def y

        public String toString() {
        "{x: $x, y: $y}"

new T(1, 2) // fails saying no matching constructor found

I got my knickers knotted on this issue, it is true! Still:

I would have also assumed that named parameters based constructor call would go through for enums as it does for regular classes. But that is about your 2nd surprise reported. To me also, that enhancement would make sense.

Tags: Groovy, Programming

Java Technology and Development Courseware: Now DonationWare


I am opening up old courseware to the world on a "pay if you like it" or have it free basis.

My fifth offering is Java Technology and Development.

(You will find other offerings in this site tagged with DonationWare.)

This course was started in ~1996 as Java was becoming popular. I stopped hacking it sometime around 2002, so it had a pretty good run. This version is from sometime in 2001 (it was pretty much the first "reasonably up-to-date" copy I found in my archive…actually a big pile of CDs).

This course had a lot of mileage: it went around Australia and the US many times, it went around various bits of Asia a couple of times and it went to NZ a few times.

It was used by a team of presenters, each of whom presented it very differently (interestingly enough), and contributed bits and pieces and bugfixes to it (thanks, guys!). Nonetheless, it retained my somewhat cynical/quirky view of the Java Universe.

It was presented under a few different banners. Never under the transentia banner in Australia.

It was even 'informally' licensed (meaning I pretty much got ripped-off!) to a US company for their purposes (whatever they were…I never really found out).

I have also presented Java courseware for a number of other organisations and I still believe that this is the best.

I remember presenting it for the very first time, to a local ISP in Darwin. After discussing Applets, I was talking about how Applets could be used to build a Tsunami-style D.O.S. attack and bring down a whole network. Suddenly one participant jumped up and walked out and I didn't see him for quite a whle. Turns out that he was the owner of the company. He later explained that he had just spent a day madly reconfiguring his servers and network to be more resistant to the type of attack I had been talking about. I really scared the poor guy!

When the course first burst onto the world, the course participants were all keen and clever "early adopters": for exercises, it was enough to say "Here is a Java compiler, go build me an 'X'." and everyone had fun, and learned lots along the way. By the time I knocked it on its head-no more early adopters were coming through and in some cases we had to deal with people who simply didn't want to know but were being told to follow the company line-the exercises were having to be specified a lot more completely (it seemed like we had to detail practically every keypress and mouse movement). It wasn't so much fun at the end, sad to say!

I also recall telling my colleagues about one participant that really did not know how to use her mouse (this makes life really hard for an instructor; to this day, the phrase "No. Use the other mouse button." has significance to us) and they were scoffing at me, thinking I was exaggerating. Until the time when one poor guy came back from presenting the course for the first time and said: "I was really shocked. I always thought you were laying it on thick, but some of these participants didn't even know how to type, let along program." I paraphrase, but you get the idea.

Fun days…

Enough reminiscing! Here's the 'blurb':

Java Technology and Development

A five-day hands-on overview of the Java language and environment


Programmers, Technical IT Managers, World-Wide Web Administrators and Developers, other IT Personnel and Consultants.


The Java programming language attracts enormous interest throughout the on-line community. IT professionals are also recognizing the importance of such technologies. This course will provide an understanding of what Java is, its history, how it works and is used, its application areas, industry support, competing technologies, and so forth.

The course includes a number of practical exercises spread over the five-day period.


The aim of this course is to provide a proper description and overview of Java as a programming language and distributed system technology. At the end of the course the student will have a sufficient understanding of Java to enable him or her to undertake software development using Java in various situations, including the development of executable content for the World-Wide Web and the construction of stand-alone applications.

Note: Java is strongly derived from C so knowledge of C or C++ is needed for this course.

Day One: The Java Language

An Overview of Java

An examination of why Java is the sensation it is; where it came from and what it can do:

  • history
  • comparing Java to other languages
  • buzzwords: simple, object-oriented, distributed, robust, secure, architecture neutral, portable, interpreted, high-performance, multithreaded, and dynamic.

The Basic Java Language

An overview of the more straightforward of Java's features together with a brief comparison of Java with its ancestors: C/C++:

  • tokens
  • reserved words
  • types and data values
  • operators
  • garbage collection

Java Tools

A look at Sun's Java Development Toolkit (JDK):

  • why choose the JDK?
  • JDK for Windows95/NT4:
    • appletviewer
    • javac
    • javah
    • java
    • javadoc
    • javap
    • jdb
    • rmic
    • jar
    • javakey

A quick look at some other tools:

  • IBM VisualAge for Java
  • Microsoft Visual J++

Programming Java Applications

Writing standalone applications in Java:

  • program structure and environment
  • application versus applet
  • a whole new phylum: aglets, servlets, beans

More Basic Java

More data types:

  • arrays
  • strings

The flow of control:

  • if, switch, for, while, do
  • labeled statements

Some of the changes Java 1.1 has brought to the language:

  • desktop colors
  • internationalization
  • deprecated features
  • 'blank' finals
  • anonymous arrays
  • type wrappers

Day Two: More Java Language/Java Applets

Object-Oriented Programming with Java

An examination of the features that make Java an Object-Oriented language:

  • classes and objects
  • constructors and object finalization
  • methods, overriding and parameter passing
  • initializers
  • inheritance and the IS-A/HAS-A relationships
  • accessing run-time type information
  • encapsulation: packages visibility modifiers and techniques
  • abstract classes
  • interfaces

The New Java 1.1 Object-Oriented Features

Java 1.1 introduced a number of features that substantially increased the power and flexibility of the language:

  • reflection
  • inner classes:
    • nested top-level classes
    • member classes
    • local classes
    • anonymous classes
  • instance initializers

More Java Language

An examination of the ways in which Java promotes creating robust software:

  • exceptions
  • using and understanding threads:
    • the Runnable interface
    • synchronization: mutual exclusion and critical sections
    • conditions

Java Applets

Java and executable content on the World-Wide Web:

  • applet capabilities
  • the <APPLET> tag
  • responsive applets
  • dual-purpose applets and applications

Day Three: User Interfaces & Java's Abstract Windowing Toolkit

An AWT Overview

A look at the basic concepts underlying Java's "window on the world":

  • the Abstract Windowing Toolkit (AWT):
    • aim
    • fundamental organization

Using Java for simple graphics programming:

  • primitive graphics tools
  • sounds in applets

Multimedia and Interactivity

Multimedia is one of the driving forces behind Java:

  • color handling
  • fonts
  • images
  • animation and double buffering

More AWT

The building blocks of a Java User Interface:

  • components:
    • button
    • checkbox
    • scrollbar
    • menu
    • label, text area and text field
    • canvas
  • containers:
    • panel
    • frame
    • window
    • dialog
  • event handling
  • layout managers

AWT Enhancements

The enhancements and changes that Java version 1.1 introduced:

  • a new event model
  • delegation
  • listeners and adapters
  • lightweight components
  • printing
  • data transfer; copy and paste; drag and drop

Java Foundation Classes

  • Java 2D
  • model-view-controller paradigm
  • 'swing' components
  • drag & drop

The Stream Zoo

A look at some of the many classes for handling input/output:

  • standard streams
  • "mix & match" capabilities
  • files
  • random access streams
  • tokenizers
  • serialization and externalization
  • writer classes

The Java Utility Classes

An overview of the classes supplied to remove the need for developers to have to "reinvent the wheel":

  • type wrappers
  • vector
  • enumeration
  • hashtable
  • property
  • random, stack, date, bitset
  • Java Collection Classes

Day Four: Advanced Java Programming

Java Beans

An introduction to the Java-based component software infrastructure:

  • why Java beans?
  • properties:
    • simple
    • indexed
    • bound
    • constrained
  • events
  • methods
  • the BeanInfo class


An examination of why and how Java claims to be a secure programming environment for the World-Wide Web:

  • the sandbox
  • the bytecode verifier
  • the class loader
  • the security manager
  • hostile attacks
  • code signing
  • access control lists

Java Database Connectivity

A look at interfacing Java with SQL-based relational databases:

  • the DriverManager class
  • drivers
  • connections
  • statements
  • SQL Utility classes
  • ResultSet handling
  • metadata

Native Code

A look at the facilities that exist to allow Java to interact with other programming environments:

  • Java Native Interface
  • Java invocation API

Day Five: Distributed Systems Using Java

Java features aimed at making the development of distributed systems easier:

  • URL
  • URLConnection
  • sockets:
    • clients
    • servers
  • Remote Method Invocation
    • naming
    • clients
    • servers
    • stubs & skeletons
    • security
  • Servlets
  • Enterprise Java Beans
  • Java and CORBA

The Future

An overview of some of the exciting developments currently happening in the Java world, such as JDBC, the "100% Java" initiative and the Network Computer.

The course is now well and truly at End of Life.

I figure that it would be such a pity for it to end as a set of bits decaying away on my hard disk so I am opening it up to the world on as "as-is" basis:


(MD5: 197bf97bf6020c2ca2ba440f87b59790; size: 6,615,799 bytes)

Some (unfortunately necessary) legalese:

  • This content is provided "as-is", with no guarantees.
  • Feel free to use it, but not to abuse it (to give a couple of examples: don't make hundreds of copies for friends; don't claim it as your own work).
  • I retain copyright, so "all rights reserved."


If you like it, or have any questions/comments, send me an email ( ).

If you find this material useful, please consider paying me a small amount: via PayPal.

Tags: DonationWare, Java

SOAP/WebServices Courseware: Now DonationWare


I am opening up old courseware to the world on a "pay if you like it" or have it free basis.

My fourth offering is SOAP/WebServices Overview.
(You will find other offerings in this site's DonationWare Category.)

This course was created in mid-2003.

It was a quick, one-day overview/review of the current "state of the art."

How things change!

I remember going down to Sydney to give this course on behalf of "A Famous Database Company" for a group of South Korean V.I.P.s…who (it turned out) did not speak ANY English. The poor translator almost had a nervous breakdown. It was a very strange session, almost surreal!

Here's the 'blurb':

The new internet-focussed software architectures now on the drawing boards of the World-Wide Web Consortium (W3C) and the major vendors are being planned around a triumvirate of standards-oriented XML-based technologies: SOAP, the Simple Object Access Protocol; WebServices; and UDDI, the Universal Description Discovery and Integration system. These new technologies are fated to become ever more important as they slowly assume the role of underpinning major initiatives such as Microsoft's .NET and grow to provide the foundation for much of what HP, IBM and the various members of the open source community are intending to provide for the next iteration of the Internet.

This session will provide an overview of the new business-to-business technologies that are being promulgated for what some cynics have called "basically a more object-oriented, somewhat buzzword-compliant upgrade to CGI" and others have more charitably called the "grown up internet."

The course is now well and truly at End of Life.

I figure that it would be such a pity for it to end as a set of bits decaying away on my hard disk so I am opening it up to the world on as "as-is" basis:

(MD5: 150f88d70d5a86d1129af4e21059594c; size: 6,692,573 bytes)

Some (unfortunately necessary) legalese:

  • This content is provided "as-is", with no guarantees.
  • Feel free to use it, but not to abuse it (to give a couple of examples: don't make hundreds of copies for friends; don't claim it as your own work).
  • I retain copyright, so "all rights reserved."


If you like it, or have any questions/comments, send me an email ( ).

If you find this material useful, please consider paying me a small amount: via PayPal.

Tags: DonationWare, SOA