Naming convention for getters/setters in Java

Simon picture Simon · Jun 1, 2010 · Viewed 18.4k times · Source

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);

?

Answer

Thomas Einwaller picture Thomas Einwaller · Apr 22, 2013

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.