Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about System.getProperties

 
George Lin
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,


I am wondering where does the properties retrieved from System.getProperties defined, in some system level environment variables, some files or some other repositories. I am also wondering if I retrieved a specific property from System.getProperties, could I find out where it is defined (system level environment variable, some files or some other repositories).


Thanks in advance,
George
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From my understanding, the JVM generates some of the values itself, such as the vendor and version number. The OS-specific values are retrieved from the operating, probably with a native method that calls some function in the OS's API. This means that the location where the value is stored is system dependent. AFAIK, Java does not provide any way to determine the location where the values are stored.

Is this just an academic question, or do you need to know the location for some reason?

Layne
 
George Lin
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Layne,


Originally posted by Layne Lund:
From my understanding, the JVM generates some of the values itself, such as the vendor and version number. The OS-specific values are retrieved from the operating, probably with a native method that calls some function in the OS's API. This means that the location where the value is stored is system dependent. AFAIK, Java does not provide any way to determine the location where the values are stored.

Is this just an academic question, or do you need to know the location for some reason?

Layne


Your reply is very helpful. I am very interested in the internal operations of where to find these properties and in what sequence are they loaded (for example, loading OS defined properties before loading VM specific properties). Do you know where can I find any online resources dealing this topic?


regards,
George
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose if you really need to know you could define properties in your environment and on the java command line (-Dfoo=bar) that you know the JVM will overwrite to see which one wins over the others.

I must assume it sets its internal properties first, so the real question is which first: environment or arguments?

As to which come from where, I bet most of the JVM ones are defined in the System class JavaDocs or should be obvious from inspection. Your environment variables are available to you with the set command. But as Layne said I doubt there's a way to do this dynamically.
 
George Lin
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David,


Originally posted by David Harkness:
I suppose if you really need to know you could define properties in your environment and on the java command line (-Dfoo=bar) that you know the JVM will overwrite to see which one wins over the others.

I must assume it sets its internal properties first, so the real question is which first: environment or arguments?

As to which come from where, I bet most of the JVM ones are defined in the System class JavaDocs or should be obvious from inspection. Your environment variables are available to you with the set command. But as Layne said I doubt there's a way to do this dynamically.


Your reply is very helpful. Maybe I have not made myself understood. I do not want to know how to define a property. I want to know the internal operations of where does VM find these properties and in what sequence are they loaded (for example, loading OS defined properties before loading VM command line specific properties). Do you know where can I find any online resources dealing this topic?


regards,
George
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by George Lin:
I want to know the internal operations of where does VM find these properties and in what sequence are they loaded (for example, loading OS defined properties before loading VM command line specific properties).
That's precisely what my reply was designed to test. If you want to know which is done first, system vs. command line properties, here's what you do.
  • set system property PROP_TEST to "system"
  • run java program to dump out PROP_TEST value with command-line property PROP_TEST set to "cli"
  • PROP_TEST's value should tell you which takes precedence (is assigned last)

  • Yes, I'm sure you can look this up somewhere; what Google queries have you tried so far?
     
    George Lin
    Ranch Hand
    Posts: 125
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks David,


    Originally posted by David Harkness:
    That's precisely what my reply was designed to test. If you want to know which is done first, system vs. command line properties, here's what you do.
  • set system property PROP_TEST to "system"
  • run java program to dump out PROP_TEST value with command-line property PROP_TEST set to "cli"
  • PROP_TEST's value should tell you which takes precedence (is assigned last)

  • Yes, I'm sure you can look this up somewhere; what Google queries have you tried so far?


    Your reply is very helpful. I am wondering what key words should I use to do a Google search. Google tells me many API descriptions other than the internal operations (for example, sequence to find properties), which I am really interested in.


    regards,
    George
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic