Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

how to set properties?

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I read that we can setproperties through setProperty(), so why the following program is incorrect?



And given the command line invocation:
java -DcmdProp=cmdValue Values
What is the result?
A. null myValue null null
B. cmdValue null null cmdValue
C. cmdValue null null newValue
D. cmdValue myValue null cmdValue
E. cmdValue myValue null newValue
F. An exception is thrown at runtime

Can anybody explain me why answer is F?

 
Ranch Hand
Posts: 82
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I ran the program, and am Getting E as expected, not run time exception,
 
Mansi Agarwal
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Don,

That's true.. But in the book (SCJP Study Guide by Bert) it is mentioned F.

That's why I got confused.
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interesting thing. With JDK 1.7, I see -


Regards,
Dan
 
author
Posts: 23912
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please QuoteYourSources.

Henry
 
Mansi Agarwal
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anybody explain me how it is working??
 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mansi Agarwal wrote:Can anybody explain me how it is working??



You shouldn't ignore Henry's advice and Please quote your sources. that way somebody can have direct reference to the source and will be able to explain it faster
 
gurpeet singh
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dan Drillich wrote:Interesting thing. With JDK 1.7, I see -


Regards,
Dan



Don you have to invoke the program using command line switch -D.
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In eclipse, if you pass -DcmdProp=cmdValue as VM arguments then the result is "cmdValue myValue null newValue", if you pass as program aguments then it is "null myValue null newValue". It has nothing to do with JDK 1.7 i suppose.
 
Surender Suri
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mansi Agarwal wrote:Hi Don,

That's true.. But in the book (SCJP Study Guide by Bert) it is mentioned F.

That's why I got confused.


Strange, i see the answer as E. It might be misprinted.

E is correct. System properties can be set at the command line, as indicated correctly in
the example. System properties can also be set and overridden programmatically.
 
Mansi Agarwal
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Suri..

I guess I already did quote the resources but at wrong place.. Will keep this in mind in future.

Thank you all.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic