Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I am a systems administrator and for many years I worked with *nix servers. My main experience programming is with Perl and shell scripting, but in my new job I've been told to learn Java and well... I'm not even interested in it. But what I am interested in is in game development, so while I don't have any interest in Java, I was wondering if I could use it to develop games?

I was wondering whether this is viable and if so, what approach should I take?

share|improve this question

marked as duplicate by Byte56 Jul 12 '13 at 19:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

As a meta comment, I'm not so keen on your attitude about job requests ;) A nicer way to phrase it would be, "I've been asked to learn Java, and am interested in game development and maybe I can learn Java by doing some games." – Tim Holt Jul 29 '11 at 22:17

I think java proved itself as quite a viable programming language for programming games the same way that C# did with libraries such as XNA. It may not be as efficient as a low-level language like C++ in some situations because it is managed but it doesn't change the fact that it removes the need to manage memory by yourself (but then you have to deal with the garbage collector though).

Some successful java games: Minecraft, Runescape, other java games

Things java might be missing for game development.

I guess you could start out learning with this link and move on with other online tutorials after that.

Even though java can do the job, I'd still recommend trying out C# with XNA. C#'s syntax is, in a way, similar to java and won't take too much time to learn (if you know java).

Here are some resources for learning XNA and let me add this link that I recently discovered that is simply fantastic too.

But, hey, if you like java, program in java! Just program games in the language you prefer. Don't worry too much about how "efficient" or "viable" a language is until you feel like you master the game development's concepts enough to chose a language to use it at its full potential.

Just my little 2 cents on the subject.

Happy coding!

share|improve this answer
(+1) Concise, correct answer. It is primarily your choice. It used to be the case that Java's dependence on it's VM meant that it was very slow, too slow to be used for games. However, recent improvements mean this is no longer the case, and Java has very good portability, because it runs on a virtual machine. :) – Shaktal Jul 29 '11 at 16:37
Good answer, but I hold off the +1 for now, since I have to disagree with "the fact" that it's easier/faster to develop games in Java compared to C++ (or even C# which would make it clearly false). Memory management is sometimes a concern, but it isn't half as hard to manage as managed-people make it out to be. In fact, I'm sure anyone with a little bit of programming experience can handle it easily. Apart from that, C++ has some features which can make game development easier (templates, multiple inheritance), plus the amount of available libs online in C++ is just enormous compared to Java. – TravisG Jul 29 '11 at 17:02
@heishe: Alright, I must admit that I'm not a java programmer at all, I just assumed that it was kind of easier the same way that I personally find it easy to program with C# than with C++. I'll rephrase to show that it only removes the need to manage memory. – Jesse Emond Jul 29 '11 at 17:13
@Jesse Emond: +1 :) – TravisG Jul 29 '11 at 17:30

Java can definitely be used to develop games, and there have been some very successful games developed in Java. I think Jesse has already done a good job of giving some examples of desktop game development in Java, but I wanted to point out that you can also write mobile games for Android in Java. Don't expect to make much money on it, but the mobile space is very hot right now, and it's a great place to get some exposure for your work.

Additionally, check out the Java4K site for some other small projects written in Java. All of the games on the site use 4,096 bytes of memory or less in their compiled and packaged forms, including all art assets.

The one concern I'd have about writing a game in Java is that, while you get the convenience of automatic portability between PC operating systems, you'd have to completely rewrite your game if you wanted to port it to a platform like iOS. If you wrote it in C or C++, you'd have a bit more work to make it portable in the first place, but there would be no limit to the number of platforms you could port it to. But for a starting game developer, that's a minor concern. You should focus on just making some games before you worry about portability.

share|improve this answer
Java is write-once-run-anywhere-that-has-a-compatible-JVM. C++ is write-once-compile-anywhere. You are correct that you need to use a bit of preprocessor magic and be careful to write portable code in order to make your C++ code portable. However, when you're writing a game, the only platform-specific code you really need is for file system and networking operations, so that's not very difficult. Sure, you can forego ALL of that code with Java, but you will NEVER get your Java app to run on iOS, whereas even a C++ app not written for portability will work on iOS with a little extra effort. – Mitch Lindgren Jul 30 '11 at 1:49
Additionally, if you're targetting any combination of platforms more varied than Windows/Linux/OS X, you will probably need platform specific code with Java anyway because of how implementations vary. You could not, for instance, take Minecraft and build it for Android without any changes. (To be fair, that's because Android is "not really" Java, but the same applies to many other platforms.) – Mitch Lindgren Jul 30 '11 at 1:53
Thanks for those helpful comments (+1 for each one and also for your answer now). The only point I would differ on is that the Android OS doesn't have a typical JVM like other platforms do, although it does run Java classes -- there are many unique requirements that make it a very different JVM environment (which is unfortunate, and I hope that Google will change this in the future so that stand-alone applications can be used some day, although I suspect this may create some major architectural challenges mostly centred around the GUI). – Randolf Richardson Jul 30 '11 at 2:57
Also, in the interest of fairness, I forgot to mention that threading code is platform specific in C/C++ and that's quite a bit more difficult to manage than I/O. So that's a big win for Java. – Mitch Lindgren Jul 30 '11 at 5:40
I use threading heavily. I used to program with pthreads in ASM (using the C calling convention) many years ago, and I agree with you that threading is very inconsistently implemented across different OSes. I also find that most people seem to have a lot of trouble programming threads, which is why I believe the forking model is still so popular. Regarding downvoting, I've never done that (my profile should confirm that) because I believe that if a question really has some problems that it should instead be closed (or even deleted) if the author isn't willing to improve it. – Randolf Richardson Jul 30 '11 at 16:23

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