From my colleague I received an email but with unknown type : winmail.datHe should send me office document.I asked him to sent it again, he forwarded the email again but I still received winmail.dat in attachment.

After googling about this I found out that winmail.dat is generated by Outlook (I using thunderbird).From About.com :

It’s Outlook’s fault, in a way. Or the recipient’s email client’s. If Outlook sends a message using the RTF format (which is not very common outside Outlook) for bold text and other text enhancements, it includes the formatting commands in the winmail.dat file. Receiving email clients that do not understand the code therein display it as a stale attachment. To make matters worse, Outlook may also pack other, regular file attachments in the winmail.dat file.

Fortunately, you can get rid of winmail.dat altogether by making sure Outlook does not even try to send mail using RTF.

And there’s also a way to disable this feature on Outlook. You can open it for more detail.I would focus on how non-Outlook user can handle this format.I know I can not ask all Outlook user who sent me attachment to turn off this feature.

So I search a program to open this content type “application/ms-tnef”.I encounter this good console program : WMdecodeYou just need to extract this. When running the program it’ll search winmail.dat in current folder and extract it.The program working great although it just console application, no GUI.

Other tool I search is add on for Thunderbird.I found : LookOutThis add on will automatically decode the winmail.datAlso working great but it won’t decode winmail.dat in emails that you received before installing the add-on.So I think it’ll only decode winmail.dat on new email received.

Often we want to make sure that only 1 instance our application running.
Because something terrible could happen when more than 1 instance running (for example the whole server would exploded and that would make you fired 😉 )

Nevertheless what the reason, one of the way to make this happen is by creating a lock file as a sign that an instance is currently running.
So you application will have this flow:

Check if the lock file exists.

Try to delete the lock file to check if there’s really a running process lock the file.

Get the file lock.

If failed to get the lock file, show error that there’s already an instance running –&amp;amp;amp;amp;amp;amp;gt; the end

If successfully get the lock then go on with your application want to do.

When application ended/closed release the lock and delete the file lock.

Microsoft planning to buy Yahoo for $44.6 billion. Until now Yahoo hasn’t give final answer it.
I’m wondering why do Microsoft want to buy Yahoo, is it for fighting Google?
Or Microsoft just want to kill one of his rival.

Okay, finally you decide it’s time to create a unit testing for your project (after a long ad hoc programming life :p).
When you create a sample unit testing, it’s all seem so simple.. you fascinate by the junit easiness, how it can do reflection and make it simple.

When you want to create a real unit testing for your project, you realize that a ‘real’ method is not like just adding 2 int argument and return a result. It’s more complex and using interface as parameter is common…
Now a thought cross your mind “do I have to create all stupid classes to implement all the interface I need?”, you starting to think that creating unit testing is really waste of time & you don’t want to do it anymore :p

It’s time mock object framework come to rescue… before you fall to the darkness of untested code 🙂
There’re several mock object framework like jMock, easymock, etc

This sample will create an instance of HttpMethod (which is an interface) and when this mock object’s ‘getResponseBodyAsString’ method called it’ll return “sample response”.
So now we can easily create all interface implementation we need.Of course there’re more in jMock than just this simple feature, check it more at jMock Cookbook

There are cases where we need to add classpath at runtime. For example adding jar to classpath, but depends on configuration or some logic at runtime.

The class who responsible for handling classpath list is URLClassloader.
You can get current system URLClassLoader with:
URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();

If you check javadoc about this class you’ll see:

protected void addURL(URL url)
Appends the specified URL to the list of URLs to search for classes and resources.

So you’ll just need to call the addUrl method to add new path/jar file.
But wait a minute, the method is protected… 😦 do I need to create a subclass or put the caller class on same package?
Creating a subclass is one way to do it, but there’s simpler way (I’ll create article about creating URLClassLoader subclass next time :p)

Here come the savior : Reflection
By using reflection we can break OOP concept about encapsulating method. It’s feel good to break the rules right (warning : use this at your own risk, you know you’re breaking the OO rule. So I won’t responsible if your computer explode or you’ll fighting with OO fans because of this)

But the editor showing error on ‘ConfigurationException ex’ saying that ConfigurationException is not subclass of Throwable Class (I’ve upload the screenshot)

When I try to build it’s showing different error “class file for org.apache.commons.lang.exception.NestableException not found”

It’s look like Apache Common Configuration is using Apache Common Lang library (I also look to the source-code ‘ConfigurationException extends NestableException’). Error when compile showing me more help than error in editor.

So I create a library name ‘Apache_Common_Lang’ and add commons-lang-2.3.jar to that library

After add the library the editor still showing the same error : “ConfigurationException is not subclass of Throwable Class”

But when I run build, it run successful . No error at all. (Now I confused)

It’s look like there’s a bug in the Editor. And that red line & error icon in project window really bugging me, although I know it’s the editor bug not my code error.

So to make this ‘red-line’ disappeared, I combined commons-configuration-1.5.jar & commons-lang-2.3.jar into 1 jar file. And set a library to this jar (instead using 2 library or 2 jar file).

A friend who is using Netbeans 6 ask how to configure Netbeans so it’ll open his start.tml as an html file not just as ordinary text file (So the editor will full with color I assume, not just black text :p)

I didn’t asked him why the hell he using .tml not just .html 🙂 but I tell him that he can configure Netbeans 6 with: