I understand that a Java Bean is a Java class that adheres to the 3 conditions:
- Having a no-arg ctor
- Having private fields with setters and getters
- Be serializable
However, I'm having hard time to understand when is it useful and why. It seems from the spec that it has something to do with visual tools, as the spec defines What is a Java Bean:
“A Java Bean is a reusable software component that can be manipulated visually in a builder tool.”
The rest of the section goes on about visual builders and stuff. So do Java Beans only come handy in the context of visual builders?
The idea is that some UI tool can, based on nothing but the name of a class, show you a dialog box with its properties. It does that by inspecting its methods using reflection. It can figure out, for each property:
setFooandgetFooboth exist?foois the name of this property).void setFoo(String)exists,String getFoo()exists, therefore,foois a property whose value is String).This notion is about 30 years obsolete. Nobody and Nothing uses this concept or thinks about it. The idea never took off. One reason might be that this system is woefully inept:
<select>was not possible with this. There was no system to indicate what kind of values were allowed. For example, a property of typeintcould not indicate that its value must be positive. At best, the UI can offer a component that can allow any value, and will deal withIllegalArgumentExceptionto tell you about it. But it can't give you a UI widget that is more fundamentally designed to do positive numbers only.setName(Name name)and then define name asclass Name {String first, last; /* setters and getters here */}and hope that the UI does a reasonable job rendering this hierarchical take. But if you don't want the hierarchy, you just want 'first' and 'last' name together, there's no way to indicate this.In general the idea of "I want to define a UI" was never even feasible with this system, and insofar that you really want that, HTML won that fight.
The second idea is that you have a 'live' system where you can 'live' edit things, which involves not just this beanspec thing but also that you can 'observe' changes, but this never took off either: Having a system that dynamically reacts to a value being changed by an outside force (such as that property being exposed in a UI so that a human can modify it) is complicated, and the complicated part is not in any way the actual exposing of the endpoint. It's writing a system to deal with it. Hence, the 'value' that the beanspec provides is zero, and if you've gone through the considerable hardship of writing a system that can react to dynamically changing properties, you do not toss out 50% of the value by failing to spend 1% of the effort on a slightly nicer UI for it than 'a name, a java type representing the data, but no way to modify in any way what it looks like, or add descriptions, or even group things together meaningfully, or affect how it looks'.
TL;DR: This isn't relevant. Whatever documentation or tutorial you are reading became completely irrelevant to the IT sphere about 25 years ago. Delete it.