Reading a properties file using design patterns I am trying to read properties file using a singleton class. I would like to know if there are any best practices and design patterns to read the properties file. I found dependency injection is one way to read properties file. But, I did not find any examples on the DI design pattern. Any sample code and links would be helpful.

package com.cisco.propertiesreader;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.Set;

import org.apache.log4j.Logger;

public class ReadProperties {

    private static final Logger LOGGER = Logger.getLogger(ReadProperties.class);

    private final Properties props = new Properties();

    private ReadProperties() {
        InputStream in = this.getClass().getClassLoader().getResourceAsStream("config.properties");
        try {
            props.load(in);
        } catch (IOException e) {
            LOGGER.error(e.getMessage());
        }
    }

    private static class PropHolder {
        private static final ReadProperties INSTANCE = new ReadProperties();
    }

    public static ReadProperties getInstance() {
        return PropHolder.INSTANCE;
    }

    public String getProperty(String key) {
        return props.getProperty(key);
    }

    public Set&lt;String&gt; getAllPropertyNames() {
        return props.stringPropertyNames();
    }

    public boolean containsKey(String key) {
        return props.containsKey(key);
    }
}
DI means injecting dependencies in  and not creating them directly in a class. Your properties file contains the String value of the keys. You need not compile your java classes if the string value are changed. Thus your string literals and your classes are de-coupled from each other. 

Dependency Injection is a Design principle. (I suggest you to study SOLID design Principles). Along with it also we should pay due respects to principles like KISS and YAGNI. These say we should keep the code simple and avoid over-engineering. 

You should have different Properties object for each file and pass the object from which you wish to read in your PropHolder.