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

Problem: You're working on a Java application, and you're repeatedly performing a test to determine whether a String (or many strings) are either blank or null.


Create a simple Java method to perform this test for you. The following Java method returns true if a String is blank or null, otherwise it returns false:


One of the nice things about Java is javadoc. The javadoc utility lets you put your comments right next to your code, inside your ".java" source files. When you're satisfied with your code and comments, you simply run the javadoc command, and your HTML-style documentation is automatically created for you.

The 4th of July delivers a new look and feel for this blog, as well as huge changes to the main Java page for the site.

I've been working mostly on Java/Swing/JFC projects for the last several years, so I haven't done a lot with CSS lately. But one thing I will say is that I've bent over for IE6 just as much as I care to right now. Maybe my CSS skills need a lot of work, but hey, I'm not doing any rocket science here. From what I've seen Swing on Java is just as portable as CSS on different platforms. That's my whine for the day.

Hey, I'm not a John Edwards fan myself, and I wouldn't know Ann Coulter if she was standing at my front door, but anyone that says something like this is sick:

"If I'm going to say anything about John Edwards in the future, I'll just wish he had been killed in a terrorist assassination plot."
Ann Coulter

Ms. Coulter, you need to get yourself some help.


Wow, for me, getting Apache server side includes (SSI's) to work on my Apple Mac OS X installation was nothing like what I read elsewhere. Oh, you do have to do the setup work as shown in this Apache SSI configuration document, but on Mac OS X the setup is a little different.

The key on the Mac was that instead of restarting Apache, I decided to stop and start Apache manually, like this:

sudo apachectl stop

followed by:

Hah, everything got so fast at the end I forgot to mention one minor detail here: I moved to Alaska.

On May 8th, 2007 I packed up everything that would fit in my RAV4 and left Louisville, Kentucky and drove to Alaska (yes, Alaska).

It's Sunday, the weekend after Apple's WWDC 2007 event, and as an Apple shareholder, I have to say that for the first time in a long time I'm concerned about the company.

Someone asked yesterday if you can use animated GIF images in Java applications using the JFC/Swing toolkit. That's something I hadn't tried with Java and Swing before, so I wrote a quick test program, and sure enough they work.

I just load an animated GIF as an ImageIcon, then put it on a JLabel and display it on a JFrame, and the animation starts right up. Note that I'm using a Java/JDK 1.4.x release.

Here's a "generic" version of a simple test plan I just wrote for testing one wizard in a GUI software application my team is currently developing. I wrote this for one specific wizard, then realized that many of these tests are generically-applicable to all wizards.

Without any further introduction, here is my sample test plan. Feel free to use it as a template for creating your own test plans.

I get the following error messages some times when running JRuby scripts:

For some reason I didn't work w/ the Mac much until last year. Actually, to be fair to myself, a lot of that probably had to do with unpleasant experiences with earlier versions of the Mac OS.

But as I was talking to a co-worker this morning I realized that it was a mistake not to spend some quality time with Mac OS X when it came out. Having worked with it for over a year now I've come to take many things for granted that it can do. The discussion this morning had to do with the power of scripting native Mac applications with AppleScript.

Here's a sample Ruby mail program that I created that finds and prints all of the unique email addresses in my IMAP inbox. Hopefully the source code is readable enough that it doesn't need much description. The only hard part is trying to figure out how to get the email address from the Envelope, and that's only because the documentation is hard to find.

Ruby mail program

Here's my Ruby IMAP mail program source code:

Here's a Ruby "read file" example program that shows how to read a file as one string. You just have to pass a file name in to the get_file_as_string method, and this Ruby method will read in all the records from the file, and return the contents of the file as a string.

Writing software is a funny thing. You do something one day and you think it's really cool, then come back another day and go "WTF was I thinking?", so you tear it apart and rewrite it.

Today I ran the JRat Java profiler (Runtime Analysis Toolkit) on some code I wrote about 10 days ago, and it showed that I was looking for a pixel 10,000,000+ times on a 1024x768 resolution image.

Linux wget command FAQ: Can you share an example of a wget command used in a Linux shell script?

Here's a Unix/Linux shell script that I created to download a specific URL on the internet every day using the wget command. Note that I also use the date command to create a dynamic filename, which I'll describe shortly.

Cygwin crontab FAQ: How do I get the crontab system started when using Cygwin?

I can't remember where I found it, but using this series of commands from the Cygwin prompt got the Cygwin crontab system enabled for me. First this command:

cygrunsrv -I cron -p /usr/sbin/cron -a -D

followed by:

net start cron

I haven't used this cygwin feature before, so it feels weird knowing that crontab is running on my Windows system under cygwin.

The grand experiment has begun. The problem: I've been on a project developing a very deep application for four years now, and lately it's become so complex and intertwined that things are starting to break. Developers have been known to say "The application is smarter than I am." I'm just a wee bit concerned about our software quality.

Throughout all of this I started to notice that many of these bugs could be found if we had ... (drumroll) ... automated GUI tests.

I still have a lot to learn about Ruby, but here's a Ruby script that runs a series of system commands (Kernel.system()), which in my case means calling a series of JRuby scripts. I send all of the output from this script and from the system calls to a file by (a) writing directly to the file using Ruby and (b) redirecting STDOUT when making each system() call. I think this is a hack, but I can't find a better way to redirect STDOUT.

I'm doing some crazy things at the moment, basically calling JRuby from a Ruby script on a Windows 2000 system. I'm doing this because there are a bunch of JRuby scripts that I want to run sequentially, and I also want to check for errors after each run, so what better way to invoke them and look for resulting errors than with Ruby, especially on a Windows system? :)

Here's some sample JRuby code that I just used to take a screenshot of my desktop. It uses the Toolkit and Robot classes from Java to make it all happen. It could probably be a little shorter, but I don't know much about JRuby yet. I also had a problem getting the Java File class to work properly, and referencing it as shown was the only way I could get it to work.