Tuesday, 23 April 2013

How JavaBeans differ from POJO's ???

JavaBeans are governed by certain Java Specifications which a POJO is free from.

The JavaBean specification requires a java class to ...
  1. be Serializable
  2. have getters and setters
  3. have a no argument
JavaBean Property Naming Rules ...
  1. If the property is not a boolean, the getter method's prefix must be get e.g. getSize()
  2. If the property is a boolean, the getter method's prefix should be either get or is e.g. getEmpty(), isEmpty()
  3. The setter method's prefix must be set e.g. setSize()
  4. Name of the getter or setter method is completed by changing the case of the first letter of the property name to UPPERCASE e.g. if property is size then methods are getSize() and getSize()
  5. setter methods should be marked public with void return type with an argument that represents the property type
  6. getter methods should be marked public, take no arguments, and have a return type that matches the argument type of the setter method

No comments:

Post a Comment