Why is it that C# is that popular for gamedev, and only a few titles use JVM?
Why is it that C# is that popular for gamedev, and only a few titles use JVM?
Other features are also critical to performance such as true generics. Say List<Vector3f> in C# is specialized for that type, no overhead from objects, no extra pointers, no casting.
In C#, if you are very careful, you can get close to the performance of C++. I don't think the same can be said about Java, because the language does not give you the tools to achieve that.
Not as important, but still: C#, as a language, became pretty sophisticated during the recent years. It picked up quite a few functional idioms from OCaml, F#, Haskell and other functional languages, so you have pretty decent horsepower under your fingers. For instance, it can validate for possible null reference access during compile time now, thus nearly eliminating NRE (NullRefenceException) bugs in run time.
Most game engines are written as a large chunk of C++ code that runs each frame's timing, and the big subsystems like physics, particles, sound, and the scenegraph. All the important engineers will be dedicated to working on this engine and it behaves like a framework. The "game logic" is generally considered to be a minority of the code, and because less-technical people generally author it, it gets written in a higher-level "scripting" language.
This creates some serious constraints on that language. It must be possible to call into the scripts from the main engine and the overhead must be low. The scripts often have to make calls into the data structures of the main engine (e.g. for physics queries) and the overhead of that should be low as well. It should also be possible to control the scripting language's GC because the main engine is pretty timing-sensitive. Memory consumption is pretty important as well.
All these requirements point towards two implementations specifically: Lua (and LuaJIT), and Mono. Those two runtimes go out of their way to make it easy and fast to embed. A third option which a lot of engines pick is to write their own scripting language where they control everything about it. Any other language you can think of (with the possible exceptions of Haxe) will have some major hurdle that prevents easy embedding. The fact that you can compile multiple languages to Mono bytecode pushes some folks in that direction; if you're planning to write a lot of code in the scripting engine (not all of them do! See: Unreal) that's nice flexibility to have.
There's one big difference in the feature set: unless things have changed very recently, the JVM lacks value objects.
But actually, C# was always meant as a “managed c++” in a way, while Java rather optimizes on the runtime level (which is helped by less control by the developer). Nonetheless, Java is more than fine for game development, besides the obvious Minecraft there are plenty small to big indie games written in Java.
Unity.
edit: also C# allows precise measurement of memory usage and padding, while in Java one can only guess