So, in the end, the time has changed and Java is no longer called "slow, memory hungry" language as everyone stated to me.
It's an old bias many people still hold dearly. It is true in some instances, but not in all of them. A normal java prog will be just as fast as a C++ one most of the time.
Even most of the Benchmarks, be it for or against java, deal with stuff in a millisecond range. If you don't do such stuff in a big loop, the time difference is not even observable for a human user.
It also depends on the external code you use. Take for example md5sum, which was done in C or C++, as far as I know. It's one of the basic binaries you find on pretty much every linux system, yet the "
Fast MD5 Implementation in Java" actually outperforms it. But then again, the fastest mode of FMIJ uses native code and the standard java MD5 mechanism is slower than md5sum. So in short, the not-as-optimized native code runs faster than the not-as-optimized java code, but slower than the optimized one.
Since no one probably always reinvents the wheel and uses libraries and stuff to help him, the speed of the program also always depends on the speed of that external code. If you used md5sum in a C++ project and someone else used FMIJ in java, chances are his stuff would run faster (assuming, of course, that the MD5-summing would be a mayor part of the project).
However, it also always depends on the circumstances. Some stuff can be slower/faster or memory-heavier/lighter in java depending on the way you use it. For example, Strings in Java are UTF-16, which I think is great because it's a mayor pain in the butt to work with non-ASCII in vanilla C++/STL. But if you're handling a big pile of ASCII, then this will mean a huge memory waste in Java because instead of a single byte per character as in C++, java uses two and therefore uses the double amount of memory (it may be a good idea to instead build an
ASCII-String-class in that case). On the other hand, if you're dealing with the same strings over and over again, you have to allocate and de-allocate memory for every single string in C++, while in java, two instances of the same string point to the same memory location. Something like
String y = "bla"; String x = "bla";
would therefore use the double amount of memory in C++ and waste time allocating.
But I digress..
You can't say "Java is slower than C++" or "Java is faster than C++", it always depends on what you do with it.