This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes y to implement serializable in getter & setter ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "y to implement serializable in getter & setter ?" Watch "y to implement serializable in getter & setter ?" New topic
Author

y to implement serializable in getter & setter ?

Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 753
why do we implement serializable in getter and setter ???


Jigar Naik


Shubha Sridhar
Greenhorn

Joined: Feb 22, 2007
Posts: 2
The data you are going to set or get using getter or setter method some times may need to pass through network from one remote to another remote system.Serializable is property that allows you to write the data or the object state into an output stream and fetch it back from there...
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

why do we implement serializable in getter and setter ???

Can you please explain your question more clearly?

Getters and setters are methods. You cannot implement interface Serializable in a method. Is your question about what Serializable means?

Or did you mean to ask why in a Java Bean (which is a class that has getter and setter methods) you should implement Serializable? If you meant that, that's because it's one of the criteria which makes a class a Java Bean. Wikipedia says:

"In order to function as a JavaBean class, an object class must obey certain conventions about method naming, construction, and behavior. These conventions make it possible to have tools that can use, reuse, replace, and connect JavaBeans.

The required conventions are:

* The class should be serializable (able to persistently save and restore its state)
* It should have a no-argument constructor
* Its properties should be accessed using get, set and other methods following a standard naming convention
* It should contain any required event-handling methods"


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

"y" is not a word. Please use real words such as "why" when posting. Please read this for more information.
[ February 22, 2007: Message edited by: Ernest Friedman-Hill ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
I would say that the Wikipedia article is wrong at least about the getXXX() setXXX() naming convention being required.


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41054
    
  43
I would say that the Wikipedia article is wrong at least about the getXXX() setXXX() naming convention being required.

How so? The rules a bean must follow are mentioned here, and nothing about that naming convention sounds optional to me.


Ping & DNS - my free Android networking tools app
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
Maybe it is because for booleans you can use the isXXX method.


Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: y to implement serializable in getter & setter ?
 
Similar Threads
y to implement serializable in getter & setter ?
Problem assigning long values
Why and When to use reflections
SERIALIZABLE INTERFACE
Can a servlet access the bean created by the JSP