• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

What is a bean?

 
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?

 
Creator of Enthuware JWS+ V6
Posts: 3348
303
Android Eclipse IDE Chrome
  • 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
 
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.


 
Sheriff
Posts: 9671
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • 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..
 
I'm just a poor boy, I need no sympathy, because I'm easy come, easy go, little high, little low, little ad
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic