首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

哪位高手可以告诉小弟我下static后面的代码是什么意思啊

2012-01-18 
谁可以告诉我下static后面的代码是什么意思啊 ?private static final byte[] encodingTable {(byte) A

谁可以告诉我下static后面的代码是什么意思啊 ?
private static final byte[] encodingTable = {
  (byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D', (byte) 'E',
  (byte) 'F', (byte) 'G', (byte) 'H', (byte) 'I', (byte) 'J',
  (byte) 'K', (byte) 'L', (byte) 'M', (byte) 'N', (byte) 'O',
  (byte) 'P', (byte) 'Q', (byte) 'R', (byte) 'S', (byte) 'T',
  (byte) 'U', (byte) 'V', (byte) 'W', (byte) 'X', (byte) 'Y',
  (byte) 'Z', (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd',
  (byte) 'e', (byte) 'f', (byte) 'g', (byte) 'h', (byte) 'i',
  (byte) 'j', (byte) 'k', (byte) 'l', (byte) 'm', (byte) 'n',
  (byte) 'o', (byte) 'p', (byte) 'q', (byte) 'r', (byte) 's',
  (byte) 't', (byte) 'u', (byte) 'v', (byte) 'w', (byte) 'x',
  (byte) 'y', (byte) 'z', (byte) '0', (byte) '1', (byte) '2',
  (byte) '3', (byte) '4', (byte) '5', (byte) '6', (byte) '7',
  (byte) '8', (byte) '9', (byte) '+', (byte) '/'
  };
  private static final byte[] decodingTable;//定义一个静态decodingTable字节数组
  static {
  decodingTable = new byte[128]; //实例化decodingTable数组
  for (int i = 0; i < 128; i++) {
  decodingTable[i] = (byte) -1;
  }
  for (int i = 'A'; i <= 'Z'; i++) {
  decodingTable[i] = (byte) (i - 'A');
  }
  for (int i = 'a'; i <= 'z'; i++) {
  decodingTable[i] = (byte) (i - 'a' + 26);
  }
  for (int i = '0'; i <= '9'; i++) {
  decodingTable[i] = (byte) (i - '0' + 52);
  }
  decodingTable['+'] = 62;
  decodingTable['/'] = 63;
  }


[解决办法]

Java code
private static final byte[] encodingTable = {             (byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D', (byte) 'E',             (byte) 'F', (byte) 'G', (byte) 'H', (byte) 'I', (byte) 'J',             (byte) 'K', (byte) 'L', (byte) 'M', (byte) 'N', (byte) 'O',             (byte) 'P', (byte) 'Q', (byte) 'R', (byte) 'S', (byte) 'T',             (byte) 'U', (byte) 'V', (byte) 'W', (byte) 'X', (byte) 'Y',             (byte) 'Z', (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd',             (byte) 'e', (byte) 'f', (byte) 'g', (byte) 'h', (byte) 'i',             (byte) 'j', (byte) 'k', (byte) 'l', (byte) 'm', (byte) 'n',             (byte) 'o', (byte) 'p', (byte) 'q', (byte) 'r', (byte) 's',             (byte) 't', (byte) 'u', (byte) 'v', (byte) 'w', (byte) 'x',             (byte) 'y', (byte) 'z', (byte) '0', (byte) '1', (byte) '2',             (byte) '3', (byte) '4', (byte) '5', (byte) '6', (byte) '7',             (byte) '8', (byte) '9', (byte) '+', (byte) '/'         };     private static final byte[] decodingTable;//定义一个静态decodingTable字节数组     static {//这个是加载到内存的,不依靠该类的对象的。        decodingTable = new byte[128]; //实例化decodingTable数组         for (int i = 0; i < 128; i++) {             decodingTable[i] = (byte) -1;         }         for (int i = 'A'; i <= 'Z'; i++) {             decodingTable[i] = (byte) (i - 'A');         }         for (int i = 'a'; i <= 'z'; i++) {             decodingTable[i] = (byte) (i - 'a' + 26);         }         for (int i = '0'; i <= '9'; i++) {             decodingTable[i] = (byte) (i - '0' + 52);         }         decodingTable['+'] = 62;         decodingTable['/'] = 63;     }
[解决办法]
编码而已,把A-z以及数字/ +重新编码,对应上(byte)1-(byte)63,其它为-1
利用char的值喵~`
[解决办法]

探讨
第二个for循环一下是对A~Z,a~z,0~9,以及+和/的重新编码,但是第一个for循环for (int i = 0; i < 128; i++) { 
decodingTable[i] = (byte) -1; 

又如何解释呢?

[解决办法]
static 块中的代码,会在该类被JVM加载到内存时被执行!

热点排行