中国高校课件下载中心 》 教学资源 》 大学文库

南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)08 对象序列化和持久化 Serialization and Persistence

文档信息
资源类别:文库
文档格式:PPT
文档页数:95
文件大小:1.69MB
团购合买:点击进入团购
内容简介
对象序列化 对象持久化  Language level  Databases Hibernate
刷新页面文档预览

Object Serialization and Persistence 对象序列化和持久化 Institute of Computer Software 2022-2-27 Nanjing University

对象序列化和持久化 Object Serialization and Persistence 2022-2-27 Institute of Computer Software Nanjing University 1

&雪扇 摘要 UNIVE 2 口对象序列化 口对象持久化 ▣Language level ▣Databases Hibernate Institute of Computer Software 2022-2-27 Nanjing University

摘要  对象序列化  对象持久化  Language level  Databases  Hibernate 2022-2-27 Institute of Computer Software Nanjing University 2

&雪扇 摘要 UNIVE 口对象序列化 口对象持久化 ▣Language level ▣Databases Hibernate Institute of Computer Software 2022-2-27 Nanjing University

摘要  对象序列化  对象持久化  Language level  Databases  Hibernate 2022-2-27 Institute of Computer Software Nanjing University 3

&雪扇 摘要 UNIVE 4 口对象序列化 口对象持久化 ▣Language level ▣Databases Hibernate Institute of Computer Software 2022-2-27 Nanjing University

摘要  对象序列化  对象持久化  Language level  Databases  Hibernate 2022-2-27 Institute of Computer Software Nanjing University 4

&扇 Object Serialization o Why What 0 How Institute of Computer Software 2022-2-27 Nanjing University

Object Serialization  Why  What  How 2022-2-27 Institute of Computer Software Nanjing University 5

&扇 Java Object Serialization --Why 1002 UNIVE 6 ▣ Serialization is used for lightweight persistence and for communication via sockets or Remote Method Invocation(RMI). Institute of Computer Software 2022-2-27 Nanjing University

Java Object Serialization -- Why  Serialization is used for lightweight persistence and for communication via sockets or Remote Method Invocation (RMI). 2022-2-27 Institute of Computer Software Nanjing University 6

Java Object Serialization --Example 102 public class Client{ public static void main(String args[]){ try {//Create a socket Socket soc new Socket(InetAddress.getLocalHost(),8020); OutputStream o soc.getOutputStream(); ObjectOutput s new ObjectOutputStream(o);s.writeObject("Today's date"); s.writeObject(new Date()) s.flush(); s.close(); catch(Exception e){ System.out.println(e.getMessage()); System.out.println("Error during serialization"); System.exit(1); Institute of Computer Software 2022-2-27 Nanjing University

Java Object Serialization -- Example public class Client { public static void main(String args[]) { try { // Create a socket Socket soc = new Socket(InetAddress.getLocalHost(), 8020); OutputStream o = soc.getOutputStream(); ObjectOutput s = new ObjectOutputStream(o); s.writeObject("Today ' s date "); s.writeObject(new Date()); s.flush(); s.close(); } catch (Exception e) { System.out.println(e.getMessage()); System.out.println("Error during serialization "); System.exit(1); } } } 2022-2-27 Institute of Computer Software Nanjing University 7

&扇 Java Object Serialization --Example public class Server public static void main(String args){ ServerSocket ser null; Socket soc null; String str null; Date d null; try{ ser new ServerSocket(8020); soc ser.accept(); InputStream o soc.getlnputStream(); ObjectInput s=new ObjectInputStream(o); str =(String)s.readObject(); d =(Date)s.readObject(); s.close(); System.out.println(str);System.out.printIn(d); catch(Exception e){ System.out.printIn(e.getMessage()); System.out.println("Error during serialization"); System.exit(1); } Institute of Computer Software 2022-2-27 Nanjing University

Java Object Serialization -- Example public class Server { public static void main(String args[]) { ServerSocket ser = null; Socket soc = null; String str = null; Date d = null; try { ser = new ServerSocket(8020); soc = ser.accept(); InputStream o = soc.getInputStream(); ObjectInput s = new ObjectInputStream(o); str = (String) s.readObject(); d = (Date) s.readObject(); s.close(); System.out.println(str); System.out.println(d); } catch (Exception e) { System.out.println(e.getMessage()); System.out.println("Error during serialization"); System.exit(1); } } } 2022-2-27 Institute of Computer Software Nanjing University 8

&扇 Java Object Serialization -Example 1902 9 Writing to an object stream /Serialize today's date to a file. FileOutputStream f new FileOutputStream("tmp"); ObjectOutput s new ObjectOutputStream(f); s.writeObject("Today"); s.writeObject(new Date()); s.flush(); Institute of Computer Software 2022-2-27 Nanjing University

Java Object Serialization -- Example  Writing to an object stream 2022-2-27 Institute of Computer Software Nanjing University 9 // Serialize today's date to a file. FileOutputStream f = new FileOutputStream("tmp"); ObjectOutput s = new ObjectOutputStream(f); s.writeObject("Today"); s.writeObject(new Date()); s.flush();

Java Object Serialization -Example 1902 10 Reading from an object stream /Deserialize a string and date from a file. FilelnputStream in new FilelnputStream("tmp"); ObjectInputStream s new ObjectInputStream(in); String today =(String)s.readObject(); Date date =(Date)s.readObject(); Institute of Computer Software 2022-2-27 Nanjing University

Java Object Serialization -- Example  Reading from an object stream 2022-2-27 Institute of Computer Software Nanjing University 10 // Deserialize a string and date from a file. FileInputStream in = new FileInputStream("tmp"); ObjectInputStream s = new ObjectInputStream(in); String today = (String)s.readObject(); Date date = (Date)s.readObject();

刷新页面下载完整文档
VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
相关文档