I've found that there are several times when I need to be able to find a Java class inside of a jar file. Usually this happens when something isn't working, and I get something like a Java ClassNotFoundException. In the process of debugging this problem -- especially if I'm using a jar library that I haven't used before -- I list the contents of one or more jar files to debug the problem.

Here is some code that I use at the beginning of a MySQL database script to (a) create a database, (b) create a local user to access that database ('foo_user'@'localhost'), (c) create a remote user that can access the database ('foo_user'@'%'), and (d) then use that database (which I need to do before starting a bunch of CREATE TABLE statements):

iPhone reboot FAQ: How do I restart (reboot) an iPhone, iPod, or iPad?

As a new iPhone user, after hearing that the iPhone may suffer from a memory leak which causes applications to become slower over time, I looked at my phone and wondered "How do I turn off my iPhone?", quickly followed by "How do I restart my iPhone?"

Java memory FAQ: How do I control the amount of memory my Java program uses (i.e., Java RAM usage)?

One of the Linux servers that I use is a little starved for memory, but I need to run a Java program on it periodically to run some utility tasks. However, every time I try to run the program I get this Java heap size error message:

Thinking about my own work when using Linux and Unix systems, a lot of the work is based around files, and when you're working with files, tools like the Linux find command are very helpful. So, I've decided to put together this list of find command examples/recipes that I'll update from time to time when I use the find command in different ways.

How to find all files beneath the current directory that end with the .jsp extension:

Summary: This post shares some Unix/Linux sed command swap/replace examples, where you replace one string or regular expression with another string.

Here's the source code for a sed script that I used to convert some poorly formatted HTML into a format that I preferred. I ran this on a set of almost 30 JSP files from an open source project I recently worked on. The good news is that the previous format of the files was consistent, so I was able to use this sed script to convert all the files at once.

Linux shell script for loop FAQ: Can you share an example of a Linux shell script for loop, for instance, to do something for every file in the current directory?

Here's a shell script that you'll find on all the Unix, Linux, and Mac OS X computers I've worked on. The general process of this script is "for every file in the current directory do XYZ".

This article is now part of my new eBook, which is only $2.99 on Amazon.com:

You want me to do what? A Survival Guide for New Consultants

I hope you enjoy my book, and more than that, I hope it helps you have a very profitable and rewarding career.


Here's a simple Java toString method that I've added to my model objects in a recent project. It uses reflection to dynamically print the fields in your Java class and their values. By using this dynamic toString method you don't have to custom-code every toString method in each of your classes.

Nagios FAQ: I'm trying to get Nagios to work, but when it starts running there is an error message in the log file that says something like "Nagios, Error Code 127, Make sure the plugin you're trying to run actually exists". How I can fix this?

I've had my iPhone 3G for 72 hours now, so here's my first review of it:


I hear that Microsoft has come out with a marketing campaign to make Vista seem like a better product. This reminds me of the premise for the movie "Thank You for Smoking", but in an effort to help I've come up with a few Vista ad slogans:

Spring JDBC DELETE FAQ: Can you provide some examples of using SQL DELETE queries using Spring JDBC (Spring Dao classes and methods)?

Here are a few Spring Dao examples, specifically JDBC/SQL DELETE examples.

Spring JDBC delete example #1: Delete a record by the primary key

In this first Spring JDBC DELETE example, I pass in an id parameter, which represents the primary key in my hosts database table. This JDBC/SQL statement deletes the record from that table that matches that id field.

I wrote the following Java class today that is a "helper" class for a project I'm working on to create a web interface for Nagios. The Nagios part isn't too relevant, because mostly what I'm trying to show here is how to use the Apache Commons IO project to make it easier to interact with files and directories from Java code.

In short, the following Java class shows how to use the Commons IO project to accomplish the following tasks. Without any further delay, here is the complete source code for my class:

A Spring JDBC SELECT and INSERT example: Here's the source code for a complete Spring DAO class from a project that I'm currently working on (a Java-based web interface to the open source Nagios project) that shows how to use a few Spring JDBC methods, including both a SELECT example and a simple INSERT example.

I'll add more examples to this site later (and with more introduction/description), but for now I'm just going to drop this Java class sample out here and hope that it helps you "Learn Spring JDBC by example".

A JDBC MySQL transactions tip: If your transactions aren't working with your new MySQL database you may have the same problem I just had. I created my database tables with the default MySQL storage engine (MyISAM), and guess what? MyISAM doesn't support transactions.

I got a really brutal looking error message from Spring and MySQL yesterday. I've been working on a Java-based web interface for Nagios for a client, and I ran into an error message that basically says "Cannot add or update a child row: a foreign key constraint fails". If you like ugly, gruesome error messages here is the full-blown error:

Summary: An Ant multiline text replacement example.

I'm working on a Java project where we recently started using the JNDI capabilities in Glassfish, but our development environment has been to use Tomcat as our application server (without JNDI lookups). To keep my Apache Ant build process working in both environments I quickly learned that I was going to need to perform multiline text replacements with Ant.

I don't know how TextMate decides where it's going to put the project drawer (the drawer that slides out when you open a directory or project instead of opening a file), but sometimes the drawer comes out on the left when I want it on the right, and other times it comes out on the right when I want it on the left.

Unfortunately it's not at all obvious how you're supposed to move the project drawer from one side to the other, but after digging through the help documentation I finally found it.

Slow Apple TimeCapsule backups: Two tips for increasing the speed of Apple TimeCapsule backups.

I've found the initial backup with the Mac Time Machine software and the Apple Time Capsule to be very slow, you might say "insanely slow". ;) I'm trying to perform the initial backup using a MacBook Pro over a Wireless-G network in my home network to a 500 GB Time Capsule that I just purchased, and it has been crawling along.