Search code examples
javac#cil

C# vs. JAVA - What benefit is there to interpreting Java bytecode vs JITing?


I was reading this comparison between JAVA and C# and was wondering about this statement:

NOTE: While the Java platform supports interpretation of byte code or byte code being JITed then run natively, the .NET platform only supports native execution of C# code because the IL code is always natively compiled before running.

Was this purely a marketing play on the part of Microsoft to make is hard to deploy C# to OS's other than Windows or Does it provide some benefit such as performance or security?


Solution

  • With the just in time approach the byte code is translated into native code at the time of the first execution. Compiling just before execution require more time, so the first time a method is executed it's slower than the second time. .Net compiles the entire program only one time. So during the first time the execution phase is shorted because there is no lag due to compilation. The difference is only in the first time the code is executed, so the more times the code is executed more and more the two approaches become similar in terms of speed.