Parsing ISO 8601 Date Format in Java

These are dates in a format like “2010-05-17T09:30:47-04:00″ optionally including date, time and time zone, which are commonly found in XML documents.

In .NET you can just use DateTime.Parse(), but in Java the answer is not as obvious.

Assuming that you are using the Apache libraries, the simplest approach is probably to just use org.apache.xmlbeans.XmlCalendar:

Calendar c = new XmlCalendar("2010-05-17T09:30:47-04:00");

If that isn’t an option, try this.

Solving Port Conflicts in Windows

Suppose that you start a server application like JBoss and get an error message like this one:

14:13:51,561 ERROR [AbstractKernelController] Error installing to Start: name=jboss.remoting:protocol=rmi,service=JMXConnectorServer state=Create mode=Manual requiredState=Installed

java.rmi.server.ExportException: Port already in use: 1090; nested exception is:
java.net.BindException: Address already in use: JVM_Bind

“Wait a minute,” you say, “That port should be free! Who’s using it?”

To find the answer, open a command window and type:

netstat -ab | findstr 1090

substituting the actual port number for “1090″. Under Windows 7 you will need to open the command window as an Administrator.

The netstat command will take a long time to run, but eventually it will give you the name and PID of the offending process. At that point you can decide whether to kill the offending process or make your application use a different port.

Facebook “Privacy”

More and more people are saying that you should log out of Facebook as soon as you are done. If you stay logged in and go to another site with which Facebook has an information-sharing agreement, Facebook will tell the other site all sorts of things about you that you thought were private. (You can “opt out” of this, but the procedure may be too complicated for most mortals.)

But have you noticed that Facebook is the only site on the Web that requires you to log in, but does not give you a simple one-click “Log Out” link on each page? What you have to do is first click “Account”, then click “Logout”, which is much less obvious.

Also: Five Hidden Dangers of Facebook.

FTC Blogging Guidelines

The new FTC blogging guidelines are supposedly intended to go after the big commercial astroturfing campaigns, where publicity agencies pay large number of bloggers and tweeters to push commercial products. However anyone who blogs or posts to social networks needs to be aware of the rules, since it would be pretty easy to run afoul of them.

This raises significant free-speech concerns. Jack Shafer in Slate has a pretty good run-down of the issues: The FTC’s Mad Power Grab.

The USA as a Third-World Country

In The Quiet Coup Simon Johnson, former chief economist for the International Monetary Fund (IMF), says that the current financial crisis resembles on a larger scale the sort of messes that emerging markets get into. He says that if we don’t want things to get worse we need to impose the kind of reforms that the IMF would demand of a small country that came to it for help.

Megan McArdle seems sympathetic to this notion, but in Foreigners + Money = Crisis? she points to claims that the IMF thoroughly botched its handling of the Asian financial crisis of 1998, which like the current crisis had a lot to do with countries being flooded with volitile foreign investment.

.NET Dictionary with Case-Insensitive Comparison

How do you create a IDictionary that does case-insensitive key matches. There are a number of solutions posted on the web, but none of them seem quite correct. The following should work.

IDictionary map = new Dictionary(new StringCompInsensitive());

where

public class StringCompInsensitive : IEqualityComparer
{
    public bool Equals(string x, string y)
    {
         return String.Compare(x, y, true) == 0;
    }

    public int GetHashCode(string obj)
    {
          return ((string)obj).ToLower().GetHashCode();
    }
}