| Author |
question about Array index - ojective 7.6 on K&B SCJP book
|
adam Lui
Ranch Hand
Joined: Sep 03, 2007
Posts: 186
|
|
This is in chapter 4 page 309... Given: class Fork { public static void main(String[] args) { if(args.length == 1 | args[1].equals("test")) { System.out.println("test case"); } else { System.out.println("production " + args[0]); } } } And the command-line invocation: java Fork live2 What is the result? the answer is compilation fails. the book states "Because the short circuit (||) is not used, both operands are evaluated. Since args[1] is past the args array bounds, an ArrayIndexOutOfBoundsException is thrown" I just dont get that..."Fork" on the command line invocation shall be args[1], and java, lives are args[0] and [2] respectively. wat's the trick here any masters?
|
boolean b = true;<br />System.out.println ("I believe in Java.<br />Java will make my dream come " + b);
|
 |
Arun Kumar Gaddam
Ranch Hand
Joined: May 05, 2007
Posts: 58
|
|
|
Here "Java Fork Live2" -->java Fork is to run Class and Live2 is the command line argument.
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9939
|
|
|
You're thinking like a C programmer, not a java programmer.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
adam Lui
Ranch Hand
Joined: Sep 03, 2007
Posts: 186
|
|
stupid me, i get it now, thank you!
|
 |
Alexsandra Carvalho
Ranch Hand
Joined: Jul 13, 2007
Posts: 75
|
|
Hello, one correction: the answer is runtime exception, not compilation fails. Alexsandra
|
 |
 |
|
|
subject: question about Array index - ojective 7.6 on K&B SCJP book
|
|
|