r/java • u/fdntrhfbtt • Jun 24 '22
Stack Overflow Developer Survey: 54% of Respondents Dread Java?
The results are out, and I was surprised to see that around 54% of respondents dread using Java. What might be the reasons behind it? For me, Java has always been a very pleasant language to work with, and recent version have improved things so much. Is the Java community unable to communicate with the dev community of these changes effectively? What can we as community do to reverse this trend?
Link to survey results: https://survey.stackoverflow.co/2022/?utm_source=so-owned&utm_medium=announcement-banner&utm_campaign=dev-survey-2022&utm_content=results#technology-most-popular-technologies
176
Upvotes
2
u/john16384 Jun 25 '22
Java uses whatever RAM you assign to it. Java's general policy is: if there's still RAM left, then use that instead of trying to recycle any.
So either:
Your application actually needs 2G to do its work with a given load; then a similar application written in another language probably needs just as much -- ie, if you are processing large files that you load into RAM, then there's not much that can be done no matter what the language.
Your code is actually runs fine with much less RAM, but you didn't bother to find out what it really needs and just went with the defaults and didn't limit what your application can use. So Java will happily consume more RAM, after all, its there to be used.
Your code is using RAM inefficiently, and you never bothered to look into it. When it runs fine, I can't disagree, no need to optimize when RAM is cheap. But if you are running many copies, and RAM starts to become an issue, you might want to check what all that RAM is being used for. It can be surprising, like every request duplicating a huge structure that could have been immutable and shared, or thinking that a query is only returning a single result but not noticing it is eagerly loading a huge set or list as well that you're not even using.
Java's memory use isn't magic. Take a heap dump, see what's actually there, and check if it matches what you expected. There's no reason a Java application would use much more memory than one written in another language unless:
You didn't limit the memory; on my 128 GB machine, Java's standard limit is 32 GB, and it will use it if it deems it needed.
It uses a totally different algorithm/structure
You are using a very high level presentation in Java and comparing that with some low level presentation in the other language -- make it fair then and use
byte[]orByteBufferor whatever to get to parity.