Difference between revisions of "JavaBeans Naming"

From Suhrid.net Wiki
Jump to navigationJump to search
(Created page with "JavaBeans are Java classes that have properties. * Properties which are represented as private instance variables. * Exposed through getters and setters. Getters * camel-case, ...")
 
 
Line 19: Line 19:
 
* public void addXListener(XListener xl);
 
* public void addXListener(XListener xl);
 
* public void removeXListenerClassName(XListener xl);
 
* public void removeXListenerClassName(XListener xl);
 +
 +
[[Category:OCPJP]]

Latest revision as of 23:29, 21 June 2011

JavaBeans are Java classes that have properties.

  • Properties which are represented as private instance variables.
  • Exposed through getters and setters.

Getters

  • camel-case, prefixed with get: getPropertyName(). In case of boolean variable, prefix can also be "is".
  • should be public, return type same as that of the property, void argument.
  • e.g. public int getAge();

Setters:

  • camel-case, prefixed with set: setPropertyName()
  • should be public, return type void, and argument of the same type as the property

Events:

  • Methods in the source to register events:
  • camel-case, prefix with add or remove followed by Listener Class Name, with argument as the Listener object

e.g.

  • public void addXListener(XListener xl);
  • public void removeXListenerClassName(XListener xl);