File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes System.getProperty question from SunExam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "System.getProperty question from SunExam" Watch "System.getProperty question from SunExam" New topic
Author

System.getProperty question from SunExam

Meghna Bhardwaj
Ranch Hand

Joined: Jun 08, 2007
Posts: 109
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

Joined: May 08, 2009
Posts: 28
"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

Joined: Apr 24, 2009
Posts: 317
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


SCJP 6 - SCJD - SCWCD 5 - SCBCD 5
JavaEnterpriseEditionFaq - TomcatFaq
Meghna Bhardwaj
Ranch Hand

Joined: Jun 08, 2007
Posts: 109
Thank you guys...got it! i was getting confused with the class name and args. Thanks a bunch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: System.getProperty question from SunExam
 
Similar Threads
Runtime behavior after command-line invocation
question about properties and command line arguements
Command line argument question
head first java - mixed messages
Chapter 5 K&B -Doubt