wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes What is a bean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "What is a bean?" Watch "What is a bean?" New topic
Author

What is a bean?

Parth Twari
Ranch Hand

Joined: Jan 20, 2010
Posts: 163
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?


Parth Tiwari
| Pursuing Bachelor of Engineering | OSUM Club Leader | SCJP 6 | SCWCD 5 |...
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1640
    
  23

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

Joined: Feb 11, 2009
Posts: 8
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

Joined: Jan 20, 2010
Posts: 163
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

Joined: Feb 11, 2009
Posts: 8
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

Joined: Aug 03, 2008
Posts: 9291
    
  17

Parth, you can call the JobBean without any getters or setters too a bean...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Parth Twari
Ranch Hand

Joined: Jan 20, 2010
Posts: 163
Ok thanks..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is a bean?
 
Similar Threads
Can't pass changed beans values from one JSP page to another
bean setProperty
weird error when using a java bean with my jsp
jsp:useBean and default scope (head first mock exam question)
Doubt on jsp