My New Java Stickpin! (and use of the Java logo)

Been there, done that, got the stick pin. I’m now officially a Java Certified Programmer - and I’ve got the card to prove it! It was certainly a fun exam, and it took me the whole two hours just to get the thing finished. I probably should have studied harder, but hey, I passed, and I’m very happy. Also learned a lot more than any man should about scope rules relating to inner classes, and more esoteric uses of the wait()/notify() calls.

The kicker is that I actually did this cert just to put the logo on my Business Card (hey, our company is called Bytecode, it would be nice to have a Java logo on it!). To actually use the logo, however, I’ve got to sign a strict license agreement which, in part, requires me to also place the following phrase on my card under the logo:

The Sun Certified Professional Logo is a trademark of Sun Microsystems, Inc.

Now, I’m all for protecting your brand, but come on, we’re talking a lot of card real estate here. There’s also rules on where on your card the logo can be placed, how big it must be (“it must appear smaller than your name and personal information combined”). Serious! Looks like I’ll be sticking with the Bytecode dog!

I still highly recommend the certification deal. Probably won’t get you a job, and it’s probably not even that good measure of your technical skill (I reckon about 50% are “trick” questions - where the most natural answer is actually wrong because of some subtle complexity/variable shadowing/omission of a break; or whatever) - but it is stretching, and does get you familiar with some less used features of the language (ask me about signed and unsigned bit shifting operators. Go on. Anything. I dare you!).

[Read More]

SAX, Stacks and XML Parsing Patterns

I used to be a hardcore DOM-style man, and dom4j remains my favourite XML API, but these days I’ve been doing a lot of performance and load sensitive stuff in the middle tier, which means that I tend to go for streaming solutions like XML pull and SAX. My basic lesson has been that streaming = performance. I mean, the numbers just don’t lie - we’re talking at least 3 times faster than any DOM-based solution in my benchmarking, often up to 10 times faster - depending on what you’re doing. The other big plus for SAX is that you get it for free with 1.4 so you don’t need to bundle stuff.

The painful thing about SAX (and XML pull), which puts most people off, is that you end up tracking your own state while processing things. I used to end up setting a whole bunch of booleans “nowInsideName = true”, “nowInsideAddress = true”, then I bumped into a guy at our local JUG who gave me a killer tip “Why don’t you use a Stack for state tracking?”. Duh! What a great idea.

So here’s the gist:

  • When you hit a start tag, push it onto the stack;* When you hit an end tag, pop the stack;* When you hit an “characters” or “text” entry, do a peek of the stack to see what element you’re in.

When I wrote the little app that converted my MoveableType XML over to Pebble blog format, I used this “Stack” type approach. I used XML pull, but exactly the same concepts work for SAX. Here’s an extract of the source:

        Stack tagStack = new Stack();
        int eventType = xpp.getEventType();
        while (eventType != xpp.END_DOCUMENT) {
            if (eventType == xpp.START_TAG) {
                tagStack.push(xpp.getName());

            } else if (eventType == xpp.END_TAG) {
                tagStack.pop();
                if (xpp.getName().equalsIgnoreCase(mte.ENTRY_TAG)) {
                    mtList.add(mte);
                    mte = new MoveableTypeEntry();
                }

            } else if (eventType == xpp.TEXT) {
                String tagName = (String) tagStack.peek();
                String tagValue = xpp.getText();
                if (tagName.equalsIgnoreCase(mte.TITLE_TAG)) {
                    mte.setEntryTitle(tagValue);
                } else if (tagName.equalsIgnoreCase(mte.TEXT_TAG)) {
                    mte.setEntryText(tagValue.replaceAll("n", "
n"));
                } else if (tagName.equalsIgnoreCase(mte.DATE_TAG)) {
                    mte.setEntryCreatedOn(tagValue);
                }
            }
            eventType = xpp.next();
        }

There are some constraints on this approach, right? You have to assume that you know some stuff about the documents structure (validating against a DTD can help here!), and in the example above, I don’t cater for elements of the same name in different portions of the document (Although you can do a Stack.search(parentTag); to find out that info if you need to confirm it).

Overall, I reckon this is a good way to go for SAX and pull type processing. I don’t know what other ways people do this sort of stuff, but it’s certainly a lot more maintainable than state tracking with a billion boolean fields!

[Read More]

Porting my MoveableType data to Pebble

I’ve just spent the arvo moving my data over from MoveableType to Pebble, and after some gotchas it should all be good.

I took a longer route than most since I had to go via phpMyAdmin to get an XML dump of my MT data first (since I don’t have shell access to the mysql box, and I can’t get to it from remote hosts).

The basic operation was:

  • Work out the naming of Pebble entries (all good, turns out to be a simple Calendar.getTimeInMillis() deal)
  • Work out the file format of Pebble entries (only two gotchas here - some custom formatting of Date entries which can be handled by SimpleDateFormat, and the CDATA sections in blog comments - where MT used PCDATA here. There were also some issues in swapping MT cr/lfs with first class br elements, but that’s another story).
  • Write some XML Pull to make the glue happen.
  • I also learned about File.makeDirs() which turns out to be a very useful little comment for making all required parent directories to a particular location. Useful, say, if you need to create /2004/06/13/ in a directory tree. BTW, took me a while to work out the “06” story, and not “6” which causes all sorts of pebble issues when trying to browse to a particular entry.

So I have to say it again, XML Pull Parsers are very, very handy for hacking together some parsing code. The XML stuff was the easiest part of the port - which was not always the case for me in the past. And, of course, Pebble - just rocks.

[Read More]

New Company Logo

This year I’m really making an effort to get Bytecode’s image up to scratch as an Aussie Java company, so I’ve tracked down a sensational Aussie Web Designer - Cameron Adams to help lift our image.

First stop was getting the corporate id sorted out. Cameron has put up with my incessant tweaking and come up with something that I just love. You read it first here! Check it out (the black is his recommended option and I agree):

I can highly recommend Cameron. Very reasonable rates, easy to work with, and fantastic output. You should see the new web site he’s putting together for us. Two words: Sen-sational. If you’re in the market for a CSS specialist or graphic designer, check out his blog.

[Read More]

Now hosting on Linode with Pebble!

I’m now hosting my blog on my own Linode which is basically a hosted Unix service where you have root access. Fantastic stuff. I’ve installed my own DNS and mail servers, an instance of Tomcat, my wiki (a JSPWiki) and now some new Java blogging software - Pebble. If you’re looking for Java hosting … and don’t mind getting dirty with a little Linux, you can’t do better than root access! Ultimate flexibility.

Now, the only thing left to do is port my old MoveableType content over to Pebble, which I’ll get around to over the next week or so. Or let me know if anyone’s written a script to do the same.

I’ve gotta say that Pebble looks very neat. It’s got all the features I need in a blog, is 100% Java, and it’s well documented. Installation was a 5 minute process (and that’s the multi-user version - cause Nick will be here soon too). Fantastic stuff.

[Read More]

XML Pull Parsers Zoom!

I’ve been playing around with profiler technologies, and recently started having a look at JProfiler - attaching it my ejb running insider JBoss and then running my unit tests. The interesting thing was that I was burning a ton of time inside my XML parser (dom4j).

Some of that time I can put down to being a little too keen on XPath, but a good swag was inside parseDocument, so it’s not like I’m going to be able to tune that!

Anyways, just for kicks, I started to have a look at XPP3 - one of these “XML Pull Parser” technologies. I notice that XSteam have switched to using it - so I thought it was worth a go.

Put some metrics in my unit test for the XML->Object conversion and the stats went from 407 ms (dom4j) to 49 ms (XPP). I love dom4j’s API - but these lightweight parsers sure are zippy. For time critical portions of code, I’m going to look at turning them with XPP.

Worth a look.

[Read More]

BeanShell? Did you say...

Ok, so I know the world is in the grip of Groovy madness right now, but for the rules engine of our little spam filter app I’m leaning towards BeanShell.

The big sell for me is the lightweight story - less than 200k for the whole thing - including Swing editor - with no other dependencies. Plus I don’t really need to learn any new syntax! It’s groovy in it’s own way ;-)

The other thing I really like is that it’s very straightforward to extend the language with your own commands. Need a stripHtml command for a spam rule? Piece of cake. Define a stripHtml.bsh, fill it with:

`

import org.apache.regexp.RE;

stripHtml( String textToStrip ) {

RE r = new RE("<[^>]+>");

String replaced = r.subst(textToStrip, "", RE.REPLACE_ALL);

return replaced;

}

`

Then just use a stripHtml(); in your scripts wherever you like (with an importCommands("/path/to/commands"); somewhere in your setup). Good to go. Simple. Straightforward. Small. Just works.

[Read More]

Loving MockRunner

I’ve blogged earlier about my love for MockEJB… and I’ve since come across MockRunner which not only lets you test EJBs outside the container… it lets you test Servlets, Tags and Struts apps to boot (it actually uses MockEJB to do the underlying EJB stuff, but gives you a nice high level facade to make it happen). Comes with a mock JDBC layer as well (to mock in your DB implementation).

I have a servlet which called a session bean, passing in some info gathered from the HttpSession scope, and now I’ve got unit tests for the whole process running entirely outside the container. You’ve just gotta love that. The best part is that it passes the Glen Smith “just works” test - up and running within the hour courtesy of some nice example code from their web site.

A little heavy on the dependent jars (commons-just-about-everything.jar), but we don’t have to ship em right? Just for for our Ant test classpathref.

Good stuff, lads. A very neat library.

[Read More]

MockEJB - Testing Outside the Container

I’ve never really had much joy unit testing EJBs. I’ve had a look at Cactus, but never found it that easy to understand (I mean, testing inside the container has to be a good thing for accuracy, but it has to be a pain to regularly deploy test suites to your container on every run?). Inevitably I end up give up after stuffing around for a while.

Anyways, I’ve since discovered MockEJB and it is one very neat little mock library for EJBs. Getting a basic test of my SLSB outside the container was a snap… and not it just runs as part of my standard JUnit test suite (without a stack of dependencies on other infrastructure being up and running).

Another neato feature is a relatively complete Mock JNDI Context. I’m registering little local datasources against the JNDI names the bean is expecting and it works just great.

The other great thing about it is that it comes with some very nice example code of common things you’re likely to want to do, and enough documentation to get you hitting the ground running. Recommended. Great job Alexander!

[Read More]

Icons for Swing Apps

We’re chasing a few icons for our Swing GUI, and I’m surprised about the relatively few sites that do bundles of commercial icons. Most people will price you per icon, but that ends up being quite a big figure (in the order of $50USD per icon).

Anyways I’m looking for a bundle that I can buy for the Bytecode that we can use on future projects too, and I’ve shortlisted the candidates to two options:

* [IconExperience](http://www.iconexperience.com/) who have some fantastic icon bundles and who specialise in the Java deal (these guys did the Alloy L&F); and* [glyFX](http://www.glyfx.com/) who also do some great bundles (and seem to be an Aussie company - yeh!) - but who don't have the same range as IconExperience.

Sun also supply a bunch of icons at the Look and Feel Repository… but they look pretty dated, and really only suite the Metal Look and Feel.

So, anyone else recommend any good icon packs out there? I don’t mind spending the dollars - especially for the standard of icons that IconExperience and glyFX are producing.

[Read More]

Cool Swing-ish Stuff

After a ton of interesting feedback last time, I’ve scoped out some interesting Swing bits and pieces. I’ve got most of what I needed, but here’s the summary so far:

* JGoodies [Forms](http://www.jgoodies.com/freeware/forms/index.html) for layout management - I finally have found a layout manager that I understand and that does what I want! * [l2fProd](http://www.l2fprod.com/software/l2fprod-common/index.php) provides exactly the button bar I was after (very Mozilla-ish) * [exe4j](http://www.ej-technologies.com/products/exe4j/overview.html) is a very polished little exe maker for Windows to give you that nice icon/launch option.

Still looking for a nice grid… but something will come up…

Loving the Swing… Hope to have some screenshots to post of our new Spam filter by the end of the month. Still early days, but the pieces are coming together.

[Read More]

Commercial Swing Components?

I’m interested in hearing any reviews from people who’ve used commercial (or otherwise) Swing component libraries. I’m after a slick set of controls that are easy to use and visually spot on. Surprisingly, Google doesn’t seem to be turning up too many Swing component libraries out there.

The JSuite stuff looks pretty darn nice… but fairly expensive. I’d love to get a nice OutlookBar style guy, as well as an ultra-flexible grid control… and I’m willing to pay the money if it’s something the company can re-use.

So, any of you guys used any commercial Swing stuff? I’m all ears…

[Read More]

The Joy of JNI, DLLs, and XP

We’ve got an Applet that makes a JNI call to a DLL. Been working happily on several hundred Windows NT (don’t ask) boxes out there for some time. Good good. Then we start testing against XP… and the core dumps begin…

I’ve been using debug mode in VC++ and stepping through the whole call trace. All good. Then I build a Release version of the DLL. Unlucky - crashes IE straight away. So I inserted a stack of OutputDebugString() in the DLL to see where it fails… and it fails in different locations on different invocations.. and sometimes it doesn’t fail at all.

So I linked against a static version of the C Runtime instead of a shared DLL version. No problems. Buggered if I know what the problem is. I know there are problems when you new() with one version and delete with a different one, so maybe that’s got something to do with it…

All this whole exercise proved to me was how much I love coding in Java. Memory allocation is such a deal to track down problems with.

In other news, JNIWrapper looks like an interesting little product. When we’re looking at Windows integration for our SpamFilter product I’ll definitely be evaluating!

[Read More]

Matt Raible is the man!

I was checking out Matt Raible’s AppFuse code earlier today and geez that guy can write clean code!

One very neat thing that caught my eye was also in his build script. Get this, he has an Ant task that buddles his FAQ, Release Notes, and HOWTOs directly from his Wiki into a local html file.

Basically he uses the <get> task to a URL like http://yourwiki/wikitohtml.jsp?Install&ReadMe&FAQ&HowTo where the JSP must just piece together the various Wiki pages into a single HTML file. You’ve gotta love that!

Another neat trick is to modify your log4j config to have a pattern like @@APPNAME@@ %c %p %d %m%n and use the <replace> task to sub in your app name at build time. Very neat for when you’re watching a Tomcat console logger!

+1 to the Matt Raible fan club. His code rocks!

[Read More]

Moved to Java hosting

Thanks to all the folk who made recommendations on JSP hosting providers. To summarise, I hear nothing but good things about KGBInternet - pretty much total control of your Tomcat config, running on a private JVM for $20/month Canadian. People RAVE about the support they receive there, and the operators are very Java-savvy.

The only neg is the 1Gb traffic limit (which is probably heaps if you’re just running a blog, but if you’re offering downloads I think you’ll get to that pretty quickly.

The guys at WebAppCabaret look pretty competitive too, giving you. 10Gb traffic, private VM, a couple of subdomains and a database for around $20US/month.

I’ve ended up going with HostForWeb simply because they give a 50Gb monthly allowance for $20USD/month. Even cheaper if you pay for 12 months, and at the current Aussie dollar exchange rate, I could get a year of hosting for about $22/month AUD. Their biggest neg is that you only get one Tomcat context (on a shared VM) and basically no control over your config.

You do however get 750Mb of disk, unlimited MySQL databases, unlimited subdomains, and a pretty smooth operation. I’ll let you know how things pan out once I’ve tried deploying a Struts app or something.

[Read More]

Java Hosting Recommendations

Anyone got any good recommendations for JSP hosting?

I’ve heard good things about KGBInternet, but they’ve got fairly small traffic limits - but apparently very switched on as far as Java Web hosting goes, and terriffic support. By contrast, HostForWeb offer a 50Gb limit, but only give you ONE tomcat context to play with - with extra monthly fees for each context that you add, and their turn around on answering emails is several days.

Both have pretty good pricing at around $20/month USD.

Anyone else got any good recommendations?

[Read More]

Newbie Struts Question

Doing a fair bit of work with Struts at the moment, but there’s a fairly basic question that still bugging me. What is the best strategy for handling generic success messages?

So for example, say you’ve got an Action that does AddUser, one for EditUser, and one for DeleteUser. Do you need to supply specific JSPs for each of the success results?

At the moment, I’ve got something like: addUser.jsp >> AddUserAction >> addUserSuccess.jsp if AddUserAction returns success (or back to addUser.jsp with an errors collection on failure if something wasn’t quite right).

But that means every JSP has a corresponding blahSuccess.jsp, which seems like a lot more editing than I’d like. How do people handle that in bigger apps? Do you use a generic success.jsp and pass in some kinda message telling the user all was fine?

Ideas welcome!

[Read More]

Our first staffer (and our Java Spamfilter)

Well, it’s finally happened. Bytecode has employed its first non-Glen developer. Welcome Nick Wheatstone.

For a while I’ve been tinkering away on a Java spam filter for the desktop (since I just can’t find one that really does it for me). I’ve decided to put in some dollars and get the app to a commercial stage… actually first to get it working… and then to get it to a commerial stage ;-). We’re also hoping to use the engine itself for a server product, but that’s further down the road.

Nick a sensational young developer from University of Canberra, who’s relatively new to Java, but has plenty of developer runs on the board. He’ll be blogging about his progress, so if you’re new to Java or Spamfiltering, he’ll have lots to share. We’re hoping to ship a product by the end of June (and we’ll be asking for some testers closer to the time).

It’s great times at Bytecode!

[Read More]

Cool Java Gantt Software

If you’re looking for an open source Microsoft Project (minus the file compatibility), check out the very slick looking GanttProject. 100% Java, XML file format, and a very slick Swing UI (which says a lot coming from me!).

Check it out!

[Read More]

Tomcat 5.0.16 considered safe

Well, the upgrade from 4.1.26 to 5.0.16 was certainly painless. Location of XML deployment fragments changes in this version, but everything else looks pretty straightforward… Stuts still runs… and sitemesh 1.5 is still a goer too.

Can’t wait to take advantage of the JSP 2.0 options….

[Read More]

Finally on ISDN

After ages and ages on 28.8kb, I’ve finally managed to step up to 128kb ISDN (can’t get ADSL or Cable in my area, so the options were Sat or ISDN.. and ISDN is much better pricing).

Now to do some serious downloading of the latest version of every Java library imaginable…

[Read More]

Anyone got Sitemesh working on Tomcat?

Looking at some presentation options for Struts, the frontrunners being Tiles and SiteMesh.

I really like the idea of SiteMesh, even more so after playing with Tiles (which adds its own management problems into the equation with the requirement to edit tiles-defs.xml for each new page, and forcing you to author html fragments rather than real McKoy valid pages). Sitemesh look very elegant and ultra-low-maintence when adding new pages!

Unfortunately, though, I can’t Sitemesh to run under Tomcat (either 4.1.24 or 5.0.16). Both give the same deal:


org.apache.jasper.JasperException: getOutputStream() has already been called for this response

...

at com.opensymphony.module.sitemesh.filter.PageFilter.applyDecorator(PageFilter.java:169)

The readme makes noice about using jsp rather than html for page extensions, but even changing that just gives me..


org.apache.jasper.JasperException: Cannot call getWriter() after getOutputStream()

at the same line. The readme also notes that Sitemesh has issues on WebSphere, WebLogic, and other containers… so I may just be one of the unlucky ones.

Anyways, I’m not doing anything tricky, just autodeploying the sitemesh-example.war that comes with the package.

Anyone got it working on Tomcat? I’m playing with sitemesh-2.0.1.

[Read More]

Native code compilers for Windows?

We’re developing a product that we’d like to offer as a download without the client needing to also download another 10 meg of JVM runtime. Anyone done any stuff with native code compilers on Windows? The app doesn’t have a GUI (uses HTTP), so there’s no need for Swing support.

I know that Excelsior have a product, but it’s unclear whether you still need to bundle a whole bunch of support DLLs there too. I’m told gcc also supports some kind of Java compilation via gcj, but is that going to work on Windows? Or will I need to bundle a whole bunch of Cygwin stuff with it?

Any war stories out there?

[Read More]

Powerfinger Rock Canberra

Ok. Not strictly Java, but caught Powerfinger in Canberra last night on the Vulture Street tour. They guys are an Aussie act from Brisbane who’ve made it good on the world stage. Outstanding show… and definitely worth catching live if they hit your area.

The support act, The John Butler Trio were also sensational. I’ve got to get some of their stuff on shiny disc.

Anyways, back to the 1’s and 0’s.

[Read More]