Why I love Java:
- The fact that I don't have to worry about dynamic resource management— GC's the way to go, baby!
- Each topmost class has to be in a separate file— cleaner code, easier to read class file source, and best of all I don't have to declare the interface of my classes in a separate .h header
- Large class library— no need to worry about coding up a home-brew solution to the most common tasks, such as regexps and I/O
- Object-orientation, single rooted inheritance tree, and interfaces— I like the
interfaceconcept. Clean, I'd say. And I can treat everything as an Object safely. AndArraysactually know their length! I can write a generic arrayforloop! - The reflection API. I did a home-brew ORM layer once, and originally using it meant having to declare a method returning an array of Strings representing the database fields of a particular object. I toyed with the idea of using reflection on the base class, tried it out, and was amazed that it actually worked. Wow. Smart objects.
- Hibernate— a tool I recently discovered. Quite amazing... I'd say the above home-brew ORM layer would have eventually evolved into this, what with the reflection stuff I did. (Right... dream on).
- JDBC— clean, easy to use, and dammit, I don't have to worry about DB-specific APIs! Oh, and
PreparedStatements rock, especially in a webapp. - The
Stringclass. I couldn't ask for anything more. No more trying to figure out whether or not achar *fits.
Why I hate Java:
- Checked exceptions by default: Bah, do I really have to catch them? Most of the time,
catchclauses end up empty in my code (someone'll argue that that's a code smell, but I say Java smells, not my code). Exceptions should be first and foremost unchecked (i.e. RuntimeException and its kin). The presence of NullPointerException does nothing good either— it's a sign of bad code, sure, but really now, I thought Java didn't have pointers. (Yes, I know that strictly speaking, object references are pointers, but really, if Java were to be completely OO, null should just be an object that does nothing). - Strict typing, no generics/templates: Look, I'd prefer to stay off this particular holy war, but hey— the presence of class casts distresses me, especially when using the
java.utilcollections. It scares me that I have to be careful when iterating through a List— ClassCastException, anyone? I mean, if you want to go strict on the typing and stuff, there should be some sort of framework so that I can declare collections that strictly accept one and only one class of objects, and which I can use out of the box, without having to create a wrapper around the Collections framework to do so. C++ has the STL, has templating... - Ugly iteration mechanism: Have you ever written code that looks like the one below?
for(Iterator i = someCollection.iterator(); i.hasNext(); ) {
doSomething((SomeClass) i.next());
}
You probably have, and you probably hate that class cast there. And it's ugly, not to mention barely readable IMHO. (That's why I really like Velocity'sforeachmacro, and actually prefer Velocity over JSP as the View of an MVC app) - Swing.
- Sluggish IDEs built on Java: hey, I like Eclipse and it actually runs pretty decently on butiki, but it's still too slow for my tastes. (<tongue-in-cheek>I use Emacs as my editor, FWIW</tongue-in-cheek>)
- Large class library— and no one can store it all in his head. Which makes it necessary to have a reference handy. I use O'Reilly's Java In A Nutshell, as well as the online Sun Javadocs.
- JSP: Okay, they're strictly not Java. JSPs still offend my coding sensibilities, especially with a project I had to maintain that was coded almost entirely in JSP, sprinkled liberally with scriptlets. All together now: "Hard to read". Many a time I had difficulty tracing through a mistake just because it was hard to figure out where each block of code began and ended. Also, some JSP design decisions look brain dead, IMHO.
Some of my issues with Java will be resolved in Java 1.5, IIRC, but hey— they're still there now.
NOTE: Take with a grain of salt. I've been coding professionally for the better part of two and a half months, but I've been coding as a hobby ever since I learned BASIC when I was 11. (Oh God, not that language, I can hear the gallery saying. And yes, I got past all the brain damage that BASIC gave me)
Previously: Work Is Fun