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

Note to self: Don't *ever* take shortcuts when writing code, even prototypes. Every time an application gets to a certain size, you'll regret those shortcuts, because you won't be able to do what you want to do in a timely manner.

There's something good to be said about "the simplest thing that could possibly work", but don't take that to mean "taking really dumb shortcuts is okay".

 

Java String array FAQ: Can you share an example of how to determine the largest String in a Java String array?

Sure, in this tutorial I'll share the source code for a complete Java class with a method that demonstrates how to find the longest String in a Java string array.

Finding the longest string in a Java string array

Here's the source code that shows how to find the longest string in a Java String array:

Java Date format FAQ: Can you show me how to format a Java Date object in a human-readable format?

It's pretty easy to get a Date in a Java program, but it takes a little more work to print a Date in a human-readable format. This article shows how to print a date in a human-readable format.

Java Date format example

Here's a snippet of Java date formatting code I'm working on right now:

Here's a quick example of how to set a default value for an HSQLDB TIMESTAMP field:

create cached table directories (
  dir_id identity NOT NULL,
  directory varchar(255) NOT NULL,
  time timestamp default 'now'
);

There are other ways to do this, but the important line that sets the default timestamp in the above SQL is this:

time timestamp default 'now'

This is where I'm creating a timestamp field named "time" that automatically defaults to the current date/time when a record is created.

 

I've written a lot of use case documents lately for software requirements specifications, and as use cases get more complex, I find the need for "sub use cases" or "alternate scenarios". When referring to these from the main use case (or anywhere else), it's nice to be able to use LaTeX's reference capability.

Here are a couple of quick links to articles to the Joel on Software site:

I've been working on a document for one of my customers named "Use Case Best Practices", but then I decided to search the Internet to see if I could find anything similar to what I was thinking.

The best thing I've found is this Coad Letter on Borland's web site. There is enough meat here that I'm scrapping my plans and just suggesting they read that document instead. Kudos.

 

The checklist provided below isn't ready for prime time, but I wanted to make sure I put a copy of this information somewhere. Basically, I have started to create a checklist of detailed items I need for user interface screens when creating a detailed design specification. So, what I've started to do is list all possible user interface field types, and what features of each interface element that can vary.

Frankly I'm not sure if this is a good idea or not, but if you're into heavyweight processes, this information is certainly needed by someone at some point.

One of the things I learned (or was reminded of) is that -- properly done -- Use Cases really bring out some state-related issues that you can't get from plain old requirements.

I'm working with a client on fixed price software development (and have been doing so for nearly two years now), and this brings a lot of risk to my side of the table, so I'm very careful that we all understand exactly what's being developed.

Here are two quick links to free programs that I've used to convert Microsoft Word documents (aka, ".doc" files) to plain text:

I just started using catdoc today in combination with glimpse, and I'm pretty happy with it. Note that catdoc also includes an XLS to CSV converter, which is most helpful for my current project.

 

JBuilder has a nice feature that I've started using lately to track "to do" items. These are the places in my Java projects where I know that I need to fix or change something, but I just don't have the time to do it at the moment. So, what I do is create a "todo" Javadoc tag that I can use as both a reminder and a management tool. Here's how it works:

Don't like your curly braces at the end of the line? Rather have them on the next line? What about your block indentation, your else's, your while's, and your catch's, implements, extends, and throws? How about those import statements, and what about that line wrapping?

Problem - the CSV file

You have a file that contains columns of data, and each column is separated by a comma (a CSV file). The width of each column can vary, but the column data is guaranteed not to contain any columns itself, so it's safe to think of the comma as truly being a column separator. So, how do you read the data?

Solution - the Perl split function

Okay, so what you're saying is that you have CSV file data that looks like this:

I've finally finished creating my first two JBuilder OpenTool projects. They are very simple, but time is scarce, so the development process was drawn out. Here are quick links to the two tools:

Keith Wood has written a book about the JBuilder OpenTools, appropriately named "Inside the JBuilder OpenTools API". Here is a link to his site, and here is an even more direct link to the JBuilder OpenTools code samples he has on his site.

Go to Tools | Preferences, and then when the resulting Preferences dialog shows up, choose Browser in the tree on the left hand side of the dialog, then Look & Feel. In the Look & Feel combo box on the right you can choose from the following options:

Here's a link to the Java API doc for how to set a mouse pointer/cursor shape to one of the predefined shapes. It's amazing how bad the memory gets ... here's a link to an article I wrote a long time ago about "How to turn the Java mouse cursor (pointer) into an hourglass".

 

I've been using JBuilder X Foundation a lot lately. I've had to do a lot of prototyping for a current project, and as far as I've seen JBuilder has the best JFC/Swing generating tools around, bar none. So, I ditched an attempt to start working with Eclipse and I went back to the free version of JBuilder, and I haven't been disappointed.

Here is a quick dump of JBuilder-related bookmarks I added to my personal collection last week. These are all related to Open Tools, and more recently how to build JBuilder applications using Ant.

Here's an example of how to add a JPopupMenu to a JTable. The purpose of the popup menu is to let the user right-click on contents in the table and work directly with those contents.

In the code below I've taken a real class and trimmed it down considerably for these demo purposes. I hope the code remaining is useful enough to help you implement your own JPopupMenu on a JTable, or perhaps in other components as well.