Java Reference
In-Depth Information
public static void main(String x[])
static void main(String x[])
7.30
Show the output of the following program when invoked using
1. java Test I have a dream
2. java Test “1 2 3”
3. java Test
public class Test {
public static void main(String[] args) {
System.out.println( "Number of strings is " + args.length);
for ( int i = 0 ; i < args.length; i++)
System.out.println(args[i]);
}
}
K EY T ERMS
anonymous array
258
index 246
indexed variable
array 246
array initializer 248
binary search 265
garbage collection
248
linear search 265
off-by-one error
251
256
selection sort
269
C HAPTER S UMMARY
1.
A variable is declared as an array type using the syntax elementType[] arrayRefVar
or elementType arrayRefVar[] . The style elementType[] arrayRefVar is
preferred, although elementType arrayRefVar[] is legal.
2.
Unlike declarations for primitive data type variables, the declaration of an array variable
does not allocate any space in memory for the array. An array variable is not a primitive
data type variable. An array variable contains a reference to an array.
3.
You cannot assign elements to an array unless it has already been created. You
can create an array by using the new operator with the following syntax: new
elementType[arraySize] .
4.
Each element in the array is represented using the syntax arrayRefVar[index] . An
index must be an integer or an integer expression.
5.
After an array is created, its size becomes permanent and can be obtained using
arrayRefVar.length . Since the index of an array always begins with 0 , the last
index is always arrayRefVar.length - 1 . An out-of-bounds error will occur if you
attempt to reference elements beyond the bounds of an array.
6.
Programmers often mistakenly reference the first element in an array with index 1 , but
it should be 0 . This is called the index off-by-one error .
 
 
Search WWH ::




Custom Search