[Java123] JavaBean

Posted CathyGao2018

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Java123] JavaBean相关的知识,希望对你有一定的参考价值。

 

https://stackoverflow.com/questions/3295496/what-is-a-javabean-exactly

A JavaBean is just a standard

  1. All properties private (use getters/setters)
  2. A public no-argument constructor
  3. Implements Serializable.

That‘s it. It‘s just a convention. Lots of libraries depend on it though.

With respect to Serializable, from the API documentation:

Serializability of a class is enabled by the class implementing the java.io.Serializable interface. Classes that do not implement this interface will not have any of their state serialized or deserialized. All subtypes of a serializable class are themselves serializable. The serialization interface has no methods or fields and serves only to identify the semantics of being serializable.

In other words, serializable objects can be written to streams, and hence files, object databases, anything really.

Also, there is no syntactic difference between a JavaBean and another class -- a class is a JavaBean if it follows the standards.

There is a term for it because the standard allows libraries to programmatically do things with class instances you define in a predefined way. For example, if a library wants to stream any object you pass into it, it knows it can because your object is serializable (assuming the lib requires your objects be proper JavaBeans).

 

https://stackoverflow.com/questions/1973073/what-is-a-java-bean

 

以上是关于[Java123] JavaBean的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript 有用的代码片段和 trick

Java123Yaml格式

JavaBean简单及使用

JavaBean实操代码

JavaBean简单及使用

JS+JavaBean判断管理员增删改的操作权限