comp 1 Flashcards
is a named list of data items that all have the same data type.
Array
data items of an Array.
Element
Array declaration:
Syntax: datatype[] ArrayName; or datatype ArrayName[];
NOTE: the preferred format among Java programmers is to
place the brackets following the variable type and before the variable name.
After creating an array variable,
you need to reserve memory space.
Syntax:
ArrayName = new datatype[number of elements];
or
Datatype[] Arrayname = new datatype[number of elements];
is an integer contained within square brackets that specifies one of an array’s elements.
Subscript (sub for short) -
They are also called index, which can be seen in error messages in compiler.
sub
NOTE: An array elements are numbered beginning with _
0
When you declare int[] someNums = new int[10];, someNums holds an _____
address
but each element of someNums has a value of 0 by default because someNums is an
integer array.
The following default values are used for different array types:
Each element in an int array is assigned 0.
Each element in a double or float array is assigned 0.0
Each element in a char array is assigned \u0000, which is the Unicode value for a null character.
Each element in a Boolean array is assigned the value false.
Each element in an array of objects, including Strings, is assigned null by default.
To initialize an array, use an____separated by commas and enclose within curly braces.
initialization list of values
is called when the programmer provides values to all the elements of the array.
Populating the array
Common programmer error is
to attempt to use length as an array method -> scoreArray.length();