Alvin Alexander | Java, Scala, Unix, Perl, Mac OS X

Need to show how objects collaborate during the lifetime of a software application? You'll want to use a UML interaction diagram -- either a sequence diagram or a collaboration diagram.

I prefer the sequence diagram, because the time sequence of events it displays more easily demonstrates the interaction of objects over time, but other developers prefer collaboration diagrams.


Question: I want to visually model a multi-threaded software application. Can UML help?

Yes, UML activity diagrams can be a great tool for visually modeling the flow of control in a multi-threaded application. A UML state diagram can also be used to show the states objects can be in during their lifetimes.


Question: I want to visualize the activity in a use case ... what UML diagram can I use to do this?

Use an activity diagram. These UML diagrams are good for visual workflow modeling. Swimlanes in UML activity diagrams can also show the behavior of different actors within a workflow process.


Following a speech two days ago, I'm struck by how very little we use the Unified Modeling Language (UML) on our software projects. Occasionally I'll create some activity diagrams to model how users get their tasks done, but that's about it. Typically when we create a software requirements specification this is what we deliver:

Some times when exceptions occur when users are running a Java JFC/Swing application, it's nice to be able to show them a long message about what happened, i.e., something more than a one-line message. To that end I created a really simple Error Message Panel ( that you can use with the JOptionPane to display long messages.

Here's a link to a Code Kata site. It discusses the importance of practice in the software industry. It seems like the basic theory is "If musicians and athletes believe that practice is extremely important, why don't developers (and organizations that develop software)?"

At the moment I'm not aware of any software organization that takes time out for skills practice, unless training on new products or languages counts ... and I don't think it does. Kudos.

Here is some sample Java source code that shows a simple technique to display a GIF, JPG, or PNG image using a Java ImageIcon and JLabel.

Java array FAQ: Can you share some examples of how to create arrays in Java (Java object arrays)?

While I generally work with lists and maps in Java, I occasionally need to create object arrays in Java. Since I don't use arrays that often, I thought I'd share some examples here so I can have a handy Java array syntax reference.

A simple Java String array

I work with the String class a lot, and here's how to create a String array in Java:

Here is a link to Steve McConnell's Classic Mistakes Enumerated, from his book titled "Rapid Development". It is a great listing of 36 common problems that plague software development projects.

Linux grep FAQ: How can I use the grep command to search for multiple patterns with one command?

A little while ago I needed to search for all files in a CVS repository that contain multiple character patterns. That is, I wanted to be able to grep multiple patterns in multiple files. In my case the patterns I was looking for were the strings "prevayl" and "jtable".

One thing to note about jEdit if you're going to use it on Microsoft Windows: If you like to open files from the Windows Explorer by right-clicking on a file, and then selecting an option like "Open with jEdit", you need to use the Windows installer.

I don't write much in the way of business application code any more, but if I did, I would generate Java code like crazy.

Think about it, whenever you write database-driven applications, one common denominator is that every database driven project has the database design completed before you start coding. And then, once you start coding, I'll bet 80% of the code is related to what I call CRUD ("create, read, update, delete") functionality.

And you know what -- you can generate this Java database code, either statically, or more powerfully, dynamically.

I can never find a list of states for an HTML select/option list (aka, combobox, drop-down list) when I need one, so I’m putting two versions here. The first select/option list shows a list of states, but only shows the abbreviations of the states:

By default jEdit stops at the beginning and end of each word when using the "next word" (CTRL + Right Arrow) and "previous word" (CTRL + Left Arrow) actions. Personally, I don't like this; I'd much rather it stop only at the beginning of each word. Fortunately the authors have made it easy to change this, if not easy to find.

To change this behavior in jEdit, you just need to remap the keystrokes to alternative actions. Just follow these steps:

Java servlet redirect FAQ: Can you provide an example of how to perform a Java servlet redirect?

Some time ago I wrote about forwarding from a servlet to a JSP. Depending on the circumstance I might rather redirect from a servlet to a JSP. When I need to to do a redirect instead of a forward I use this code:

Here's a quick note for those of us that like to create prototypes during a requirements process using HTML. Whenever you want to create a button that is supposed to simulate the action of moving to another screen, you can use code similar to the following code snippet to simulate this behavior:

Java Hibernate debug faq: How can I see the SQL that is actually being run/executed when I'm using Hibernate?

To debug Hibernate output, just configure this parameter in your file:


This Hibernate configuration parameter will cause Hibernate to show the actual SQL that is being generated/used when your queries are run. Of course it can be a little verbose, but hopefully it will also give you all the SQL you need to troubleshoot your problem.

This Java class still needs some work, but it's my first attempt at creating a Java Swing component that simulates a hyperlink. Basically, if you use this label (a JHyperlinkLabel to be precise) instead of a JLabel you should see hyperlink behavior on your Swing labels (JLabel).