Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Serializable exception

 
Saral Saxena
Ranch Hand
Posts: 203
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Folks,

I was going through a nice question and it was that...Suppose super class of a new class implement Serializable interface, how can you avoid new class to being serialized?

TH/he answer to this solution is ..as per my understandings...If Super Class of a Class already implements Serializable interface in Java then its already serializable in Java, since you can not unimplemented an interface its not really possible to make it Non Serializable class but yes there is a way to avoid serialization of new class. To avoid java serialization you need to implement writeObject () and readObject () method in your Class and need to throw NotSerializableException from those method.

Now could you guys please show me through a small program demo,,!!that will be a great help...!! thanks in advance..!!


 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saral Saxena wrote:
Now could you guys please show me through a small program demo,,!!that will be a great help...!! thanks in advance..!!


How about you writing it?
 
Saral Saxena
Ranch Hand
Posts: 203
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

Please if you could provide me a short demo , I can then grasp from it, THANKS in advance..!!
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NO. YOU write it. You clearly already have all the information you need available. And if you get stuck while trying to write it, google for examples. And, after you spend at least an hour trying to write it yourself and trying to figure out your problems by searching on your own, if you're still stuck, then post a question here, showing what you've tried, and providing details about what exactly you're having trouble with.

Why is it necessary to tell you this in almost every thread you post?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15282
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saral Saxena wrote:Now could you guys please show me through a small program demo,,!!

Saral, if you are serious about learning to program in Java, you will need to take initiative yourself, instead of constantly asking other people to write examples for you.

The best way to learn programming is to experiment yourself. Write code yourself, if it doesn't work, carefully try to understand what the error messages mean, change your program and try again, until it works.

It's also much more fun when you do that - the satisfaction of solving a problem you have been working on for a while is nice.

Now, about this question. You know already exactly what has to be done, because you wrote this yourself:
Saral Saxena wrote:To avoid java serialization you need to implement writeObject () and readObject () method in your Class and need to throw NotSerializableException from those method.

It's very easy to make a short program with exactly this. The API documentation of the interface java.io.Serializable (<= link, click on it) tells you exactly what the writeObject() and readObject() methods should look like.

Try it yourself, and post your results, then we'll tell you if you did it correctly.
 
Saral Saxena
Ranch Hand
Posts: 203
Eclipse IDE Java Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,

This is the piece of code which finally solves the things...



and there is a subclass...




 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15282
39
Android IntelliJ IDE Java Scala Spring
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic