• 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:

serialization: object casting doubt

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i was reading the code below:


My question is that the why is the casting done as in the statement seperated from the rest of the code? can somebody explain please?





======================================================

Past doubt:don't refer

Hi all,

The below is a statement from K & B book:

What does it really mean to save an object? If the instance variables are all primitive types, it's pretty straightforward. But what if the instance variables are themselves references to objects? What gets saved? Clearly in Java it wouldn't make any sense to save the actual value of a reference variable, because the value of a Java reference has meaning only within the context of a single instance of a JVM. In other words, if you tried to restore the object in another instance of the JVM, even running on the same computer on which the object was originally serialized, the reference would be useless.

what does the stuff in bold mean?

2] How do we know if something is non-serializable?Is there a way to find that out?
 
Sheriff
Posts: 9709
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Piya first of all lemme explain you what the statement means if you don't understand it. Saving a reference is like purchasing a postal address for $100000 instead of a real house. When you save a reference, the actual object referenced by the reference is saved so you get a real house for your 100000 bucks.

Single instance of JVM means a running JVM. When you run the java command, an instance of JVM is created. That is a JVM is started to run your program. That is an instance of JVM. It exists as long as your program is running. If you run the same program or a different program, then a different JVM instance will be created to serve that request...
 
Marshal
Posts: 80869
505
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try the instanceof operator with java.io.Serializable.
 
mansi gupte
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:You can try the instanceof operator with java.io.Serializable.




this does not serve to answer my query.


bounce!
 
Campbell Ritchie
Marshal
Posts: 80869
505
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using instanceof with Serializable will tell you whether it is serializable or not. It does not however tell you whether all its fields implement Serializable.
 
reply
    Bookmark Topic Watch Topic
  • New Topic