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

Count me in as one of the football fans who are upset about tonight's game between the Green Bay Packers and the Dallas Cowboys being shown on the NFL Network. Okay, compared to a lot of other things this is a pretty trivial concern, but moving games to a premium cable channel sets a bad precedent. The NFL can do whatever they want, but this being America, consumers can also say "Screw you NFL", and this is your time to vote.

Note: Amazingly, I wrote this review way back in 2007. I just tried to use Poseidon UML again in 2010, and I wouldn't change a word of it. (Okay, I'll change one thing: I now use UMLet instead of MagicDraw UML.)

A nice feature of Eclipse is that you can easily generate hashCode and equals methods for your Java class using the editor. You'll really appreciate this capability when you need to create these methods whenever you're doing anything related to sorting, comparisons, comparators, etc.

I just learned that Eclipse can automatically create (or suggest) variable names for you. The suggestions are based on the class of the object you're about to create, and any characters you've typed for the variable name so far.

For example, if I'm in a method and I type Connection, followed by a space, then press the [Control][Space] keys, Eclipse adds a variable named connection, so my line changes to Connection connection.

Using Eclipse, if your cursor is positioned in between the parentheses of a method call, the [Control][Spacebar] keystroke will show you the signature of the method, i.e., the parameters that the method accepts. I just read where the documentation shows that you should use the [Control][Shift][Spacebar] keystroke to see method parameters, but I've found that [Control][Spacebar] works fine for me.

I've just recently started using Eclipse a lot, and I just typed System.err.println() one more time than I cared to. I just looked it up, and Eclipse also has templates, and one of the pre-built templates lets me type sys, then hit the [Ctrl][Spacebar] keystroke. This brings up a list of options I can choose from, one of those options being to insert the System.err.println() text in place of my sys text.

Java File I/O FAQ: Using Java, how can you test to see if a file or directory exists?

Java test to see if a file or directory exists

Answer: Here's a sample Java method that shows this test. All you have to do is use the exists() method of the File class (java.io.File) to perform this test.

Develop with pleasure. That's the IntelliJ IDEA slogan, and at least through Version 5 I think they nailed it on the head.

So this product review is simple: If you're a Java developer go get an eval copy of IntelliJ IDEA right now and give it an honest eval. You won't be sorry.

Working on tag support for this blog, I've cut a little sample code out of a Java servlet, and I'm showing it below. I was looking at the HttpServletRequest, and was curious about the difference between request.getPathInfo(), request.getPathTranslated(), and request.getRequestURI(), so I created this demo code. Here's the example code from the servlet:

AppleScript Finder FAQ: How do I get the full Mac OS X Finder path in an AppleScript script?

I don't know if this Java/JDBC sample program will help anyone, but I thought I'd share it here. It's a variation of a program I use to connect to a JDBC database (in this case a Postgresql database) whenever I need to look at some information. In this particular case I wrote the program because I didn't have access to the psql command-line tool, so I created this Java program, compiled it, and ran it to see what I wanted to see.

Java SQL FAQ: Can you provide a Java PreparedStatement example that shows how to use a SQL UPDATE?

Sure. I have quite a few examples on this website, just see the "Related" section for those. But for now, here's a short sample method that performs a JDBC SQL UPDATE using a Java PreparedStatement:

Here's a little Java code sample that shows how to try to perform a Java String to int conversion. In this example, if the conversion works, the variable pageNum will hold the int version of the pageNumString. If the conversion doesn't work a NumberFormatException will be thrown, and you'll need to deal with that.

Java String "alphanumeric" tip - How to remove non-alphanumeric characters from a Java String.

Wow, I haven't worked with images in Java in a while, and it turns out that opening and reading an image file in Java is very easy these days. Just use the read method of the Java ImageIO class, and you can open/read images in a variety of formats (GIF, JPG, PNG) in basically one line of Java code.

Mac drag and drop FAQ: How do I copy files on a Mac OS X system using drag and drop between one or more Mac Finder windows?

It turns out that when you drag and drop a file between two Finder windows on the same Mac OS X filesystem you end up moving the file. Unfortunately that's not usually what I want to do; usually I want to copy the file, which recently begged the question "How do I copy files when using drag and drop?"

Some times when you're editing a file with really long lines it's easier to work with the file if the lines don't wrap on screen. That's usually when I use the "no wrap" feature of the vi (or vim) editor.

If you don't want the lines to wrap in vi just type this command:

:set nowrap

That command tells vi not to wrap the lines. The result is that any line that was wrapped before will now scroll off the screen to the right. If you want to return it to the default wrapping mode just type this command:

If you get a Postgresql error message like this:

ERROR:  must be owner of relation [your_table_here]

don't worry too much, it probably means what it says: You don't own the table (or relation) you're trying to modify. Well, I guess you can worry if you can't get someone to fix the permissions, but if you can it's no big deal.

Here's a quick example of how to use a JDBC PreparedStatement with an SQL SELECT query when accessing a database. To make it a little more complicated I added a LIKE clause to the SELECT statement. So, this is really an example of a PreparedStatement that uses a SELECT query that uses a LIKE clause.

With Postgresql (or Postgres, as I call it) you can execute commands from a file like this:

\i your_file_name_here

I just did that to run a subset of the restore commands from a backup file that I created, and it worked just fine. In my case I put the file in my current working directory, but I'll guess that you can also supply a path to the file and it will work from there as well.