I think that largely depends on what kind of game you're dealing with. If you have large or detailed graphics, or anything that's really CPU intensive, I'd go with C++ hands down. But, if you're working with a networked game (if your game's slowed down waiting for a 56K modem, what's the diff?), a game that's turn-based (if your game has to wait a minute for user input, that extra 2 secs doesn't really matter), or some other situation where the CPU speed is of lesser importance, Java wins because of its portability. Sorry, C++ fans, but the fact that I can run my game on Macs, Windoze and Linux with limited difficulty is enough for me to put up with the slowness unless I really need the speed.
As far as ease goes, I have to say that Java comes naturally to me, while C++ is still a chore. Java's my language of choice... Doesn't mean I'll use it for everything, but it's really useful.
This question gets asked roughly once every two weeks- take a look through the archives here, in the Java3D forum and over at http://www.javagaming.org to see what other people have said, but the conclusion is usually that most of us are hobby game writers- we're not going to write the next Doom or Unreal Tournament and fundamentally the language we use is going to be a lot less important than our skill at that language. You could execute any idea you have in either Java or C++ so you might as well go with the one you know best.
I have finished to programme a game (Space Commanders) using pure java
http://www.geocities.com/ddmusc/SpaceCommanders. Now I am re-programming the game using Visual C++ . Once I finish I shall put the windows version on the same site. It will be an interseting example of differences in performance between java and C++.
For programming I think java is easier since it takes automatic control of memory. Problems such as wild pointers , memory leaks and this kind of stuff are not an issue in Java. Unfortunately this is in itself also a disadvatage since you don't have much control on the amount of memory java is allocating (and at what time it deallocates it).
Java is also a bit slower because of its automaticity and high level structure. What makes me a bit angry about java is that programmes are normally CPU intensive. It is difficulty to run java programmes on old computers such as 486 or Pentium 1. This reduces the portability of the programme which though it can run on many different OSs it can't run on many different computers.
Daniel
not quite the same though - a mem. leak in C, is when the pointer to a mem. address goes out of scope before the mem. it address is deallocated.
mem. 'lost' in Java is never truly 'lost', it just gets into a state where it cannot be garbage collected.
Java mem leaks require you to explicitly write code to cause them, C mem leaks require an absence of code to cause them.
rob,
A leak is when the program hasn't recovered memory used by the program. It can happen in Java in the same way that it happens in C. It isn't GC'd because there is a pointer to the memory, but the program has lost that pointer. Array stacks are a good example of this. The memory is allocated by the program and never reclaimed by the system. I'm guessing what you mean is that is seems easier to do in C than in Java. I don't know. Seems careless programmers can do it either way. On the one hand in C you have to remember to reclaim the memory, but in Java a lot of people think it can't happen because of GC and don't bother to think about it.
> A leak is when the program hasn't recovered memory
> used by the program. It can happen in Java in the
> same way that it happens in C. It isn't GC'd because
> there is a pointer to the memory, but the program has
> lost that pointer.
You mean the program isn't "using" it. In Java, when you lose the pointer, the garbage collector will clean up. Only in C++ do you have that kind of memory nonsense.
Also, to answer the original question, I would suggest using Java no matter what. However, if you have some serious game logic, you might want to implement some stuff native. However, Java 2D & 3D rendering API's are great, and highly capable!
> Also, to answer the original question, I would suggest
> using Java no matter what. However, if you have some
> serious game logic, you might want to implement some
> stuff native. However, Java 2D & 3D rendering API's
> are great, and highly capable!
but still no match for C ;]
Yes, I meant a stack implemented using an array. I would call it a bug too. A memory leak bug, just as I would call a similar incident in C a bug too.
I would go along with the recommendation to use what ever is most familiar. If you use what you know best, you will probably be able to turn out something that works much more quickly.
Its a bug, not a memory leak, cos if u filled the stack up to the top, the old objects references would be overwritten, and the old objects discarded.
also, if u discarded the Array stack itself, the objects would be discarded.
A mem leak in C is far more serious, once the reference to some allocated mem. goes out of scope - thats it, the mem is lost 4ever. This *cannot* happen with Java.
going with what you know best is good advice.
going with what is most suitable for the task, is better advice!
and there is no disputing, Java is not suitable for high performance games.
I would say that java with the possibility of native code for timing/grpahics sensitive areas is probably the best approach. Some reasons not to use java is if you are shooting for a very small footprint, going to be using very underpowered computers, and or have a large current codebase in another language.
Cheers.
> Java is not suitable for
> high performance games.
That is the most absurd and ignorant statement I've ever heard!!!
But that's alright, because the longer people believe that Java cannot do games, the longer I don't have to worry about competition.
But, for those who are sick and tired of the old-aged, deprecated, broken languages and libraries, which I won't mention (Win32 SDK & C/C++), check out http://www.javagaming.org.
Most commercial game companies will try to make games for the largest possible audience group. So if you develop for Windows, you've basically got about 85%+ of the market. So portability is not really an issue since you've already got 85% of the market covered. Provide a Macintosh version of your game, and you've got 90%.
C++ is the preferred language for the PC game industry, because of Microsoft's DirectX. Java2D and Java3D are pretty impressive, but unless you're smart in using native code, its hard to take advantage of the graphics card a specific processor is using.
Warcraft III, Heroes of Might and Magic IV, Neverwinter Nights are all written in C/C++, and they all take advantage of DirectX. Most of the most successful games out there are all written in C or C++. BTW, I believe assembly code was also used.
Oh yeah, if you've got memory leaks in C/C++, its YOUR fault, not the language. Using pointers, references and inline functions can really speed things up...but if you don't know how to use these features properly, you're screwed.
However, if you're learning gaming fundamentals, Java is a pretty good language to use. And Sun is planning with Sony to add a JVM in the PS2. You gotta admit, that's pretty cool.
Bottom line is: if you're a hobbyist, stick with Java. If you're serious, learn C/C++, Java and assembly.
Dante
It is worth noticing that although there are few commercial games written in Java at the moment, the initiative to make java more viable for games programming is a relatively recent one on Sun's part and we can expect to see the amount it is used increase rapidly over the next couple of years. From a game writing point of view it is still a young language.
asm
1. It realy depends on top speed of procesor. C or Java? For gaming is better language with little errors ie. Java. Garbage colector is important like hell. I mean gc is realy important in games, no need for pathes number 1.9199.22.1223.556.
2. Asm and java are good if you need real speed...