Junior — Middle
Can you list the main characteristics of Properties objects in Java?
sobes.tech AI
Answer from AI
Objects of type Properties in Java represent a specialized class for storing key-value pairs, where both the key and value are strings. Main characteristics:
- Inherits from
Hashtable<Object,Object>, but is usually used withString. - Often used for storing configuration parameters.
- Allows loading and saving data in
.propertiesformat viaload(InputStream)andstore(OutputStream, String)methods. - Supports specifying default values through constructors.
- Does not guarantee the order of elements.
Example usage:
Properties props = new Properties();
props.setProperty("username", "admin");
props.setProperty("password", "12345");
String user = props.getProperty("username");