Where is the JavaBean property naming convention defined?

deamon picture deamon · Jan 2, 2010 · Viewed 22.6k times · Source

The Spring Framework API doc says:

The convention used is to return the uncapitalized short name of the Class, according to JavaBeans property naming rules: So, com.myapp.Product becomes product; com.myapp.MyProduct becomes myProduct; com.myapp.UKProduct becomes UKProduct.

I looked at Suns website to find a definition, but didn't find one. I wonder about a rule for names with more than one upper case character at the beginning. Is the rule that the first character is upper case if the second character is upper case too?

The background is, that I want to generate variable names automatically for use in HTML templates depending on the type of the object. Example: class: SomeName --> object: someName.

Answer

Carl Smotricz picture Carl Smotricz · Jan 2, 2010

http://download.oracle.com/otndocs/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/

http://www.oracle.com/technetwork/java/javase/tech/index-jsp-138795.html

Also, a direct link to the (PDF) specification.

Section 8.8 in the linked document is entitled "Capitalization of inferred names" and briefly outlines how names of properties are derived.