aspose file tools*
The moose likes Beginning Java and the fly likes Speed in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Speed in Java" Watch "Speed in Java" New topic
Author

Speed in Java

Ali Gilani
Ranch Hand

Joined: Mar 01, 2002
Posts: 137
Will a game made in java execute with the same speed as the same game made in C++, based on the modern JVM?

Ali
M Beck
Ranch Hand

Joined: Jan 14, 2005
Posts: 323
this will depend about as much on the skill of the programmer as on the language used.

in theory, there are things the JVM must do that might slow a program down. (interpreting byte codes and collecting garbage, for two.) in another theory, there are benefits you get from the JVM that might speed a program up. (more rapid development giving you more time for optimization, the bytecode interpreter being able to do run-time optimization as part of the JIT compiling.) which of these will outweigh the other will depend on too many things to make any guesses about.

you might not, in fact, even be able to find out in practice. a game is often a large, complex program; writing the same program in two completely different languages in such a way as to make the two versions really comparable, really equivalent to one another, is almost unreasonably difficult. so even actually timing two versions of the same code might not tell you anything; the two things timed are unlikely to really be "the same" in any meaningful sense.

the best thing you can do is pick a language you're comfortable with, and become as good a programmer in it as you can, to get the best results out of it. then learn another language, and realize how little you still know even if you're already an expert.
Ali Gilani
Ranch Hand

Joined: Mar 01, 2002
Posts: 137
As complex as the answer may be, when it comes down to speed, which will work faster? Java or C++. (pick one)


Ali
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


As complex as the answer may be, when it comes down to speed, which will work faster? Java or C++. (pick one)

C++ written by an idiot will run slower than Java written by an idiot and viceversa. The only answers people can give will be vague, of the type: "generally X is quicker then Y, but not always". M Beck has offered a very good answer - if you are still curious, write the same program in the two languages and benchmark them.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by ali gilani:
As complex as the answer may be, when it comes down to speed, which will work faster? Java or C++. (pick one)


Mu.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Igor Stojanovic
Ranch Hand

Joined: Feb 18, 2005
Posts: 58
Thank you Ilja for providing link to Mu explanation Very interesting!I am always happy to learn something new




kind regards
Igor
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Yes, that link was great. I had heard of Koans before but never the Mu response.

As they have posted around my office, "The beatings will continue until morale improves."
Ali Gilani
Ranch Hand

Joined: Mar 01, 2002
Posts: 137
Mu


It is truly astonishing when the learned ridicule the ones trying to learn, for a long time ago, they were just as ignorant. If my questions were coherent, wouldnt i be the one answering them.

However thankyou all for all the help.


Ali
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8903
    
    8

Originally posted by ali gilani:

It is truly astonishing when the learned ridicule the ones trying to learn, for a long time ago, they were just as ignorant. If my questions were coherent, wouldnt i be the one answering them.


I assure you that Ilja is not making fun of you. As other people have said, the speed difference between Java and C++ is "it depends". Ilja just pointed out that there's another way to say it. Did you happen to follow his link for the explanation?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
It is truly astonishing when the learned ridicule the ones trying to learn, for a long time ago, they were just as ignorant. If my questions were coherent, wouldnt i be the one answering them.

Ali:
Not every question has a simple answer, even if you really, really want a simple answer.

Here's a riddle for you.
Question: If pigs had wings, how high could they fly?
Answer: Pigs don't have wings.

Here is a math problem.
What is 0/0 ?
Any answer is will work.

And now my favorite.
What is the sound of one hand clapping?
Mu.


Mike Gershman
SCJP 1.4, SCWCD in process
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by ali gilani:
It is truly astonishing when the learned ridicule the ones trying to learn, for a long time ago, they were just as ignorant.


I'm sorry that you felt ridiculed by my answer - that was not my intent. My intention was instead to reinforce M's and Paul's answers: your question is stated in a way that it can't be answered reasonably.

If my questions were coherent, wouldnt i be the one answering them.


The only way I know to answer an incoherent question is to point out the incoherence so that the questioner can improve his question. I'd be interested in learning an additional strategy, if you have one to share, though.

However thankyou all for all the help.


You're welcome. We could probably help even more if you helped us understanding your question. You could start, for example, by telling us *why* you want to know.

You might also want to take a look at http://faq.javaranch.com/view?HowToAskQuestionsTheSmartWay

No hard feelings, Ilja
[ February 22, 2005: Message edited by: Ilja Preuss ]
Tom Schuman
Greenhorn

Joined: Dec 30, 2004
Posts: 18
Why is then all games written in C++? At least i believe so, never heard of a game for sale made with Java?
M Beck
Ranch Hand

Joined: Jan 14, 2005
Posts: 323
i've heard of games for sale (for video games consoles, no less!) written in Common Lisp. so they're certainly not all written in C++; if i had to take a guess, i'd say plain old C likely still has a large mindshare among video games programmers.

i've seen games written in Java, but since i'm far more interested in Open Source / Free Software development than i am in proprietary stuff, they weren't projects written commercially for sale. i've also seen video games written in Perl, and i've heard of ones in Python.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


never heard of a game for sale made with Java

Java Games are very common on Mobile phones.
Tom Schuman
Greenhorn

Joined: Dec 30, 2004
Posts: 18
So it's possible to write a game like doom 3 or half life 2 with java? I have always thought the most compicated game you could do with java was something like runescape.
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
There really is no reason you could't write a game such as Doom3 or HalfLife2 in Java and still have the same kind of performance. You may, however have to write libraries, if something like jogl won't cut it, to talk to the graphics hardware.

The main reason most commercial games are still written in C/C++ is that C/C++ works, and it is hard to push new technologies to a company when they know what they have will work. So we end up with the chicken and the egg problem.

A major company won't take the risk (money) on Java until it sees proof that it can be used to create a high quality game, but you can't prove Java can be used to create a high quality game until you get a company to take the risk on Java. There are some pretty cool little games written in Java be some part time and small shop game programmers, but you simply can't get a game on the scale of Half Life 2 out of a small shop or somebody working part time on it.
[ February 23, 2005: Message edited by: Steven Bell ]
M Beck
Ranch Hand

Joined: Jan 14, 2005
Posts: 323
modern games are often multi-tiered affairs; they'll have a lower-layer "engine" (for, let's say, rendering 3-D graphics and simulating player physics) and, on top of that, a higher layer for scripting game events, plot, and such. Quake was an early example of this; lots of in-map stuff was scripted in QuakeC, which by most measures was a considerably higher level language than the C/C++ the game engine was written in.

since the map design and plotline scripting is often done by non-programmers, it makes sense for the "game language" to be as high-level as practicable, so that they won't have to worry about learning low-level programming as well as designing a video game. in fact, if the overall design were up to me, i might consider even Java too low-level for this sort of use; i'd look to Python, Perl, Ruby, or some similar language for such an application.

games aren't the only example of the utility of an embedded scripting engine, of course. the larger and more complex an application becomes, the more likely you'll want to write parts of it in some custom language tailored to the task of writing such an application. (think AutoCad, think Emacs, think s-lang, ...) Lisp programmers found this out long ago; perhaps unfortunately, they were working with a language whose syntax and complexity makes it approachable only to professional programmers. it's only since bytecode-compiled and interpreted scripting languages have been made fast enough and powerful enough for general purpose use that this notion has become widely rediscovered. Java deserves partial credit for this; if the JVM were easier to embed into larger applications for use as a scripting engine...
Ali Gilani
Ranch Hand

Joined: Mar 01, 2002
Posts: 137
I suppose another reason that java in game programming hasnt taken off is that Sun itself isnt too crazy about the idea. U have java 2d and 3d, but not real documentation on how to interact with graphics hardware, OpenGL etc..

I think Sun should take a go at make a game playable on the PS2. Java could sure use a boost in its image, which is mainly an applet-concentrated language to the common user. The plot and storyline work no doubt is hard, but hey greatness never comes easy.

ALi
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Steven Bell:
A major company won't take the risk (money) on Java until it sees proof that it can be used to create a high quality game


Actually, they won't take the risk until they see the potential for big improvement. After all, switching had to make up for all the re-training of their developers, rewriting of their existing homemade libraries etc. pp.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

Originally posted by M Beck:
in fact, if the overall design were up to me, i might consider even Java too low-level for this sort of use; i'd look to Python, Perl, Ruby, or some similar language for such an application.


There was a "Q2Java" library that let you script Quake2 in Java. I played with it once, long ago; at the time the only Windows machine I had access to was an NT 4 machine, and Quake2 was not thrilled about running on that platform in the first place; the whole thing was very unstable. But it was certainly fun to play with.


[Jess in Action][AskingGoodQuestions]
Cedric Crowe
Greenhorn

Joined: Feb 24, 2005
Posts: 3
Originally posted by Tom Schuman:
Why is then all games written in C++? At least i believe so, never heard of a game for sale made with Java?


IL2 Sturmovik was written mostly in Java.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Speed in Java