lcaohoanq
86 words
1 minute
Java Bean
A JavaBean is just a standard. It is a regular Java class, except it follows certain conventions
- All properties are private
- Public getters/setters
- A public no-argument constructor (public all-argument constructor, optional)
- Implements Serializable.
- Example code:
@Getter@Setter@NoArgsConstructor@AllArgsConstructorpublic class Student implements Serializable { private int age; private String name;}So why use JavaBeans?
The ‘beans’ of JavaBeans are classes that encapsulate one or more objects into a single standardized object (the bean). This standardization allows the beans to be handled in a more generic fashion, allowing easier code reuse and introspection