java:object_serialization

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
java:object_serialization [2017/02/17 14:03]
gthanos
java:object_serialization [2017/02/17 14:05]
gthanos [Παράδειγμα Serialization]
Line 48: Line 48:
    ​public String address;    ​public String address;
    ​public int AMKA;    ​public int AMKA;
-   ​public ​transient ​double salary; +   ​public double salary; 
-   ​public ​transient ​Employee next; +   ​public Employee next; 
-   ​public ​transient ​ArrayList<​Employee>​ list;+   ​public ArrayList<​Employee>​ list;
        
    ​public String toString() {    ​public String toString() {
Line 152: Line 152:
       System.out.println(e);​       System.out.println(e);​
       System.out.println(e1); ​     ​       System.out.println(e1); ​     ​
 +   }
 +}
 +</​code>​
 +
 +<WRAP todo 80% center round>
 +Στο παραπάνω παράδειγμα δηλώστε τα τελευταία τρία πεδία της κλάσης Employee ως transient, oπως παρακάτω. Μεταγλωττίστε και τρέξτε ξανά τις κλάσεις SerializeDemo και DeserializeDemo. Τι παρατηρείτε;​
 +</​WRAP>​
 +
 +<code java Employee.java>​
 +import java.util.*;​
 +
 +public class Employee implements java.io.Serializable {
 +   ​public String name;
 +   ​public String address;
 +   ​public int AMKA;
 +   ​public transient double salary;
 +   ​public transient Employee next;
 +   ​public transient ArrayList<​Employee>​ list;
 +   
 +   ​public String toString() {
 +      String str = "Name: " + name+"​\n";​
 +      str+="​Address:​ " + address+"​\n";​
 +      str+="​AMKA:​ " + AMKA+"​\n";​
 +      str+="​Salary:​ " + salary+"​\n";​
 +      if(next != null)
 +        str+="​Next:​ " + next.name+"​\n";​
 +      ​
 +      if( list != null) {
 +        Iterator<​Employee>​ it = list.iterator();​
 +        if( it.hasNext() ) {
 +          str+="​List:​ ";
 +        }
 +        while( it.hasNext() ) {
 +          str+= it.next().name+",​ ";
 +        }
 +        str+="​\n";​
 +      }
 +      return str;
    }    }
 } }
java/object_serialization.txt · Last modified: 2017/02/17 14:11 by gthanos