• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bean Property

 
Harshana Dias
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • 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.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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: 348
  • Mark post as helpful
  • send pies
  • 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.

 
Mateus Lucio
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • 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: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mateus..its clear now
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic