Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Serialization & transient attributes

843789Apr 3 2009 — edited Apr 3 2009
Hello,
I'm very new to Java programming and this site, so I apologize if this question has already been asked numerous times. I have to do a project for my intro to java class that is suppose to have binary file I/O in all of our classes we have to do. All of the classes are serializable, however, one of the classes extends another class which is not serializable. I thought that if I put the transient keyword in front of all the calls to the super class that that would allow for proper serialization but when I try to compile my code it tells me "illegal start of expression" if i do something like say :

public Example(){
transient super();
this.attribute1=" ";
this.attribute2=" ";}

So does this mean that I can call on the super class constructor when it's not serializable in its subclass that is serializable and there won't be a problem?

another question that is an extension of the first:

This super class has two properties for example String title and int numTitles so would you ever need to have attributes in the subclass that account for these properties? If so is the representation below appropriate? When I compiled it I didn't receive any errors.

transient MainExample title;
transient MainExample numTitles;

I understand the concept of serialization but I still don't seem to get how to work with it completely, especially with dealing with nonserializable properties as well. So if anyone can help me get this concept and how to take it and translate it into proper coding/tell me why what I have here is wrong, I would GREATLY appreciate it!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 1 2009
Added on Apr 3 2009
7 comments
871 views