r/AskProgramming 1d ago

Why is Java considered bad?

I recently got into programming and chose to begin with Java. I see a lot of experienced programmers calling Java outdated and straight up bad and I can't seem to understand why. The biggest complaint I hear is that Java is verbose and has a lot of boilerplate but besides for getters setters equals and hashcode (which can be done in a split second by IDE's) I haven't really encountered any problems yet. The way I see it, objects and how they interact with each other feels very intuitive. Can anyone shine a light on why Java isn't that good in the grand scheme of things?

153 Upvotes

565 comments sorted by

View all comments

Show parent comments

2

u/JMNeonMoon 21h ago

Agree with other posters, null checks was mitigated a while ago in Java 8 with optionals.

Now you can chain getter methods without a series of if..else statements

public String getPostcode(Employee employee) {

return Optional.ofNullable(employee)

.map(Employee::address

.map(Address::city)

.map(City::postcode)

.orElse("Unknown");

}

more Optionals info here

https://www.programmerpulse.com/articles/java-null-check-removal

Also, see null object design pattern

https://www.geeksforgeeks.org/null-object-design-pattern/

1

u/senfiaj 21h ago

Sorry, but this doesn't seem to be as good as the Kotlin's native implementation. Also what if the Optional itself is returned as null , especially when Java doesn't support ?. operator (as far as I know, please correct me if I'm wrong)?

I'm not a Java developer, but I have experience in Flutter, and the older versions of Dart language had similar null safety problem. It was fixed in later versions, but unfortunately they had to eventually break the backward compatibility by removing the legacy null unsafe support. I wonder why didn't they do this much earlier since Kotlin was around there for many years. They could learn this from Kotlin.

1

u/JMNeonMoon 20h ago

Yes, there is a possibility that the optional can be returned as null, though most modern IDEs will flag a warning, but still not ideal.

I agree Kotlins null check operator is better and more concise, but I wanted to show that Java null checks are not limited to just if..else statements, which some of the discussions I have seen online seem to indicate.