import java.io.*; import java.util.*; public class PropertiesExample { public static void main(String[] args) throws Exception { Properties props = new Properties(); FileReader reader = new FileReader("config.properties"); props.load(reader); String url = props.getProperty("url"); String username = props.getProperty("username"); String password = props.getProperty("password"); System.out.println("URL: " + url); System.out.println("Username: " + username); System.out.println("Password: " + password); } }
import java.util.*; public class PropertiesExample { public static void main(String[] args) { Properties defaultProps = new Properties(); defaultProps.setProperty("programName", "My Program"); Properties props = new Properties(defaultProps); String programName = props.getProperty("programName"); System.out.println("Program Name: " + programName); } }In this example, we create a default Properties object and set a default value for the programName key. We then create a new Properties object with the defaultProperties as its defaults. Since we didn't set the programName key in the new object, it will use the default value. Package/Library: java.util