File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Questions about java bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Questions about java bean" Watch "Questions about java bean" New topic
Author

Questions about java bean

Adnan Gondal
Ranch Hand

Joined: Apr 30, 2011
Posts: 32
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

Joined: Aug 22, 2008
Posts: 191

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.


Do not wait to strike till the iron is hot; but make it hot by striking....
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
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
 
subject: Questions about java bean