deamon
deamon

Reputation: 92437

Where is the JavaBean property naming convention defined?

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.

Upvotes: 21

Views: 26832

Answers (2)

Carl Smotricz
Carl Smotricz

Reputation: 67760

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.

Upvotes: 32

Edward Q. Bridges
Edward Q. Bridges

Reputation: 18320

the implementation of this functionality is in this class: http://java.sun.com/javase/6/docs/api/java/beans/Introspector.html

Upvotes: 3

Related Questions