• Post Reply Bookmark Topic Watch Topic
  • New Topic

what is state and persistance?  RSS feed

 
Sreedhar mar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

I am confusing about state and persistance. Actually what is difference between them or is both are same?

please give details in example.


Regards
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Java in General (beginner) forum...
 
Edwin Keeton
Ranch Hand
Posts: 214
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
State refers to the values of the properties of an object.

Persistence refers to the permanent storage of data (like storing in a database table), such as the state of an object. You persist the state of an object so that you can later restore (or re-create) that object just as it was before it was removed from memory (it was garbage collected, the program ended, etc.)
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
State refers to the collective values of an object's variables.

Persistence refers to an object being saved outside of the Java program, so that it doesn't vanish when the program is finished. This is achieved by serializing an object, and the state of the serialized object is its "persistent state."

(Note that variables modified with the keyword "transient" are not stored to an object's persistent state.)

See the API for the Serializable interface (in java.io)...

http://java.sun.com/j2se/1.4.2/docs/api/java/io/Serializable.html

Also see "Object Serialization" in the Java Tutorial...

http://java.sun.com/docs/books/tutorial/essential/io/serialization.html

See especially the topic on "Providing Object Serialization for Your Classes," which discusses how to customize serialization (and thus an object's persistent state)...

http://java.sun.com/docs/books/tutorial/essential/io/providing.html
[ September 23, 2004: Message edited by: marc weber ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!