• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Command Line Invocation

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is from Sun Certified Programmer for Java 6 Study Guide, Page 320,


And the command-line invocation:
java Fork live2

What is the result?

A. test case
B. production live2
C. test case live2
D. Compilation fails
E. An exception is thrown at runtime

Answer:
E is correct. Because the short circuit (||) is not used, both operands are evaluated. Since args[1] is past the args array bounds, an ArrayIndexOutOfBoundsException is thrown. A, B, C, and D are incorrect based on the above. (Objective 7.6)

Why isn't args[1] = live2? therefore not outofbounds?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Why isn't args[1] = live2? therefore not outofbounds?



Arrays are zero based -- so the first element is args[0]. Hence, args[0] is live2, and args[1] is out of bounds.

Henry
 
Chadd Franck
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hehe yea I see it, I was thinking that Fork was an arg for some reason, I can see that it is the name of the class (G)...
 
reply
    Bookmark Topic Watch Topic
  • New Topic