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

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 hibernate.properties file:

hibernate.show_sql=true

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).

JTable popup menu introduction

Here's a copy of a class file I created to demonstrate how to put a popup menu (JPopupMenu) on a JTable in a Java application. Actually, the intent of this particular class was to see if I could get the popup menu to work on the header cell of a JTable, but that ended up being a no-brainer.

Wow, it's been a long time since I've done anything out here. Busy, busy, busy. Here's a link to a tutorial I've written about creating a splash screen for Java applications.

Introduction

This Java Monte Carlo simulation tutorial, and the corresponding Java program, was inspired by the story and subsequent movie "Minority Report", as well as my recent interest in Monte Carlo simulations.

A co-worker, Chris Smith, created a very elegant Perl program to parse a Microsoft Excel XLS file for me some time ago. I recently modified that program to convert what was essentially a "glossary" in an Access database.

I first saved the Access database table as an Excel file. Then I used the following Perl program to extract the contents of the second and third columns from that file, and write them out to another file. The output file was in a Wiki (technically TWiki) format.

Here's a link to a tool named JSmooth that lets you create Windows executable files from standard Java JAR files. It looks like this can make the installation process on the Windows platform much more friendly.

 

Ant web build script FAQ: Can you share an example Ant build script for a web application?

Sure, here's a sample Ant build script for a Java web application. I've included other example Ant scripts for Java Swing/JFC/GUI applications on this website, but this one demonstrates how to use Ant to build a web app instead.

Ant Swing build script FAQ: Can you share an example of an Ant build script for Java Swing applications?

Here is another sample Ant build script for a Java application. Again, I hope it can help you "Learn Java by Example", or in this case, "Learn Ant by Example".

Ant Java build scripts: Can you share an example of an Ant build script for a standalone Java application?

This is a sample Ant build script for a Java application I wrote. It is a GUI/Swing application named "AlwaysOnTop". I include it here because I'm a big believer in learning by example, and maybe this Ant script can help you create an Ant script for your own applications.

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.