Why Hate Java

WhyHateJava?

PublicStaticVoidMain. Not a big issue, as has been resolved on the page, but still annoying.

Lack of OperatorOverloading. As was said so eloquently by DanielYokomiso: The operators could be confused with the mathematical ones and... Hey, wait a minute, I'm doing math here. Thankfully I wasn't using some language whose designers know better than me which numeric types I'll ever need.

Execution in the Kingdom of Nouns, or, when classes and OOP design patterns go to far.

sin(x)? No!

Let's write Math.sin(x), wrap that functionality in a class.

Or x.sin(), howsabout. Let's embed that functionality in the class.

Going overboard with x.sin()-like stuff:

    x.getSinHelper().execute()
Going overboard with Math.sin(x)-like stuff:
    Math m = Math.getInstance() //Singleton pattern
    m.sin(x)
Now, maybe I'm exaggerating. But I think that Java is actually a class-oriented language, pretending to be OOP.

It isn't pretending to be OOP, it is that flavour of OOP that has static class definitions, along with C++, C#, etc. Some of your examples above are illustrations of the fact that Java overloads the 'class' construct to represent both classes and modules.

Which I think promotes the idea of taking the concept too far. Singletons, over-objectification...Help!


...At least C++ doesn't force you to use static methods. Anyway, you can use C++ static members to do arcane template hacks and come out with what are essentially duck-typed instances of HaskellLanguage type-classes. Try doing that with generics and inner classes, hey?

I don't dislike OO. I like subclassing and subtyping. I even think that static methods have a purpose (essentially, being very slightly cleaner than friend functions).

(And in retrospect, the Math.getInstance().sin(x) is actually more OO than Math.sin(x), since in Java, classes aren't objects. Or rather, classes are objects, but Math isn't actually a reference to the Math object, it's the name of the Math class, the object is at Math.class and Math itself isn't even first class...)

Basically, the problem is that I find Java to be ideologically indecisive. "Everything is an object! Well, except for classes, unless you use reflection. Oh, and primitives, which are magical. How magical? Well, only primitives get to use operators, you don't get to overload them. What? No, String doesn't count, String is special..." and so and so on. That and the bloat. Seriously. I mean, take initialization constructors:

      // C++ constructor
      class Point {
        const int x;
        const int y;
      public:
        Point(int _x, int _y) : x(_x), y(_y) {}
        int getx() {
          return x;
        }
        int gety() {
          return y;
        }
      }

// Java constructor class Point { int x; int y; public Point(int _x, int _y) { x = _x; y = _y; } public int getx() { // Gotta declare everything public individually? WTF? return x; } public int gety() { return y; } }

And even C++ has better anonymous functions than Java now:
      final String you = your.name()
      event.register(
        new Runnable() {
          public void run() {
            System.out.println(you+", run awayyy!")
          }
        });

vs
      std::string you = your.name()
      event.register([=] { cout << you << ", run awayyy!" << endl; }

I mean, I mean, seriously. C++. Cleaner syntax.


EditText of this page (last edited October 29, 2012) or FindPage with title or text search