开发者

Beans in java programming [duplicate]

This question already has answers here: What is a JavaBean exactly? 开发者_StackOverflow (23 answers) Closed 6 years ago.

What are beans in java programming?Is having an understanding of Struts vital for learning Spring?


That depends.

You could be talking about Spring beans, Enterprise Java Beans or some other variant.

The general answer is that beans are some type of generic object (or POJO perhaps) that hold information - almost think of them like their own data type. The distinction is that they typically don't have much in the way of behaviors eg, they only have: simple fields, getters, setters.


From Wikipedia:

JavaBeans are reusable software components for Java that can be manipulated visually in a builder tool. Practically, they are classes written in the Java programming language conforming to a particular convention. They are used to encapsulate many objects into a single object (the bean), so that they can be passed around as a single bean object instead of as multiple individual objects. A JavaBean is a Java Object that is serializable, has a nullary constructor, and allows access to properties using getter and setter methods.


Java Bean is a class that conforms to the following convention:

  • The class must have a public default constructor (no-argument). This allows easy instantiation within editing and activation frameworks.
  • The class properties must be accessible using get, set, is (used for boolean properties instead of get) and other methods (so-called accessor methods and mutator methods), following a standard naming-convention. This allows easy automated inspection and updating of bean state within frameworks, many of which include custom editors for various types of properties.
  • The class should be serializable. This allows applications and frameworks to reliably save, store, and restore the bean's state in a fashion independent of the VM and of the platform.

Source: Wikipedia.


A "bean" can be everything, depending on context. Thus it is roughly equivalent to an "object". (Note that it can also be viewed as equivalent to "class", although I think it's more about instances than definitions. Hence "bean class" is more often used)

  • a spring bean is any spring-managed object
  • a javabean is an object of class the conforms to the javabean spec (properties, getters and setters)
  • enterprise java bean is a container-managed object

As for your second question - no, struts and spring are rather separate technologies and neither of them requires knowing the other.


Is having an understanding of Struts vital for learning Spring? No, both follow the MVC pattern so knowing struts will help you to know spring..but otherwise there are lot of differences..in how the two work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜