Wednesday, December 10, 2008

Weaknesses

On the Downside: Java's Weaknesses

So far, I've been tooting Java's horn pretty loudly. Lest you think that learning Java is a walk in the park, the following paragraphs point out some of Java's shortcomings (note that many of these drawbacks have to do with the API rather than the language itself):

  • The API is way too big. It includes so many classes and methods, you'll most likely never learn even half of them. And the sheer size of the Java API doesn't allow you to wander through it on your own, hoping to discover that one class that's perfect for the problem you're working on.

  • The API is overdesigned. In some cases, it seems as if the Java designers go out of their way to complicate the things that should be simple to use. For example, the API class that defines a multi-line text input area doesn't have a scroll bar. Instead, a separate class defines a panel that has a scroll bar. To create a multi-line text area with a scroll bar, you have to use both classes. That's fine if you ever want to create a text area that doesn't have a scroll bar, but you never will. Java's designers complicated the design of the text area and scroll panel classes to provide for a case that no one ever uses or would want to use.

  • Some corners of the API are haphazardly designed. Most of the problems can be traced back to the initial version of Java, which was rushed to market so it could ride the crest of the World Wide Web explosion in the late 1990s. Since then, many parts of the API have been retooled more thoughtfully. But the API is still riddled with remnants of Java's early days.


  • TECHNICAL STAUFF

    In my opinion, the biggest weakness of Java is that it doesn't directly support true decimal data. This issue is a little too complicated to get into right now, but the implication is this: Without special coding (which few Java books explain), Java doesn't know how to add. For example, consider this bit of code:

         double x = 5.02;
    double y = 0.01;
    double z = x + y;
    System.out.println(z);

This little program should print 5.03, right? It doesn't. Instead, it prints 5.029999999999999. This little error may not seem like much, but it can add up. If you ever make a purchase from an online store and notice that the sales tax is a penny off, this is why. The explanation for why these errors happen-and how to prevent them-is pretty technical, but it's something every Java programmer needs to understand. You can find all the gory details in Bonus Chapter 1 on this book's Web site.

No comments:

Post a Comment