Disliking Java

Sep 21, 2010

If you were to ask me which programming language I hated, my first answer would most certainly be Lisp (short for "Lots of Stupid, Irritating Parentheses"). On the right day, my second answer might be Java. But seeing as hate is such a strong word, I'll opt for the statement that I dislike Java instead.

For the first time in probably 7 or 8 years, I'm having to write some Java code for a project at work. In all fairness, one of the main reasons I dislike the language is that I'm simply not very familiar with it. I'm sure that if I spent more time writing Java code, I might warm up to some of its quirks. But there are too many annoyances out of the gate to make me want to write stuff in Java for fun. Jumping back into Java development reminds me just how lucky I am to work with Perl and C++ code on a daily basis. Here are a few of my main gripes:

  1. It's a little ridiculous that the language requires the filename containing a class to exactly match the name of the class (so, a class named MyClass has to be placed in a file named "MyClass.java"). Other than making it easy to find where certain code resides, what's the benefit of this practice? The compiler simply translates your human-readable code into machine-specific byte code; filenames get lost in the translation!
  2. It pains me to have to write System.out.println("Some string"); to print some text, when in Perl it's simply print "Some string";. This leads me to my next major gripe:
  3. Java is way too verbose. I have to write 100 lines of code in Java to do what can be done in 10 lines of Perl. My time is worth something and I'm spending too much of it dealing with Java boilerplate code. In C++, I can use the public: keyword once, and everything that follows is public (until either another similar control keyword is reached or we come to the end of the block). It doesn't look like that's allowed in Java. Instead, I have to place the public keyword in front of each and every member variable and function. Ugh!
  4. Surprisingly, Java's documentation is pretty poor. Examples are few and far between and varying terminology makes it unclear when to use what function. For example, in some list-based data structure classes, getting a count of the items in said list might be getSize(), it might be getLength(), it could be just length(), or it might even be getNumberOfItems(). There's apparently no standard. Every other language manual I've ever used, be it PHP, Perl, or even the official C++ manual, has examples throughout, and relatively sane naming conventions. I can find no such help in Java-land.
  5. Automatic memory management can be handy, but it can also be a bother. I know for a fact that there are folks out there who make competent Java programmers who wouldn't last 10 minutes with C++ code. Pointers still matter in the world of computing. That Java hides all of those concepts from programmers, especially young programmers learning the trade, seems detrimental to me. It pays to know how memory allocation works. Trusting the computer to "just handle it" for you isn't always the best solution.
  6. Nearly all Java IDE's make Visual Studio look like the greatest thing on the planet; and Visual Studio sucks!

All that being said, the language does have a few redeeming features. Packages are a nice way to bundle up chunks of code (I wish C++ had a similar feature). It's also nice that the language recognizes certain data types as top-level objects (strings being one; again, C++ really hurts in this department, and yes I know about STL string which has its own set of problems).

I know there are folks who read this site that make a living writing Java code, so please don't take offense at my views. It's not that I hate Java; it's just that I don't like it.



8:54 PM on Sep 21, 2010
A few comments- What IDE are you using? I haven't used anything but Eclipse in years, and I find it pretty great. It's a memory hog, but the last time that was an issue for me was because I was on a machine with 512 MB of RAM. (Are you doing command-line development or GUI development? I'll give you that there's no great option for doing truly visual Java development.) Any list-like data structure should implement the List interface, or at least the Collection interface (List is actually a subinterface of Collection). All Collections have a size() method. Any other methods you are seeing are likely relics from Java 1 & 2, before all Collections were unified under common interfaces. Java's documentation is pretty thorough, but I guess a lot of the time you would need some idea of what class or interface to go looking for. If you've been out of the Java world for a while I can see this being confusing. The restriction is actually only to one public class per .java file. You can add other classes to the file, just leave off the public descriptor. The class will have default (package) visibility, meaning any other classes in the same package can use it. If you have a small application that you're developing and everything is in the default package, then this solves your problem. (You don't even have to have a public class at all!) But the rule is generally a good thing for large applications, because it makes it much easier to find where a class is defined, and prevents the definition from being split across several files.


9:03 PM on Sep 21, 2010
Correction- arrays are list-like but don't implement List, because they are primitives. And if you're using reflection on an array you'll get an Array object, which also doesn't implement List because it's just a wrapper around the primitive type. The whole primitive/Object distinction leads to a lot of redundancy, and I'm sure if they could design it all over again they'd make all primitives behave like classes, the way c# did.


12:03 AM on Sep 22, 2010
I'm currently using the latest release of Eclipse (Helios) as my IDE. It's shockingly slow on my work laptop (2GHz Core-2 Duo, 2GB RAM, Win XP). Just today I had to disable auto-complete; every time I typed a variable name followed by a dot, it would literally take up to 15 seconds or so for the box to show up. During this time, the application locked up and one of my CPUs was pegged. This happened every time, even with the same variable (nothing was being cached, apparently). I quickly disabled the feature. All the structures I've been using seem to be all over the place on their naming convention. Perhaps I'm looking at deprecated classes? I'm working with Swing stuff (blech). My problem with the Java documentation isn't the lack of coverage on methods and properties; it's the lack of clear examples and usage. They give me the who and what. They don't give me the how, and the how is what matters.

Leave a Comment

Ignore this field:
Never displayed
Leave this blank:
Optional; will not be indexed
Ignore this field:
Both Markdown and a limited set of HTML tags are supported
Leave this empty: