Posted by jrake
on October 27, 2009 at 12:28 PM PDT
I have just started studying java and this question has been bugging me .
I know C/C++ is present for almost every platform/machine . Java creates a platform free programs by having a compilation done to intermediate bytecode and then platform dependent interpretation done JVM , then
How is JVM interpreter plus compiler cheaper than a compiler made for C/C++.
Since lexical analyzer, syntax analyzer and semantic analyzer would be same if we make the compiler for different platforms only thing that would change is optimization modules (platform specific optimization) . Since C/C++ compilers does non platform specific optimization on it's intermediate abstract tree representation , only thing left to change is platform specific optimization modules in the compiler .But i think JVM would also be doing platform specific optimization to improve efficiency.
And incase JVM is not doing any platform specific optimization then isn't the final
code quite less efficient than native platform compilation .