473,383 Members | 1,868 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How do I use ObjectOutputStream with my objects?

Do I have to implement the serializable interface?
Is the default implementation of the serializable interface enough?


Jul 17 '05 #1
6 3861
On Mon, 27 Sep 2004 11:23:13 +0530, Kiran Kumar Kamineni <kk****@hp.com>
wrote:
Do I have to implement the serializable interface?
Is the default implementation of the serializable interface enough?


That depends on what your Objects are. If they consist only of primitives
and Serializable
Objects, yes. If not, no.

--

Whom the gods wish to destroy they first call promising.
Jul 17 '05 #2
Suppose my object consists of a set of string objects and a date object?
Will it be serialised (am asking because a "NotSerialisable" exception is
being thrown, everytime i try to write to a file using the
Objectoutputstream).

"Stefan Schulz" <te***@spacetime.de> wrote in message
news:opsey2l4qpq1fd9p@localhost...
On Mon, 27 Sep 2004 11:23:13 +0530, Kiran Kumar Kamineni <kk****@hp.com>
wrote:
Do I have to implement the serializable interface?
Is the default implementation of the serializable interface enough?


That depends on what your Objects are. If they consist only of primitives
and Serializable
Objects, yes. If not, no.

--

Whom the gods wish to destroy they first call promising.

Jul 17 '05 #3

"Kiran Kumar Kamineni" <kk****@hp.com> wrote in message
news:41********@usenet01.boi.hp.com...
Suppose my object consists of a set of string objects and a date object?
Will it be serialised (am asking because a "NotSerialisable" exception is
being thrown, everytime i try to write to a file using the
Objectoutputstream).


Your actual object needs to implement Serializable. You don't have to do
anything other than that, as long as the instance variables of your object
are also Serializable
Jul 17 '05 #4
Kiran Kumar Kamineni wrote:
Do I have to implement the serializable interface?
Is the default implementation of the serializable interface enough?


As a side note: Don't use the Object OutputStream unless you know
what you are doing. It is not suited for making objects persistent
as it doesn't handle versioning very well (store a class instance,
change the class definition slightly, and your stored object is
forever beyond reach).

The ability to serialize objects was invented to handle object
transfer over a network, but is widely misused as a persistence
technology because it makes object save/retrieve so (apparently)
simple.

To store objects, use text files a'la properties files, XML
or something similar. It takes a bit more effort as it needs
custom save/load methods.

Jul 17 '05 #5
"Kiran Kumar Kamineni" <kk****@hp.com> wrote in message news:<41********@usenet01.boi.hp.com>...
Do I have to implement the serializable interface?
Is the default implementation of the serializable interface enough?


Read my article on the subject:
http://www.sys-con.com/story/?storyid=44199

Regards,
Yakov
Jul 17 '05 #6
Good point about serialization, Jacob.

To overcome the pitfalls of ObjectOutputStream, you may want to look at
XMLEncoder in the java.beans package.
http://java.sun.com/j2se/1.4.2/docs/...MLEncoder.html

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Aguilar, James | last post by:
Hey guys. A new question: I want to use an STL libarary to hold a bunch of objects I create. Actually, it will hold references to the objects, but that's beside the point, for the most part. ...
6
by: Alfonso Morra | last post by:
I have written the following code, to test the concept of storing objects in a vector. I encounter two run time errors: 1). myClass gets destructed when pushed onto the vector 2). Prog throws a...
1
by: Kannan T via .NET 247 | last post by:
Hi All, Is there any equivalent C# method for reset method of ObjectOutputStream in Java If so do let me know. Advance Thanks ! ! ! -------------------------------- From: Kannan T ...
161
by: KraftDiner | last post by:
I was under the assumption that everything in python was a refrence... so if I code this: lst = for i in lst: if i==2: i = 4 print lst I though the contents of lst would be modified.....
7
by: Jo | last post by:
Hi, How can i differentiate between static and dynamic allocated objects? For example: void SomeFunction1() { CObject *objectp = new CObject; CObject object;
21
by: George Exarchakos | last post by:
Hi everyone, I'd like your help... Can we have a std::list<BASEwhere BASE be the base class of a class hierarchy? I want to add to this list objects that are inherited from BASE class but not...
14
by: Jess | last post by:
Hello, I learned that there are five kinds of static objects, namely 1. global objects 2. object defined in namespace scope 3. object declared static instead classes 4. objects declared...
6
by: khajeddin | last post by:
hi: i have a program which should read and werite on a file but after the first time it writeon the file it can read te records.but other times it write on the file but just read the records which...
1
by: MiziaQ | last post by:
I have this code to write to a file. However, this only saves one entry. How can I save multiple entries, each saved in separate lines ? At this point the output in the .txt file is strange: ’...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.