Java Reference
In-Depth Information
SR 8.8 Whenever a reference is made to a particular array element, the
index operator (the brackets that enclose the subscript) ensures
that the value of the index is greater than or equal to zero and less
than the size of the array. If it is not within the valid range, an
ArrayIndexOutOfBoundsException is thrown.
SR 8.9 An off-by-one error occurs when a program's logic exceeds the boundary
of an array (or similar structure) by one. These errors include forgetting to
process a boundary element as well as attempting to process a nonexistent
element. Array processing is susceptible to off-by-one errors because their
indexes begin at zero and run to one less than the size of the array.
SR 8.10 for ( int index = 0; index < values.length; index++)
{
values[index]++;
}
SR 8.11 int sum = 0;
for ( int index = 0; index < values.length; index++)
{
sum += values[index];
}
System.out.println(sum);
SR 8.12
An array initializer list is used in the declaration of an array to set up
the initial values of its elements. An initializer list instantiates the array
object, so the new operator is not needed.
SR 8.13
An entire array can be passed as a parameter. Specifically, because an
array is an object, a reference to the array is passed to the method.
Any changes made to the array elements will be reflected outside of the
method.
8.3 Arrays of Objects
SR 8.14
An array of objects is really an array of object references. The array
itself must be instantiated, and the objects that are stored in the array
must be created separately.
SR 8.15
a. String[] team = new String[6] ;
b. String[] team = { " Amanda " , " Clare " , " Emily " , " Julie " ,
"Katie" , "Maria"} ;
SR 8.16
a. Book[] library = new Book[10] ;
b. library[0] = new Book( " Starship Troopers " , 208) ;
Search WWH ::




Custom Search