The 10 Worst Things In Java

I’ve been thinking about this for while and I finally managed to compile a list of the 10 worst things in Java. And by the way, I love Java, the language and the platform. So lets get started

javac BadThings.java
  1. Weak, Soft, and Phantom references. Those are evil, if you like chasing weird bugs in an unpredictable program, then use them. Basically the program’s behaviour will rely on the GC which is unpredictable.
  2. Every object is a mutex, if you have a reference to an object you can lock on it.
    List<Integer> list = getList();
    synchronized(list){
     ..
    }
    

    That is bad and can cause deadlocks if some inconsistent lock ordering is going on. Designated Lock objects were added to the JDK later.

  3. Every object is a condition, this is similar to the one above. wait, notify, and notifyAll methods reside in Object. Conditions were added later to the language.
  4. Every object has hashCode and equals inherited from Object. Programmers always have to remember to implement them in order store them in collections. Interfaces should have been added for those.
    interface Hashable{
     int hashCode();
    }
    interface Equatable<T>{
     boolean equals(T other);
    }
    
  5. Checked Exceptions. They becoming worst with lambdas and method references. Anders Hejlsberg described their ugliness here. Although I believe throws isn’t too bad as an annotation for the programmer and the machine.
  6. Arrays are covariant, I’ve posted about it previously.
  7. Bytes are always signed
  8. Method overloading resolution rules are a tricky business, I wrote about it previously here and Lukas Eder wrote a great blog about it as well.
  9. extends and super keywords are so confusing to describe covariant and contravariant types. You always need remember PECS
  10. Cloneable has no clone method.
Advertisements

2 Comments

Hi Jnedi, nice list but how can you not add java.util.Date on this list? The simplest way to create Date object is not intuitive at all, months starts from 0 than 1, the year starts from 1900, and you can change the Date as well because it’s mutable. I guess, that’s the reason Java 8 introduced new Date and time API :-). Btw, I have shared a couple of examples of Java 8 Date and time classes, your readers may find it useful.

    I thought about it, its definitely horrible and every single detail in it is bad. But I tried to limit the list to the bad things that are so deep in the language rather than bad APIs.

Leave a Reply

Name and email address are required. Your email address will not be published.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

You may use these HTML tags and attributes:

<a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <pre> <q cite=""> <s> <strike> <strong> 

%d bloggers like this: