Jump to content
  • Advertisement
Sign in to follow this  
TomX

[java] Will Java ever had the speed/facilites of C++?

This topic is 5133 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Well the subject is self-explanatory I think, will Java have the speed and graphical facilites as good as C++? Will Java ever be able to compete with C++ in terms of 3D games? Thanks in Advance TomX

Share this post


Link to post
Share on other sites
Advertisement
Yes. The real question is whether Java will be around long enough, given that it's an evolutionary dead-end.

Share this post


Link to post
Share on other sites
If a machine is ever invented that runs Java code natively, then sure, it's possible. Barring that, Java always runs on an emulator designed for the target system, so it can never match the speed of a compiled language.

Of course, this is assuming that code written in both languages is equally effective; differences in algorithm design can make a huge difference. Also, keep in mind that computers are incredibly powerful today; even if Java can't match the execution speed of C++, it doesn't really matter all that much to the end user, especially when most of the time-consuming code is being executed natively, anyhow.

Share this post


Link to post
Share on other sites
It depends what changes are made to Java. Java is now a JIT (Just-In-Time) Compiled Langauge, meaning that the code is compiled once on the target machine the first time it is run, and then thereafter the compiled version is run, unlike how it was bytecode interpreted originally. That will result in a speed increase. Java has gone through plenty of changes since the original version, and it may become much more like C# in the near future.

[Edited by - wyrzy on September 19, 2004 4:08:55 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by psamty10
http://www.idiom.com/~zilla/Computer/javaCbenchmark.html

Whats especially interesting about this are the reasons given for Java being easier to optimize than C++.

Interesting article. Especially the part about "garbage collection is slow" is supposively a myth, and that it says it can be faster than new/delete in C++. In all the classes that I've taken in college, the professor would always preach how Java, do to the fact of the garbage collector, could never be used in real-time applications, and being a student, I believed it. But how can the garbage collector not be slow. What if it tries to delete objects when you want to render graphics or something. I have heard that there is some way to request that the garbage collector not run, but the article says the garbage collector can really delete objects whenever it feels like it, provided there are no remaining refrences attached to it.

But the only question I have is, if this article is correct and Java can be so fast, why haven't more programmers been using it. I know it has began to pick up in places, but I would say over 90% of games are still programmed in C++. I'm sure that one reasone for this is the fact that they already have so much code that can be reused from existing projects.

Share this post


Link to post
Share on other sites
I don't think Java will ever be as fast as C++. But in most cases it is close enough that it don't mather.

With regards to 3D speed you've got OpenGl in Java. If you limit the JNI overhead by limiting the number of gl calls, you've got almost the same 3D speed as with C++.

Then again if you are pushing the cpu with AI, physics, shadow volume creation etc, you might have a performance benifit from using C++. It depends on the game. I read that Doom3 uses most of the cpu time calculating shadow volumes. This might might run to slow in Java.

There are more important resons why Java is not used to create games:
-Small casual games needs a big runtime
-No DirectX
-Can't port To consoles
-Memory usage
-Slow startup times

Personally I would rather play a game created with C++ than with Java. But Java is i nicer language, so I would rather program a game in Java rather than C++.

Share this post


Link to post
Share on other sites
Quote:
Original post by wyrzy
Quote:
Original post by psamty10
http://www.idiom.com/~zilla/Computer/javaCbenchmark.html

Whats especially interesting about this are the reasons given for Java being easier to optimize than C++.


But the only question I have is, if this article is correct and Java can be so fast, why haven't more programmers been using it.


The article's basis is that Java could theoretically be faster than C++. It never states that it will always be the case. What they are saying is, as the machines become faster, the overhead for running Java and doing Garbage Collection decrease; and simultabeously, the ability to optimize those exact problems they mention becomes more relevant, thus possibly making Java code run faster than C++.

Share this post


Link to post
Share on other sites
My personal opinion is that, at least for games, deleting objects when you want to is going to be faster than using a garbage collector. Why? Because you could do things like, putting all of the objects that will be deleted in a list, and then actually delete them in between levels. Although it may be slower than using the garbage collector, I think most people would prefer a little lag time when switching levels in a game than having a little less of a lag time during the actual game.

Currently, I do not believe that you can have full control over the garbage collector in Java. Until Java gives you that control, I believe that C++ will be faster.

Also, I agree with the point that Microsoft never is really going to support java so that means no DirectX for java, and due to the fact that DirectX is used by a large portion of PC games, that will definetly damage support for java in PC games.

Share this post


Link to post
Share on other sites
The modern garbage collector does an excellent job. It won't make the game stutter even if you create loads of garbage. Most of the garbage is collected in a fraction of a millisecond.

You can also avoid creating garbage. My game loop only generates a few kb of garbage each frame. The gc runs once every few seconds and uses a fraction of a millisecond. There is no stutter and it don't use much time either.

There are also tools to optimize the garbage collector parameters. Allowing you to optimize the garbage collector to your game.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!