|
Java being slower than C++ is no urban myth. There are some cases where well written Java code can out-perform well written C++ code, but they're exceptions rather than the rule. Things like JIT in Java can give better performance, if your code does things over and over, as your code is optimised to run faster when it is run more often, but YMMV as to what code it works well with and what gains you get because it relies on internals of the virtual machine.
The JVM (which interprets Java byte codes) is a performance bottleneck for a Java program, although techniques like JIT do improve things a lot but that depends on the implementation of the virtual machine. C++ does not have a virtual machine, so no such bottleneck exists --- the primary bottleneck on performance of a C++ program is always quality of the code and libraries the program used. Java still has that bottleneck. A high quality C++ compiler optimises for the target machine, which a Java compiler does not. JIT can achieve the same effect for Java (and potentially do a better job as it occurs at run time, so can optimise execution to address actual hotspots in code) but JIT functionality is at least as difficult to implement well as high quality compiler optimiser.
|