• 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

Bean Property

 
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey,

can some one please tell me whats the different of readable and writable properties.

Its there in http://www.cafe4java.com/mockexams/scwcd/mock1/q1.php


Also if we write a bean class we have to also declare the properties know..having set get methods is not enought right?

i mean,

public class Movie {

private String genre;
private String name;

public void setGenre(String genre){
this.genre=genre;
}

public void setName(String name){
this.name=name;
}


Those variables genre and name should be there right?

Thank You.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

can some one please tell me whats the different of readable and writable properties.


Readable properties are properties you can read, usually via a getter method. And writable properties are properties whose value you can change, usually via a setter method.

Also if we write a bean class we have to also declare the properties know..having set get methods is not enought right?


Don't forget that you're still using Java. You need to declare the properties, otherwise how would you compile it ? You could use something else, like a Map, to store them. In any case, you would still need something to store them.
 
Harshana Dias
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Don't forget that you're still using Java. You need to declare the properties, otherwise how would you compile it ? You could use something else, like a Map, to store them. In any case, you would still need something to store them.



Thats right.
But then the question which i post the link(which i found from javaranch) make no sense.
It says option A is correct which is ProductBean defines two properties.
But there are no name and weight variables define only the set and get methods are define. so wouldn't that incorrect answer.

There are two variables private String productName; private int quantity; declared but no related get or set method..so we cant say for those properties right?

Thnak You.

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Based on the javabean convention the property name is based on the name of the getter and setter method.

So if you have a setWeight and setName then you have two writable properties, weight and name.
The name of the variable that holds the value doesn't matter

take a look at this example:


Imaginary declares 2 properties but doesn't implement any.
 
Harshana Dias
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mateus..its clear now
 
reply
    Bookmark Topic Watch Topic
  • New Topic