7
Serialization Allows you to turn Java Objects into serial data that can be either save to a file or sent over a network. Usefull for persisting data.

Serialization Allows you to turn Java Objects into serial data that can be either save to a file or sent over a network. Usefull for persisting data

Embed Size (px)

Citation preview

Page 1: Serialization Allows you to turn Java Objects into serial data that can be either save to a file or sent over a network. Usefull for persisting data

Serialization

Allows you to turn Java Objects into serial data that can be either save to a file or sent over a network.

Usefull for persisting data.

Page 2: Serialization Allows you to turn Java Objects into serial data that can be either save to a file or sent over a network. Usefull for persisting data

Serialization Syntax

FileOutputStream filOut = new FileOutputStream("gamestate.ser"); ObjectOutputStream out = new ObjectOutputStream(filOut); out.writeObject(gst); out.close(); filOut.close();

Page 3: Serialization Allows you to turn Java Objects into serial data that can be either save to a file or sent over a network. Usefull for persisting data

Deserialization Syntax

FileInputStream filIn = new FileInputStream("gamestate.ser"); ObjectInputStream ois = new

ObjectInputStream(filIn); gst= (GameState) ois.readObject(); ois.close(); filIn.close();

Page 4: Serialization Allows you to turn Java Objects into serial data that can be either save to a file or sent over a network. Usefull for persisting data

Ant Build Tool

Ant is integrated into Eclipse

Ant allows you to build, copy files, deploy files, generate jar files, etc.

Page 5: Serialization Allows you to turn Java Objects into serial data that can be either save to a file or sent over a network. Usefull for persisting data

Ant exe-JAR

1/ right-click your project in eclipse project- or package-explorer and select Export

2/ Select the AntBuildfiles from the General directory

3/ accept the defaults, and make sure both check boxes are selected.

4/ Select Window || Show View || Ant5/ drag your build.xml file into the Ant view. 6/ open up the build.xml file in the editor

Page 6: Serialization Allows you to turn Java Objects into serial data that can be either save to a file or sent over a network. Usefull for persisting data

Ant exe-JAR

7/ add the below target (next slide) within the enclosing <project> </project> tags

8/ save the build.xml. click on the jar target in the Ant view and click run

9/ refresh your project by clicking F5 and you will see the generated executable jar.

Page 7: Serialization Allows you to turn Java Objects into serial data that can be either save to a file or sent over a network. Usefull for persisting data

SwingWorkerSwingWorker takes two Object parameters.

+The first is the return value and is passed to done()+The second parameter is the progress value and is

passed to publish/process.

Example: SwingWorker<Boolean, Integer>

There are three important methods of SwingWorker.+doInBackGround() --background thread+process() -main UI thread+done() -main UI thread