Naming convention for properties in property file

久未见 提交于 2020-12-28 05:44:03

问题


What are the naming conventions for property names defined in properties files in Java? Can I use uppercase or only lowercase?

For example: bankAccountNumber or bank.account.number?

Is it defined somewhere on the internet?


回答1:


Naming convention is recommended as lowercase in property file. bank.account.number this is more appreciable.




回答2:


As per my understanding, there is no any standard rule written for .properties file in java. but if you see the .properties files inside the lib folder of Java\jre most of them have lower cased .properties file names. And the properties themselves are also lower cased. such as:

psfontj2d.properties

key values

courier_new=courier
courier_new_bold=courier_bold



回答3:


There's no particular standard for naming properties, but convention appears to be of the form

a.b.c.d = x

in lowercase. I would expect some sort of informal hierarchy e.g.

bank.
bank.account.
bank.account.name.
bank.account.pin.

etc.

If it's a property which directly affects a particular class I may name it after that class (or at least use the package name). However that is also an example of implementation leak, and I'd think seriously before doing that.




回答4:


In JSF you can see in ValidationMessages.properties something

javax.validation.constraints.Pattern.message

or in JsfMessages.properties

javax.faces.component.UISelectOne.INVALID

So you can use wherever you like, i like just lowercase, package formatted




回答5:


I guess there is no such common conventions for property files. However, using lowercase letters in an eligible/easy-to-understand format (e.g. bank.account.number) sounds good, and using the property files with their original extensions (.properties) is also recommended.




回答6:


Actually Resource Bundle accepts only fully qualified base name of the bundle, with no file extension. In this case it will try to load the bundle of files like this

messages/EN/properties.properties

I am sure you intend something different than the conventional internationalization, but convention would have been "messages_en.properties" (en when language, EN when country)




回答7:


There is no standard convention for naming properties in property file.

Ref: https://en.wikipedia.org/wiki/.properties

As you are Java user, you can use camelCase.

For the given example, the name can be bankAccountNumber.

In case, if the requirement is to follow the hierarchy structure, dots can be used as below.

  • bank
  • bank.account.name
  • bank.account.number
  • bank.department.name


来源:https://stackoverflow.com/questions/12473537/naming-convention-for-properties-in-property-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!