Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

System.getProperty question from SunExam

 
Meghna Bhardwaj
Ranch Hand
Posts: 109
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Please see code below:


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

The correct answer is C, however I think there are 2 bugs in the program.
First I would expect the classname to be the last parameter which will cause the program to actually run..here the
class is x and none of the answers have x as last argument.

Secondly, for output to be "found"
the parameter x needs to be same as the arg[1] supplied, in this case i think option A is right, but not completely correct
due to my first reason above.

Please if someone has the command prompt working can they please check this out by executing it from command line,
i would really appreciate it! mine is completely bananas so I can't. many thanks, waiting for some replies.

 
Alexander Danilou
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"First I would expect the classname to be the last parameter which will cause the program to actually run"
This expectation appears to be incorrect. Here is a structure of java command: java [options] class [arguments]
So class name actually follows options..
 
Bob Wheeler
Ranch Hand
Posts: 317
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Meghna Bhardwaj wrote:
C java -Dx=y x x y z

The correct answer is C, however I think there are 2 bugs in the program.
First I would expect the classname to be the last parameter which will cause the program to actually run..here the
class is x and none of the answers have x as last argument.

No. This is the structure:
java [options] classname [args]

So we have options: -Dx=y; classname: x, args: x y z

[quote=Meghna Bhardwaj
Secondly, for output to be "found"
the parameter x needs to be same as the arg[1] supplied, in this case i think option A is right, but not completely correct
due to my first reason above.

In the String p we save the property y, which is arg[1]. This way we get an output "found".

Hope this helps.
Bob
 
Meghna Bhardwaj
Ranch Hand
Posts: 109
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys...got it! i was getting confused with the class name and args. Thanks a bunch
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic