Properties defines the following instance variable
Properties defaults
This variable holds default property list associated with a
Properties object.
Properties defines following two constructors
Properties()
Properties(Properties propDefault
)
In above two cases Properties should be empty.
Properties defines following methods apart from the Hashtable.
PropertiesDemo
import java.util.*;
class PropertiesDemo
{
public static void main(String arg[])
{
Properties colours = new Properties();
Set fruits;
colours.put("Mango", "Yellow");
colours.put("Grapes", "Green");
colours.put("Orange", "Orange");
colours.put("Apple", "Red");
fruits = colours.keySet(); // LINE A
for(Object frt : fruits)
{
System.out.println("The colour of " + frt + " is " + colours.getProperty((String) frt) + ".");
}
System.out.println();
String str = colours.getProperty("Apple", "Not found"); // LINE B
System.out.println("The colour of Apple is " + str + ".");
}
}
OUTPUTThe colour of Mango is Yellow.
The colour of Orange is Orange.
The colour of Grapes is Green.
The colour of Apple is Red.
The colour of Apple is Red.
DESCRIPTIONHere first it creates Properties list in which the keys are the names of fruits and the values are the colours of fruits.At LINE A we can get set-values of keys. Look for LINE B not in list specify default value. If we run the program we can get the properties key and values but not default value.