Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is a bean?

 
Parth Twari
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Source : Marcus.

Given the following code:

And the following JSP page that uses the code


What will be output by that JSP code when invoked with the query string
?a=tom&b=dick&c=harry

A. fredjimbob harrytomdick
B. jimbobfred tomdickharry
C. harrytomdick jimbobfred
D. jimbobfred harrytomdick

Answer: D

But I feel the given class is not even a bean and it cannot be used with usebean action as it does not have the get/set Methods for each property. Isn't it?

 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2408
93
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But I feel the given class is not even a bean and it cannot be used with usebean action as it does not have the get/set Methods for each property. Isn't it?

Not necessarily: A JavaBean property can have only a gettter method (read-only property) or only a setter (write-only property) or both (read/write property).

Regards,
Frits
 
pal sahab
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

The answer given is correct, because the main requirement for a java bean is to have a no argument constructor which this bean had.The java bean with setters only is just like write only bean.

 
Parth Twari
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whew..! i did not know that there could be read only write only properties in a bean.
Now I understand the answer.

But is this a bean?

 
pal sahab
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Definition of Java Bean : A Java Bean is a reusable software component that can manipulated visually in a builder tool.

Now coming out of formal world

A Java class is called java bean = Normal java class + Some rules to follow

and some minimal rules are

1.The bean class must provide a zero-argument constructor
2.The bean must support persistence, by implementing the Serializable or Externializable interface.

so basically your class is a java bean, but with no use.The variables chef,waiter,cleaner are not properties but they are simple class level variables.
I hope this explains your query.


 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Parth, you can call the JobBean without any getters or setters too a bean...
 
Parth Twari
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic