2

Ive been learning java for maybe 5 months, and for that whole time, i mostly tried making games. I made a halfway decent game with java2D, but I want to move on to bigger and better things... 3D. I began to learn LWJGL(which is basicly OpenGL). Before I get too deep into learning java, and going 3d with it, should I move to c++? Are pointers really that essential for large programs? Can I still make anything cross platform with c++? or am I stuck with windows. If I am stuck with windows, should I just go for c#?

Thanks.

When I said halfway decent, I meant that it was good, IMO. If you want to see it, to judge where i am in 2D experience, here you go: http://www.thenewboston.com/forum/viewtopic.php?f=119&t=13249

So Java is okay for game devolepment, on large scales?

5
  • Just for reference, there are plenty of games written in languages that are not C++. Dungeons, for example, was written in C#. Aug 22, 2011 at 6:21
  • 4
    It's mostly opinion, so I'm not going to answer. One thing stuck out though, what makes you think Java doesn't have pointers? I know Java calls them reference types, but they are still pointers. In fact Java is almost totally dependent on pointers, whereas in C++ you have the choice to use pointers or not. So I think you have that distinction totally backwards.
    – john
    Aug 22, 2011 at 6:43
  • @john: Full agree. In C#, I find the semantics of object references to be almost like that of pointers, with the only thing forbidden being arithmetics on them. Apart from that, they really just miss the & and * operators. Aug 22, 2011 at 7:39
  • 1
    While Java/C# references are close relatives of pointers, there is a big difference in that they are opaque (i.e. the actual memory address is not readable). The first effect of that is as it has been mentioned, that you cannot perform arithmetic, but more importantly, objects can move (and they do) in memory transparently from user code. Aug 22, 2011 at 8:38
  • 1
    For the love of gods, please use proper capitalisation where called for. It makes the text so much more readable. Aug 22, 2011 at 18:14

7 Answers 7

5

Before I get too deep into learning java, and going 3d with it, should I move to c++?

Its worth considering knowing more than one language.

Are pointers really that essential for large programs?

This question is nonsensical, so "no".

However, C++ has some key advantages when it comes to games:

  1. Less memory overhead.
  2. Deterministic memory usage and timing.
  3. Deterministic runtime performance (with potentially better speed)

The first two of these are side-effects of Java's garbage collector and can be a problem with Java games (or any application). Whether or not they matter is completely up to you.

The third is a side-effect of the JIT. Java may not JIT all methods immediately (leading to a rough start), or at all (on a client VM). In addition, for true high end hardware usage, it may not make the best use (if at all) of extra hardware, such as vector instructions (SSE2,3,4,4.1,etc).

Can I still make anything cross platform with c++? or am I stuck with windows. If I am stuck with windows, should I just go for c#?

Yes, with effort. C++ is its self cross platform, but that is just a language. The rest is in libraries.

2
  • Agreed on the point of pointers being unnecessary in large programs. C++ can be more performant than other languages, but there's nothing in languages like Java that will prevent you from creating a large game. Aug 22, 2011 at 6:27
  • Actually as far as I know the JIT does already vectorize programs. Sure it may not make the best use of it - but neither does the C++ compiler (after all not a trivial problem; and since many game devs use VC++ they don't get any auto vectorization afaik). Though you can use compiler intrinsics in C++, which I don't think you can in Java (actually I read some paper about this sometime ago, but I don't think there's a library that does this out)
    – Voo
    Aug 22, 2011 at 15:21
3

You can use Java as long as it meets your needs. If you find something specific you want to do that can't be done with Java, that's the point I would investigate other options, unless your game development is an exercise in learning programming languages. If that's the case, then by all means, try out C++.

The main reason I can think of that people move away from Java to non-bytecode compiled languages is performance and memory usage. So you should consider if this is an issue for you.

Regarding the cross-platform capabilities of C++: You can definitely write portable C++ code that can be compiled for multiple platforms. There are game libraries that work on multiple platforms like SDL or GLUT. You can write your game once with these and compile for multiple platforms.

4
  • Upvote for the second paragraph, but I do not agree with your first. Aug 22, 2011 at 6:35
  • Which part do you not agree with?
    – user885074
    Aug 22, 2011 at 6:36
  • "You should use Java as long as it meets your needs" - I disagree. Most any language can meet your needs. But don't be an ostrich, look up at what else is out there.
    – mrjoltcola
    Aug 22, 2011 at 6:39
  • I will soften the language. I did not intend to convey that looking around was bad. I meant to communicate that using what works will get you results fastest and simplest.
    – user885074
    Aug 22, 2011 at 6:44
2

This type of question is better suited for something like the Game development stack exchange site, but here's my answer:

With respect to what language you should use: Anything works. Yes, C++ is faster. But it's also harder to write "good" C++ code if this is your first time working on it. It's very easy to make a lot of mistakes in C++ if you're used to languages like C# or Java. It's much easier to start writing a game in C#, Java, Python, or any number of other languages than it is in C++ if you've never used C++ before.

If you do Java, you can make it cross platform. C# I'm not 100% on, as Mono does exist but I'm not sure of the state of cross platform functionality with games written in C#. C++ is cross platform as well.

Overall, if you've never done cross platform programming before you may run into some hurdles as you try to develop your software. The more comfortable you are with the particular language, the easier it may be for you.


With that said, I would caution you away from jumping right into 3D games, since you've stated you haven't finished a 2D game at all.

3D games are MUCH harder than 2D games, and you shouldn't be worrying about programming when you're making games. You should focus on writing the game itself. You'll learn how to program the games as you actually design and create the various features of the games. You shouldn't do things the other way around.

10
  • On the contrary, I'd say jump right in. Game development is the first love of many a great developer.
    – mrjoltcola
    Aug 22, 2011 at 6:37
  • I never said otherwise. I merely stated he should stay with 2D games for a while before he has an understanding of how to actually create a game from scratch. The fact that the OP has stated he's only had a half finished game makes me recommend that he try actually writing a few games in 2D before making the jump to 3D. Aug 22, 2011 at 6:41
  • "It's much easier to write a game in C#,..." -> Not every game. Consider writing something massively number crunchy like the Total War series. I bet you'll be having a hard time meeting your timing constraints for sufficiently large battles there. Aug 22, 2011 at 6:50
  • @phresnel: Of course. I was generalizing a bit too much there. Fully qualified that sentence should read "It's much easier to write non-CPU intensive games in languages such as C#, etc.." When it comes down to needing raw performance, you're pretty much stuck using a low level language where you can start doing assembly optimization, like C++. Though even then, you can call native code in C#. Aug 22, 2011 at 6:52
  • You really don't need assembly. Actually, only a small fraction of a permille of C++ developers are able to beat a modern C++ compiler like g++ at its own game. There are some basic rules that don't even make your code unclean (also no need for undefined behaviour), and the compiler will do its duty well. Aug 22, 2011 at 7:01
0

Ok, keep in mind that c/c++ are compiled languages that are portable, but 3D libraries such as DirectX are not. I think a good place to start 3D programming for games is with c/c++ and OpenGL. But, programming is only a part of game development and there are a lot of options. If you want to make games, you can look into low-cost engines such as torque3d or Unity 3D that use easy-to-learn scripting languages and have everything you need built in such as physics, audio, and networking support. If you really want to know how to program 3D graphics, which is different than game development, then the low level languages like c/c++ paired with OpenGL is a good place to start.

0

Learning 3D programming and C++ at the same time is a tall order.
And sure, it's possible to write cross-platform games in C++, but you really don't want to go there. Seriously.
There are cross-platform frameworks you can use if you really want to, but adding yet another thing to learn is a certain path to despair, and before you know it you'll want to become something more exciting, like a chartered accountant.

My advice: Stick with Java while you're learning 3D. You will pick up plenty of general programming skills (and maths) along the way, but the language won't get in the way. You can always move to C++ (or some other language) later if you need it or just want to learn.

And there's no such thing as "too deep". Are you afraid that you might learn too much? That won't happen.

0

If you want to get a bunch of reasons from partisans in the Java camp, consider checking out http://www.java-gaming.org. Among other things you will see some forum threads on the very subject (c++ vs java), as well as listings for resources and examples.

Some "big" games that use Java: Minecraft, RuneScape, there's lots more.

Java allows concurrency, which is a big plus as there continue to be more multicore processors out there. JIT is fast, and can do optimization on the fly that precompiling cannot.

0

I recommend you learn C++, for one big reason. Perspective.

If you don't try C++, you'll never realize just how good C# is when you finally learn it. :)

I spent 20 years with C++. I spent years holding on, not letting go. Finally realized other software companies are eating my lunch coding in more productive languages with better SDKs. It felt good to finally let go. (Though I'm still holding out for fully compiled C# and deterministic memory management one of these days).

(I'm only half serious. C++ really should be in your toolbelt as a game or system developer).

9
  • Upon learning C# and using it professionally for some years, I realized that some parts are worse than in C++. The lack of multiple inheritance, the lack of non-OOP, the lack of templates, the lack of more sorting algorithms, the overhead of the big .net-runtime, the lack of cross platformness (except for age old C#), worse performance even after running through a codepath for the x'th time, and some more. Of course, some ideas are nice, but all in all I really don't miss my time in C#. Aug 22, 2011 at 6:57
  • @phresnel Multiple inheritance? Really? … The modern take is: “never use inheritance. Ever!” and I very much agree (note that I didn’t say “multiple inheritance”. I said “inheritance”, full stop). The problem isn’t inheritance but the fact that you cannot reuse code, thus causing potentially a lot of boilerplate to delegate methods to members. But this isn’t best solved by multiple inheritance, it’s best solved by type traits or mixins. Multiple implementation inheritance is at best a crutch. Aug 22, 2011 at 18:16
  • @Konrad Rudolph: I was not arguing how good or bad a design relying on multiple inheritance is, rather I wanted to say that sometimes it's a good tool, one that can help you to ROI faster. E.g., there was some legacy class I inherited, a huge class that did good stuff but in a bad monolith manner. Using multiple inheritance I was able to extract several interfaces from it, in a step-by-step manner as encouraged by Fowler. These views could then be installed into different parts of our system. I could then continue to make it better stepwise, making partial implementations of interfaces. Aug 23, 2011 at 8:20
  • [cont a...] Within the scope of C#, I once used some components of (afair) DevExpress, a not too well designed framework. At some part, it required deriving several interfaces. Having multiple implementation inheritance instead of having to implement a myriad of quasi-noop function forwarders would have saved me a lot of valuable time. Of course those designs were/would have been a crutch indeed, but one that helped with refactoring and a faster release cycle with a not toooooo bad design. Or, in some rare circumstances, mixin-based programming can be useful. ... Aug 23, 2011 at 8:21
  • [cont b...] Errrm, let me state it like this: It's a bit like with #define macros. You should never ever the death not use it. Full agree. But just now, after like 5 years, I've found some good use for them to implement a kind of statically checked hierarchical enum. Not using #define there would have been a bigger crutch, so I was happy to have that tool in the box. Aug 23, 2011 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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