Scala, Java, Unix, MacOS tutorials (page 400)

Perl FAQ: How do I remove an item from a hash?

Answer: Use the Perl delete function.

The general syntax you need to use is shown here:

delete($hash_name{$key_name});

If you'd like more details and examples, read on...

Perl hash - remove/delete element example

Here's a complete example where I show both how to create and print a Perl hash, and then show how to remove elements from the hash using the Perl delete function:

Perl hash question: How do I print the elements stored in a hash in Perl?

Answer: There are at least two ways to print the elements of a Perl hash, including one way that I think is easy to remember, and another way that is recommended if you have a very large hash.

Perl hash printing with a foreach loop

The easier way for me to remember is with a Perl foreach loop. In the following sample code I'll first create a Perl hash, and then I'll print out each key and value stored in the hash:

Perl hash FAQ: How do I add an item/element to a Perl hash?

Answer: Adding an item to a Perl hash is just like creating a Perl hash initially. Just assign the new item to the hash with the correct syntax, and you're in business.

In the following sample code I show how this is done by creating a hash named prices. The hash key is the name of a product, like pizza, and the hash value is the price of that product. Here's my Perl hash sample code:

I was really surprised by the installation process of the Apple iPhone 2.1 software update. From my experience with Apple and Mac OS X, their installation process is usually extremely vague, essentially saying "There's an update for your software, and we recommend that you do this upgrade", and few other details are offered, even if you follow a URL they provide.

A lot of times when you're working on a Java web application you only need to deploy your JSP files. This happens, for instance, when you're just editing the JSP files to modify the look and feel of your web application. In cases like this there's no need to rebuild your entire application, deploy it, then restart your application server (Tomcat, Glassfish, JBoss, whatever).

Ant war task example: Here's another snippet of code from my most recent Ant build scripts. This example code shows how I use the Ant war task to create my war file:

Ant replace FAQ: Can you share some examples of the Ant replace task?

I've been sharing a lot of Ant tasks lately, and here's another example, this time some Ant replace task examples.

Ant replace task examples

The Ant build script lines shown below demonstrate how to issue a series of Ant replace commands to replace a token in the file with a variable you want to substitute for that token:

Java Ant build FAQ: Can you share some examples of the Ant copy task, i.e., the Ant copy task syntax?

Sure. I've shared quite a few Ant examples on the website now (just search the website for "Ant"), and here's another snippet of code from an Ant build script that shows how to use the Ant copy task.

As you can see from this sample code, I'm using the Ant copy task to copy files from source locations to other destination locations.

Summary: An Ant clean, prepare, and compile example.

I'm not going to discuss the following Ant build script code too much, but I thought I would share it here. In short, it shows how I declare several Ant tasks, including my typical clean, prepare, and compile tasks.

Summary: An Ant classpath example.

Here's a quick example showing how I typically build a variable to represent my classpath in an Ant build script.

Our Ant classpath example

This snippet of code below shows how I use the Ant fileset task to  create a variable named class.path by including all jar files from my lib directory using the pattern **/*.jar. This syntax can be read as "Include all files named *.jar in the lib directory and all of its sub-directories".

With a little down time this morning I thought I'd start a simple CVS command line reference page (cheat sheet). I've tried to include the most common CVS command line examples here.

If you ever need to load multiple Spring application context configuration files in a standalone Java application, here's some sample code that shows how to load them. In the following Java source code I load three Spring context/configuration files named dao1Context.xml, dao2Context.xml, and dao3Context.xml:

Here's the source code for a standalone Java application where I load a Spring application context file with the ClassPathXmlApplicationContext method. In other blogs I've shown how to load the application context for web applications, but I also wanted to show how to do this for a standalone program.

Here's a source code for my Java program that loads a Spring application context file from the typical main method:

Here's a Java class that I created today that creates constants for all the FTP server return codes listed on this Wikipedia page. If you ever start doing programming against a real FTP server, or perhaps a mock FTP server, you'll know what these FTP return codes are needed for.

Without any further delay, here's the Java source code for a class I've named FtpServerReturnCodes:

MySQL shell scripts and port FAQ: Can you share some MySQL examples that show how to start MySQL on a non-standard port (non default port)?

For a variety of reasons you may want or need to run your MySQL server on a different port than the default MySQL port of 3306. In those cases the easiest thing you can do is create a Unix/Linux shell script to start your MySQL server on some other port.

Wow, today I thought I was doing some good code cleanup, and in my nice, working application, I merged a couple of Spring application context files into one single application context file, and got this horrible-looking Spring "unsatisfied dependency" error message when trying to run my suite of unit tests:

Log4J exception FAQ: "How do I print the stack trace of an exception using Log4J or Commons Logging?"

Printing the stack trace of a Log4J exception seems to be something of a trick question. In reviewing Java code from different developers at different organizations I see a lot of people working very hard to print a stack trace using Log4J, including a lot of variations of calling e.printStackTrace() method. In this short tutorial I’ll show how to solve this problem.

I don't have my putty/ssh/Firefox tunnel tutorial in the new CMS here, so to help make sure people can easily find it, here's a link to a new tutorial I've created named "How to create an SSH tunnel using Putty, and then use that tunnel as a Firefox SOCKS proxy".

 

Here's a link to a new tutorial I've published titled "How to get Swing components to grow and fill using the JGoodies FormLayout".

While I'm in the neighborhood, here are a couple of quick links to go with that tutorial: