Why do Actionscript, Java, C#, etc. compile into intermediate code?
I’m aware of cross-platform benefits of using intermediate code.
The question is: What is the benefit of compiling to intermediate code, compared to scripts (JS, Python, PHP, Perl, etc.) that are interpreted?
Is it just for code obfuscation? Or what?
In addition what is the benefit compared to compiling to native code?
First of all historically java was targeted to mobiles and embedded devices with very limited CPU/memory, and JVM on such devices can’t do any intensive optimization, like modern JITs do for now. So java engeneers decided to move optimization to compile phase.
Next, having “byte code”/IL allows you to have many compilers from different languages into such byte code – and only one JVM/JIT. It is much more efficient then to create separate VM+JIT for each language. Remember, you have Java, JRuby, JPython, Groovy, etc… in JVM world, and C#, VB#, ASP.NET, F#, etc — in .NET world, and only one runtime/VM for each.