JavaBean
A JavaBean is a Java class that should follow the following conventions:
- It should have a no-arg constructor.
- It should be Serializable.
- It should provide methods to set and get the values of the properties, known as getter and setter methods.
Serializable序列化的含义
:
That is nothing but a "marker interface" that tells Java that the implementing class consents to "serialization" -- a process that converts an instance into a stream of bytes.
Those bytes can be stored in files, sent over a network connection, etc, and have enough info to allow a JVM to reconstruct the object later -- possibly in a different instance
of the application, or even on a whole other machine!
Of course, in order to do that, the class has to abide by certain limitations. Chief among them is that all instance fields must be either primitive types (int, bool, etc), instances of some class that is also serializable, or marked as transient
so that Java won't try to include them. A class that can not abide by those limitations should not implement Serializable
(and, IIRC, the Java compiler won't even let it do so.)