Originally posted by Steve Deadsea: An array is a primitive, not an object.
Actually, an array is an object in Java. The length of the array is an instance variable of the Array class. When constructing an array, like any other object in Java, you must use the keyword "new." Corey
An array is an object in Java, but it is a special type of object which does not have an explicit class in the API, not to be confused with the class Array, which is more of a wrapper class to provide additional methods (but it has no fields of it's own). An array is composed of the members that it inherits from Object and the final variable "length". This field is unique because it is not part of the "type" of the array, as most fields are (to prevent problems with putting arrays of differing sizes in the same reference variable). However, as programmers this is invisible, and you can get at the length just as though it were a regular field in the object.
From the JVM Spec
2.15.2 Array Variables A variable of array type holds a reference to an object. Declaring a variable of array type does not create an array object or allocate any space for array components. It creates only the variable itself, which can contain a reference to an array. Because an array's length is not part of its type, a single variable of array type may contain references to arrays of different lengths. Once an array object is created, its length never changes. To make an array variable refer to an array of different length, a reference to a different array must be assigned to the variable.
"JavaRanch, where the deer and the Certified play" - David O'Meara
Joined: Jan 16, 2002
Hi Cindy Glass, Thanks for your valuable information. Regards Saran