This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Questions about java bean

 
Adnan Gondal
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all!

I am having two questions, kindly answer them.

Q1: Can we have data members with default access modifier in a java Bean?

Q2: Is it must to provide getter and setter methods for all the properties of a java bean or we can skip one if we don't need it?
 
Manoj Kumar Jain
Ranch Hand
Posts: 195
Java Linux Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Adnan,

Surely we can have data member with default access / public access in the Java Bean. But it's good practice to have data member as Private and get them access by getter and setter methods.

also you need not to make getter and setter method for each of the data member. But if you dont have a getter /setter method for a private data member you won't be able to access that data member.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The idea of a bean is that it has a no-arguments public constructor and public get and set methods for every field. That way it is possible to write the state of the class into an XML file and reconstruct it later.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic