• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What is a bean?

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok thanks..
 
reply
    Bookmark Topic Watch Topic
  • New Topic