Archive for September 2007

date puzzler explained

September 15, 2007

As someone pointed out the unexpected behavior really is coming from the parse method. Looking in the JavaDocs the behavior is likely coming from the DateFormat class:

By default, parsing is lenient: If the input is not in the form used by this object’s format method but can still be parsed as a date, then the parse succeeds. Clients may insist on strict adherence to the format by calling setLenient(false).

Although this isn’t specific, it may mean it will interpolate dates when the range falls outside of the correct value. Perhaps there is more detailed documentation, but this is all I found without being overly exhaustive about it. So beware if you are expecting parse() to perform strict date format checking for you. I have also found DateValidator() in Commons Validator to be useful in examining date formats.

a Java puzzler

September 14, 2007

I’m a fan of Java Puzzlers and came across this one on my own. Perhaps it has been brought up before though. What happens when you run this program? Hopefully I can explain the answer by tomorrow!

public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
Date d = sdf.parse("1957-02-29");
System.out.println("success: " + d.toString());
} catch (ParseException e) {
e.printStackTrace();
}
}

summer photos

September 9, 2007

Now that summer is winding down a bit, I thought I would go back through a few of my photos and link to them here.




Groovy and Google Notebook

September 8, 2007

I started learning Groovy in the past few days. So far I am wondering why I waited so long to start learning it. I like the shorthand style and the ability to get tasks that are a pain in Java done quickly. These are obvious things to like certainly since they are objectives of the language.

Anyhow, I needed something to do with the language so I chose to write a simple script to download a list of public notebooks from Google Notebook and then process the first one in the list. Here are some observations on the process.

  • It was not immediately obvious to me how to obtain my Google userid that the documentation mentions. I discovered after a bit of frustration that it is a large numeric value that is passed no the query string and is not the userid that one logs in with. This didn’t jump out at me from the documentation.
  • I used Eclipse to write my script and boy did I miss several things that the plugin lacks: code auto formatting and a debugger. Even though the script I wrote is trivial a debugger would be a nice tool in learning Groovy. Maybe one of the other IDE’s has one for Groovy?
  • Groovy still awkward to me after living the structurd life of a Java programmer for so many years. The corner-cutting takes some getting used to. The missing ;’s can feel like nails on a chalkbaord.

  • import com.google.gdata.client.*;
    import com.google.gdata.data.*;
    def myId = 'big number from google url'
    def urlUser = "http://www.google.com/notebook/feeds/$myId"
    URL feedUrl = new URL(urlUser);


    GoogleService googleService = new GoogleService("notebook", "alex sample");

    /**
    * request the feed
    */
    Feed myFeed = googleService.getFeed(feedUrl, Feed.class);

    print 'notebook name: '
    println myFeed.title.plainText;

    List l = myFeed.entries;

    println "public notebook's: "
    for (Entry e in l) {

    print e.title.plainText;

    URL notebookUrl = new URL(e.id)

    Feed notebookFeed = googleService.getFeed(notebookUrl, Feed.class);
    /* process the feed */

    }

    The Windows SDK

    September 7, 2007

    I was reflecting recently on what it was like during my first few weeks as a professional software developer just out of college. My first job out of college was for a small consulting firm that specialized in writing custom Microsoft Windows programs in C. This was 16 bit Windows 3.1. One way that I went about getting acquainted with Windows programming was to take home the SDK programmers reference and read the API from a to z. This actually proved to be beneficial as horrible as it may actually sound. I believe I got through the API’s in about one weekend of casual reading. Who can forget CreateWindowEx()?

    HWND CreateWindowEx(
    DWORD dwExStyle,
    LPCTSTR lpClassName,
    LPCTSTR lpWindowName,
    DWORD dwStyle,
    int x,
    int y,
    int nWidth,
    int nHeight,
    HWND hWndParent,
    HMENU hMenu,
    HINSTANCE hInstance,
    LPVOID lpParam
    );

    Shortly after this a lot of Windows programmers, myself included, went through a transition period as a C++ compiler and MFC was made available from Microsoft. What a wonderful idea it was and once again the power of abstraction in computer science came to the rescue to hide the gory details. At the time, MFC was a wonderful thing.

    Bringing this to today’s environment, one could not reasonably read through all of the JDK in a weekend I don’t believe. It would be a task more painful than reading through the Windows SDK for me. The breadth of the entire programming environment for Java is formidable if you attempt to survey the entire landscape. We have abstractions built upon abstractions. Entire frameworks get raised up to correct shortcomings in the JDK, or in the best cases provide abstractions that may have had little value when the JDK was first designed.

    I think much of our progression has come from the power of the Internet as a collaboration tool. When I took up Windows programming the only sharing of ideas and issues came from around the office. The notion of using the Internet as a learning or collaboration medium for professional developers, at least for me, didn’t really exist at the corporate level. Collaboration is a wonderful thing.

    As an exercise, it would be quite funny to re-create the typical 16 bit Windows development environment and attempt to write some small application that by today’s standards might be quite trivial. I would venture to guess that using the 16 bit Windows SDK to send and receive an XML request over HTTP would be a challenge. Recreating the environment alone would take time. Anyone still have a copy of Brief for DOS?