注释、序列化
一、注释
总共三种注释,前两种编译器直接跳过,从来不阅读,第三种编译器是可以看懂的,当你使用javadoc这样的命令时会用到,用来生成api时用的
1、 //
2、 /* */
3、说明注释,它以 /** 开始,以 */结束
二、序列化
对象
public class 序列化 implements java.io.Serializable { public String name; public String address; public transient int SSN; public int number; public void mailCheck() { System.out.println("Mailing a check to " + name + " " + address);} }
序列化
import java.io.FileInputStream; import java.io.ObjectInputStream; import java.io.IOException; public class 反序列化 { public static void main(String [] args) { Employee e = null; try { // 创建输入的文件对象 FileInputStream fileIn = new FileInputStream("./src/序列化、网络编程、多线程、邮件/employee.ser"); // 创建输入流对象 ObjectInputStream in = new ObjectInputStream(fileIn); e = (Employee) in.readObject(); in.close(); fileIn.close(); }catch(IOException i) { i.printStackTrace(); return; }catch(ClassNotFoundException c) { System.out.println("Employee class not found"); c.printStackTrace(); return; } System.out.println("Deserialized Employee..."); System.out.println("Name: " + e.name); System.out.println("Address: " + e.address); System.out.println("SSN: " + e.SSN); System.out.println("Number: " + e.number); } }
反序列化
import java.io.FileInputStream; import java.io.ObjectInputStream; import java.io.IOException; public class 反序列化 { public static void main(String [] args) { Employee e = null; try { // 创建输入的文件对象 FileInputStream fileIn = new FileInputStream("./src/序列化、网络编程、多线程、邮件/employee.ser"); // 创建输入流对象 ObjectInputStream in = new ObjectInputStream(fileIn); e = (Employee) in.readObject(); in.close(); fileIn.close(); }catch(IOException i) { i.printStackTrace(); return; }catch(ClassNotFoundException c) { System.out.println("Employee class not found"); c.printStackTrace(); return; } System.out.println("Deserialized Employee..."); System.out.println("Name: " + e.name); System.out.println("Address: " + e.address); System.out.println("SSN: " + e.SSN); System.out.println("Number: " + e.number); } }
一个只会点点点的测试,有疑问可以在测试群(群号:330405140)问我

浙公网安备 33010602011771号