I can understand the benefits of Java running on a JVM. Portability. Nice simple reason. But I have always been puzzled as to why Microsoft brought out their own version of a JVM – .NET. C# is supposed to be a fine language (haven’t used myself) but could Microsoft have launched product to use native. ie to generate an exe?
My colleague is learning F#. The reason it has to be a language which runs on .NET is because the Microsoft Lync API which will be used is only available on .NET. ie there is no C API for Lync.
A cynical view may be that the reason is vendor lockin. F# will only run on a Microsoft platform (or C# for that matter) and so program is locked in. But maybe I am missing some other benefit of a VM platform?
2
One of the most important aspects of the .NET virtual machine is the reason why it is called the Common Language Runtime.
All .NET programming languages compile to the same bytecode format which is executed in the same VM. This allows programs where different parts are written in different programming languages to interoperate seamlessly.
Virtual machines also have performance advantages, because they allow just-in-time compilation and just-in-time optimization. A common offline compiler can only optimize for a specific CPU architecture. When an application is distributed and the user doesn’t have exactly the same system the application was optimized for, they will experience slightly worse performance than possible. But a JIT compiler can check the architecture when the program is executed and make full use of the features available. Also, a common offline optimizer can only make educated guesses which parts of a program are executed most often and thus have to be preferred during optimization. But a JIT optimizer can monitor the program while it is running, check which branches are used most often, and optimize the program on-the-fly while it is running.
But the Java VM can do all of that too. Why isn’t Microsoft targeting the JVM then? It’s for business reasons. Microsoft is known for wanting as much control as possible over the whole stack an application runs on. Having Sun (now Oracle) control a major part of the software development ecosystem was considered a problem for them. Especially when it allows software to run on non-Microsoft operating systems! So they developed their .NET framework as a direct competition to Java to attack Sun’s (now Oracle’s) market share.
1
CLR also has value types (ie. structs on the stack) so one can argue it’s a more efficient version of JVM. The implementation of generics is also better.
2