• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

System.getProperty question from SunExam

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you guys...got it! i was getting confused with the class name and args. Thanks a bunch
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic