11

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

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
abson
  • 9,148
  • 17
  • 50
  • 69
  • have you even tried to ask http://www.google.de/#q=java+beans+example or http://en.wikipedia.org/wiki/JavaBean ? – oezi Jan 04 '11 at 09:24
  • Not at all its generic not limited to Javabeans – abson Jan 04 '11 at 09:27
  • I don't know that it is a dupe; they're asking about Spring beans too. – javamonkey79 Jan 04 '11 at 09:31
  • 1
    About your second question: Struts and Spring do not have anything to do with each other. So no, an understanding of Struts is not vital for learning Spring. – Jesper Jan 04 '11 at 10:30

5 Answers5

11

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.

javamonkey79
  • 17,443
  • 36
  • 114
  • 172
7

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.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
4

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.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
4

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.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
1

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.

Mahesh
  • 1,583
  • 13
  • 18
  • does that mean that i can go for spring without touching struts?? – abson Jan 04 '11 at 09:39
  • That is what I did, they are completely different projects not related, I just know the basics of struts, but spring I know much more..you don't even need to know that Struts exists to use Spring except may be that it is used more than Spring... – Mahesh Jan 04 '11 at 09:51