I just read C++ performance vs Java/C#.
As already said in the previous posts, JIT can compile IL/bytecode into native code at runtime. The cost of that was mentionned, but not to its conclusion:
JIT has one massive problem is that it can't compile everything: JIT compiling takes time, so the JIT will compile only some parts of the code, whereas a static compiler will produce a full native binary: For some kind of programs, the static compiler will simply easily outperform the JIT.
And I got a curiosity why java doesn't compile everything while installing it in device.
If it does, we don't need to think about performance loss with compilation time, and conform to diverse devices.
Actually it's JVM dependent. The new Google's JVM uses AOT:
ART uses an ahead-of-time (AOT) compiler that compiles to machine code when you install the app.
If you're asking why former Sun, now Oracle's JVM doesn't use AOT - it was Sun's engineers choice at the time. For desktop Java there is (usually) no step of installation of the application that would allow to do the AOT and compiling the whole classpath upon load is too time consuming.
More here and of course at Google android site.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With