It's not a secret anymore!
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Oracle Sample Questions." Watch "Oracle Sample Questions." New topic

Oracle Sample Questions.

Tim Boeckstaens

Joined: Aug 07, 2012
Posts: 5

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

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

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
I agree. Here's the link:
subject: Oracle Sample Questions.
It's not a secret anymore!