Hi Barbara
I think you mean to say Array
IndexOutOfBoundsException, and not ArrayOutOfBoundsException.
ArrayIndexOutOfBoundsException is not thrown depending upon how many arguments you specify at the command line, but how you access those arguments in your program. Remember that arrays are indexed from 0 to (length - 1). So, if you try to access any element in the array at index equal to or greater than 'length', an ArrayIndexOutOfBoundsException would be thrown.
Here's a simple example:
If you compile and run the above program as:
The program would print:
3
javaranch
is
cool
Exception in
thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at ArrayIndexTest.main(ArrayIndexTest.java:8)
It will throw an ArrayIndexOutOfBoundsException because of line marked 4. The 'length' of the array 'args' is 3 and it can be indexed only from 0 to 2. Index 3 is out of the bounds (range) of this array and hence the exception.
Hope this helps.
Cheers
Harwinder
[ November 15, 2003: Message edited by: Harwinder Bhatia ]