The other mistake that Sun made with Java was its linguistic supremacist "100% Pure Java" propaganda campaign: you should rewrite all of your code in Java instead of expecting Sun to provide you with easy seamless interoperability with existing languages and libraries.
So Sun's JNI and applet web browser integration languished while Microsoft integrated COM and CLR for seamless interoperability with the web browser and other languages like C++ into Java and CLR.
Sun also had an unholy obsession with code generation, since their attitude was to breed as much 100% Pure Java Code into the world as possible (see AspectJ, JAXB, etc). While C# took a much better approach of supporting code annotation and metadata and reflection and bytecode generation at runtime so you didn't actually have to generate and compile a huge pile of boilerplate source code (see PInvoke).
https://docs.microsoft.com/en-us/cpp/dotnet/how-to-call-nati...