This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Oracle Sample Questions. 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 "Oracle Sample Questions." Watch "Oracle Sample Questions." New topic
Author

Oracle Sample Questions.

Tim Boeckstaens
Greenhorn

Joined: Aug 07, 2012
Posts: 5
Hi!

I am going to do the exam this afternoon and I was looking at the sample questions on the oracle site where I found this: oracle sample questions

OBJECTIVE: 7.2: Given an example of a class and a command-line, determine the expected runtime behavior.
10) Given:
1. class x {
2. public static void main(String [] args) {
3. String p = System.getProperty("x");
4. if(p.equals(args[1]))
5. System.out.println("found");
6. }
7. }

Which command-line invocation will produce the output found?
a) java -Dx=y x y z
b) java -Px=y x y z
c) java -Dx=y x x y z (*)
d) java -Px=y x x y z
e) java x x y z -Dx=y
f) java x x y z -Px=y

REFERENCE:
API for java command
Option C is correct. -D sets a property and args[1] is the second argument (whose value is y)

I don't understand why they say option C is correct. The args[1] will give the second argument which is x in x x y z. While the property x will return y. So I think A is correct. Can anybody without stress clear this out for me?

Kind regards.
Tim Boeckstaens
Greenhorn

Joined: Aug 07, 2012
Posts: 5
I think I found out why. Since x is the name of the class the first x is to invoke the main method in the x class (nice class name by oracle) and then x y z are the args
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Oracle Sample Questions.
 
Similar Threads
question about properties and command line arguements
System.getProperty question from SunExam
Sun sample exam - Item 6
Command line argument question
Runtime behavior after command-line invocation