Naming convention for properties in property file

后端 未结 7 1282
感情败类
感情败类 2021-02-03 20:05

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.acc

相关标签:
7条回答
  • 2021-02-03 20:19

    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

    0 讨论(0)
  • 2021-02-03 20:23

    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
    
    0 讨论(0)
  • 2021-02-03 20:23

    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)

    0 讨论(0)
  • 2021-02-03 20:24

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

    0 讨论(0)
  • 2021-02-03 20:24

    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.

    0 讨论(0)
  • 2021-02-03 20:35

    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.

    0 讨论(0)
提交回复
热议问题