Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

29  
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. –  Ed S. Mar 5 '11 at 19:53
19  
In fact, Java is used for game development; i.e. in the mobile market. Java ME, Android. –  user281377 Mar 5 '11 at 20:14
20  
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 Mar 5 '11 at 22:56
11  
Interestingly, Minecraft is Java based. –  Uri Mar 5 '11 at 23:03
4  
@Coder Looks like the C++ code was heavily optimized, but the Java code was not. So it's an invalid comparison. –  Izkata Apr 24 '12 at 15:39
show 20 more comments

13 Answers

up vote 75 down vote accepted

Several reasons:

  • In the old days, you needed "direct access" for performance and UI. This predates JVM 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.

share|improve this answer
11  
+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 Mar 6 '11 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 Mar 6 '11 at 4:46
1  
A JVM for consoles can be included on the game disc. I don't see the problem there. –  rightfold Nov 28 '11 at 16:22
5  
Predictability of performance is not possible with a JVM. –  Klaim Nov 28 '11 at 21:52
2  
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 Oct 11 '12 at 14:04
show 4 more comments

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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 od workhorse, but the real innovation is happening with the new JVM langauges (Scala, Clojure in particular). These languages get all the advantages of the Java/JVM platform, plus they are extremely powerful modern languages.
share|improve this answer
10  
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 Oct 11 '12 at 14:07
2  
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 Mar 11 '13 at 18:50
    
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 Mar 24 at 4:12
    
RE: your points about the JVM & other languages - LuaJIT is arguably a much more portable and potentially faster jit VM. It even out performs both Java and C++ in some cases. –  Jess Telford May 16 at 18:57
add comment

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.

share|improve this answer
1  
You should seriously read about JIT compilation, and look at some benchmarks where Java is put against C++ –  Anto Mar 6 '11 at 13:52
1  
Who the heck voted this answer down? This whole question is becoming incredibly ridiculous! Good grief. –  Joe Blow Mar 6 '11 at 15:48
6  
@Joe The answer is wrong. Java isn’t interpreted. –  Konrad Rudolph Mar 6 '11 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. –  Konrad Rudolph Mar 6 '11 at 17:02
1  
@Anto What's am I suppose to look at? Speed? C++. Memory usage? C++. Look at minecraft and try hosting a server and see how much memory the game is taking up. Java consume much more memory versus C++. Making an online game, I would imagine is pretty hard in Java. Every benchmark I've seen so far Java consume more memory, now having a mmorpg game where the central server is coded in java sounds nice only if you ignore the memory aspect or change the definition of massive in MMORPG. –  mythicalprogrammer Dec 8 '11 at 21:12
show 5 more comments

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.

share|improve this answer
    
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 Nov 28 '11 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 Nov 28 '11 at 7:36
add comment

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.

share|improve this answer
add comment

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: http://stackoverflow.com/questions/1034458/why-arent-video-games-written-in-java

share|improve this answer
add comment

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.

share|improve this answer
2  
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 Mar 5 '11 at 21:10
1  
@Joe Blow: C was designed for UNIX, an operating system. That is systems programming. C++ had the same design goals as C had, so they both are systems programming languages. Assembler is not a language, it's a program which turns Assembly code into machine-readable instructions. C is not the lowest level programming language after Assembly, C provides quite many abstractions when you think about it. –  Anto Mar 6 '11 at 13:46
1  
@Phobia: But it was designed for systems programming. –  Anto Mar 6 '11 at 13:55
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 Mar 6 '11 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. –  Konrad Rudolph Mar 6 '11 at 17:33
show 17 more comments

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.

share|improve this answer
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 Nov 28 '11 at 23:01
add comment

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.

share|improve this answer
15  
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. –  Ed S. Mar 5 '11 at 19:27
11  
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 Mar 5 '11 at 20:10
10  
"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. –  bit-twiddler Mar 5 '11 at 22:21
9  
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. –  Matthew Read Mar 5 '11 at 22:25
8  
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 Mar 6 '11 at 1:49
show 14 more comments

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).

share|improve this answer
add comment

protected by MichaelT Mar 24 at 1:01

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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