Java Cool Toys

It seems like, these days, all the cool kids are dissing Java. I’ve heard phrases like “Java is the new COBOL”, and the like.

Part of me understands where some of these arguments are coming from, and a part of me really doesn’t. I mean, back in the late 80s when I had to use COBOL on a project, I hated it. Whereas, I go home on the weekend and tinker around with Java.

Over the last two weekends, I’ve been playing with some aspects of Java that I haven’t really used before. Firstly, I needed to draw some geometric shapes. Sure, I’ve got a few software packages on my machine, here: Paint Shop Pro or even Microsoft PowerPoint. They have all kinds of geometric shapes. But have you ever tried to draw a regular hexagon in those tools? Aspect ratio of 1:1.1547. If you draw patterns of hexagons, when you’re off by a certain amount, it really starts to show.

Anyway, I knew I could handle the math of what I wanted easily enough, so I pulled up Eclipse and started working with the Java2D API. Fairly quickly, I had my geometric shapes all organized and rendered.

My next trick was that I wanted to print the final result. Here’s my secret confession: I don’t think I’ve ever written anything that handled desktop printing before. Back in my mainframe days, I pumped out reports using the simple mainframe print markup: y’know, print streams are simple text files, exactly 133 characters wide, and you put the number ‘1’ in the first column to indicate a page-eject.

But for the last ten or more years, I’ve been cheating when is comes to printing. I’ve used some tools to avoid printing. I could render to HTML so that a browser could print. Or I could render to Excel, and let the user print using Office.

But, for the first time ever, I decided to take a look at the Java Print API. Within about 10 minutes, I was printing my first geometric/graphical output. I was just elated that it was so simple.

Lastly, I started playing with bundling my utility as a GUI app, and deploying it over the web. I’d worked on a project at Intelliware that used Java Web Start, but I can’t say that I ever touched any of the set-up or configuration portions. There are some nice examples on the Sun site, so again, I quickly had something working. I was especially interested in the JWS configuration where access to the machine’s resources is restricted.

I made a few modifications to my code, using things like the javax.jnlp.PrintService, and I had a version of my GUI that could run in an untrusted mode, but still access the printer (with the appropriate notifications to the user). For testing purposes, I also wrote some code that could switch services when I was launching my app from Eclipse, rather than from Java Web Start.

Here’s a list of Java technologies I used:

Technology Initial Knowledge
Swing Minor knowledge (I had built trivial Swing apps — what little GUI programming I’ve done has mostly used SWT)
Java 2D Minor knowledge (I had experiemented with it once about 3 or 4 years ago)
Java Print No knowledge
Java Web Start Conceptual knowledge

What fascinated me was that although I was branching out into personally new territory, I hadn’t touched any technology that’s not already bundled into JDK 1.4. And I was also surprised at just how easy each of those technologies have turned out to be. Printing, especially.

Maybe Java is the new COBOL. <shrug> And I don’t deny that there’s a certain “oooo, shiny” pleasure one gets out of learning a new language like Python or Ruby. Me, I’m still getting something out of discovering each previously-unexplored aspect of the Java language.

It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply