Search code examples
javanaming-conventionsjavabeansgetter-setter

Naming convention for getters/setters in Java


if I have the following private member:

private int xIndex;

How should I name my getter/setter:

getXindex()
setXindex(int value)

or

getxIndex()
setxIndex(int value)

EDIT: or

getXIndex()
setXIndex(int value);

?


Solution

  • The correct answer is

    getxIndex()
    setxIndex(int value)
    

    if you want them to be used as properties according to section 8.8: Capitalization of inferred names of the JavaBeans API specification (e.g. access them via ${object.xIndex} in a JSP.