Javac, UTF8, BOM and Notepad2
May 13, 2011 Leave a comment
Sometimes I loose all my faith in this world. And people, and direction of progress and all. For instance when we discuss browser compatibility – that’s the most obvious case. I started my Java career in 2000, but of course I had some HTML experience from before. Based on all the inter-browser mess and also on poor capabilities of HTML/HTTP when you wanted to deliver proper web-application I told to myself quite early: “There must be some other way, some better protocol, sooner or later, something that can push as well, etc.” That was ten years ago.
And we all know where we are now. Maybe, just maybe HTML5 will push things somehow and browsers will converge a bit – I don’t expect complete compatibility anytime soon. Just maybe.
Today my colleague committed a few Java files that couldn’t be compiled because of the compiler error:
illegal character: \65279
I quickly found out about UTF-8 and BOM (more here), there is even bug related to this – it’s funny to read ironic comments about “bug compatibility” too. After more searching I decided that our sources must not have BOM, even though that it seems it could be there (by Unicode specification) and I’d expect javac to compile it all. My colleagues compiler even did it (maybe some Jikes in Eclipse or what, not sure), but other colleagues experienced “my problem” too. BOM itself was probably introduced by some clever editor.
Now how to get rid of it easily – it was only in 5 files, some hexa editor would help. It has been some time since I installed Notepad2 on my system. Well, installed… I replaced original notepad.exe by this one. This way Total Commander opens it without any setup. Notepad2 doesn’t have hexa editor, that’s true, but I noticed that it shows “UTF-8 Signature” in status bar. So I clicked there, changed it to “Unicode (UTF-8)” (without Signature) – and that was it!
Now – Notepad2 is far from the only solution here, but I mentioned it because it was a nice surprise how easy and straightforward it was and because it’s just so lovely Notepad, that I really recommend anyone to remove original notepad.exe (quite a pain with all the needed permission messing) and install this one. It’s not replacement for your Crimson or PSPad or whatever, but whenever Windows tries to show you true power of its default Notepad, you’ll be glad you followed my advice. Trust me.
And seeing things like Notepad2, things that are simple and really work, I often find my positive way again and my faith is restored and I can go on to another endless battle with yet another technological stupidity. May that force be with you as well.