Why I hate Java

  • whenever a method throws exception, need to decorate method name with throws Exception clause
  • no var (newer versions have this)
  • no File.ReadAllText
  • no Path.ChangeExtension
  • no import as [http://stackoverflow.com/questions/2447880/change-name-of-import-in-java-or-import-two-classes-with-the-same-name]
  • no yield return [http://stackoverflow.com/questions/2352399/yield-return-in-java]
  • no properties [http://stackoverflow.com/questions/70471/no-properties-in-java]
  • no static class [http://stackoverflow.com/questions/1844355/java-static-class]
  • no ref and out keywords [http://stackoverflow.com/questions/2806545/does-java-have-something-like-cs-ref-and-out-keywords]
  • no delegates [http://stackoverflow.com/questions/44912/java-delegates]
  • no extension methods [http://stackoverflow.com/questions/4359979/java-equivalent-to-c-sharp-extension-methods]
  • no LINQ [http://stackoverflow.com/questions/1217228/what-is-the-java-equivalent-for-linq]
  • no events
  • no support for C# style verbatim strings that start with @ [http://stackoverflow.com/questions/2673855/java-equivalent-of-cs-verbatim-strings-with]
  • no indexers [https://stackoverflow.com/questions/13403881/is-there-an-equivalent-of-c-sharp-indexer-in-java]
  • cannot have static method in a non-static inner class [http://stackoverflow.com/questions/975134/why-cant-we-have-static-method-in-a-non-static-inner-class]
  • Generics are a complete joke when compared to C# [e.g. http://stackoverflow.com/questions/3403909/get-generic-type-of-class-at-runtime%5D. This by far is the biggest pain point when moving to Java. I have spent countless hours trying to find out how one can get the type in a Generic class and its just not possible.
  • no support for multiline strings [http://stackoverflow.com/questions/878573/java-multiline-string]
  • Buggy tools and ecosystem [e.g., http://stackoverflow.com/questions/36755799/unexpected-maven-dependency-mediation-behavior%5D
  • In C# when I am writing a generic method, I can use the where keyword to tell that the type parameter should be of a certain type. C++ also supports this with concepts (C++20). But Java has no support for this.
  • no support for conditional compilation [1]. C# supports it [2] and of course C++ is famous for its compile-time flags.
  • javadoc documentation (e.g., [1]) is extremely unhelpful as it doesn’t tell you what artifact you need to import in order to use a class. By contrast C# docs tell you the dll in which a class resides. You then know which dll you have to import in order to use the class. This by far is the biggest problem with Java development and I am further amazed the community has not developed any solution for this [1]. I cannot overstate how many countless hours I have spent trying to figure out what Maven artifact to import just to be able to use a class. Edit: Today I did a test and even some C# docs (e.g., [1]) suffer from this problem. So am I unnecessarily bad mouthing Java here?
  • Inconsistent from top to bottom. The -cp option for specifying classpath works for java but not for jdb. For jdb you have to use -classpath.
  • Inconsistent. You can use --add-opens in MAVEN_OPTS for mvn exec:java but it won’t work for mvn test
  • no partial classes [1]
  • for a new project I tried using JPMS (Java Platform Module System). It has been 6 years since it was released with JDK 9. I kept running into so many issues and spending so much time to fix them that eventually I decided to abandon after wasting weeks of effort just to keep it going. The problem is not the JDK. Its fucking Maven [1,2,3,4,5,6,7]. Maven is 1,000 times more ugly than Java itself. A large part of the reason I hate Java is not because of Java per se, but because of Maven. Oracle for its part works hard to release JDK with a certain level of quality. But Maven is a completely separate project developed by indie developers – full of bugs and zero quality control. The problem is without Maven, Java is incomplete. Oracle needs to own development of Maven as well. A broken Maven gives bad name to Java as well.
  • some people compare C# to a luxury car (Lexus) and Java to a Camry or Corolla. I think the more accurate analogy is that Java gives you an engine and a transmission system. You want to ride a car? Use Maven to get the other parts, chassis etc.
  • So many times whenever I work on a multi-module Java project, Maven will build the project and all sub-modules successfully but at runtime you will get ClassDefError, ClassNotFoundError, ClassNotFoundException, IllegalClassFormatException and so on. And these are the hardest to fix.
  • At times Maven would fail the build and simply re-running it the build will pass. I am not hallucinating. What gives? One user aptly calls it the Maven Uncertainty Principle and no – its not gone; it still exists.
  • Over here one person in their test of ASP.NET Core vs Spring Boot says that “both Golang and ASP.NET Core memory consumption decreases to around 10 MB and 100 MB respectively, while Spring Boot stays over 1 GB until I kill the process”.
  • It is surprising and embarrassing that basic things (the 101) are broken out of the box on mature frameworks like Spring [e.g. 1]
  • With Java, what I have realized is that it unwittingly invites you to write ugly code. This is not by intention but just happens to be by virtue of the fact how the language and its best practices are designed. All Java frameworks and libraries are over-engineered and require you to study realms of documentation to be able to use. Compare to how easy it is to use something like Node.js.

It is my sincere advice to anyone working on a new project to stay away from Java if you have the option to do so. Java will make your life miserable and kill your productivity. You will no longer enjoy coding.

This entry was posted in Software. Bookmark the permalink.

Leave a comment