Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

what is "Serializable"?

Status
Not open for further replies.

quickblueink

Technical User
Apr 5, 2001
57
US
Can anyone give me a quick rundown as to what is and why anyone uses the serializable interface? Thanks,
M.austin
 
Since that site is slightly hard to read (I know what serializable is and I had to blink twice per word) I'll give a short "no nonsense" summary.

Serializable means you can store the object in binary form without much of a hassle.

When you write a class you want to be able to do that, you implement the Serializable interface and then can *relatively* easily write it away to disk as a binary object and also read it back in... tho you'll need a class cast, if I'm not mistaken.
 
>> Since that site is slightly hard to read

Why? Could you explaing that please?

>> Serializable means you can store the object
>> then can *relatively* easily write it away to disk as a
>> binary object and also read it back

Oh... so serialization is for storing or writing/reading Java Objects to disk. Interesting, someone once told me it was used for things like Remote Procedure Calls and Distrubuted Computing. Thanks for clearing that up.

 
It is hard to read because it does not mention the actual puprose of serializing... or at least it doesn't do it in a clear and comprehensible way.

Btw, you could have also corrected/completed me without the insult/sarcasm. If you wanted to prove just how arrogant you are, you succeeded.
 
Thanks y'all. I read the API before I wrote this note, but it didn't really tell me much. The reason that I wanted to know about it is because I read that to make a java class into a java bean, all you have to do is make sure the constructor doesn't have arguments and that it implements Serializable.

I am trying to switch classes to beans for testing purposes. The project I am working on is using Websphere, which has a unit test module for beans but not classes.

can anyone tell me if there is something else I need to do to *officially* make them beans? Do I need to Serialize certain methods, or just implement the Serializable Interface? If that's the case, is the whole class considered the bean, or just the binary output of the methods that serialize?

I'm sure I'm overcomplicating an issue that is relatively simple, but it's just because I'm an idiot. Thanks for all your help.
--M.austin
 
There's no BeanInterface, so to officially become a bean you only have to follow the pattern of accessors and mutators (getters and setters), have a null constructor (so that an IDE could construct one for you) and make the class serializable (so that an IDE could remember the state and bring it back again later).

A bean is accessed via introspection, i.e. the instance is examined to find its methods. By following the bean naming conventions Java can identify its properties. It is possible to create a BeanInfo class that goes with your bean to manually control which properties are visible.

I expect that WebSphere has unit tests for beans as these are classes that can be accessed from JSP pages.

Not all your classes will be able to become beans. You might consider JUnit, HttpUnit, etc. for these. Jeremy Nicholson, Director of a UK-based Java and Data Warehousing consultancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top