File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 18505

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)...
wood burning stoves
subject: Command Line Invocation
Similar Threads
operators (sourece k & b)
operators Q
question about Array index - ojective 7.6 on K&B SCJP book
question about mock test
K&B doubt(unofficial errata) Moderators,Please keep this thread on the top so all to see and add