lint [] array_name; int array_name [];
lYou don’t specify the size of an array because no space is allocated for the elements at this point
lAll we have is a
reference to an array
•(like in
C++ where the name of the array is the starting address of the first element, now in Java the name of the array is a
reference)
lTo allocate memory we must specify an initialization expression (which unlike C++ can happen anywhere in your code
•int [] array_name = {1,2,3,4,5}; //starting with element zero
•A reference can then be used to also access this
array:
•int [] reference;
•reference = array_name;
lWe can also allocate
arrays on the heap
•reference = new int [size];
lAll arrays have an implicit member that specifies how many elements there are (its length)