• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Serializable

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is Serializable in java?i want desription abt Serializable and how to use?and why we have to use?
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

'Serializable' is a marker interface. A marker interface is one that has no methods. By implimenting a marker interface, you're telling the JRE that your class has specific properties. For example, if your class implements Serializable, then the JRE knows that it doesn't have to do anything special to serialize it. (convert an object of your class into a byte stream) Hope this helps.

_steve.
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Also "googling" will help more...

Regards,
Maulin
 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

For permanent storage of object details (Object State) outside the program scope (i.e. store to a file/ pass the object across the network) we implement the class with Serializable marker interface as follows.

class Test implements Serializable{
.....
}

Generally, basic data types can be literally stored into any file permanently, when it comes to object state, Java provides an inbuilt way of storing the instance variables of the objects to any stream using Serializable Interface.

Hope this helps.

Regards
Roshini
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am still not getting the concept of using Serialization in Java.

Can anybody eloborate?

When do u need feel to serialize an object. If I have an employee object and want to store it in database, do I need to serialize employee object?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ritika Agarwal:
If I have an employee object and want to store it in database, do I need to serialize employee object?



That would be one way, but not the only way, to do it.

Just one common example: serialization is often used to save and migrate user sessions in a servlet container. Imagine you have a whole server farm with machines A, B, C, and D. Machine A handles a request, and after the request, stores the user session into a file on a shared disk using serialization. Machine C gets the next request from that user, so loads the session and services the request. It's easy, simple, and doesn't require the server to know anything about what's in the session.
 
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
See The Java Tutorial:

Object Serialization
[ July 28, 2006: Message edited by: Jesper Young ]
 
Myra Rose
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ernest Friedman-Hill:


That would be one way, but not the only way, to do it.



What can be the other possible way?
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ritika Agarwal:

What can be the other possible way?



"Object-relational mapping". If you have a large number of instances of class X to store, then you can define a database table X with columns that correspond to the fields of X. To store an object, you create a new row in the table, saving each field into the apropriate column. To retrieve an object, you create an empty one, and store the data from one row in the table into its fields.

There exist many software packages that do this automatically -- Hibernate is a very well known one.
 
permaculture is a more symbiotic relationship with nature so I can be even lazier. Read tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic