This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Command Line Invocation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Command Line Invocation" Watch "Command Line Invocation" New topic

Command Line Invocation

Chadd Franck
Ranch Hand

Joined: Nov 05, 2008
Posts: 50
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

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?
Henry Wong

Joined: Sep 28, 2004
Posts: 20034

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.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Chadd Franck
Ranch Hand

Joined: Nov 05, 2008
Posts: 50
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)...
I agree. Here's the link:
subject: Command Line Invocation
It's not a secret anymore!