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

A doubt about Serializable

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
These are what I think are true:
1. Serializable is an interface with no methods
2. Once we implement Serializable, we can store the status of objects
3. ObjectOutputStream can write even the properties of a Serializable object
Now, how can ObjectOutputStream get access to the properties of a Serializable Object? This will defy the OO priciples. Now if ObjectOutputStream can access the properties of a Serializable Object, then any can a Class be written to access the properties of any Serializable object?
-- Hari
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. The Serializable keyword only flags to the VM that this object can be serialized and sent across the network (or written to disk). The recieving VM will only allow an Object of that type to be created and then all rules apply as normal. Some properties, private, are usally not desired to be exposed on the network and should be marked transient and the VM will not send those properties.
Hope this helps.
David
 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hari,
ObjectOutputStream uses Java's reflection capability which allows any class to look into the fields and methods of another class. The class java.lang.Class actually has methods for setting the field values of another class!!! You right, this does seem to violate the principal that one class can not access private members of another class. However, using normal object to object interaction is not affected. 'private' variables help us programmers enforce encapsulation - there not for implementing security.
 
reply
    Bookmark Topic Watch Topic
  • New Topic