• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Serializable exception

 
Ranch Hand
Posts: 203
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..!!


 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

Please if you could provide me a short demo , I can then grasp from it, THANKS in advance..!!
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Oracle Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's right!
 
reply
    Bookmark Topic Watch Topic
  • New Topic