vibhor
vibhor

Reputation: 109

Confuse among JavaBeans, POJO, beans?

As far as I know, JavaBeans are the simple getter and setters methods of whatever fields are there in your Java class, on the other hand POJO seems similar (fields and its getter/setter) whats the difference then?

As that's not enough, here comes the beans floating around in all your JSPs and Struts config files, does (according to my knowledge) same stuff...

  1. I am confuse by naming, whats the difference, what are the magic words?
  2. Why do they call it bean, what should I say, if any one ask me describe bean in context of Java EE / JSP / Struts.

Upvotes: 1

Views: 625

Answers (2)

dantuch
dantuch

Reputation: 9283

A JavaBean is a POJO that is serializable, has a no-argument constructor, and allows access to properties using getter and setter methods. An Enterprise JavaBean is not a single class but an entire component model (again, EJB 3 reduces the complexity of Enterprise JavaBeans).

So main difference that could be seen is POJOs can be more encapsulated - have argument constructors and throw away some setters that should be used only once per object. JavaBean as you mentioned enforces some strick standard which isn't the best solution to every need.

Upvotes: 0

Jens Schauder
Jens Schauder

Reputation: 81862

A POJO is a plain java object that doesn't adhere to any framework standard. Often Java Beans are considered POJOs as well, since the Java Beans Standard (or what is used of it) is kind of weak.

Java Beans are Java classes that adhere to certain naming conventions (mainly the getter setter thing) and are used in many contexts. JSPs is one of them. There is actually more to Java Bean then most people use. You can learn about it in this tutorial: http://docs.oracle.com/javase/tutorial/javabeans/index.html

Why is it called bean? I can only guess: Java -> Coffee -> Bean on one hand and on the other hand a bean is something simple, self contained which is kind of appropriate for a 'component'

Upvotes: 3

Related Questions