System.setProperty and System.getProperty

后端 未结 4 1716
太阳男子
太阳男子 2020-12-23 21:09

I didn\'t understand when I used System.setProperty to define a parameter, where the data is stored?

If say that I used System.setProperty

4条回答
  •  暖寄归人
    2020-12-23 21:34

    System class has a static member variable named props which is of type Properties. Adding to that, Properties is a subtype of Hashtable class. All the property values are stored as Key and Value. So, datastore is Hashtable.Answering the other question, You can very well use System.getProperty(propertyKey) method throughout your application since it is a public static method. You haven't understood how java programs work. When you run a Java program, you are actually starting a JVM instance. That instance will have its own System properties. That is where you have to put your property. When you run the other program, that will have its own System properties. So, you cannot expect a property which you set in one JVM instance to be accessible from another JVM instance! You can access the System.getProperty(propertyKey) in all classes running in the same JVM instance. Hope you can understand!

提交回复
热议问题