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

CVS checkout FAQ: How do I get a snapshot of a CVS repository back to a certain date?

To solve your first problem, let's assume that yesterday was September 14, 2001, and your project name was KickStart. To check out the code from your KickStart repository from late last night, use this cvs checkout (cvs co) command:

"CVS tag" FAQ: How do I tag a release of a software project with CVS?

Assume that you have a software project named KickStart checked into a CVS repository. Further assume that you want to tag the current release of the project with the name "Release-2001_09_15". Here's how to tag that release with the "cvs tag" command:

Several times when working with CVS I've forgotten to check a binary file into CVS with the binary file flag. Fortunately this problem can be fixed using the cvs admin command. It's just important to remember that fixing this problem is a two-step operation.

CVS binary file FAQ - How do I add a binary file to a CVS repository?

Answer: You add a binary file to a CVS repository with the cvs add command, like this:

cvs add -kb myfile.zip

 

CVS remove FAQ - How do I move or rename a file that is checked into a CVS repository?

Good question. This is neither obvious or straightforward with CVS. It also requires administrator priviledge.

cvs remove example - how to move a file

To move a file that's checked into CVS and save it's revision history, do the following:

CVS FAQ - How do I go back to a previous version of a file?

Solution: What revision would you like to revert to?

Let's see ... I just messed up revision 1.25, so I would like to go back to version 1.24.

And what is the name of the file?

LoginController.java

Move to the directory where your file is located, then run this command:

JBuilder FAQ: Is there a way I can see the parameters a Java method expects?

Yes, assuming that your cursor is position right after the opn parenthesis, type this magic keystroke:

[Ctrl][Shift][H]

You will see a list of parameters that the method accepts, and it will not disappear right away.

How did you know that?

I found it one day in the JBuilder menu system. I also heard it at the Borland Developer Conference.

To browse a symbol when using JBuilder, you just need to use the magic keystroke: [Ctrl][Enter].

Java number formatting FAQ: How do I format numbers for output on reports in Java programs?

Generally speaking you want to use the Java NumberFormat class and its descendants, such as the Java DecimalFormat class.

Quoting the API documentation, the Java DecimalFormat class "also supports different kinds of numbers, including integers (123), fixed-point numbers (123.4), scientific notation (1.23E4), percentages (12%), and currency amounts ($123). All of these can be localized."

Java random numbers FAQ: How do I create random numbers in Java?

To create random numbers in a Java program, use the java.util.Random class.

As a simple example, this code generates a random number between 0 and 9:

Java Swing FAQ: How do I set my Java/Swing (GUI) application to use the default look and feel of the current system/platform?

In a Java / Swing application, to use the default look and feel of the current operating system (platform), first import the necessary class:

import javax.swing.UIManager;

Then use this code:

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

Java Swing FAQ: How do I set my Java look and feel to the "metal" look and feel?

To set your Java / Swing application to use the metal look and feel, first import the necessary classes:

import javax.swing.UIManager;
import javax.swing.plaf.metal.MetalLookAndFeel;

Then put this in your code:

UIManager.setLookAndFeel( new MetalLookAndFeel() );

Question: I don't like the default JBuilder keyboard key mappings -- can I change them?

When using JBuilder, you can set bookmarks in your open files to easily move back-and-forth between these files. For example, suppose you have five files open at one time, but for a little while you just want to move back and forth between File1.java and File2.java. Bookmarks let you do this. You set one bookmark in File1.java, and another bookmark in File2.java.

Because you set bookmarks at specific line numbers, you also go right back to the same line each time you move back and forth.

Okay, so how do I set a bookmark?

When you have more than one file open at a time with JBuilder, use the keystroke [Ctrl][F6] to move between your open files.

They have many different pages, but here is a high-level URL for Sun's online Java documentation.

Java PreparedStatement FAQ: Can you share an example of a Java PreparedStatement that executes a SQL INSERT query?

Yes ... I just realized I don't have a Java PreparedStatement INSERT example out here, so ... (searching, searching) ... here you go. Here's the source code for a Java/JDBC PreparedStatement "INSERT" query example:

Java/JDBC connection FAQ: How do I connect to a database using Java and JDBC?

Let's take a look at a JDBC database connection example. In this example I'll connect to a Postgresql database, but as you'll see from the code and other examples on this web site, the steps are always very similar.

A Java/JDBC Postgresql database connection example

To get a JDBC connection to a PostgreSQL database do this:

Java Date FAQ: Can you show me how to get today's date in Java?

Getting a Java Date object that represents "today" or "now" is fairly simple. The following sample code shows how to do this:

Date date = Calendar.getInstance().getTime();

If you haven't worked with the Java Date class before, I should point out that I'm referring to a java.util.Date class here, and not a java.sql.Date class. To make this a little more clear, I could write that same code like this:

Postgresql Backup FAQ: How do I create a backup of a Postgresql database?

Solution: I create a Postgresql backup (a Postgresql dump) for this website using the pg_dump command, like this:

pg_dump -h db_server -U db_user -W db_name > db.20070725.dump
Password:

With this Postgres / pg_dump command I'm doing the following: