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

I'm probably goofing around a little too much today, but I just created an Apple/Mac landing page on the site. I'm not going to link up to it just yet (other than this post) but I thought I'd experiment using a black background with similar structure and content.

I won't tell you how long ago I started it, but I've (finally) posted a new tutorial "Mac Podcast - How to Create a Podcast on the Mac with GarageBand". I'm looking forward to writing more, longer tutorials like this now that I have a little bit of a system set up. I hope you like it.

Hmm, more rumors that Google may come out with their own browser. There's nothing to be seen at Gbrowser.com right now, but maybe some day.

Working on my Mac OS X system, when I use the ls command on a remote system, that system is configured to show blinking text for all files ending with the ".sh" filename extension. If you've ever had to look at blinking text when trying to read output from an ls command you know that can be really annoying. (Is there ever a time that blinking text isn't annoying?)

So, to disable blinking text in the Mac OS X Terminal application just follow these steps:

Mac DVD burn FAQ: How do I burn a CD or DVD on a Mac? (iMac, MacBook, Mac Pro, etc.)

It's funny, I've had a MacBook Pro for well over a year now, but haven't burned a CD or DVD until today. I actually didn't know how to do it, so I just inserted a blank DVD-R into the drive and then figured out what to do. Here's a quick summary of the "Mac CD/DVD burn" steps I followed.

Working on a Unix system, I just needed to reverse the contents of a file, and thought I'd show how I ended up doing it.

My file-reversal needs

For my situation I needed to (a) get 10 lines from the end of a file, (b) reverse those ten lines, and (c) save them to another file. If my Unix system supported the -r option of the tail command this would have been a no-brainer, but it didn't, so I had to work a little harder.

After a few requests/suggestions I've added digg links to the blog pages. So, if they all say "0 diggs", hey, it's a new feature. :)

The Linux tar command is used to created and extract archives. An archive is one file that contains one or (usually) many other files. The name "tar" itself comes from the phrase "tape archive", but that's just an old name. I mostly just create archives and then send them over the wire these days.

Creating Unix/Linux tar archives

To create an archive of all files in your current directory, and all subdirectories, use this tar command:

The other day, when I was trying to compile all the Tame Swing examples, I had a problem running one of the examples. The problem was that I was running the example in Eclipse, and I was getting an error message showing the Eclipse (the JVM really) couldn't find the icon image files.

Linux/Unix more command FAQ: Can you share some Linux more command examples?

The Unix/Linux more command lets you scroll through large files, or large amounts of output from other commands.

Linux more command examples

To scroll through the contents of a large file named "large_file" you can use the Unix more command like this:

more large_file

As a quick aside, I see a lot of people use the Linux cat command and more commands this way:

The Linux locate command lets you easily find files in the filesystem. It works by maintaining a system-wide database of "all files which are publicly accessible". The database itself is updated periodically by a background process. Because of this approach it returns results much faster than the find command, which only looks for files when you tell it to. Depending on your system, the locate command may need to be configured initially, or it may be pre-configured to work out of the box.

As its name implies, the Linux mkdir ("make directory") command lets you create new directories.

Creating a new directory in your current directory is very simple. In our first mkdir example, we'll show how to create a new directory named "dir1":

mkdir dir1

If you want to create several directories at one time you can use a mkdir command like this:

Linux head/tail FAQ: Can you share some examples of the Linux head and tail commands?

Sure. The Linux head and tail commands are very similar, so I've included them here together. The head command command prints lines from the beginning of a file (the head), and the tail command prints lines from the end of files. There's one very cool extra thing you can do with the tail command, and I'll show that in the tail example commands below.

The Linux cat command means "concatenate and print files". Usually all I use it for is to display a file's contents, like this command that displays the contents of a file named "lighten-images.sh":

Whew, getting all the images together for the Tame Swing sample applications is taking a little time and a lot of effort. I hadn't thought about how to organize it, and now that I have a better feel for what I want to do it's just a matter of time.

If you want to see the images of the running applications I do have them on a temporary page here. Please note that this page may change at any time.

Question: How do I convert a String to a double with Java?

Answer: Converting a String to a double requires that you first convert the String to a Double object, then convert the Double object to a double data type (Double is an object, while double is a primitive data type).

Here's the source code for an example Java program that performs this conversion:

Java file writing FAQ: How do I append text to the end of a text file in Java?

The short answer is that you should create a FileWriter instance with the append flag set to true, like this:

BufferedWriter bw = new BufferedWriter(new FileWriter("checkbook.dat", true));

The rest of this article explains this.

Java String/float FAQ: How do I convert a Java String to a float?

Converting a String to a float requires that you first convert the String to a Float object, then convert the Float object to a float data type (Float is an object, while float is a primitive data type).

An example of a simple program that performs this conversion is shown below:

Question: How do I convert a String to a long with Java?

Answer: The Long class includes a method named parseLong() that serves just this purpose. An example of a simple program that performs this conversion is shown below:

As I note here I just uploaded the Tame Swing examples to the web site. Please read that post for more information.