Java!
Mood: mellow
Music: The Killers - "Mr. Brightside"
Posted on 2006-06-15 10:25:00
Tags: java programming
Words: 689

I was feeling a little blah yesterday, so I did what usually clears that up for me - start a new project! (this probably isn't a great long-term solution, but it works for now) I decided to write a program that would turn my iTunes playlists (which are stored in the iTunes XML file) into plain ol' .m3us so I could listen to them served up from my computer. Not too tricky, since I already have an analysis of my songs in iTunes that parses the iTunes XML file.

To make it more exciting, I started writing it in Java, which I used extensively at Rice, but hardly at all since then. I was going to parse the XML file and then use XPath to get the stuff I needed, but the file is so big (200000+ lines!) that Java runs out of memory getting the nodes. Sigh. So I went back to plain ol' parsing it line by line and just picking out the parts I need, which turned out to be pretty easy.

It's not done yet, but I've already extracted the playlists and which songs they refer to (by referencing the database that is created when I do the analysis of my songs), so I just need to write the code to output them as .m3us which is pretty straightforward. But the point of this post is to point out some new stuff in JDK 5 (which is really 1.5) that are very nice compared with what we had back at Rice :-) The link describes them, but I'll point out the highlights:


So, anyway those made programming in Java a bit less painful, but it's still awkward going from a dynamically-typed language (Ruby, Python) to a statically-typed one (Java). Just takes some getting used to, is all.

On a random note, I rearranged my home page a bit, hopefully for better clarity and for putting the most important/interesting stuff towards the top.


5 comments

Comment from omega697:
2006-06-15T11:27:03+00:00

Technically, Generics don't come with type safety, AFAIK. The compiler just makes sure that all the things in angle brackets are the same throughout. Speaking of which, LJ suppressed your angle brackets above.

Comment from gregstoll:
2006-06-15T11:31:54+00:00

Well, it means you don't have to do unsafe casts when you get stuff out of the vector, for instance. And I'm pretty sure you'll get a compile-time error if you try to insert something that isn't an Integer into a Vector<Integer> (based on the discussion of generics), so that seems like type safety to me.

Ah, thanks! Should have seen that coming, but it's fixed now.

Comment from omega697:
2006-06-15T11:41:07+00:00

It's close, but not quite.

"Generic types (or generics) bear a superficial resemblance to templates in C++, both in their syntax and in their expected use cases (such as container classes). But the similarity is only skin-deep -- generics in the Java language are implemented almost entirely in the compiler, which performs type checking and type inference, and then generates ordinary, non-generic bytecodes. This implementation technique, called erasure (where the compiler uses the generic type information to ensure type safety, but then erases it before generating the bytecode), has some surprising, and sometimes confusing, consequences. While generics are a big step forward for type safety in Java classes, learning to use generics will almost certainly provide some opportunity for head-scratching (and sometimes cursing) along the way"

From http://www-128.ibm.com/developerworks/java/library/j-jtp01255.html

Comment from gregstoll:
2006-06-15T14:47:33+00:00

Ooh, that's interesting. Thanks!

Comment from brittongregory:
2006-06-15T15:08:36+00:00

Ugh. That's tricky. Of course, .NET (the tongue of choice in my group) doesn't have anything like generics or templates -- you have to either create a child to do the type-checking or do the (gulp!) Unsafe Cast of Evil. Still, I find templates so tremendously hideously ugly that I don't mind so much. Then again, I'm weird that way.

This backup was done by LJBackup.