Key Value - Properties (Property file) in Java.
Properties are values managed as key/value pairs of string datatype. The key identifies, and is used to retrieve, the value.
The implementation of the property class (java.util.Properties) extends java.util.Hashtable
The Java platform itself uses a Properties object to maintain its own configuration.
See the property method of the system class.
Access to system properties can be restricted by the Security Manager.
To set a system property when starting the jvm
java -D<name>=<value>
Properties extends java.util.Hashtable. Some of the methods inherited from Hashtable support the following actions:
// create and load default properties
Properties defaultProps = new Properties();
FileInputStream in = new FileInputStream("defaultProperties");
defaultProps.load(in);
in.close();
// create application properties with default
Properties applicationProps = new Properties(defaultProps);
// now load properties
// from last invocation
in = new FileInputStream("appProperties");
applicationProps.load(in);
in.close();
applicationProps.getProperty(String key, String default)
for (String key: properties.stringPropertyNames()){
System.out.println ("The key ("+key+") has the value ("+properties.getProperty(key)+")";
}