import java.util.Properties; public class PropertiesExample { public static void main(String[] args) { // create Properties object Properties props = new Properties(); // add properties props.setProperty("db.url", "jdbc:mysql://localhost/mydb"); props.setProperty("user.name", "myuser"); props.setProperty("user.password", "mypassword"); // retrieve property value String dbUrl = props.getProperty("db.url"); System.out.println("Database URL: " + dbUrl); } }
import java.util.Properties; public class DefaultPropertiesExample { public static void main(String[] args) { // create Properties object Properties props = new Properties(); // retrieve property value with default String dbUrl = props.getProperty("db.url", "jdbc:mysql://localhost/test"); System.out.println("Database URL: " + dbUrl); } }The java.util package library contains the Properties class.