Nov 16 2007

SQL Server Query Shortcuts

Sometime back I detailed the command to describe the details a database table for Microsoft SQL Server. To detail the a given database table you can use the sp_help command. If you don’t want to type sp_help every time you want to see the structure of a table you can use a query shortcut. Microsoft SQL Server Management Studio Express has a series of shortcuts, available under the Options | Options menu. You can add custom query shortcuts. The shortcut for sp_help is Alt + F1. Just select a table name and hit Alt + F1 to see the table details. If no table is selected you will get details on all the available tables.

SQL Server Query Shortcuts

Technorati Tags: , , , ,


Nov 16 2007

Developing Your Programmer’s Intuition

The other day I solved a bug. I didn’t think much of it. The bug basically manifested itself when the user search for data but none was returned. We write an ‘enterprise-grade’ software application, so there is a lot of code and tiers between clicking the search button and displaying the data in the client. But in thinking about this bug I had pin pointed only a few methods in a few classes. The problem ended up being that in the database there was a value that was padded with an extra white space and one of the SQL queries used returned an empty set. I didn’t think much about the fix to the bug, but when I described the problem and solution to my coworker he said, ‘How did you know there was an extra whitespace? I would never have thought of that, you can’t tell if there is a white space by just doing a select.”

I think that as software programmers, we do develop of certain intuition that allows us to better understand software. This code sixth sense aids us in debugging, problem solving, and trouble shooting your own code, as well as third party applications. After seeing soo many null pointer and cast class exceptions, you develop a noise for sniffing out smelly code.

Here are a short list of root causes for stupid bugs I have encountered. I have seen bugs in hash maps because the key is case sensitive. I have seen a lot of problem when trying to parse a file extension type and someone uses the String’s indexOf (use lastIndexOf instead). You are comparing the equality of a string against a string literal, code defensively to avoid null pointer exceptions (“LITERAL”.equals(stringVariable)). Encapsulation means nothing if you provide a public getter and setter for every field for every class. Code against interfaces. Objects that are are globally cached should be immutable. Runaway memory leaks are caused by maps that cache large objects that are not removed. In batch files, you need to quote paths if they have spaces.

If you are a novice programmer you can read into smelly code and try to write effective code to develop your programmer’s intuition. Programmer’s intuition is developed through experience.

Technorati Tags: , , , , ,


Nov 13 2007

Java Outlook Connector 2.0 Review

If you work with Java and need to access meetings, contacts, emails, etc from the users Outlook, you could have done it using Groovy and Scriptom. But to write Java code, instead of Groovy code, you can use Java Outlook Connector (JOC) from Moyosoft. JOC is basically a wrapper to COM for accessing Outlook. Once you have added JOC to your project and you have imported the JOC classes you can write code to read and write data to outlook. Here an example that reads your contacts and prints out the full name and company name for each contact…

[source:java]
// Get Outlook Application
Outlook outlook = new Outlook();

// Find default Contact folder
OutlookFolder contactFolder = outlook.getDefaultFolder(FolderType.CONTACTS);

// Iterate over the contact items in the default contact folder
for(ItemsIterator j = contactFolder.getItems().iterator(); j.hasNext(); ) {
OutlookItem item = (OutlookItem)j.next();
// Verify that the item is a contact
if(item.getType().isContact()) {
OutlookContact contact = (OutlookContact)item;
// Print some contact info
System.out.println(“Full Name; “+contact.getFullName());
System.out.println(“Company; “+contact.getCompanyName());
}
}

// Get contact subfolders
FoldersCollection contactFolders = contactFolder.getFolders();
for(FoldersIterator i = contactFolders.iterator(); i.hasNext(); ) {
OutlookFolder folder = (OutlookFolder)i.next();

for(ItemsIterator j = folder.getItems().iterator(); j.hasNext(); ) {
OutlookItem item = (OutlookItem)j.next();
if(item.getType().isContact()) {
OutlookContact contact = (OutlookContact)item;
// Print contact info
System.out.println(“Full Name; “+contact.getFullName());
System.out.println(“Company; “+contact.getCompanyName());
}
}
}

// Dispose the library
outlook.dispose();
[/source]

Here is another example that lists all folders (contact, meetings, inbox, etc) from Outlook in a neatly indented format. In this example I will create a function which will call itself recursively for subfolders.

[source:java]
public static void searchFolders(FoldersCollection folders, String indent) {
// Iterate over outlook foldres
for (FoldersIterator fi = folders.iterator(); fi.hasNext();) {
OutlookFolder folder = (OutlookFolder)fi.next();
// Print the folder name
System.out.println(indent+”Folder Name; “+folder.getName());
// Recursively search subfolders
searchFolders(folder.getFolders(), indent + ” “);
}
}
[/source]

To invoke the searchFolders method to actually print out all the folders in Outlook, I would use code like the following.

[source:java]
// Get Outlook Application
Outlook outlook = new Outlook();
searchFolders(outlook.getFolders(), “”);
// Dispose the library
outlook.dispose();
[/source]

Again, for the above example to work you need to add the joc and moyocore jars to your project. Once these jars have been added you can import them. All the code in these examples throw exceptions which has been omitted to keep the samples simple.

Java Outlook Connector has support for Outlook notes, meetings, mails, contacts and more. If you are a Java developer that has to write software solutions that integrate with Outlook, you might already have discovered the usefulness of Java Outlook Connector.

Technorati Tags: , , , , , ,


Nov 11 2007

2008 JavaOne Call for Papers

If you ever wanted to be a speaker at JavaOne, you have until November 16 to submit your proposal for technical or Birds of a Feather sessions. Last year a big theme was Java scripting with Groovy and JRuby and I expect this to be a hot topic at the JavaOne 2008. I also think that there is enough interest that some technical sessions will be devoted to Scala. Web frameworks that depended on these programming languages, such as JRuby on Rails, Grails, and Lift, would be great Bird of a Feathers sessions.

At JavaOne 2007, some popular sessions where those that pimped out business application GUIs, such as the Filthy-Rich Clients talks by Chet Haase and Romain Guy. Anything session talk that promises to jazz up an application UI will definitely be well received. Last year, Sun made a big splash by announcing JavaFX Script and I am sure there will be a lot of interest on this technology at JavaOne 2008.

If you think you can give a talk on any of these topics, you have until November 16 to submit your proposal. Good luck and see you there at JavaOne 2008!!

Technorati Tags: , ,


Nov 5 2007

The Programmer’s Text Editor

Software programmers love things that are free, such as free and open source software and freeware. Developers also love their text editors. Over my development experience I have used a ton of editors. As a programmer I like an editor with code and syntax highlighting, code folding, tabs, and all the bells and whistles.

Here are the top text editors that I use, in no particular order. All of the text editors listed below are installed in my home and development machines.

  • jEdit – The primer Java-based editor.
  • Vim – Vi Improved.
  • Scintilla SciTE – My Windows-based editor of choice.
  • Notepad++ – Free source code editor and Notepad replacement, based on Scintilla.
  • Notepad 2 – Also based on Scintilla.
  • Komodo Edit – Free editor based on Komodo IDE. Komodo Edit has a nice FireFox extension project support.
  • Jext – Free source code editor written in Java.
  • ConTEXT – ConTEXT is a small, fast and powerful freeware text editor.
  • TextWrangler – My favorite general purpose text editor for Mac.

Even though they are not free, there are some great commercial text editors too. Many Rails enthusiasts use TextMate on OS X. I also seen a lot of programmers use UltraEdit.

If I missed your favorite text editor, feel free to tell me about it in the comments. I’m always open to try a new editor out.

Technorati Tags: , , , , , ,


Nov 4 2007

Mac OS X Boot Camp

Boot Camp allows you to run Microsoft Windows on your Mac, natively just as you would on any laptop from Dell or HP. In essence, boot camp allows you to start and run either OS X or Windows on your Apple hardware.

Boot Camp is easy to set up and configure and perhaps that is why I was unable to find any tutorials or instructions on how to set it up, so that is why I am writing this post.

Before you begin, I would recommend you back your data.

If you are using Mac OS X Leopard, just launch Boot Camp Assistant located under the Applications | Utilities folder. Select ‘Create or remove a Windows partition’ to create a separate disk partition to install Windows on. Select the size for the Windows partition.

Once you have created the partition, you can insert an ‘authentic’ Windows installation CD and restart your system. You should use Windows XP with SP2 or Windows Vista. When your computer restarts, it will ask to load from the CD which takes you through the Windows installation process. Before the installation can begin, you will be prompted to select the partition to install Windows to, select the partition with BOOT CAMP in the name. Be careful not to delete or install over you Mac OS X partition.

Once you have installed Windows, insert your OS X Leopard installation CD to install the required drivers for your Apple hardware. At this point, you should have both Windows and Mac OS X installed on your Mac. To switch from one operating system to another, restart you computer and hold down the Option key. Holding down the Option key will allow you to choose which system to start. If you don’t hold down the Option key you will boot using the default system.

It is also a good idea to update your Windows installation with the latest security patches. After I installed Windows I had to restart Windows twice; once to get 86 patches including IE 7, and the second time to get additional patches for IE 7. I’ve discovered that Windows security is an oxymoron!

To change the default operating system which your computer boots from, you can use the Startup Disk application found under the System Preference in Mac OS X. In Windows launch the Boot Camp application in the Control Panel and select the default system on the Startup Disk tab.

It is great that I can boot either OS X or Windows on my Mac, but I would prefer if Apple would provide the same level of Boot Camp support for Ubuntu!

Technorati Tags: , , , , ,