Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.setProperty and System.getProperty

Tags:

java

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 in one java file, then can I use the properties anywhere? But this is not true, I can't use it anywhere, only in the same java file I called setProperty.

I really do not know why and what the function of this method is.

like image 937
Rocky Hu Avatar asked Jan 18 '14 12:01

Rocky Hu


People also ask

What is the difference between setProperty and getProperty?

The setProperty and getProperty action tags are used for developing web applications with Java Beans. In web development, The Bean class is mostly used because it is a reusable software component that represents data. The jsp:setProperty action tag sets a property value or values in a Bean using the setter method.

What is the system setProperty?

setProperty manages the initialization of the Chrome driver in the first step. The System. setProperty() method forms the basis for test case automation on any browser. Naturally, QAs must understand how to use this fundamental method for all automation purposes in Selenium.

What does system getProperty mean?

The getProperty(String key) method in Java is used to returns the system property denoted by the specified key passed as its argument.It is a method of the java.

What is the use of system setProperty in Selenium?

setProperty(“propertyName”, “value”)” . It implies that it sets the system property 'propertyName' to have the value 'value'. While testing with Selenium, you will make use of the setProperty method because the browser doesn't have a built-in server to run the automation code.


1 Answers

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!

like image 183
Keerthivasan Avatar answered Sep 21 '22 04:09

Keerthivasan