..


Sponsored Links

Precautions in the use of serializable

Article written by Damiano Verda
Page 1 of 2

The Serializable interface is commonly used by programmers to create Java persistent objects. Normally, in fact, an object exists as long as the Java Virtual Machine (JVM) (or the virtual machine through which they run Java programs) is active.

The persistence mechanism, activated by the serialization, instead of creating objects that can exist independently from the fact that the JVM is running or not. In other words, the serialization process saves the state of an object in a series of bytes and to reconstruct the object based on the information contained in those bytes.

Example Usage

Using Serializable is extremely simple. It will be enough to develop any public class (we see it in the next block of code the keyword public), import (through the keyword import) library and implement java.io.Serializable (using the keyword implements) the interface Serializable. For example:






 import java.io.Serializable;







 import java.util.Date;







 import java.util.Calendar;







 public class PersistentTime implements Serializable







 {



 



 private Date time;





 



 public PersistentTime ()



 



 {



     



 time = Calendar.getInstance (). getTime ();



 



 }



 



 public Date getTime ()



 



 {



     



 return time;



 



 }







 }



In this way we can to have a time-based data (the data is in fact a member of the class of type Date) persistent. It should be noted, however, as the use of Serializable requires the programmer to the mastery of some concepts, which allow, if the situation requires it, to make appropriate arrangements.

In the same category ...
E-Learning
Linux (Course) Linux (Course)
Complete guide to open-source system. From 49 €.
PHP (Course) PHP (Course)
Full course for creating dynamic Web sites. From 49 €.
Ruby and Ruby on Rails (Course) Ruby and Ruby on Rails (Course)
Create software and Web applications with Ruby and RoR. From 39 €.
Sponsored Links