Why does .NET use a JIT compiler instead of just compiling the code once on the target machine?

Technology CommunityCategory: .NET CoreWhy does .NET use a JIT compiler instead of just compiling the code once on the target machine?
VietMX Staff asked 3 years ago

There are two things to be gained by using an intermediate format like .NET or Java:

  1. You can run the program on any platform, exactly because the code is represented in an intermediate format instead of native code. You just need to write an interpreter for the intermediate format.
  2. It allows for some run-time optimizations which are not (easily) possible at compile-time: for example, you can take advantage of special features on new CPUs, even if those CPUs didn’t exist when you wrote your program – only the JIT compiler needs to know about that.