Latest Publications

Technorati Formality

I just claimed my blog on Technorati.com – and they want me to put up a link to my profile on their website on my blog.

So here it is Technorati Profile

Reflection with Java

During my recent clean-my-hard-drive-of-all-obsolete-files spree I discovered a small article I had written about RTTI (Run Time Type Identification) in Java. Instead of pasting everything on the blog (and risk destroying the formatting) I decided to export it as a PDF file so that you can download it here.

Despite me not having edited the file at all after JDK 1.5 it should mostly be relevant.

Setting Pixels in Swing

Some time back I faced a problem in a (Java based) project on which I am still working on – I needed a swing component which would have a suitable interface allowing me to set the color of individual pixels. Since I could not find anything which had a similar functionality I extended javax.swing.JPanel and created a component of my own. Check it out here [test code included].

Blogging about Logging

I recently discovered a really nice package in Java – java.util.logging. Classes inside this package make adding logging functionality to your application both intuitively simple and fun. Here what I would like to think to be a short guide to using the package.

The very first thing you need to understand that there may be multiple loggers active in a Java application at a given time. Each such logger has a name associated with it. The names are hierarchical – you have the concept of a logged being the sibling or the parent of another logger. We will come to how that exactly works in a minute. Every logger has one or more handlers associated with it. It is these handlers which decide what exactly happens when you log a message (for example the handler may write to a file or print the messages out to the PrintStream). By default a logger also uses the handlers registered with its parents, recursively. You can change this behavior if you want to.

A global namespace is maintained containing the names of all the loggers. The logger names follow a dot-separated convention, somewhat like the one followed by the Java packaging system. This means that “parent.someChild” is a child of “parent” while “parent.someChild.someGrandChild” is a child of “parent.someChild“. “parent.sister” and “parent.brother” are siblings. “” is the root – the parent of each and every logger, either directly or indirectly.

Every logger has a Level associated with it – the minimum required urgency of a message for it to actually get logged. Similarly every log you make also have an associated Level, underlining the measure of its urgency. For instance if you wish your logger to log only the very critical messages you may set the level of the logger to Level.SEVERE or to Level.WARNING. There are other levels too, like Level.FINE and Level.INFO. You may set the level of a logger to Level.ALL or to Level.OFF to log all messages or no messages at all respectively.

The best part about the system is that you do not need to pass around objects – since there is a one to one mapping from the logger names to logger objects in global namespace, you can simply pull out the Logger associated with a name using Logger.getLogger (String name). The first call to Logger.getLogger ("mylogger") will create a new logger and return it while subsequent calls will simply return the previously constructed Logger instance.

So if you need to log from within your application you basically create Logger instances from inside each module you wish to log somewhat like Logger theLogger = Logger.getLogger ("myproject.thisModule"). Now you can use this object in your code – theLogger.warning ("Something happened"). In the application initialization code you have the liberty of setting the Levels of each logger to control what all information gets logged. You also have the freedom to write custom Filters using which you can control exactly what all is logged.

The world of a Hacker

I read this piece somewhere … It was written back in 1986; by someone named ‘The Mentor’

Another one got caught today, it’s all over the papers. “Teenager Arrested in Computer Crime Scandal”, “Hacker Arrested after Bank Tampering”…

Dang kids. They’re all alike.

But did you, in your three-piece psychology and 1950’s technobrain, ever take a look behind the eyes of the hacker? Did you ever wonder what made him tick, what forces shaped him, what may have molded him?

I am a hacker, enter my world…

Mine is a world that begins with school… I’m smarter than most of the other kids, this crud they teach us bores me…

Dang underachiever. They’re all alike.

I’m in junior high or high school. I’ve listened to teachers explain forthe fifteenth time how to reduce a fraction. I understand it. “No, Ms. Smith, I didn’t show my work. I did it in my head…”

Dang kid. Probably copied it. They’re all alike.

I made a discovery today. I found a computer. Wait a second, this is cool. It does what I want it to. If it makes a mistake, it’s because I screwed it up. Not because it doesn’t like me…

Or feels threatened by me…

Or thinks I’m a smart aleck…

Or doesn’t like teaching and shouldn’t be here…

Dang kid. All he does is play games. They’re all alike.

And then it happened… a door opened to a world… rushing through the phone line like heroin through an addict’s veins, an electronic pulse is sent out, a refuge from the day-to-day incompetencies is sought… a board is found.

“This is it… this is where I belong…”

I know everyone here… even if I’ve never met them, never talked to them, may never hear from them again… I know you all…

Dang kid. Tying up the phone line again. They’re all alike…

You bet your life we’re all alike… we’ve been spoon-fed baby food at school when we hungered for steak… the bits of meat that you did let slip through were pre-chewed and tasteless. We’ve been dominated by sadists, or ignored by the apathetic. The few that had something to teach found us willing pupils, but those few are like drops of water in the desert.

This is our world now… the world of the electron and the switch, the beauty of the baud. We make use of a service already existing without paying for what could be dirt-cheap if it wasn’t run by profiteering gluttons, and you callus criminals. We explore… and you call us criminals. We seek after knowledge… and you call us criminals. We exist without skin color, without nationality, without religious bias… and you call us criminals. You build atomic bombs, you wage wars, you murder, cheat, and lie to us and try to make us believe it’s for our own good, yet we’re the criminals.

Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for.

I am a hacker, and this is my manifesto. You may stop this individual, but you can’t stop us all… after all, we’re all alike.

Arch Linux – Chiselled to Perfection

I have been using GNU / Linux for about five years; regularly for a year and exclusively for about six months. Over these years I have used Mandriva, Ubuntu, openSUSE, Fedora, SLAX and one or two distros whose names I do not remember. Yet I found each of these distros lacking in something or the other. Mandriva is buggy, Fedora is slow and buggy, SLAX is unstable and openSUSE is slow (though not as buggy). Even though Ubuntu was (is) the most intuitive distro in the list there are certain things even Ubuntu lacks (!). In an attempt to offer ease of use it lacks many qualities prized by the average GNU / Linux geek. It was on one such night of frustration I discovered Arch Linux.

It would a slight misnomer to call Arch Linux a complete distribution; especially on the face of what you get after a full install. A full install entitles you to a basic kernel installation (with the required modules), bash and some ‘optional’ command line utilities like ‘make’ and ‘cc’. After that you are on your own. It does have a (very fast) package manager named ‘pacman’ and the package update process is automated (you need to type something like … say … ‘pacman -S maxima’) which is a relief. Since almost nothing is installed by default you can ensure that your installation contains only those packages you need. Even the main installation procedure involves some hand-editing of files like rc.conf. Some people may find this to be a pain; I on the other hand quite enjoyed the experience. What I like about Arch Linux that it itself does not assume anything about what you intend to use it for – Arch Linux is what you make it.

One thing I noticed about Arch Linux is that is well equipped with all the development packages (am talking about a base install). Compiling VLC on Ubuntu has always been a huge pain in the neck (censored) – you need to install loads of stuff like sqlite3-dev (apparently sqlite0-dev or sqlite3 will not do) and packages which are not there in the repositories and need to be hand-compiled (and then you have their dependencies) etc. but VLC compiled like a charm on Arch Linux.

Let me be clear – Arch Linux is not for the faint hearted or for those who do not know what nano is or how to set up alsa. I have always supported Ubuntu and still do; it is just that once you feel the need to progress beyond ’sudo apt-get’ do give Arch Linux a try. To customize your distro beyond Arch Linux you will have to create your own from scratch.