which is better for gaming Java or C++?

a friend of mine told me that C++ is better for gaming, but i'm not sure. the thing about C++ is that i've been studing it for the past 3 years and still don't have a strong grasp of it, but java is much more direct and i'd much rather develop my games in java.
[279 byte] By [DaShiznit] at [2007-9-27 14:55:10]
# 1

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.

cbisbee at 2007-7-5 22:55:18 > top of Java-index,Other Topics,Java Game Development...
# 2

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.

Breakfast at 2007-7-5 22:55:18 > top of Java-index,Other Topics,Java Game Development...
# 3

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

Rabbi at 2007-7-5 22:55:18 > top of Java-index,Other Topics,Java Game Development...
# 4
Of course you can have memory leaks in Java. Just take a look at "Effective Java" for an example of objects that never get GC'd = leak.
nalenb at 2007-7-5 22:55:18 > top of Java-index,Other Topics,Java Game Development...
# 5

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,

Abuse at 2007-7-5 22:55:18 > top of Java-index,Other Topics,Java Game Development...
# 6

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.

nalenb at 2007-7-5 22:55:18 > top of Java-index,Other Topics,Java Game Development...
# 7
Array stacks?are you refering to a stack implemented using an array, and when it pops a value, it just decrements the stack pointer, but doesn't clear the array reference?if so, i'd call that a bug!rob,
Abuse at 2007-7-5 22:55:18 > top of Java-index,Other Topics,Java Game Development...
# 8

> 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!

javanova at 2007-7-5 22:55:18 > top of Java-index,Other Topics,Java Game Development...
# 9

> 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 ;]

Abuse at 2007-7-5 22:55:19 > top of Java-index,Other Topics,Java Game Development...
# 10

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.

nalenb at 2007-7-5 22:55:19 > top of Java-index,Other Topics,Java Game Development...
# 11

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.

Abuse at 2007-7-5 22:55:19 > top of Java-index,Other Topics,Java Game Development...
# 12

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.

ericew at 2007-7-5 22:55:19 > top of Java-index,Other Topics,Java Game Development...
# 13
It seems that I have created a havoc with this memory leak but many people seem to have understood what I am saying. Sorry for getting the thread out of subjectDaniel
Rabbi at 2007-7-5 22:55:19 > top of Java-index,Other Topics,Java Game Development...
# 14

> 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.

javanova at 2007-7-5 22:55:19 > top of Java-index,Other Topics,Java Game Development...
# 15
javanova - if that statement is so wrong - show me a current mass market game that is written in Java.
Abusea at 2007-7-18 11:41:38 > top of Java-index,Other Topics,Java Game Development...
# 16
make that a mass market, technically impressive game ;]who wants to be a millionaire doesn't count - it being a pile of shite.
Abusea at 2007-7-18 11:41:38 > top of Java-index,Other Topics,Java Game Development...
# 17

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

Dante_Shamesta at 2007-7-18 11:41:38 > top of Java-index,Other Topics,Java Game Development...
# 18

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.

Breakfasta at 2007-7-18 11:41:38 > top of Java-index,Other Topics,Java Game Development...
# 19
I heard quake 3 was going to have the qvms (graphics, game and ui modules thet ID went open source with, only keeping the core .exe to themselves) done in java, but had a couple of last minute problems, such a shame
shishthemoomina at 2007-7-18 11:41:38 > top of Java-index,Other Topics,Java Game Development...
# 20
A very good (and very long) article about java and games: http://www.rolemaker.dk/articles/evaljava/
qwerniea at 2007-7-18 11:41:38 > top of Java-index,Other Topics,Java Game Development...
# 21

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...

Raghara at 2007-7-18 11:41:38 > top of Java-index,Other Topics,Java Game Development...