faq

Scala cookbook recipes

Wow, I began by writing a few Scala programming tutorials just because I like the language, and as I look here a couple of months later I now have more than sixty tutorials. As a result, I thought I'd start organizing them here in the form a Scala Programming Cookbook.

Here's my current collection of Scala FAQs and recipes, in a "cookbook" format.

A JButton tooltip example

Java/Swing FAQ: How do I set the help text (i.e., help text, balloon text, tooltip text) on a JButton?

Just call the setToolTipText method on the JButton. Here's a quick JButton tooltip display example:

// create a button with tooltip help text
JButton button = new JButton("Click Me");
button.setToolTipText("Click this button to make something happen.");

Is there a package manager for PHP?

PHP FAQ: Is there a package manager for PHP?

Answer: Yes, PEAR (the PHP Extension and Application Repository) is what you need. As the website describes it, "PEAR is a framework and distribution system for reusable PHP components."

Here's an example of how I used PEAR to install the HTTP_Request library, showing both what I typed, and the output from PEAR as it performed the installation.

MySQL: Default a field to the current date/time

MySQL date/time FAQ: How do I create a field in a MySQL database table that will default to the current date and time whenever a new record is inserted into my table?

Answer: Just define the field in your table as a timestamp field, and combine that with the default keyword and the MySQL now() function when you define this field in your database table.

The syntax for creating a MySQL timestamp field that defaults to the current date and time when creating a new database table looks like this:

How do I access a MySQL database with the MySQL command line client?

I may have shown this before in other ways, but I wanted to take a moment to show how to use a MySQL database from the MySQL command line client. The basic command to work with an existing database is the use command, where you say something like this:

mysql> use my_database

For instance, if you have a database named orders, you would declare that you want to start working with it (use it) like this:

MySQL FAQ: How do I show the fields or schema of a database table?

MySQL FAQ: How do I show the schema of a MySQL database table?

Answer: Use the desc command from the MySQL command line client.

For instance, in my current application I have a database table named orders, and when I need to see the schema for that table I show it with the desc command like this:

desc orders

The MySQL output looks like this:

How to open the Windows Explorer from WinCVS

A lot of times when I'm using WinCVS I also need to jump over to the Windows Explorer (the file explorer, not internet explorer, although of course they are kinda-sorta the same), so I thought I'd make a note here of how to do this.

Java FAQ: How to print system environment variables

Java FAQ: How do I print system environment variables from a Java application?

Here's a source code example that shows how to print system environment variables from a Java program:

Where is Perl looking for modules to include?

I started working on a new Unix system yesterday -- an HP-UX system I've never worked on before -- and I quickly realized that I needed some Perl modules installed. While working with another person the question quickly came up, "How do you know where Perl is looking for currently installed modules?"