Reputation: 1580
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?
Upvotes: 47
Views: 63216
Reputation: 1165
Kebab case is recommended
According to the Spring Boot documentation (see notes in the table with relaxed binding
) kebab case is recommended for use in .properties and .yml files.
Upvotes: 10
Reputation: 173
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.
Upvotes: 0
Reputation: 6158
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
Upvotes: 15
Reputation: 2602
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)
Upvotes: 0
Reputation: 25950
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.
Upvotes: 1
Reputation: 1573
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
Upvotes: 2
Reputation: 272297
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.
Upvotes: 5
Reputation: 41200
Naming convention is recommended as lowercase in property file.
bank.account.number
this is more appreciable.
Upvotes: 39