What bugs you most about Java?
The Java subreddit went into overdrive last month when one dev urged users to air their issues with the platform. Can you identify with any of these?
Ah Reddit, where would we be without it to churn the waters of the internet and dredge up the finest cat pictures of the day? In the middle of all that snark though, there are some genuinely excellent discussions.
Try-catch statement blues
I’m just starting out here, but I’m kind of astonished at how complicated it is to make a program wait a second before moving on. After writing the initial command, I have to surround it in a try-catch statement. Probably not that bad for experienced coders, but it bugs me so much. The exceptions with anything IO related makes simple things incredibly verbose too. When I just want to do something quickly I end up being incredibly bad and adding “throws Exception” to every method signature.
No, no, no
I also hate the get provider by name stuff used in so many Java libraries. I like to have compile-time checking that the implementation I want is actually there.
- No of unsigned integers
- No operator overloading
- No properties
- No delegates (although I’ve been hearing good things about the features in Java 8 – not really looked into it myself)
Where is the love?
The thing that I hate most about Java is all the Java hate. Seriously, all the hate is one of the biggest reasons that I don’t use it for hobby projects. The other big thing is the modularity of the JRE. Even if you use tools like Launch4j, you still require users to install 200+ MB of framework.
No getter or setter
Java needs a getter and setter annotation. That would be simple to add and would remove more boilerplate code than anything else.
Lack of modules makes it feel creaky. There’s some talk of modules coming in 9.x I think but yeah, more than anything this is my biggest complaint.
Why can’t we all just cooperate?
The biggest issue I have is how poorly primitives and objects work together. For example, converting char to List is far more verbose than it needs to be.
- More than anything else, I miss context-sensitive functions from Perl, and what they could have become in a language with real exceptions.
- I wish we had some kind of autoboxing for multiple return values, the way Perl can easily return lists.
- I wish the standard libraries that use exceptions could be called from a context where exceptions aren’t appropriate and do something else with failures.
- It really irks me that I have to deal with IOExceptions when using a StringWriter.
- The lack of macros is a big minus for me (but not preprocessor macros like in C/C++, I’m thinking about something like the ones you find in Lisp/Scheme).
- Having to create a class for everything, even when you don’t really need it. Say I want to extract a frequently used piece of code and reference it anywhere – to do this, I’ll have to make it a final static method of some class, for which I will have to conceive a meaningful name… It could’ve been much less trouble (and it is in some languages, esp. when you’ve got macros in your language).
- Its weak generics. C++ templates are much more powerful.
- The fact that you cannot instantiate a class on a generic unless you’re given that class as a parameter.
- The inability to dispose a class and allow it to have a destructor. RAII would be so useful at times.
- No operator overloading. C++ allows you to use the == operator with strings just fine. Also, BigInteger math sucks for the same reason.
Oh, OK then
NO UNSIGNED PRIMITIVES. WHAAAAAAAAAT THE FUCK!
Again with the getters and setters
Those are the ones I can think of off the top of my head. I think there are a few more. Formerly, the verbosity of using callbacks was a big one but Java 8 will solve that so I take some pleasure there =)
- null (big gripe)
- Getters and setters (i.e. no properties)
- Positional arguments only. I like the verbose argument style of Smalltalk, or the new keyword-only argument style in Python 3. In Smalltalk a method call with two arguments is something likemyInstance myMethodWithFoo: arg1 Bar: arg2In Python you can force your method to be called using syntax likemy_inst.my_method(foo=arg1, bar=arg2)
- …No multiple dispatch?
- Default visibility. No modifier given should mean private, not package-protected.
- Default mutability. Final (in all its usages) should be the default, with a ‘var’ modifier. At the moment a developer would be less likely to mark all parameters to a method as final, as it makes it unreadable very quickly. At the same time, it’s much less common to reassign your parameters.
- Collection interfaces. There should be a ‘readable’ set (, list, map…) interface, that the existing Set descends from, with mutator methods excluded. This would prevent the refused bequest you see in Collections.unmodifiable…() and 3rd party APIs, giving better type safety.
- Lack of expressive power. After playing in Scala (or most modern PLs), Java feels clunky and verbose. It’s a common complaint, but it’s still true.
Forced exceptions – Amen brother. Why the hell should I have to surround every single Thread.sleep()…? I’ve literally never run into the InterruptedException I’m required to account for. I know this isn’t a super popular perspective, but I agree with the annoyances of checked exceptions. They really do clutter code and they make refactoring a complete bitch. I understand what they’re meant for (and it does make sense in theory) but they’ve never done me any good. Whatever you do, don’t do nothing in a catch even if you think it will never happen. Just wrap the Exception with a RuntimeException and rethrow it.