Saturday, November 3, 2012

What Are The Differences Between Java References and C Pointers

While the Java specification does not mandate that Java References be implemented using Pointers, it is usually the case. You may have additional layers to help in Garbage Collection but in the End Java References are implemented using C Style Pointers.

However there are some important differences


  • No Pointer Arithmetic
        In C you can increment a Pointer and its valid , such operations are not allowed on Java References.
  • Auto Derefencing
        In C you need to deference the Pointer using '*' to get the value. This happens automatically in Java References.
  • References are Strongly Typed
        In C you can cast a int *  pointer with char * and use it . However Java References can only be of the allowed type. You can cast an object as String only if it is actually of type String.

The differences make C Pointers more powerful but also very dangerous. 

No comments:

Post a Comment