// Project: Serialization Example // Module: serialization3 // Source code file Test.java // Create a programmer defined collection class, // which is able to serialize its own objects. // Project: Serialization // Module: serialization3 // Source code file Test.java // Create a programmer defined collection class, // which is able to serialize its own objects. import java.io.IOException; public class Test { public static void main(String[] args) throws IOException, ClassNotFoundException { EmployeeRoster roster = new EmployeeRoster( ); roster.add(new Person("Alice", 'F', 23)); roster.add(new Employee( "Thomas", 'M', 34, 1234, 65000)); roster.add(new Executive( "Gloria", 'F', 48, 3456, 134000, 90000)); // Print Person objects in original collection. System.out.println("Original roster items:"); for(Person p : roster) { System.out.println(p); } System.out.println("Roster size: " + roster.size( ) + "\n"); // Save elements in roster. roster.save( ); // Clear roster and verify size. roster.clear( ); System.out.println("Roster after clearing:"); System.out.println("Roster size: " + roster.size( ) + "\n"); // Load elements from disk. roster.load( ); // Print items and verify size of // deserialized roster. System.out.println("Deserialized roster items:"); for(Person p : roster) { System.out.println(p); } System.out.println("Roster size: " + roster.size( )); } }