Java IO Learning Note (v) Object flow

Source: Internet
Author: User

1. Object Stream: writes or reads an object directly. 2. Serialization: convert the object directly into a byte stream to write to the hard disk or Network. 3, If you want to convert an object into a byte stream, the Object's entity class must implement the serializable interface, the serializable interface is a labeled interface, it does not have any method, just to identify that the class can be Serialized. 4, transient keyword, used to modify the member variable, indicating that the member variable is transparent, and the serializable interface with the same, indicating the serialization is not considered when the member Variable. The default value for the data type of the member variable is stored at serialization Time. 5, Externalizable Interface is a subclass of the serializable interface, the implementation of serializable interface JDK will help control how the serialization process, and the implementation of the Externalizable interface can control the implementation of the serialization Process. the interface has two methods: readexternal (objectinput in), and the object is read through Objectinput. writeexternal (objectoutput out); write the object through Objectoutput. in general, let the JDK be implemented, This interface is not commonly Used.  Practice Small Examples:package test.io.object; Import java.io.FileInputStream; Import java.io.FileOutputStream; Import java.io.IOException; Import java.io.ObjectInputStream; Import java.io.ObjectOutputStream; Import java.io.Serializable; public class objectstreamtest { Public static void main (String args[]) { FileOutputStream fos = null; ObjectOutputStream oos = null; FileInputStream fis = null; ObjectInputStream ois = null; try { fos = new fileoutputstream ("e:/technical learning/java/test/socket/objecttest.txt" ); oos = new objectoutputstream (fos); Stu s = new Stu (); S. School = "dd" ;Oos.writeobject (s); fis = new fileinputstream ("e:/technology learning/java/test/socket/objecttest.txt" ); ois = new objectinputstream (fis); Stu s2 = (Stu) ois.readobject ();System. out. Print (s2. old + " " + s2.School + " " + s2.name + " " +s2.Teacher); } catch (classnotfoundexception e) { e.printstacktrace (); } catch (ioexception e) { e.printstacktrace ();           }     }    } class Stu implements serializable{ private static final long Serialversionuid = 1L; int old =; String name = "bjh"; transient String teacher = "cj"; String school = "lgd"; }Operation Result:dd BJH NULL

Java IO Learning Note (v) Object flow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.