86

I'm not a game developer or anything, but I know that Java is not very widely used for game development. Java should be fast enough for most games, so where's the catch? I can think of some reasons:

  • Lack of game developers with expertice in Java
  • Lack of good game development frameworks
  • Programmers don't want to accept Java as a games programming language. Most only accept C++ as that?
  • No support for game consoles (though the PC market still exists)

It could of course be something else. Could someone who knows the business better than me explain why Java isn't getting momentum when it comes to game development?

25
  • 43
    And now wait for all of the "Java is slow, C++ is fast" answers that really only touch the surface of the issue in an overly broad and completely correct way. Be aware that people answering this way are almost certainly not professional game developers. Commented Mar 5, 2011 at 19:53
  • 24
    In fact, Java is used for game development; i.e. in the mobile market. Java ME, Android.
    – user281377
    Commented Mar 5, 2011 at 20:14
  • 23
    Why should it be used? What does Java offer a game developer, that the more widely used languages don't have? Java provides an enourmously rich ecosystems to business application developers, that outweighs its shortcomings as a language, but when it comes to game development, the Java platform offers little tools compared to a number of alternatives.
    – back2dos
    Commented Mar 5, 2011 at 22:56
  • 14
    Interestingly, Minecraft is Java based.
    – Uri
    Commented Mar 5, 2011 at 23:03
  • 5
    @Coder Looks like the C++ code was heavily optimized, but the Java code was not. So it's an invalid comparison.
    – Izkata
    Commented Apr 24, 2012 at 15:39

13 Answers 13

100

Several reasons:

  • In the old days, you needed "direct access" for performance and UI. This predates VM languages like Java and C#.
  • Most consoles (e.g., 360, PS3) do not have a JVM, so you cannot reuse code from the PC version. It is much easier to compile C++ code to support various devices.
  • Most mainstream game engines (e.g., Unreal) have C++ bindings. There are some Java connectors (e.g., for OpenGL) but nothing like it.
  • For PC gaming, DirectX doesn't really have strong Java support (if at all).
  • Web based games run in JavaScript or Flash. You could write them in Java though using things like GWT.
  • The iPhone runs an Objective-C variant.

Java is primarily used in Android games these days, simply because it's the primary language for that platform.

11
  • 14
    +1 "Most consoles (e.g., 360, PS3) do not have a JVM, so you cannot reuse code from the PC version. It is much easier to compile C++ code to support various devices" If the device doesn't have the runtime, you won't see games developed based on that unavailable runtime. Xbox 360 and Windows phone have managed .Net runtimes, so game development using them is possible, and likely a growing trend. However, because the runtime isn't on the other major platforms (PS3, and to a much lesser extent, Wii), its hard to justify a completely seperate codebase. It really is not a performance issue at all.
    – JustinC
    Commented Mar 6, 2011 at 0:09
  • 2
    It's called XNA, which is currently subset of the .Net 2.0 framework. There are some other interesting frameworks in the wild: MonoXNA, MonoTouch, and XnaTouch among others.
    – JustinC
    Commented Mar 6, 2011 at 4:46
  • 7
    Predictability of performance is not possible with a JVM.
    – Klaim
    Commented Nov 28, 2011 at 21:52
  • 5
    Very good points. However, I'd add the fact that the GC can cause unpredictable pauses/load . If this isn't a problem for server apps, it is for a real time game. This is for instance visible in minecraft.
    – deadalnix
    Commented Oct 11, 2012 at 14:04
  • 2
    @Klaim It's also not possible with malloc or new, so if that's a concern you're going to implement pooling no matter what. Unrelated to that point, a big issue with Java is that it doesn't support value types, unlike C#.
    – Doval
    Commented Oct 25, 2016 at 21:24
86

Technical reasons:

  • Most of the best 3D game engines are written in C/C++. This is a big deal, since most game developers don't want to compromise on their 3D engine, but nor do they want to write one from scratch. Java has jMonkeyEngine which is open source and actually really good but it still can't yet compete with the Unreal Engine.
  • For some very rare situation, there are advantages in getting "close to the metal" in C or assembly language, specifically for access to special hardware features. This is not so important nowadays, but professional game developers still like to have the option.....
  • Java has a garbage collected, managed runtime. 99% of the time this is a huge advantage, it certainly makes coding easier and less error-prone and is one of the big reasons why Java is so popular. However it does cause an occasional latency issue for games as garbage collection cycles can cause noticeable pauses. This is getting to be less of an issue with the newer low-latency JVMs, but is still an issue for graphically intensive games where maintaining high FPS is critical.

Non-technical reasons:

  • Professional game development houses are heaviliy invested in C/C++ skills and technologies. This creates a huge amount of inertia.
  • The largely irrational perception that Java is slow. Possibly true in the 90s, definitely not true now - you can certainly write a profitable, commercial 3D game with Java (Runescape anyone? Or how about Minecraft? )
  • A pretty fair perception that Java is more focused on business applications and the web rather than gaming. This might change with the growth of Mobile and the need for more cross-platform development, but is certainly true at present.

Interestingly there are also some good reasons why game developers should consider Java:

  • Portability - as the number of target platforms proliferate, Java becomes more and more attractive with it's pretty much unparalleled ability to create genuinely cross-platform binaries
  • Library ecosystem - with the very important exception of 3D game engines, Java has the best range of libraries overall of any platform. Networking, sound, AI, image processing, key/value data stores, you name the topic and there's probably an open-source Java library for it.
  • Server side development - Java is a great langauge/platform for the server, and as more games incorporate massively multi-player elements the server side will become more and more important. Java on Linux looks pretty compelling here as a platform.
  • The JVM - is probably the best engineered VM execution environment in the World, with fantastic garbage collection, JIT compiler, concurrency support etc. It's only going to get better, and as game developers increaingly start to use dynamic languages within their games they will want the best possible runtime environment.
  • Other JVM languages - Java is a solid old workhorse, but the real innovation is happening with the new JVM langauges (Kotlin in particular). These languages get all the advantages of the Java/JVM platform, plus they are extremely powerful modern languages.
6
  • 19
    No, protability isn't better in Java in the video game world. Most console don't have a JVM. For portability reasons, C++ is prefered to java in video game world.
    – deadalnix
    Commented Oct 11, 2012 at 14:07
  • 5
    Why is library ecosystem a bonus for Java? Networking, sound, key-value pairs - that's not a thing; that's avilable everywhere nowadays. I would actually argue that AI and image processing is much easier done with C/C++ libraries (fann, OpenCV).
    – MrFox
    Commented Mar 11, 2013 at 18:50
  • 4
    More important than FPS, I would perhaps emphasize consistent frame rates. I can have my game running at 100FPS, but if some of those frames take half a second, that's just not going to do. Even if GC is fast, if it causes noticeable irregularities it's still a problem. (This speaks nothing to Java's performance in particular, just a general problem to keep in mind)
    – Gankro
    Commented Mar 24, 2014 at 4:12
  • 2
    I wrote a first person shooter in Java and I have never had any trouble with the garbage collector even when I didn't use one with low latency. Anyway, when the memory isn't allocated on the Java heap, it's up to me to deal with it without the garbage collector and most of my memory footprint comes from the VBOs. In other terms, the garbage collection isn't a problem because it works when it's used for what it's designed for and it's not up to it to handle large objects on the GPU or on the native heap (!= Java heap). Don't blame an anvil for not being an efficient mean of brushing your teeth.
    – gouessej
    Commented Aug 4, 2017 at 11:22
  • 2
    @deadalnix The video game world isn't only composed of the consoles.
    – gouessej
    Commented Aug 4, 2017 at 11:26
37

Okay, theres a lot of misinformation in this thread.

I know the game business extremely well, having been in it for 25 years. I also know Java in games extremely well having been Sun's Java Game technical evangelist and lecturing Java performance programming expert.

In terms of computational speed, Java beats C++ in many scientific computing benchmarks today. You can write pathological code in either language that performs badly if you want to, but over-all, they are at par and have been for a long time.

In terms of memory usage, Java does have some over-head. HelloWorld is a 4K program in java. But that overhead is pretty meaningless in todays multi GB systems. Finally, Java does have more of a startup time. I would not recommend using Java for short run-time utilities like Unix command line commands. In those cases startup will dominate your performance. In a game however, its fairly insiginficant.

Properly written Java game code does not suffer GC pauses. Just like C/C++ code, it does require some active memory management but not to the level C/C++ does. As long as you keep your memory usage to either long lived objects (persist for an entire level or game) and very short lived objects (vectors and such, passed around and quickly destroyed after calculation) gc should not be a visible issue.

In terms of direct memory access, Java has had that for a LONG time; since Java 1.4 in the form of Native Direct Byte Buffers. Bit twiddling in Java can be slightly annoying due to the lack of unsigned integer types but the work rounds are all well known and not terribly onerous.

While its true Java has never had a Direct3D binding, thats because Java technologies strive for portability. It has TWO OpenGL bindings (JOGL and LWJGL) and OpenAL binding (JOAL) and a portable input binding (JInput) that binds under the hood to DirectInput on Windows, HID Manager on OSX, and a Linux binding (I forget which).

Its true that no complete game engines have featured Java the way, say Unity, has featured C# and that is a weakness in the independent space. On the other hand, there were two good Scenegraph level APIS that were totally platform portable across Windows, OSX and Linux. Both written by Josh Slack, the first was called JMonkey engine and the second Ardor3D.

The top poster is correct that the two biggest things that held Java back in game development were prejudice and portability. The latter was the biggest issue. Although you could write a Java game and ship it on Windows, OSX and Linux, there was never a console VM. This was due to total ineptitude in Sun middle management. The few of us working on Java in games actually had deals with Sony no less then 3 times to get a VM on a Playstation and all 3 times Sun middle management killed it.

While Sun flirted with client technologies, the fact of the matter is that Sun management never got consumer products. Thats why Java as a client language from Sun never succeeded in any form, and why it took Google and Dalvik (the Android java-like VM) to make Java a platform success anywhere.

And thats why I code games in C# today. Because Mono went where Sun management refused to.

9

Java is great for business logic, servers, and platform independent code that has to run reliably. There are several factors why Java isn't often used in games:

  • bounds checking & other safety mechanisms (marginal performance difference these days)
  • having to convert between C++ data structures and Java data structures (can't just copy memory between buffers)
  • many of the books and tutorials follow the crowd so it is hard to find non-C++ game dev information
  • the core graphics libraries (DirectX and OpenGL) and many off-the-shelf engines are C/C++ based
  • many games try to run as fast as possible so they can add more visually appealing features

It is not easy to work with C++ libraries from bytecode languages like Java (writing a JNI layer) and .net (lots of marshalling/unmarshalling, api/structure attributes). So it adds quite a bit of work for little benefit.

A side note: some game servers use Java.

Similar post here: https://stackoverflow.com/questions/1034458/why-arent-video-games-written-in-java

12
  • You don't have to write JNI yourself, just use JogAmp or any similar library.
    – gouessej
    Commented Aug 4, 2017 at 11:31
  • Good point. I have used JOGL and JMonkeyEngine in Java. More recenlty in I have used XNA/MonoGame to DirectX and OpenTK to OpenGL with nvorbis/naudio/openal in C#. And they work great for small to mid-size games especially when working with shaders. Big improvement to productivity over C++. Then your only real problem is the same as any GC-based language: preventing/mitigating the GC. It will stall your framerate periodically so you'll want fixed-size arrays, static allocations, or long-living buffers that can be tossed when gameplay is stalled (menus, loading, cinematics). Commented Aug 4, 2017 at 13:55
  • I've used JOGL since 2006 and I haven't had this kind of problem even on very low end hardware in desktop environment. The garbage collector isn't to blame because the biggest objects are often either in the GPU RAM or in the native heap (typically the direct NIO buffers), the former isn't managed by the "normal" garbage collection and the latter aren't directly managed by the "normal" garbage collection as it takes care of Java objects on the Java heap. It's up to the developer to release the memory allocated on the native heap efficiently.
    – gouessej
    Commented Aug 5, 2017 at 16:32
  • In my humble opinion, the problem rather comes from some "optimizations" imagined by programmers not in a Java mindset that prevent the garbage collector from doing its job. If you keep some strong references on some useless Java objects linked to some native resources, the garbage collector will never consider them reclaimable. Off-heap allocation can be useful in some cases but if you abuse of it, your long-living resources will stay in memory and you won't be able to create new objects.
    – gouessej
    Commented Aug 5, 2017 at 16:43
  • Some game programmers prefer allocating huge buffers at the beginning, slicing them at runtime and managing this memory by themselves but they'll probably do it worse that the operating system and then, Java will spend much time to free some space to create new objects. Avoiding memory leak isn't harder in Java and a more viable solution consists in tracking only the objects whose memory isn't allocated on the Java heap to release them at an appropriate time (during a pause, when switching from a level to another one, ...), it has nothing to do with the garbage collector.
    – gouessej
    Commented Aug 5, 2017 at 16:52
6

Java isn't fast enough for most game development. It's far slower than using C++/Assembly, which is the standard. It's the same reason more game development isn't done using C# or VB. Game developers need and plan every last clock cycle that they can get their hands on for things like physics calculations, AI logic, and environment interactions.

For simpler games, Java could be used quite effectively. If you want to create a Tetris clone or Bejeweled, or something else of that level of detail, then Java would work fine. But Java can't possibly create games like Halo, Medal of Honor, Command & Conquer, and so forth and make it playable. At least as it exists nowadays.

And the reasons you list in your question are valid as well. Except, I think, for the lack of game developers with Java expertise. Many games on phones and other portable devices are written in Java (including most Android games), and some of the games are quite excellent. So I think there is a decent, and growing, base of game developers with Java knowledge.

The thought is changing on the ability to use these higher level languages for some of the more advanced games. For instance, one of my favorite games, Auran's Train Simulator, is written with large portions in C#, and it works quite well. So the base is growing and will continue to evolve.

20
  • 17
    You leave out one of the most important points; the vast majority of the tools and API's one would use are written in C++ and rewriting them to work with Java or any other language would be a ton of work. Also, your generalization that "[Java is] far slower than using C++/Assembly" is too broad to be accurate. Assembly isn't used as often as you may think in PC games because a good compiler will likely generate more efficient code than you will writing assembler. Deterministic resource use and the ability to get right at the hardware is required however. Commented Mar 5, 2011 at 19:27
  • 15
    Someone really needs to create a better example of Java's capabilities than Minecraft. Until someone can create the equivalent of WoW or C&C or MOH or Starcraft in Java or C#, I will continue to hold to what I've said.
    – BBlake
    Commented Mar 5, 2011 at 20:10
  • 12
    "Assembly isn't used as often as you may think in PC games because a good compiler will likely generate more efficient code than you will writing assembler." That's another generalization. I have yet to see a compiler than can generate better IA32 machine language than an experienced IA32 assembly language programmer. Compilers generate code for an abstract machine that is mapped onto a target machine. An assembly language programmer takes full advantage of the underlying processor, including machine idioms. Commented Mar 5, 2011 at 22:21
  • 10
    Don't forget memory usage. Memory use is probably more important than speed. Java's not designed for direct memory control like C++ and the garbage collector means memory use is always significantly higher than C++ for the same task. Commented Mar 5, 2011 at 22:25
  • 9
    This is not 1985. We have more than 640k of memory, better than 50 mghz processors, and more than 1.44 mbs of removable storage. Game developers challenge today isn't the same as it was 25 years ago. Go ahead and find an example of hand crafted x86/or ia64 code for a modern game. Certain myths are just plain wrong. The challenge is portability, and down level clients using relatively ancient operating environments. Least common denominator vs compelling imersion.
    – JustinC
    Commented Mar 6, 2011 at 1:49
5

Modern games are all about 3D graphics happening in special purpose hardware.

Even back in 2002, Jacob Marner found in his report "Evaluating Java for Game Development" that Java was quite usable for games, except for the most performance dependent parts, and due to the robustness of the language and the underlying JVM that it was cheaper to do it this way.

http://java.coe.psu.ac.th/FreeOnline/Evaluating%20Java%20for%20Game%20Development.pdf

It is my personal opinion that with the progress that has happened since, especially in 3D-graphics, and with the excellent bindings to OpenGL et al, that this disadvantage is much less pronounced these days.

Hence the problem must be elsewhere. A likely reason is the size of the Java runtime (which is much less an issue these days with multi-DVD games), and another the inertia of existing code. It is notoriously brittle to start working with native code in Java. A third reason is what the star developers doing the games are familiar with. A fourth is whether Java is at all available on the platform.

One thing is certain though - most games are moving into being scriptable instead of having it all burned in C code from the start, and you want the best runtime underneath your scripting language. These days this essentially means either the CLR or the JVM.

2
  • 1
    oddlabs.com/technology.php - "We have based our development on the combination of LWJGL and Java, which allows the game to run on any LWJGL supported platform without modifications and at a speed comparable to platform-dependent native code."
    – user1249
    Commented Nov 28, 2011 at 23:01
  • Jake2 outperformed Quake2 more than 10 years ago. We're no longer in 2002.
    – gouessej
    Commented Aug 8, 2017 at 13:33
4

Game developers like to be close to the metal and often will write their tight inner loops in assembly. Java doesn't offer the same level of possible performance, both in terms of consistent speed or memory use (running a JIT takes its toll).

4

I think the limiting factor for most people is the (lack of) availability of good game engines. To get very far, we need to look at why those aren't available.

I would look at that from the other direction for a moment. Developing a game engine (for example) is a lot of work. Who would benefit enough from developing one to invest the time and effort to do so?

Most of the obvious candidates for framework-like development in/for Java (e.g., IBM, Oracle) seem to have zero interest in games. The obvious candidates for game development (e.g., Id, EA) seem to have almost equally little interest in Java.

Nearly the only candidate I can think of that seems at all reasonable would be Google. The primary development language for the Android is Java, and encouraging game development for Android could provide a real advantage for the platform.

As far as I know, they haven't done so (yet?) though, which leaves some pretty severe limits for almost anybody else. Without little in the way of modern, high-performance game engines to use development on Java means quite a bit of extra work, with (what looks to me like) little prospect for producing a lot of benefit in return for that extra work.

2
  • I think you've hit an important issue with the game engines - I think this is the biggest reason why Java hasn't caught up with C/C++. It's possible that open source may level the playing field a bit however - I've been very impressed with jMonkeyEngine (jmonkeyengine.com).
    – mikera
    Commented Nov 28, 2011 at 0:50
  • and don't forget that game developers are extremely conservative overall (technically), and most of the large (influential) shops have existed for decades and are C(++)/ASM centric so aren't going to invest in Java development as it'd mean extensive investment of time, money, and other resources up-front when they've an entire C(++)/ASM architecture ready to roll.
    – jwenting
    Commented Nov 28, 2011 at 7:36
1

The question is on par to asking something in the lines of:

What is better to power your car, a boat engine or jet engine.

It comes down to scalability, bug avoidance, speed, memory signature, modularity and a whole host of things. The question should not be be about what is better as an industry standard, the question should be "what is better for me" as in what you know or how well you know it. If it does the job then it does the job, if you can actually sell the idea then it works and who knows you might even bend a few spoons.

0

Java wasn't made with game development in mind, Java was made to be a language "for the web".

As for game development, Sun didn't really support Java as a game development language as Microsoft backed C#.

I think the lack of compelling game development frameworks is what really killed Java in this aspect.

21
  • 3
    But C++ wasn't made as a games language either, but as a systems programming language just like C. And Sun actually did make some effort on Java as a games language, I think they were cooperating with Sony to bring Java to the PS2 or something, but it never happened...
    – Anto
    Commented Mar 5, 2011 at 21:10
  • 1
    @Phobia: But it was designed for systems programming.
    – Anto
    Commented Mar 6, 2011 at 13:55
  • 1
    @Phobia: I'm saying that it is a general-purpose programming language, just like C++. In your answer you say that Java wasn't designed as a game programming language, but you forget that C++ is not either designed as that.
    – Anto
    Commented Mar 6, 2011 at 14:41
  • 2
    @Joe Blow: From the Wikipedia page about C: "Although C was designed for implementing system software, it is also widely used for developing portable application software." I think that is pretty clear, isn't it?
    – Anto
    Commented Mar 6, 2011 at 16:56
  • 2
    @Phobia I’m sorry about your personal preferences but they are completely irrelevant to the discussion. Furthermore, I don’t want to contest that nowadays C++ is used almost exclusively in application programming. This isn’t what this discussion was about. Your claim that Java was designed with web programming in mind. Well, C++ was designed with systems programming in mind. Says its designer. End of discussion. Commented Mar 6, 2011 at 17:33
-1

It's easier to glue C more directly to brand new unconventional hardware and drivers. The sooner and closer a game programmer can get to the hardware, the better they can outspec competing games. Later game programmers just stick with the same methodology and tools as those prior proven games.

For games where optimizing to the latest hardware is less important, such as casual cell phone games, using C in this way is less important than is Java's greater portability.

-4

For some people reason has nothing to do with speed, libraries, or availability. It is simply because of the language itself. Some people simply do not like Java the language. Other people would rather use their favorite programming language instead of using Java to make games.

1
  • this reads more like a comment, see How to Answer
    – gnat
    Commented Jun 30, 2015 at 12:08
-7

It could of course be something else. Could someone who knows the business better than me explain why Java isn't getting momentum when it comes to game development?

It's an interpret language, ie slow. You're dealing with graphic and graphic card which is hardware. What's a good language to deal with hardware? Well C++, it's pretty low, and you deal with pointers and whatever.

If you want to pump out crazy graphic like crysis and whatever you're not going to do Java for it.

Not only that, Oracle owns Java, the thought that a company can sue you doesn't bold well. Especially when you want to build your own interpretor for JAVA to target gaming without getting sue due to fragmentation FUD.

10
  • 2
    You should seriously read about JIT compilation, and look at some benchmarks where Java is put against C++
    – Anto
    Commented Mar 6, 2011 at 13:52
  • 1
    Who the heck voted this answer down? This whole question is becoming incredibly ridiculous! Good grief.
    – Fattie
    Commented Mar 6, 2011 at 15:48
  • 8
    @Joe The answer is wrong. Java isn’t interpreted. Commented Mar 6, 2011 at 17:00
  • 3
    @Anto Forget those silly benchmarks. C++ is orders of magnitude faster than Java where it counts, see programmers.stackexchange.com/questions/29109/29136#29136 and programmers.stackexchange.com/questions/368/13888#13888. Commented Mar 6, 2011 at 17:02
  • 1
    @Konrad As far as I can tell you are only offering a single conunter example based on sort - how is that better than "silly benchmarks"? Commented Nov 28, 2011 at 15:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.