Sunday, July 23, 2006

Java Weekend


The secret's already been partially out that I'm attempting to return to school to study Computer Science. Part of the requirements for the school I'm trying to attend is a program of some sort written in Java along with a personal statement. I submitted a ported variation of a program I wrote a while back in C# as a response to this blog entry. My program applies a Haar transform on an image file.

It's been a while since I've used Java. I downloaded and used Eclipse as my IDE, and that was a great experience - I'm curious to know if the GUI development parts of Eclipse are well developed.

Working in Java, after all this time in C#, was a bit strange. There are the small arbitrary things, like camelCase for methods rather than PascalCase, and then there are the bigger things, like doing type conversion (in .NET I just use Convert.ToXXYYZZ (e.g. Convert.ToInt32, Convert.ToDouble, and so on... )), and then there are the massive things like trying to emit an image file to disk. In C# this is very trivial. In Java, it's painful enough that doing a search on Google will yield all kinds of Bitmap implementations that people have written to make up for a lack of support in the language.

Speaking of which, the program took about 2 hours to port but for these lines:

File output = new File(filePath);
ImageIO.write(myBufferedImage,"bmp", output);

The kept succeeding only in writing an empty bmp file. I didn't stop to figure out the debugger in Eclipse (wouldn't have mattered if I did), but couldn't for the life of me get to the root of the issue.

I used to think Javadoc comments were such a beautiful thing until I began searching Google for ImageIO.write examples. Apparently everyone has taken it upon themselves to have a copy of the Javadoc online with redundant information. And the Javadoc itself has no clear information about the method either, especially for cases like mine where it succeeds, over and over again, at creating nothing. (Why not use an enumerated type for the format parameter of the write method if it's going to be limited?)

After a few hours I'm at the video game point of debugging (just trying different things) and ran it with the following:

File output = new File(filePath);
ImageIO.write(myBufferedImage,"jpg", output);

Lo and behold, a file is created on my machine. And it sort of clears up for me that the write method's format is limited out of the box ( I think, but did not confirm) to jpg / gif / png formats. I'm guessing at a disdain for "bmp" as a Windows specific format or something of that nature pushing ImageIO to exclude it in its base support. Although there may be ways around this (I saw a class called ImageWriter which may have had those capabilities) it makes me really wonder.

I think it also shows a difference between Microsoft and other companies. At Microsoft, they'll spend extraordinary efforts for a guy like me on a weekend like this to be able to write:

Bitmap bmp = new Bitmap();
// do stuff

We could all write our own implementations of a Bitmap helper class, but IMHO, I'd rather be thinking about other things like perfecting the transform.


1 comment:

best4chance said...

I'm impressed with your site, very nice graphics!