7 Java Irritants

Java is a pretty robust language for the objectives it seems to set itself - being a clean and easy-to-learn object-oriented language - although the slippery slope towards featuritis is very apparent in 5.0. The automatic garbage collection, in particular, is a godsend for someone migrating from C++.

But there are still plenty of little niggles that could be rectified:

  1. Make the structure of the program dependent on indentation, like Python, and get rid of the curly braces everywhere. It makes sense.

  2. Get rid of the primitive data types (int, long, etc.) at the source level. Auto-boxing in Java 5.0 makes them less annoying, but they still aren’t necessary - the lack of a primitive string datatype makes that clear.

  3. Have an explicit modifier for package-private/friendly visibility, for consistency, and make it mandatory to specify a visibility modifier. These things make the code less ambiguous for those unfamiliar with the rules.

  4. Remove the one-class-per-source-file restriction (in theory this is for public classes only, but because of this, most people use a separate file for each class). It makes for huge and unwieldy build and deployment structures. C++ shows how it can be done.

  5. Get rid of the syntatic inconsistency between interfaces and classes. Methods in interfaces are always abstract as they cannot have a body. Java allows the _abstract _modifier to be missed out, however. This can be confusing.

  6. Make /* */-style comments nestable. It is very irritating to comment out a block, but have to do it in bits because of a ‘real’ comment block that’s part of the code. Colour-coding text editors mean that there shouldn’t be any confusion when doing this. It would also make //-style comments largely redundant.

  7. Merge the concepts of list and arrays, as Perl does. This allows for a far greater degree of expression in the language, and reduces some of the OO waffle necessary in Java when dealing with lists.

This kind of stuff is almost always about personal preference, so it’s unlikely that you’ll agree with all of the above. But I’d love to hear your comments anyway. What little things annoy you about Java?

Comments

4/7 - I think that's pretty good going. I understand where you're coming from with the lists/arrays thing - performance is important. I think my comment mainly stemmed from the observation that many programs I write (typically where performance isn't important) don't use arrays at all, because Lists are far more flexible and useful for many applications. I wish Java had simpler and less verbose syntax for manipulating them, that's all (like Perl's funky list syntax). I guess throwing away arrays might not be so wise.
+1 on points 3,4,5,6 -1 on 7 - esp. in resource constrained environments exposing array types which are better maps to the underlying hardware and "do what they say on the tin" is very valuable. The Collections framework is a slighty clunky but ultimately pragmatic bridge between the two.