Properties file vs Constants class in Java

前端 未结 8 1194
臣服心动
臣服心动 2020-12-16 11:03

I am a bit confused between using a constants file and properties file in Java.

How to decide when to use Constants.java and when to use a .properties

8条回答
  •  有刺的猬
    2020-12-16 11:44

    Properties have the advantage of being externalizable. You can have one property file for development, another for test and another for production. A lot of times, though, rarely changed properties, that are internal to the workings of the software are put into properties file making them hard to manage.

    OTOH constants are compiled so any errors will be caught at compile time.

    So the answer is , it depends. If the values in the properties are truly configuration changes you want to externalize then use properties file. else make them Java constants. You might end up using both, though.

提交回复
热议问题