Java

using IBM java

set PATH="D:\IBM\SDP\jdk\bin";%PATH%

echo %PATH%
echo %JAVA_HOME% 
//Must set it under System Variables 
SET JAVA_HOME = D:\IBM\WID\jdk
SET PATH = %PATH%;%JAVA_HOME%\bin

System and Properties

The System class maintains a Properties object that describes the configuration of the current working environment.

(1) System.properties are used as a read only list.

public static Properties getProperties()
public static void setProperties(Properties props)

They determines the current system properties. First, if there is a security manager, its checkPropertiesAccess method is called. Note that even if the security manager does not permit the getProperties operation, it may choose to permit the getProperty(String) operation.

If you don't want to modify many properties, it's better to use System.setProperty(key, value) than alternatives like System.setProperties(props) or System.getProperties().setProperty(key, value).

The difference is how SecurityManager handles these calls. For System.setProperty(key, value) the SecurityManager is asked for permission to modify a single specific key. For System.getProperties() call the SecurityManager is asked for permission to read/write anything. So it's possible that the installed SecurityManager protects only some of properties, thus setProperty(key, value) will succeed, but getProperties().setProperty(key, value) will fail.

If you need to read the specific property, always use System.getProperty(key) instead of System.getProperties().getProperty(key). If installed SecurityManager disables property writing, but enables property reading, then the second call will fail.

(2) should you want to write your properties out somewhere, you would probably be better off putting it in a database table (if you are going to be changing these options at runtime) and working with it like that. You might want to try using a properties file if it's a relatively static list of program options that you need to be able to be different on different instances of your application, so maybe for something like branding.

//PropertiesTest then uses System.setProperties to install the new Properties objects as the current set of system properties.
import java.io.FileInputStream;
import java.util.Properties;

public class PropertiesTest {
    public static void main(String[] args)
        throws Exception {

        // set up new properties object
        // from file "myProperties.txt"
        FileInputStream propFile =
            new FileInputStream( "myProperties.txt");

        //This statement initializes the new properties object, p, with the current set of system properties
        //This has the effect of adding the properties listed in myProperties.txt to the set of properties created by the runtime system at startup.
        Properties p =
            new Properties(System.getProperties());

         //note that the value of system properties can be overwritten! 
         //For example, if myProperties.txt contains the following line, the java.vendor system property will be overwritten:
         //       java.vendor=ABC

         //also note that an application can create p without any default Properties object, like this:
         //   Properties p = new Properties();

         //In general, be careful not to overwrite system properties.

        p.load(propFile);

        // set the system properties
        System.setProperties(p);
        // display new properties
        System.getProperties().list(System.out);
    }
}

Data Type

Data Type

results matching ""

    No results matching ""