我的java培训日记-1

来源:互联网 发布:c 字符串转char数组 编辑:程序博客网 时间:2024/05/01 21:56
 
传智播客北京java培训日记-1
 
  
1. 字符编码的讲解
SCII与Unicode码的转换规则,演示记事本显示字符时的趣味问题,分析乱码原因,GB2312中也包含英文字符,如何识别GB2312中的英文与汉字。最后课结束时讲了GB18030
2. xml文档的作用举例
<world>                                                                                                               }
<country>
</country>
<country>
       <name>中国</name>
       <chairman></chairman>
       <provinces>
              <province>
                     <name>湖北</name>
                     <chairman></chairman>
                     <cities>
                            <city>
                     </cities>
              </province>
              <province>
                     <name>湖南</name>
              </province>
              <province>
                     <name>北京</name>
              </province>
       </provinces>
</country>
</world>
分析该内部原理:
World类{
//这里引出了对泛型的讲解                                                                        ArraList<Country> countrys = new ArrayList<Country>;
       //为什么world元素下面要加countries元素                                                             countrys.add(new Country())
}
3. 编码转换程序
              char [] codes = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
              byte b = (byte)Integer.parseInt(args[0]);
              System.out.print(codes[((b>>4) & 0x0f)]);
              System.out.println(codes[(b & 0x0f)]);      
得到字符的big5
<%@page pageEncoding="GBK"%>
<%@page contentType="text/html;charset=GBK"%>//修改contentType="audio/x-mp3"说明头的作用
<%
       String china="中一二";
       for(int i=0;i<china.length();i++)
       {
              out.println(Integer.toHexString((int)china.charAt(i)));
       }
       System.out.println();
       byte[] bufGBK = china.getBytes("GBK");
       for(int i=0;i<bufGBK.length;i++)
       {
              out.println(Integer.toHexString(bufGBK [i]));
       }
       byte[] buf = china.getBytes("Big5");
       for(int i=0;i<buf.length;i++)
       {
              out.println(Integer.toHexString(buf[i]));
       }
       byte [] buf ={0xa4, 0xa4,0xa4,0x40,0xa4,0x47}
%>
输出big5给浏览器:
<%
       byte [] buf ={(byte)0xa4, (byte)0xa4,(byte)0xa4,(byte)0x40,(byte)0xa4,(byte)0x47};
       response.getOutputStream().write(buf);
%>
www.itcast.cn
原创粉丝点击