For creating a game, is Java or C++ better?

8 points by Nimitz14 ↗ HN
Me and a friend what to team up and program together.

The problem is I primarily know Java, he C++. Note we're both still newbies - better than somebody who's just taken a programming course - but still far away from being experienced programmers.

Our current plan is to first program a 2d game together, and then we'll see what we feel like doing next (I personally think it would be cool to take a loot at some open source engines).

So the question is, what are the pros and cons of each language considering the circumstances I just described?

16 comments

[ 4.4 ms ] story [ 60.0 ms ] thread
1. Wrong forum

2. Java, because it is way easier. C++ is an expert only language.

C++

It's what most game engines are done in. You get more control over performance. You can go all the way down to the metal if you want/need to.

It's a bit of a cliche for newbie game developers to get instantly sucked into engine-development/performance-concerns and then never actually birth their _game_ idea.

Use anything. Finish a game. Worry about the best technology next time.

This is much better advice than it might seem at first glance. The temptation to get sidetracked by pointless bikeshedding and unnecessary optimization can be huge, when you're trying to find out the 'right' way to do something.

I know because i've done tutorials and started projects far too complicated to finish in Unity, Gamemaker and C++. I wasn't even aware of how counterproductive it was to actually finishing a project because in the moment it feels like you're making progress, but you're usually not, at least as far as finishing the game is concerned.

I maybe should have mentioned we both have already made a simple game (coincidentally both of us did Space Invader). The 2D game idea is supposed to be a stepping stone getting us to the same level before we try 3D, and we both are the type of person who thinks it's cool to optimize things. ;)
Try GameMaker by yoyogames ... I have an artist friend who did not code, he is close to finishing his game using this engine. It's 2d, but very easy to use.
Neither. Learn something else. There are 1000 better languages for video games than what you mentioned. You won't get far with either because you'll delve into the unneccessary complexity of how those languages are organized, and you'll never recover to the real world to make a concrete game. You'll have a load of abstraction that does nothing.
My personal and entirely subjective preference would be C++ and SDL2, or Unity with C#. I'm not that great at Java so I can only say I like what I know, which isn't very useful.

Although, if you care more about education than shipping, why not try building the same game in both? You would each learn how it's done in both languages and you could test which seems better.

My two cents:

If you can develop a game in a garbage collected strongly typed language with a [mostly] cross platform run time that sometimes allows you to forgo porting when moving between platforms and minimizes the amount of porting when it is required, then that seems like a good way to go.

Selecting a "faster" language only matters if there is a performance bottleneck and the "faster" language happens to be faster in exactly a way that removes the bottleneck. Most performance bottlenecks are IO or algorithmically based.

Even deeper, I'd consider prototyping in a scripting language because scripting languages make it easier to iterate quickly than enterprise class compiled languages. For a game, gameplay rules and a fast game with gameplay that sucks still sucks. And the scripting language game may be good enough.

Carmac used C++ for Doom. It was the first game I stayed up all night playing. My rig had a 160 megabyte Hard drive, 5 megabytes of RAM, and a 25 megahertz AMD CPU. These days I download 160 megabyte files without a pause and there are webpages with 5 megabytes of JavaScript...and Quake [not Doom] can run in a Browser.

Focus on shipping. Choose tools for that purpose.

Good luck.

Define "better".

If you want something more efficient/performance, C++. If you really want to get into game programming: C++. If you're still learning basics about programming: Java. If you want something that's memory managed, and easier to write: Java.

Honestly, either is possible to build a game in. However, if you want to or will need to use the GPU you will likely want to stick with C/C++. There is nothing that says Java is bad or evil, implemented properly it is a completely viable language and tool. C++ is just closer to the hardware and will be more performant most of the time, but not always. You can implement some real crap in C/C++ that will perform worse than Java would. And speed to market generally favors languages like Java and C#.

So boil it down to what you need to do and what you are both more capable of doing. Likely Java will happen faster and get it launched, which is usually more important initially than raw performance. So maybe that is the way to go at least initially.

I generally focus mostly in C/C++, Javascript (some Go now) and the like, no Java anymore. Just putting my bias out there so you know.

I'd go with Java. I wrote a bot in Java back when I barely knew any programming, and it wasn't really that hard. C++, on the other hand, would have cripplingly slowed me down -- because it already had, when I tried it as a newbie. Keep in mind, that's when I knew almost nothing and a "LinkedList" was an abstract novelty to me -- I'd written a few games in TI-BASIC and QBASIC 4.5. A few years later, when I was more clueful, I used Java for what was essentially a 2D game and it was nice.

Java pros: memory safety, documentation, it just f'ing works.

C++ pros: not relevant to your situation.

Particularly read frau_dh's comment.

Proper usage of C++14 should remove the "expert" and "difficult" mystique surrounding it. In fact, I would say that nowadays, it's easier than Java. But that's not really what you should be looking at. Instead, consider what library you want to use. In the end, that is what will make it easy or hard for you.
About 5-6 years ago, I chose Java when I was in a similar position and writing a game. It's a much easier language (I don't feel like justifying this claim, others have done so) and the final product is easier to share with friends (package your code in a runnable jar when you're done). One other word of advice, I found it simpler to write my own basic engine rather than learn another. If I had my current level of experience, I would definitely start by learning an engine. However, if you don't have a lot of experience coding, it might be easier to write it yourself. For example, you won't need to figure out the documentation for plugging into the game loop because you will have written your own game loop. (1)

1. http://gameprogrammingpatterns.com/game-loop.html