Tuesday, 29 October 2013

Reference Type Summary

The distinction between primitive types passed by value, and objects and arrays passed by reference is a crucial one in Java. Be sure you understand the following:

  • All objects and arrays are handled by reference in Java. (Those object references are passed-by-value to methods, however.)
  • The = and == operators assign and test references to objects. Use clone() and equals() to actually copy or test the objects themselves.
  • The necessary referencing and dereferencing of objects and arrays is handled automatically by Java.
  • A reference type can never be cast to a primitive type.
  • A primitive type can never be cast to a reference type.
  • There is no pointer arithmetic in Java.
  • There is no sizeof operator in Java.
  • null is a special value that means "no object" or indicates an absence of reference. 

No comments:

Post a Comment