Sun Certified Programmer for Java 2 Platform, Standard Edition 6 question

Hey guys, I'm learning my first Java Cert! Hurah! Sorry, I do not want to sound so insulting, but I can not help it :) Anywho, trying to understand the following question and answer. I do not understand., I do not really use this command line (mainly NetBeans, and I get to know Eclipse). Any pointers are welcome.


PURPOSE: 7.2: Using the example and command line examples, 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. }

What command line call will print the result?

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

// So, the answer is C

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


., [1] ? , "p" String {y x x y z}?

+3
3

., [1] ? , "p" String {y x x y z}?

. ) x x y z. -D , x y.

, x:

  • args `String [] { "x", "y", "z" }
  • p "y".

p args[1]... : equal.

(, , x, , :-))

+7

, java -Dx=y x x y z, -Dx=y - x y, , x - , "x, y, z" , .

, , -D, , . x y, y x x y z.

+3

class x {

, , "java" ( ) - ( "x" ), - .

I do not think this is a good question. Who will call the class “x” at all? The person who developed this question should be hanged.

0
source

All Articles