Hello, David Eng!
You said:
Henry <
[email protected]> wrote in message
Hi,
[this is not a message to start a flame war]
I often heard that Java is slow. Does someone is aware of any papers
describing this fact ?
Java is slower than C/C++ and it is also faster. It is easy to
find some feature which goes one way or the other. Depending on
your goal, you can find evidence to support your conclusion.
It is like one of my favorite sayings: Statistics are often used
as a drunken man uses a lamp post, for support rather than
illumination.
One cannot say either is always faster than the other. Clearly
they are both in the same ballpark and any differences are not
significant for most applications.
The papers claim the Java is as fast as C++ is fundamentally false.
The slowness of Java is not cause by the same language feature
comparing with C++. It is because of lacking of flexibility Java has.
I will give you two examples to explain it.
Java and C++ can create objects in the heap. If you compare this
feature between Java and C++, no doubt that the speed is about the
same. However, C++ can allow you to create object in stack. In this
case, object creation is fast than in the heap. Most papers don't do
this kind of comparison. But in real world, the lack of flexibility
makes Java slower.
You obviously have never read about the generational garbage
collector used in modern VM's. Objects in Java are actually
allocated on a stack called the nursery. However it is not freed
per method call. It is freed when the nursery fills up, it is
freed in one fell swoop. Any objects that are still reachable are
then copied to the heap. For short-lived objects (which is
usuallythe most common case) this can actually be faster than
C/C++ and be much safer without the possibility of dangling
pointers.