Sign in to follow this  
TomX

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

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
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
Guest Anonymous Poster
Quote:
Original post by tombr
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.


Plus, if you are adventurous, you can write your own garbage collector.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by TomX
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


Why does crap like this not get moderated? The OP screams "troll" with some assumptive questions that are not based in fact but fantasy, and people respond with random bull**** about how GC is slow, as if they know what they're talking about.

I've read every reply and almost all of them contain at least one derogatory comment which is simply not true, and demonstrates that the poster is either naive, stupid, or lazy (i.e. they have their head in the sand and don't listen to the world around them OR they are too braindead to understand simple english OR they can't be bothered to learn how to program java properly).

For anyone actually interested in the real world, I suggest you ignore everything in this thread and go to a real forum like www.javagaming.org, where you can ask questions of people who actually use the language; professional java games developers and professional mainstream IT developers; people who - not to put too fine a point on it - actually understand what they're talking about.

And to the OP: What you're asking about happened a couple of years ago. Not that this really matters so much: in the games industry, speed is usually less important than project cost (3000 games released each year, less than 50% break even in project costs. They aren't going bankrupt and sacking the staff, or failing to pay wages, because the frame rate was too slow...)

Sheesh. No wonder the java forum on GD is dead - 99% noise, 1% signal?

Share this post


Link to post
Share on other sites
Java OpenGL/DirectX where available acceleration enabled under the hood. C++ Graphic acceleration in C++ standard library? Where?

to Escherial
On modern processors C program would highly likely run in emulated mode. This would apply for D, Delphi, and other statically compiled languages. ONLY language that's unlikely to be runned in "emulated" mode is ASM, and only becose it was optimalized already.

to wyrzy
Quote:
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

I supose you never wrote a game. Right? Putting all "you know them sooner than on the runtime and reliably on top of that" objects...
BTW users DISLIKE lag time when switching levels. Also users dislike swithching levels.
DirectX is monstrosity from Mickerosoft that looks and behaves horrible. The worst thing about it is COM. JNI is COM compatibile so creating DirectX layer for Java exactly like for C# isn't a problem. There isn't any DirectX on Unix, nor on MAC. This means, why DirectX when we can use OpenGL?

Is this a trollfest? Aka who would write the most biased Java post of this month?

Share this post


Link to post
Share on other sites
1.4.2 released new collectors. There aer a variety of possibilities and they can be highly tuned based on type of application as well as type of hardware. Read the docs if you really want to know the different possibilities. 1.5 will likley introduce even more options as well as further optimizations.

There are plenty of articles showing current Java apps to be faster than C++, and vice versa. The previous slowness of Java is gone. It is now much more a matter of the programmer's ability. A C++ programmer will write faster C++ than Java, a Java programmer will write faster Java than C++. Highly optimized applications compete with one another, each having strengths in different areas.

There is a lot of information on this, and what it comes down to is:

1.) Yes, it is possible to write decent games in Java
2.) Examples exist
3.) You need to do some research and some tests to decide if it is suitable for your app or not.

Share this post


Link to post
Share on other sites
Sun's 5.0 VM has the following experimental options

-XX:MaxGCMinorPauseMillis
-XX:MaxGCPauseMillis

which some people say have totally eliminated GC pauses. Also with dual core chips becoming common in the next couple years GC is only going to become faster.

Share this post


Link to post
Share on other sites
Quote:
Original post by Konfusius
An optimal solution in C++ will always be faster than an optimal solution in Java.

Prove me wrong.

Konfu


In some cases Java may be faster due to it's dynamic compilation.
Google for dynamic vs static compilation.

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

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.


The problem is that the GC is non-deterministic. Someone mentioned that the GC is fast and only takes a fraction of a millisecond; to a crtical RT system that's could be an unacceptable amount of jitter. Also, that's a millisecond of jitter on a multi-gigahertz CPU, not on a 60MHz ColdFire or 12MHz PIC. Recall that the program can do nothing else during the collection; this is unacceptable in the kernel which is often the nature of RT code as well (e.g. respond to an interrupt within 500us).

Quote:

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.


Java is very popular, just video games is just an area it's not so much. The GC wasn't always so fast, and JRE issues add another layer the developers have to deal with, but no more so than DirectX or .Net do.

[Edited by - Magmai Kai Holmlor on October 2, 2004 9:34:53 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Magmai Kai Holmlor
Also, that's a millisecond of jitter on a multi-gigahertz CPU, not on a 60MHz ColdFire or 12MHz PIC.


Completely unrelated, but I thought Coldfire == Motorola 68000? They clocked those up to 60MHz? The one in my Mac Classic was only 7.83... :(

Share this post


Link to post
Share on other sites
Quote:
Original post by Magmai Kai Holmlor
The problem is that the GC is non-deterministic. Someone mentioned that the GC is fast and only takes a fraction of a millisecond; to a crtical RT system that's could be an unacceptable amount of jitter.


I always thought this was a cool quote from the Java SDK license:



"You acknowledge that Licensed Software is not designed or
intended for use in the design, construction, operation or
maintenance of any nuclear facility."



Java is clearly a server and applications programming language, not a systems language and obviously not intended for the highly specialised area of real-time systems, let alone critical ones. For the intended types of programs, GC is a fantastic way to free up programming time and prevent bugs.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this