C++ V.S Java for game programming.

Started by
31 comments, last by SimonForsman 12 years, 2 months ago
Obviously, this is a highly debated subject, and you've all heard this kind of post 1000x before. But this isn't my only question, I would like to know your reasoning. What are the pros/cons for both languages?

Thanks :)
Advertisement
Pro for the one you're familiar with:
* You're familiar with it.

Con for the one you're not familiar with:
* You're not familiar with it.
I've got a better question. Red or blue. Which one is a better car color?
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
So, i'll post a serious response to this, since I often ask this question myself. Firstly, I am more familar with C++ than I am with Java, however I have dabbled in Java, and know enough to be able to make a decent definition of both.

C++

- Because Java requires the JVM and converts there source to Byte Code, (I believe this is called Interpretation), which is then compiled into native by the JVM makes it
slower than C++ which compiles directly to Native Code. There C++ is a faster language, and for games, the faster they run, is generally the better.

- Ability to handle memory allocation/deallocation, I guess some would find this a disadvantage, but personally I think this little facet is very useful for a lot of things.

- Object Orientated Support, in both languages, is a pro to mean.

- Industry standard. Why fight the craze? As they say, can't beat em, join em.

Java

- With C++ you need to use external libraries to alot of things, like graphics rendering, platform handling, networking, threading, etc, etc. While with Java, this pretty much all comes with the language in a tight little package. Sure they lack support for 3D (I think, might have changed since I last checked), but it still comes with numerous elements
that make it useful to just begin programming.

- Its cross-platform, meaning you can target your games to all devices, not to mention the JVM is portable to pratically any device or most, such as mobile phones, meaning you code once, and then its gonna work on any machine running the JVM. C++ requires that you compile to native for a specific OS/Architecture, furthermore the use of libraries like WinAPI and DirectX render your application unsuitable for cross-platform usage.

- Is it my lack of thorough understanding of Java, or is that it seems to be pretty much fully OOP orientated. I heard that its supposed to support multi-paradigms, but to me, it supports generally two, OOP and Generic. (And would we even called Generic Programming a paradigm ? or a feature? ).

Thats all I can think of now, its early and I have college soon, but that pretty much defines it for me.
Game Programming.. Creativity and Logic in one massive bundle. Gotta love it.
I forgot what programmer used to say that picking a programming language is like picking a bar to hang out in. I tend to agree laugh.png
[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe

I've got a better question. Red or blue. Which one is a better car color?


I'm gonna expand on this, seeing as someone rate-- it (which is fine by me, I'm not whining about it), just so people can know what it was I was trying to get at in case it wasn't clear originally.

The answers to the C++ vs Java for game programming question don't really mean much. Both are cross-platform computer languages which one can use to create games (or other applications, if desired). Particularly, when it comes down to a person's opinion/reasoning for their conclusion, it's mostly just a matter of personal preference. I might prefer to not have a garbage collected language, whereas someone else may prefer that. I might like a red car, but someone else might like a blue car. Knowing what someone else prefers isn't going to really help anyone that much.

A much better question is "what are the differences between C++ and Java (particularly in game programming [despite the fact that the game programming part of the question doesn't really change the responses too much])?" The reason this is better is because now you get the technical differences between the languages and you can form your own opinion of the two. Having a C++ vs Java debate implies that one is better than the other. Really, they're just tools one uses to create something. One isn't inherently better than the other. There are differences between the two, and understanding those differences yourself is much more important that knowing another person's opinion.

Basically I'm trying to steer you away from the idea that any one is better than the other. If there was an absolute answer, then the question wouldn't have been asked 1000x times before (and asked again). There isn't. There are just technical differences between the two. Understanding those technical differences yourself will do you so much more good than trying to decide which one is better than the other.

For the record, you may find this interesting. Now, if there's a more specific question you have, then it'd be much easier to answer it (i.e. what tools/APIs/libraries exist between the two languages that facilitate game development; why does there seem to be more C or C++ games than Java games; etc). But this C++ vs Java question is so big and vague and meaningless, and it's been asked so many times before, and the answers never change (hence anything you find via googling the question is almost guaranteed to be the same as the responses you'd get here).
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

Obviously, this is a highly debated subject, and you've all heard this kind of post 1000x before. But this isn't my only question, I would like to know your reasoning. What are the pros/cons for both languages?

Thanks smile.png


How exactly are the 1000's of other threads about this not sufficient for you?

The pros and cons are too numerous to list here; frankly my reasoning doesn't matter here. My experience using each language and solving programming problems in a variety of settings and enviroments are what color my opinions of each. Reason has little to do with it.

I've got a better question. Red or blue. Which one is a better car color?

Blue. Red is more attention-grabbing to most everyone, including law enforcement. Thus, if you wish to push the speed limit more, you don't want a car that screams "Look at me!"

To keep my post on topic, I would say that for more complicated games C++ is a better choice since you can get far better speed from low level optimizations. I also would say that nothing good has ever come of Java, but that may be because my day-to-day experience with it is my crappy set top box that can't do anything right.

I also dislike that you have to download a 160-200MB runtime (not counting 3D libraries) to run a 2MB program whereas with C++ at worst it's a 20MB runtime (again not counting 3D libraries).

Finally, I hate the verbosity and poor design decisions of Java (everything must be in a class, no operator overloading, etc.) that ends up making things more complicated than they need to be.

OTOH I do like the "compile once, run anywhere" you get with most Java programs. Too bad that goes out the window once you need to use native code to do something (like 3D).

The "interpreted language, so it's slower" thing isn't so true anymore, since the JVM is more of a JIT compiler (it rebuilds the Java bytecode as native code as it runs) so a particular piece of code is slower only the first time it's run.

In all, I prefer C++ because it's less verbose, doesn't force you to adopt the "One True Project Style," allows operator overloading (which helps cut down verbosity and clarify the code if done right) and allows you to much better push the hardware to the limit.

I forgot what programmer used to say that picking a programming language is like picking a bar to hang out in. I tend to agree laugh.png


If you're trying to get laid, the choice between gay and straight bar will matter a lot.

So yes, it matters.



As for Java vs. C++.

They are languages. They cannot do anything. Not even a console application.

So the choice comes down to run-time. If Java:
- JEE, JDK, JME or Android (they are different in the same way C and C++ are different)
If C++:
- The OS (Linux, OSX/iOS, Windows pre-8, Windows 8+)

Each of these is what matters. They determine what can and cannot be done.

[quote name='daviangel' timestamp='1327304010' post='4905361']
I forgot what programmer used to say that picking a programming language is like picking a bar to hang out in. I tend to agree laugh.png

If you're trying to get laid, the choice between gay and straight bar will matter a lot.
[/quote]
Way too picky. Of course, if you start talking about which is better, C++ or Java, then I guess it becomes moot.

Stephen M. Webb
Professional Free Software Developer

This topic is closed to new replies.

Advertisement