TestBoolSerialize.java


import java.io.*;

public class TestBoolSerialize {

   // ***********************************************************************************
   public static void main(String[] args) throws Exception {
      // If you run out of memory, run one part a time
      // .............................................
      // Boolean
      ObjectOutputStream out1 = new ObjectOutputStream(new FileOutputStream("Bool.tmp"));
      out1.writeObject(new BoolS());
      out1.flush();
      out1.close();
      
      // Byte
      ObjectOutputStream out2 = new ObjectOutputStream(new FileOutputStream("Byte.tmp"));
      out2.writeObject(new ByteS());
      out2.flush();
      out2.close();
      
      // Short
      ObjectOutputStream out3 = new ObjectOutputStream(new FileOutputStream("Short.tmp"));
      out3.writeObject(new ShortS());
      out3.flush();
      out3.close();
      // Output file Bool.tmp and Byte.tmp will be the same size
      // Output file Short.tmp size doubled as contrast
      // Actually boolean will occupy 8 bits, even only 1 bit is used
   }    
}

// ***********************************************************************************
class BoolS implements Serializable {
   boolean[] array = new boolean[1000000];
}
// ***********************************************************************************
class ByteS implements Serializable {
   byte[] array = new byte[1000000];
}
// ***********************************************************************************
class ShortS implements Serializable {
   short[] array = new short[1000000];
}

Last updated: 12-10-2002
Copyright © 1999 - 2003 Roseanne Zhang, All Rights Reserved
[ Java certification page] [ SCJP FAQ] [ JavaChina]