Saturday, July 31, 2010

Logical Operators:

Courtesy of SCJP Sun® Certified Programmer for Java™ 6 Study Guide Exam (310-065) (9780071591065)
Chapter 4, Question 3

If we invoke with the following:

java Fork test

the program will throw an ArrayIndexOutOfBoundsException at runtime. Because we are using | (or) rather than || (short-circuit), on line 3, both args.length == 1 and args[1].equals("test") are evaluated. Since there is only one argument, i.e. test, the args[1] on line 3 is out-of-bounds.

No comments:

Post a Comment