??xml version="1.0" encoding="utf-8" standalone="yes"?>欧美男男激情freegay,亚洲女人视频,日韩一区日韩二区http://www.aygfsteel.com/xiaoyi/category/34076.html阛_d风雨?让我们在雨中毅然前行,收获每一份喜(zhn)的Ƣ笑o(∩_?o...zh-cnFri, 20 Sep 2013 03:06:25 GMTFri, 20 Sep 2013 03:06:25 GMT60重写 FastJson 属性过滤器 http://www.aygfsteel.com/xiaoyi/articles/404150.html可爱的小?/dc:creator>可爱的小?/author>Mon, 16 Sep 2013 14:36:00 GMThttp://www.aygfsteel.com/xiaoyi/articles/404150.htmlhttp://www.aygfsteel.com/xiaoyi/comments/404150.htmlhttp://www.aygfsteel.com/xiaoyi/articles/404150.html#Feedback0http://www.aygfsteel.com/xiaoyi/comments/commentRss/404150.htmlhttp://www.aygfsteel.com/xiaoyi/services/trackbacks/404150.html阅读全文

]]>
毅收藏?-----Java式实现JS的Escape以及(qing)Unescapehttp://www.aygfsteel.com/xiaoyi/articles/298203.html可爱的小?/dc:creator>可爱的小?/author>Wed, 14 Oct 2009 06:04:00 GMThttp://www.aygfsteel.com/xiaoyi/articles/298203.htmlhttp://www.aygfsteel.com/xiaoyi/comments/298203.htmlhttp://www.aygfsteel.com/xiaoyi/articles/298203.html#Feedback0http://www.aygfsteel.com/xiaoyi/comments/commentRss/298203.htmlhttp://www.aygfsteel.com/xiaoyi/services/trackbacks/298203.htmlpublic class EscapeUnescape {

    
public static String escape(String src) {
        
int i;
        
char j;
        StringBuffer tmp 
= new StringBuffer();
        tmp.ensureCapacity(src.length() 
* 6);
        
for (i = 0; i < src.length(); i++{
            j 
= src.charAt(i);
            
if (Character.isDigit(j) || Character.isLowerCase(j)
                    
|| Character.isUpperCase(j))
                tmp.append(j);
            
else if (j < 256{
                tmp.append(
"%");
                
if (j < 16)
                    tmp.append(
"0");
                tmp.append(Integer.toString(j, 
16));
            }
 else {
                tmp.append(
"%u");
                tmp.append(Integer.toString(j, 
16));
            }

        }

        
return tmp.toString();
    }


    
public static String unescape(String src) {
        StringBuffer tmp 
= new StringBuffer();
        tmp.ensureCapacity(src.length());
        
int lastPos = 0, pos = 0;
        
char ch;
        
while (lastPos < src.length()) {
            pos 
= src.indexOf("%", lastPos);
            
if (pos == lastPos) {
                
if (src.charAt(pos + 1== 'u'{
                    ch 
= (char) Integer.parseInt(src
                            .substring(pos 
+ 2, pos + 6), 16);
                    tmp.append(ch);
                    lastPos 
= pos + 6;
                }
 else {
                    ch 
= (char) Integer.parseInt(src
                            .substring(pos 
+ 1, pos + 3), 16);
                    tmp.append(ch);
                    lastPos 
= pos + 3;
                }

            }
 else {
                
if (pos == -1{
                    tmp.append(src.substring(lastPos));
                    lastPos 
= src.length();
                }
 else {
                    tmp.append(src.substring(lastPos, pos));
                    lastPos 
= pos;
                }

            }

        }

        
return tmp.toString();
    }


    
public static void main(String[] args) {
        String tmp 
= "中文";
        System.out.println(
"testing escape : " + tmp);
        tmp 
= escape(tmp);
        System.out.println(tmp);
        System.out.println(
"testing unescape :" + tmp);
        System.out.println(unescape(
"%u6211%u4eec"));
    }

}

以上Z个工L(fng)Qؓ(f)解决中文q
html前台:escape(escape('你好'))
后台:String txt=EscapeUnescape.unescape(aStringText); 

escape本n参数~码为ISO8859-1,escape中文传替lservlet?x)直接?f)null接收不到Q经q以上特D处理即可解?其他Ҏ(gu)也可Q如Q手动{?..

]]>
毅收藏?-----日期cȝ加减?qing)java中所以日期类的操作算法大?http://www.aygfsteel.com/xiaoyi/articles/295044.html可爱的小?/dc:creator>可爱的小?/author>Mon, 14 Sep 2009 09:56:00 GMThttp://www.aygfsteel.com/xiaoyi/articles/295044.htmlhttp://www.aygfsteel.com/xiaoyi/comments/295044.htmlhttp://www.aygfsteel.com/xiaoyi/articles/295044.html#Feedback0http://www.aygfsteel.com/xiaoyi/comments/commentRss/295044.htmlhttp://www.aygfsteel.com/xiaoyi/services/trackbacks/295044.html阅读全文

]]>
毅收藏?-----在C#中调用Java代码 http://www.aygfsteel.com/xiaoyi/articles/281921.html可爱的小?/dc:creator>可爱的小?/author>Fri, 12 Jun 2009 14:31:00 GMThttp://www.aygfsteel.com/xiaoyi/articles/281921.htmlhttp://www.aygfsteel.com/xiaoyi/comments/281921.htmlhttp://www.aygfsteel.com/xiaoyi/articles/281921.html#Feedback0http://www.aygfsteel.com/xiaoyi/comments/commentRss/281921.htmlhttp://www.aygfsteel.com/xiaoyi/services/trackbacks/281921.html在C#中调用Java代码
  1. ?a target="_blank">IKVM官方|站下蝲IKVM需要的lg
    1. ikvm-0.40.0.1.zip
    2. ikvmbin-0.40.0.1.zip
    3. openjdk6-b12-stripped.zip
  2. 解压ikvm-0.40.0.1.zip,q将%IKVM_HOME%\bind到path中。此处的%IKVM_HOME%是指解压后ikvm的主目录?
  3. ?a target="_blank">Debian IKVM下蝲IKVM.OpenJDK.ClassLibrary.dll?
    1. 或者到rayfileM载data.tar.gz。这个文件可以直接用winrar解压?
    2. 你需要下载一个简单的工具undeb去解?deb文g?
      1. 也可以到rayfile下蝲
  4. 解压ikvm_0.38.0.2+dfsg-2_all.deb文g?
  5. 新徏一个Java文g
    package com.helloikvm.simple;

    public class SimpleReturnString 
        
    public String returnString() {
            
    return "Hello, IKVM!";
        }
     

        
    public void throwException() throws Exception {
            
    throw new Exception("Hello, Exception!");
        }

    }
     
  6. ~译SimpleReturnString文gQ然后将其打包成一个jar文gQ例如IKVM.jar.
  7. 使用ikvmc -out:IKVM.dll IKVM.jar。你现在应该在IKVM的目录下面看C个IKVM.dll文g?
  8. 新徏一个C#.NET目Q首先添加一下必ȝDLLs
    1. %IKVM_HOME%\bin\IKVM.OpenJDK.Core.dll
    2. %IKVM_HOME%\bin\IKVM.Runtime.dll
    3. %IKVM_HOME%\bin\IKVM.Runtime.JNI.dll
    4. IKVM.OpenJDK.ClassLibrary.dll[q的DLL在ikvm_0.38.0.2+dfsg-2_all.deb\usr\lib\cli文g夹中。或者也可在data.tar.gz中的usr\lib\cli中找到。参看第三步和第四步]
  9. dW?0步生成的IKVM.dll到C#.NET目中,然后using %package_name%可以实现对Java的调用?
  10. ~写C(j)#代码
    // import java package 

    using com.helloikvm.simple; 

    namespace IKVMTest
    {
        
    public partial class Form1 : Form
        
    {
            
    public Form1()
            
    {
                InitializeComponent();
            }
     
            
    private void btnTest_Click(object sender, EventArgs e)
            
    {
                
    // Initialize the Java method
                SimpleReturnString simpler = new SimpleReturnString(); 
                
    // Call Java method 
                String returnString = simpler.returnString();
                txtTest.Text 
    = returnString;
            }

        }

    }
     


]]>
毅收藏?-----java中MD5加密http://www.aygfsteel.com/xiaoyi/articles/278976.html可爱的小?/dc:creator>可爱的小?/author>Fri, 29 May 2009 17:55:00 GMThttp://www.aygfsteel.com/xiaoyi/articles/278976.htmlhttp://www.aygfsteel.com/xiaoyi/comments/278976.htmlhttp://www.aygfsteel.com/xiaoyi/articles/278976.html#Feedback0http://www.aygfsteel.com/xiaoyi/comments/commentRss/278976.htmlhttp://www.aygfsteel.com/xiaoyi/services/trackbacks/278976.html 

/**
* @(#)MD5.java
*
*
* @SuLyin
* @version 1.00 2008/10/6
*/
package com.sulyin.ustbphone;

public class MD5
{
   static final int S11 = 7;
   static final int S12 = 12;
   static final int S13 = 17;
   static final int S14 = 22;
   static final int S21 = 5;
   static final int S22 = 9;
   static final int S23 = 14;
   static final int S24 = 20;
   static final int S31 = 4;
   static final int S32 = 11;
   static final int S33 = 16;
   static final int S34 = 23;
   static final int S41 = 6;
   static final int S42 = 10;
   static final int S43 = 15;
   static final int S44 = 21;
   static final byte[] PADDING = { -128, 0, 0, 0, 0, 0, 0, 0, 0,
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  
   /* 计算q程中的三个核心(j)数据 */
   private long[] state = new long[ 4 ];
   private long[] count = new long[ 2 ];
   private byte[] buffer = new byte[ 64 ];
  
   /* 最Cơ计结果的16q制ASCII表示Q公共成?digestHexStrQ?/
   public String digestHexStr;
  
   /* 最Cơ计结果的二进制内部表C,表示128位的MD5|U有成员-digestQ?/
   private byte[] digest = new byte[ 16 ];
  
   public String getMD5ofStr( String inbuf )
   {
      md5Init();
      md5Update( inbuf.getBytes(), inbuf.length() );
      md5Final();
      digestHexStr = "";
      for( int i = 0; i < 16; i ++ )
      {
       digestHexStr += byteHEX( digest[ i ] );
      }
      return digestHexStr;
   }
  
    public MD5()
    {
    md5Init();
    return;   
    }
   
    private void md5Init()
    {
    count[ 0 ] = 0L;
    count[ 1 ] = 0L;
    state[ 0 ] = 0x67452301L;
    state[ 1 ] = 0xefcdab89L;
    state[ 2 ] = 0x98badcfeL;
    state[ 3 ] = 0x10325476L;
    return;
    }
   
    /* F,G,H,I四个基本的MD5函数Q实现简单的位运?/
    private long F( long x, long y, long z )
    {
    return ( x & y ) | ( ( ~x ) & z );
    }
   
    private long G( long x, long y, long z )
    {
    return ( x & z ) | ( y & ( ~z ) );
    }
   
    private long H( long x, long y, long z )
    {
    return x ^ y ^ z;
    }
   
    private long I( long x, long y, long z )
    {
    return y ^ ( x | ( ~z ) );
    }
   
    /* FF,GG,HH和II调用F,G,H,Iq行q一步变?*/
    private long FF( long a, long b, long c, long d, long x, long s, long ac )
    {
    a += F( b, c, d ) + x + ac;
    a = ( ( int )a << s ) | ( ( int )a >>> ( 32 - s ) );
    a += b;
    return a ;
    }
   
    private long GG( long a, long b, long c, long d, long x, long s, long ac )
    {
    a += G( b, c, d ) + x + ac;
    a = ( ( int )a << s ) | ( ( int )a >>> ( 32 - s ) );
    a += b;
    return a;
    }
   
    private long HH( long a, long b, long c, long d, long x, long s, long ac )
    {
    a += H( b, c, d ) + x + ac;
    a = ( ( int )a << s ) | ( ( int ) a >>> ( 32 - s ) );
    a += b;
    return a;
    }
   
    private long II( long a, long b, long c, long d, long x, long s, long ac )
    {
    a += I( b, c, d ) + x + ac;
    a = ( ( int )a << s ) | ( ( int )a >>> ( 32 - s ) );
    a += b;
    return a;
    }
   
    /* md5Update是MD5的主计算q程Qinbuf是要变换的字节串QinputLen是它的长度,q个函数由getMD5ofStr调用Q?调用之前需要调用md5InitQ因此把它设计成private?*/
    private void md5Update( byte[] inbuf, int inputLen )
    {
    int i, index, partLen;
    byte[] block = new byte[ 64 ];
    index = ( int )( count[ 0 ] >>> 3 ) & 0x3F;
    if( ( count[ 0 ] += ( inputLen << 3 ) ) < ( inputLen << 3 ) )
       count[ 1 ] ++;
    count[ 1 ] += ( inputLen >>> 29 );
    partLen = 64 - index;
    if( inputLen >= partLen )
    {
       md5Memcpy( buffer, inbuf, index, 0, partLen );
       md5Transform( buffer );
       for( i = partLen; i + 63 < inputLen; i += 64 )
       {
        md5Memcpy( block, inbuf, 0, i, 64 );
        md5Transform( block );
       }
       index = 0;
    }
    else
       i = 0;
    md5Memcpy( buffer, inbuf, index, i, inputLen - i );
    }
   
    /* md5Final整理和填写输出结?*/
    private void md5Final()
    {
    byte[] bits = new byte[ 8 ];
    int index, padLen;
    Encode( bits, count, 8 );
    index = ( int )( count[ 0 ] >>> 3 ) & 0x3f;
    padLen = ( index < 56 ) ? ( 56 - index ) : ( 120 - index );
    md5Update( PADDING, padLen );
    md5Update( bits, 8 );
    Encode( digest, state, 16 );
    }
   
    /* md5Memcopy是一个内部用的byte数组的块复制函数Q从input的inpos开始把len长度的字节复制到ouput的outpos位置开?*/
    private void md5Memcpy( byte[] output, byte[] input, int outpos, int inpos, int len )
    {
    int i;
    for( i = 0; i < len; i ++ )
    {
       output[ outpos + 1 ] = input[ inpos + 1 ];
    }
    }
    /* md5Transform是md5的核?j)变换程序,有md5Update调用Qblock是分块的原始字节 */
    private void md5Transform( byte block[] )
    {
    long a = state[ 0 ], b = state[ 1 ], c = state[ 2 ], d = state[ 3 ];
    long[] x = new long[ 16 ];
    Decode( x, block, 64 );
    /* Round 1 */
    a = FF( a, b, c, d, x[ 0 ], S11, 0xd76aa478L ); /* 1 */
    d = FF( d, a, b, c, x[ 1 ], S12, 0xe8c7b756L ); /* 2 */
    c = FF( c, d, a, b, x[ 2 ], S13, 0x242070dbL ); /* 3 */
    b = FF( b, c, d, a, x[ 3 ], S14, 0xc1bdceeel ); /* 4 */
    a = FF( a, b, c, d, x[ 4 ], S11, 0xf57c0fafL ); /* 5 */
    d = FF( d, a, b, c, x[ 5 ], S12, 0x4787c62aL ); /* 6 */
    c = FF( c, d, a, b, x[ 6 ], S13, 0xa8304613L ); /* 7 */
    b = FF( b, c, d, a, x[ 7 ], S14, 0xfd469501L ); /* 8 */
    a = FF( a, b, c, d, x[ 8 ], S11, 0x698098d8L ); /* 9 */
    d = FF( d, a, b, c, x[ 9 ], S12, 0x8b44f7afL ); /* 10 */
    c = FF( c, d, a, b, x[ 10 ], S13, 0xffff5bb1L ); /* 11 */
    b = FF( b, c, d, a, x[ 11 ], S14, 0x895cd7beL ); /* 12 */
    a = FF( a, b, c, d, x[ 12 ], S11, 0x6b901122L ); /* 13 */
    d = FF( d, a, b, c, x[ 13 ], S12, 0xfd987193L ); /* 14 */
    c = FF( c, d, a, b, x[ 14 ], S13, 0xa679438eL ); /* 15 */
    b = FF( b, c, d, a, x[ 15 ], S14, 0x49b40821L ); /* 16 */
    /* Round 2 */
    a = GG( a, b, c, d, x[ 1 ], S21, 0xf61e2562L ); /* 17 */
    d = GG( d, a, b, c, x[ 6 ], S22, 0xc040b340L ); /* 18 */
    c = GG( c, d, a, b, x[ 11 ], S23, 0x265e5a51L ); /*19 */
    b = GG( b, c, d, a, x[ 0 ], S24, 0xe9b6c7aaL ); /* 20 */
    a = GG( a, b, c, d, x[ 5 ], S21, 0xd62f105dL ); /* 21 */
    d = GG( d, a, b, c, x[ 10 ], S22, 0x2441453L ); /* 22 */
    c = GG( c, d, a, b, x[ 15 ], S23, 0xd8a1e681L ); /* 23 */
    b = GG( b, c, d, a, x[ 4 ], S24, 0xe7d3fbc8L ); /* 24 */
    a = GG( a, b, c, d, x[ 9 ], S21, 0x21e1cde6L ); /* 25 */
    d = GG( d, a, b, c, x[ 14 ], S22, 0xc33707d6L ); /* 26 */
    c = GG( c, d, a, b, x[ 3] , S23, 0xf4d50d87L ); /* 27 */
    b = GG( b, c, d, a, x[ 8 ], S24, 0x455a14edL ); /* 28 */
    a = GG( a, b, c, d, x[ 13 ], S21, 0xa9e3e905L ); /* 29 */
    d = GG( d, a, b, c, x[ 2 ], S22, 0xfcefa3f8L ); /* 30 */
    c = GG( c, d, a, b, x[ 7 ], S23, 0x676f02d9L ); /* 31 */
    b = GG( b, c, d, a, x[ 12 ], S24, 0x8d2a4c8aL ); /* 32 */
    /* Round 3 */
    a = HH( a, b, c, d, x[ 5 ], S31, 0xfffa3942L ); /* 33 */
    d = HH( d, a, b, c, x[ 8 ], S32, 0x8771f681L ); /* 34 */
    c = HH( c, d, a, b, x[ 11 ], S33, 0x6d9d6122L ); /* 35 */
    b = HH( b, c, d, a, x[ 14 ], S34, 0xfde5380cL ); /* 36 */
    a = HH( a, b, c, d, x[ 1 ], S31, 0xa4beea44L ); /* 37 */
    d = HH( d, a, b, c, x[ 4 ], S32, 0x4bdecfa9L ); /* 38 */
    c = HH( c, d, a, b, x[ 7 ], S33, 0xf6bb4b60L ); /* 39 */
    b = HH( b, c, d, a, x[ 10 ], S34, 0xbebfbc70L ); /* 40 */
    a = HH( a, b, c, d, x[ 13 ], S31, 0x289b7ec6L ); /* 41 */
    d = HH( d, a, b, c, x[ 0 ], S32, 0xeaa127faL ); /* 42 */
    c = HH( c, d, a, b, x[ 3 ], S33, 0xd4ef3085L ); /* 43 */
    b = HH( b, c, d, a, x[ 6 ], S34, 0x4881d05L ); /* 44 */
    a = HH( a, b, c, d, x[ 9 ], S31, 0xd9d4d039L ); /* 45 */
    d = HH( d, a, b, c, x[ 12 ], S32, 0xe6db99e5L ); /* 46 */
    c = HH( c, d, a, b, x[ 15 ], S33, 0x1fa27cf8L ); /* 47 */
    b = HH( b, c, d, a, x[ 2 ], S34, 0xc4ac5665L ); /* 48 */
    /* Round 4 */
    a = II( a, b, c, d, x[ 0 ], S41, 0xf4292244L ); /* 49 */
    d = II( d, a, b, c, x[ 7 ], S42, 0x432aff97L ); /* 50 */
    c = II( c, d, a, b, x[ 14 ], S43, 0xab9423a7L ); /* 51 */
    b = II( b, c, d, a, x[ 5 ], S44, 0xfc93a039L ); /* 52 */
    a = II( a, b, c, d, x[ 12 ], S41, 0x655b59c3L ); /* 53 */
    d = II( d, a, b, c, x[ 3 ], S42, 0x8f0ccc92L ); /* 54 */
    c = II( c, d, a, b, x[ 10 ], S43, 0xffeff47dL ); /* 55 */
    b = II( b, c, d, a, x[ 1 ], S44, 0x85845dd1L ); /* 56 */
    a = II( a, b, c, d, x[ 8 ], S41, 0x6fa87e4fL ); /* 57 */
    d = II( d, a, b, c, x[ 15 ], S42, 0xfe2ce6e0L ); /* 58 */
    c = II( c, d, a, b, x[ 6 ], S43, 0xa3014314L ); /* 59 */
    b = II( b, c, d, a, x[ 13 ], S44, 0x4e0811a1L ); /* 60 */
    a = II( a, b, c, d, x[ 4 ], S41, 0xf7537e82L ); /* 61 */
    d = II( d, a, b, c, x[ 11 ], S42, 0xbd3af235L ); /* 62 */
    c = II( c, d, a, b, x[ 2 ], S43, 0x2ad7d2bbL ); /* 63 */
    b = II( b, c, d, a, x[ 9 ], S44, 0xeb86d391L ); /* 64 */
    state[ 0 ] += a;
    state[ 1 ] += b;
    state[ 2 ] += c;
    state[ 3 ] += d;
    }
   
    /* Encode把long数组按顺序拆成byte数组Q因为java的longcd?4位的Q所以只拆低32位,以适应原始c实现的用?*/
    private void Encode( byte[] output, long[] input, int len)
    {
    int i, j;
    for( i = 0, j = 0; j < len; i ++, j += 4 )
    {
       output[ j ] = ( byte )( input[ i ] & 0xffL );
       output[ j + 1 ] = ( byte )( ( input[ i ] >>> 8 ) & 0xffL );
       output[ j + 2 ] = ( byte )( ( input[ i ] >>> 16 ) & 0xffL );
       output[ j + 3 ] = ( byte )( ( input[ i ] >>> 24 ) & 0xffL );
    }
    }
   
   /* Decode把byte数组按顺序合成long数组Q因为java的longcd?4位的Q因此只合成?2位,?2位清?*/
    private void Decode( long[] output, byte[] input, int len )
    {
    int i, j;
    for( i = 0, j = 0; j < len; i ++, j += 4 )
    {
       output[ i ] = b2iu( input[ j ] ) |
        ( b2iu( input[ j + 1 ] ) << 8 ) |
        ( b2iu( input[ j + 2 ] ) << 16 ) |
        ( b2iu( input[ j + 3 ] ) << 24 );
    }
    }
   
    /* b2iu是一个附加的把byte按照不考虑正负L(fng)原则?#8220;升位”函数Q因为java没有unsignedq算 */
    public static long b2iu( byte b )
    {
    return b < 0 ? b & 0x7F + 128 : b;
    }
   
    /* byteHEX()用来把一个bytecd的数转换成十六进制的ASCII表示Q因为toStringҎ(gu)无法做到q一?*/
    public static String byteHEX( byte ib )
    {
    char[] Digit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'D', 'E', 'F' };
    char[] ob = new char[ 2 ];
    ob[ 0 ] = Digit[ ( ib >>> 4 ) & 0x0F ];
    ob[ 1 ] = Digit[ ib & 0x0F ];
    String s = new String( ob );
    return s;
    }
   
    public static String toMD5( String source )
    {
    MD5 md5 = new MD5();
    return md5.getMD5ofStr( source );
    }
}



]]>
毅收藏?-----JAVA加密解密工具c?http://www.aygfsteel.com/xiaoyi/articles/278975.html可爱的小?/dc:creator>可爱的小?/author>Fri, 29 May 2009 17:49:00 GMThttp://www.aygfsteel.com/xiaoyi/articles/278975.htmlhttp://www.aygfsteel.com/xiaoyi/comments/278975.htmlhttp://www.aygfsteel.com/xiaoyi/articles/278975.html#Feedback0http://www.aygfsteel.com/xiaoyi/comments/commentRss/278975.htmlhttp://www.aygfsteel.com/xiaoyi/services/trackbacks/278975.html阅读全文

]]>
毅收藏?-----从JAR与zip档案文g中提取Java 资源 http://www.aygfsteel.com/xiaoyi/articles/278972.html可爱的小?/dc:creator>可爱的小?/author>Fri, 29 May 2009 16:33:00 GMThttp://www.aygfsteel.com/xiaoyi/articles/278972.htmlhttp://www.aygfsteel.com/xiaoyi/comments/278972.htmlhttp://www.aygfsteel.com/xiaoyi/articles/278972.html#Feedback0http://www.aygfsteel.com/xiaoyi/comments/commentRss/278972.htmlhttp://www.aygfsteel.com/xiaoyi/services/trackbacks/278972.html 多数 java E序员都非常清楚使用 jar 文g组?/span> java 解决Ҏ(gu)的各U资源(?/span> .class 文g、声韛_囑փQ打包的优点。刚开始?/span> jar 文g的h帔R的一个问题是Q?#8220;如何?/span> jar 文g中提取图像呢Q?#8221;本文回{这个问题,q会(x)提供一个类Q这个类使从 jar 文g中提取Q何资源变得非常简单!
加蝲 gif 囑փ
   
假定我们有一?/span> jar 文gQ其中包含我们的应用E序要用的一l?/span> .gif 囑փ。下面就是?/span> JarResources 讉K jar 文g中的囑փ文g的方法:(x)
    JarResources JR=new JarResources(" http://www.bt285.cn /GifBundle.jar");


    Image logo=Toolkit.getDefaultToolkit().createImage(JR.getResources("logo.gif"));

    
q段代码说明我们可以创徏一?/span>JarResources对象Qƈ其初始化ؓ(f)包含我们要用的资源?/span> jar 文g -- images.jar。随后我们?/span>JarResources?/span>getResource()Ҏ(gu)来?/span> logo.gif 文g的原始数据提供给 awt Toolkit ?/span>createImage()Ҏ(gu)?/span>
命名说明
JarResource
是一个非常简单的CZQ它说明?jin)如何?/span> java 所提供的各U功能来处理 jar ?/span> zip 档案文g?/span>

 
工作方式

JarReourcescȝ重要数据域用来跟t和存储指定 jar 文g的内容:(x)
public final class JarResources {

   public boolean debugon=false;

   private Hashtable htsizes=new Hashtable();
   private Hashtable htjarcontents=new Hashtable();

   private String jarfilename;

q样Q该cȝ实例化设|?/span> jar 文g的名Uͼ然后转到init()Ҏ(gu)完成全部实际工作?/span>
   public JarResources(String jarfilename) {
      this.jarfilename=jarfilename;
      init();
   }

现在Q?/span>init()Ҏ(gu)只将指定 jar 文g的整个内容加载到一?/span> hashtableQ通过资源名访问)(j)中?/span>

     
q是一个相当有用的Ҏ(gu)Q下面我们对它作q一步的分析?/span>ZipFilecMؓ(f)我们提供?jin)?/span> jar/zip 档案头信息的基本讉KҎ(gu)。这cM于文件系l中的目录信息。下面我们列?/span>ZipFile中的所有条目,q用档案中每个资源的大小d htsizes hashtableQ?/span>
 private void init() {
      try {
          // extracts just sizes only. 
          ZipFile zf=new ZipFile(jarFileName);
          Enumeration e=zf.entries();
          while (e.hasMoreElements()) {
              ZipEntry ze=(ZipEntry)e.nextElement();
              if (debugOn) {
                 System.out.println(dumpZipEntry(ze));
              }
              htSizes.put(ze.getName(),new Integer((int)ze.getSize()));
          }
          zf.close();
接下来,我们使用ZipInputStreamc访问档案?/span>ZipInputStreamcd成了(jin)全部术Q允许我们单独读取档案中的每个资源。我们从档案中读取组成每个资源的_字节敎ͼq将其存储在 htjarcontents hashtable 中,(zhn)可以通过资源名访问这些数据:(x)     
          // extract resources and put them into the hashtable.
          FileInputStream fis=new FileInputStream(jarFileName);
          BufferedInputStream bis=new BufferedInputStream(fis);
          ZipInputStream zis=new ZipInputStream(bis);
          ZipEntry ze=null;
          while ((ze=zis.getNextEntry())!=null) {
             if (ze.isDirectory()) {
                continue;////啊哟!没有处理子目录中的资源啊 http://www.5a520.cn  说520|?/span>
             }
             if (debugOn) {
                System.out.println(
                   "ze.getName()="+ze.getName()+","+"getSize()="+ze.getSize()
                   );
             }
             int size=(int)ze.getSize();
             // -1 means unknown size. 
             if (size==-1) {
                size=((Integer)htSizes.get(ze.getName())).intValue();
             }
             byte[] b=new byte[(int)size];
             int rb=0;
             int chunk=0;
            while (((int)size - rb) > 0) {
                 chunk=zis.read(b,rb,(int)size - rb);
                 if (chunk==-1) {
                    break;
                 }
                 rb+=chunk;
             }
             // add to internal resource hashtable
             htJarContents.put(ze.getName(),b);
             if (debugOn) {
                System.out.println(
                   ze.getName()+" rb="+rb+
                   ",size="+size+
                   ",csize="+ze.getCompressedSize()
                   );
             }
          }
       } catch (NullPointerException e) {
          System.out.println("done.");
       } catch (FileNotFoundException e) {
          e.printStackTrace();
       } catch (IOException e) {
          e.printStackTrace();
       }
   }
h意,用来标识每个资源的名U是档案中资源的限定路径名,例如Q?em>不是包中的类?/span> -- ?/span> java.util.zip 包中?/span>ZipEntrycd被命名ؓ(f) "java/util/zip/ZipEntry"Q而不?/span> "java.util.zip.ZipEntry"?/span>

其它Ҏ(gu):
    /**
    * Dumps a zip entry into a string.
    * @param ze a ZipEntry
    */
   private String dumpZipEntry(ZipEntry ze) {
       StringBuffer sb=new StringBuffer();
       if (ze.isDirectory()) {
          sb.append("d "); 
       } else {
          sb.append("f "); 
       }
       if (ze.getMethod()==ZipEntry.STORED) {
          sb.append("stored   "); 
       } else {
          sb.append("defalted ");
       }
       sb.append(ze.getName());
       sb.append("\t");
       sb.append(""+ze.getSize());
       if (ze.getMethod()==ZipEntry.DEFLATED) {
          sb.append("/"+ze.getCompressedSize());
       }
       return (sb.toString());
   }

    /**
    * Extracts a jar resource as a blob.
    * @param name a resource name.
    */
   public byte[] getResource(String name) {
      return (byte[])htJarContents.get(name);
   }
      
代码的最后一个重要部分是单的试驱动E序。该试驱动E序是一个简单的应用E序Q它接收 jar/zip 档案名和资源名。它试图发现档案中的资源文gQ然后将成功或失败的消息报告出来Q?/span>
public static void main(String[] args) throws IOException {
       if (args.length!=2) {
          System.err.println(
             "usage: java JarResources < jar file name> < resource name>"
             );
          System.exit(1);
       }
       JarResources jr=new JarResources(args[0]);
       byte[] buff=jr.getResource(args[1]);
       if (buff==null) {
          System.out.println("Could not find "+args[1]+".");
       } else {
          System.out.println("Found "+args[1]+ " (length="+buff.length+").");
       }
   }
}              // End of JarResources class.
(zhn)已?jin)解了(jin)这个类。一个易于用的c,它隐藏了(jin)使用打包?/span> jar 文g中的资源的全部棘手问题?/span>

如果(zhn)曾l(f)望知道如何从 jar 文g中提取图像,那么(zhn)现在已学到?jin)一U方法。有?jin)本技巧提供的q个新类Q?zhn)׃仅可以?/span> jar 文g处理囑փQ而且可以提取魔术用?/span> jar 文g中的M资源?/span>


]]>
毅收藏?-----------利用Comparator接口实现Ҏ(gu)List中对象的属性排?以前到q,没有qQ时间久?jin)忘(sh)(jin)。汗?http://www.aygfsteel.com/xiaoyi/articles/278224.html可爱的小?/dc:creator>可爱的小?/author>Wed, 27 May 2009 08:55:00 GMThttp://www.aygfsteel.com/xiaoyi/articles/278224.htmlhttp://www.aygfsteel.com/xiaoyi/comments/278224.htmlhttp://www.aygfsteel.com/xiaoyi/articles/278224.html#Feedback0http://www.aygfsteel.com/xiaoyi/comments/commentRss/278224.htmlhttp://www.aygfsteel.com/xiaoyi/services/trackbacks/278224.htmlCollections.sort(fileList,   new   FileNodeComparator(form.getSortName(),form.isAsc()));   
    
    
    
  
class   FileNodeComparator   implements   Comparator{   
  
private   String   sortName   =   "name";   
  
private   boolean   isAsc   =   true;   
  FileNodeComparator(String   sortName,
boolean   isAsc){   
  
this.sortName   =   sortName;   
  
this.isAsc   =   isAsc;   
  }
   
  
public   int   compare(Object   arg0,   Object   arg1)   {   
  。。。。。。。?nbsp;  
  。。。。。。。?nbsp;  
  。。。。。。。?nbsp;  
  。。。。。。。?nbsp;  
  }
   
  }


]]>
毅收藏?---------Java反射实现cM与Winform中委托的swing事g处理http://www.aygfsteel.com/xiaoyi/articles/278124.html可爱的小?/dc:creator>可爱的小?/author>Tue, 26 May 2009 20:02:00 GMThttp://www.aygfsteel.com/xiaoyi/articles/278124.htmlhttp://www.aygfsteel.com/xiaoyi/comments/278124.htmlhttp://www.aygfsteel.com/xiaoyi/articles/278124.html#Feedback1http://www.aygfsteel.com/xiaoyi/comments/commentRss/278124.htmlhttp://www.aygfsteel.com/xiaoyi/services/trackbacks/278124.html学习(fn)qJava Swing的程序员?sh)定对于Swing中相对较为复杂的事g驱动模型比较困惑Q虽然事仉动模型在Java Swing中被完完全全的体现出来了(jin)Q但是对于一个Y件初学者而言q样的近?#8220;怽”的事仉动模型确实是很难理解的?/p>

微Y公司.Net框架与Java Swing的GUI~程相比要简单很多,同样是事仉动模?Net框架p行了(jin)大量的封装处理,.Net把这U封装称之ؓ(f)委托?Delegate)Q其代码如下Q?

 

//当btnSubmit按钮被点M后要求交lbtnSubmit_ClickҎ(gu)处理// EventHandler在中间启到委托器的作用,//它负责将事g分发到指定的Ҏ(gu)中进行处理this.btnSubmit.Click += new EventHandler(this.btnSubmit_Click);//事g处理Ҏ(gu)// object sender:事g源,q里指btnSubmit对象// EventArgs e:事g处理参数Q它保存?sh)(jin)需要提供给E序员的必要信息private void btnSubmit_Click(object sender, EventArgs e){ //打印This is a button语句 System.Diagnostics.Debug.WriteLine("This is button");}

 

作ؓ(f)Ҏ(gu)Q我们来看看Java Swing的事件处理和委托p复杂很多代码如下Q?/p>

            

//为btnSubmit增加侦听器SelectHandlerQ当btnSubmit被点M?br /> //有侦听器的actionPerformed负责处理该点M件的业务
//׃事g源btnSubmit和侦听器cSelectHandler处于两个不同的类?br /> //Z(jin)让SelectHandlercd得页面的信息Q我们需要将H体对象(this)
//传入C听器?br /> btnSubmit.addActionListener(new SelectHandler(this));
//侦听器SelectHandlerQ它必须实现动作事gActionListener接口
//以达C件分发的作用
class SelectHandler implements ActionListener {
 private CommonDialogDemo form = null;
 //窗体对象CommonDialogDemo通过构造函C入SelectHandlercM
 public SelectHandler(CommonDialogDemo form) {
this.form = form;
 }
 //事g处理Ҏ(gu)Q当btnSubmit被点击,自动执行以下打印代码
 publicvoid actionPerformed(ActionEvent e) {
System.out.println("This is button");
 }
}

Ҏ(gu)以上代码Q我们可以清晰的看到Java Swing要比.Net的麻?ch)的多,而且更不能让人忍受的是Q一个页面如果有多个按钮的话Q我们必针Ҏ(gu)个按钮编写多个事件侦听类Q而且q些cM般都?x)被设?f)内部cR学qY件徏模的读者可能知道,内部软g建模在Y件工E中是不推荐使用的,所以这L(fng)代码~写明显?x)增加设计冗余度和复杂度Q因此,我们可以考虑自己~写一个类g.Net中EventHandler一L(fng)事g委托cL处理事g分发?/p>

׃我们无权修改Java的编译器Q所以我在这里将?x)借助于反技术,利用一个事件委托类处理所有的点击事gQ代码如下:(x)

            

package cn.softworks.teachersearchsystem.support;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.Method;

/**
*该类是用来处理所有的Swing按钮点击事gQƈҎ(gu)处理权<br>
*转交l用者来处理
*
*@authorChen.yu
*
*/
publicclass EventHandlerimplements ActionListener {

 //lg所在的H体对象
 private Object form = null;

 //受到委托的方法名
 private String methodName = null;

 /**
 *构造函?br />  *
 *@paramform lg所在的H体对象
 *@parammethodName 受到委托的方法名
 */
 public EventHandler(Object form,String methodName) {
this.form = form;
this.methodName = methodName;
 }

 /**
 *事g处理委托Ҏ(gu)
 */
 publicvoid actionPerformed(ActionEvent e) {

//得到H体对象的类?br /> Class formType = this.form.getClass();

try {
 //得到指定委托Ҏ(gu)的类?
 Method method =
formType.getMethod(this.methodName, new Class[] {e.getClass()});
 //调用指定的方?br />  method.invoke(this.form, new Object[] {e});

}catch(Exception ex) {
 return;
}
 }
}

现在我们来编写一个测试程序,代码如下Q?/p>

            

btnSearch.addActionListener(new EventHandler(this,"btnSearch_Click"));

public void btnSearch_Click(ActionEvent e) {
 System.out.println("This is btnSearch");
}

从以上代码中我们可以清晰的看刎ͼ事g处理和事件委托处于同一H体中了(jin)Q?Net方便的Delegate处理被我们用反射实现?jin)?/p>

]]>
毅收藏?---------截屏http://www.aygfsteel.com/xiaoyi/articles/272037.html可爱的小?/dc:creator>可爱的小?/author>Thu, 21 May 2009 09:21:00 GMThttp://www.aygfsteel.com/xiaoyi/articles/272037.htmlhttp://www.aygfsteel.com/xiaoyi/comments/272037.htmlhttp://www.aygfsteel.com/xiaoyi/articles/272037.html#Feedback0http://www.aygfsteel.com/xiaoyi/comments/commentRss/272037.htmlhttp://www.aygfsteel.com/xiaoyi/services/trackbacks/272037.htmlpublic static void captureScreen(String fileName) throws Exception {

    Dimension screenSize 
= Toolkit.getDefaultToolkit().getScreenSize();
    Rectangle screenRectangle 
= new Rectangle(screenSize);
    Robot robot 
= new Robot();
    BufferedImage image 
= robot.createScreenCapture(screenRectangle);
    ImageIO.write(image, 
"png"new File(fileName));
}


]]>
jspmartLoad文g上传下蝲http://www.aygfsteel.com/xiaoyi/articles/232137.html可爱的小?/dc:creator>可爱的小?/author>Thu, 02 Oct 2008 15:16:00 GMThttp://www.aygfsteel.com/xiaoyi/articles/232137.htmlhttp://www.aygfsteel.com/xiaoyi/comments/232137.htmlhttp://www.aygfsteel.com/xiaoyi/articles/232137.html#Feedback0http://www.aygfsteel.com/xiaoyi/comments/commentRss/232137.htmlhttp://www.aygfsteel.com/xiaoyi/services/trackbacks/232137.html 

此例子是Zjspsmartuploadlg的,jspsmartupload是一个不错的上传下蝲lgQ但对中文支持不뀂若下蝲的文件名中有汉字Q则览器在提示另存的文件名Ӟ昄的是一堆ؕ码,让h看了(jin)很不舒服Qؓ(f)此,有h专门修改此组Ӟ做了(jin)~码的{换工作,文件名转换为UTF-8形式的编码Ş式。我用的是网上修改过的,已经可以支持中文Q相信你也可以找刎ͼ如果需要,可以联系我,我会(x)在第一旉发给你!

在网上找?jin)很多相兌料,自己也添加?jin)一些js代码Q基本实C(jin)动态添加删除多文g上传的功能,如果惌做得更完,或者把文g上传下蝲信息存储到数据库{,那就自己d善了(jin)Q以下是所有的源代码:(x)

(文g下蝲Z安全考虑是按的方式来进行的Q而不是直接给出文件下载\径地址Q所以像q雷{下载工h不能下蝲?

首先当然是上传下载的面?jin),upfile.jsp

<%@ page contentType="text/html;charset=GBK"%>
<html>
<head>
   
<title>File Upload</title>
<script type="text/javascript">
         function addFile()
        {
            var upFile = '
<input type="file" name="file1"><br>';
            document .getElementById ("files").insertAdjacentHTML("beforeEnd",upFile);
        }
        function deleteFile()
        {
            var file = document .getElementById ("files").lastChild;
            if(file == null)
                return;
            document .getElementById ("files").removeChild(file);
            
            file = document .getElementById ("files").lastChild;   //U除换行W?/span><br>所以要UM?br />             document .getElementById ("files").removeChild(file); //如果在表格里面不?/span><br>p动换行的Q可以去掉,自己把握
        }
</script>
</head>
<body>
<h3>Zjspsmart uploadlg的文件上传下?/span></h3>
<form action="servlet/ServletUpload" method="post" enctype="multipart/form-data">
   选择文gQ?/span><div id="files"><input type="file" name="file1"><br></div>
     
<input type="submit" value="上传">
     
<input type="button" value="增加文g" onclick="addFile()"> 
     
<input type="button" value="删除文g" onclick="deleteFile()">
     
<input type="reset" value="重置">
   
</form>
   
<br>
   
<form action="servlet/ServletDownload" method="post">
     下蝲文g的名Uͼ(x)
     
<input type="text" name="downloadFileName" size="20" maxlength="80">
    
<input type="submit" value="下蝲">
   
</form>
</body>
</html>
然后是实C传和下蝲的两个servletc?br />
上传文gServletUploadc:(x)

package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jspsmart.upload.SmartUpload;
import com.jspsmart.upload.SmartUploadException;

public class ServletUpload extends HttpServlet {

private ServletConfig config;

public ServletUpload() {
   super();
}

public void destroy() {
   super.destroy(); // Just puts "destroy" string in log
}

public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException { 
   int count = 0; //记录文g上传M?br />    SmartUpload mySmartUpload = new SmartUpload();
   mySmartUpload.initialize(config,request, response);
   try {
    //mySmartUpload.setAllowedFilesList("rar,htm,html,jar");//讄允许上传的文?br />     mySmartUpload.setDeniedFilesList("exe,jsp,asp");//止上传的文?br />     mySmartUpload.setDenyPhysicalPath(true); //拒绝物理路径
    mySmartUpload.setMaxFileSize(5000000);//讄允许上传文g最大ؓ(f)50000bytes
    mySmartUpload.setTotalMaxFileSize(50000000);//一ơ上传文件大最多不过5000000bytes
    mySmartUpload.upload();
    for(int i=0;i
<mySmartUpload.getFiles().getCount();i++){
     com.jspsmart.upload.File myFile 
= mySmartUpload.getFiles().getFile(i);
     
String fileName = myFile.getFileName();
     
System.out.println("文g名:(x)"+fileName);
    }
    count 
= mySmartUpload.save("/upload");
    
System.out.println(count+"文g已上?);
   } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
   doGet(request, response);
}

public void init(ServletConfig config) throws ServletException {
   this.config 
= config;
}
}

下蝲文gServletDownloadc:(x)

package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jspsmart.upload.SmartUpload;
import com.jspsmart.upload.SmartUploadException;

public class ServletDownload extends HttpServlet {

private ServletConfig config;

public ServletDownload() {
   super();
}

public void destroy() {
   super.destroy(); // Just puts "destroy" string in log
}

public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
   String temp_fileName 
= request.getParameter("downloadFileName");
   
if(temp_fileName == null || temp_fileName == "")
    return ;
   byte[] temp_t 
= temp_fileName.getBytes("ISO8859_1");
   
String fileName = new String(temp_t, "GBK");
   SmartUpload mySmartUpload 
= new SmartUpload();
   mySmartUpload.initialize(config, request, response);
   mySmartUpload.setContentDisposition(null);
   /*
   * 原型Qpublic void setContentDisposition(String contentDisposition)
   * 其中QcontentDispositiond的数据?br />    * 如果contentDisposition为nullQ则lg自动添?attachment;"Q?br />    * 以表明将下蝲的文件作为附Ӟl果是IE览器将?x)提C另存文Ӟ而不是自动打开q个文g
   * QIE览器一般根据下载的文g扩展名决定执行什么操作,扩展名ؓ(f)doc的将用wordE序打开Q?br />    * 扩展名ؓ(f)pdf的将用acrobatE序打开Q等{)(j)?br />    */
   try {
    mySmartUpload.downloadFile("/upload/"+fileName);
   
   } catch (SmartUploadException e) {
    e.printStackTrace();
   }
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
   doGet(request, response);
}

public void init(ServletConfig config) throws ServletException {
   this.config 
= config;
}
}

以下是web.xml配置文g:

<?xml version
="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns
="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation
="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
>
<servlet>
    
<description>This is the description of my J2EE component</description>
    
<display-name>This is the display name of my J2EE component</display-name>
    
<servlet-name>ServletUpload</servlet-name>
    
<servlet-class>servlet.ServletUpload</servlet-class>
</servlet>
<servlet>
    
<description>This is the description of my J2EE component</description>
    
<display-name>This is the display name of my J2EE component</display-name>
    
<servlet-name>ServletDownload</servlet-name>
    
<servlet-class>servlet.ServletDownload</servlet-class>
</servlet>


<servlet-mapping>
    
<servlet-name>ServletUpload</servlet-name>
    
<url-pattern>/servlet/ServletUpload</url-pattern>
</servlet-mapping>
<servlet-mapping>
    
<servlet-name>ServletDownload</servlet-name>
    
<url-pattern>/servlet/ServletDownload</url-pattern>
</servlet-mapping>
<welcome-file-list>
    
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

要实现无h上传其实很简单。只要利用iframe卛_Q只要把target讄为隐藏的iframe就可以?jin)?br />  Qiframe name='hidden_frame' id="hidden_frame" style='display:none'Q</iframeQ?/span>

]]>
议泛型http://www.aygfsteel.com/xiaoyi/articles/230494.html可爱的小?/dc:creator>可爱的小?/author>Mon, 22 Sep 2008 11:25:00 GMThttp://www.aygfsteel.com/xiaoyi/articles/230494.htmlhttp://www.aygfsteel.com/xiaoyi/comments/230494.htmlhttp://www.aygfsteel.com/xiaoyi/articles/230494.html#Feedback0http://www.aygfsteel.com/xiaoyi/comments/commentRss/230494.htmlhttp://www.aygfsteel.com/xiaoyi/services/trackbacks/230494.html泛型
一、什么是泛型Q?
通过泛型可以定义cd安全c,而不?x)损害类型安全、性能或工作效?

二、实例化泛型
1、可以用Q何类型来声明和实例化
2、申明和实例话都必须用一个特定的cd来代替一般类型T
3、例子:(x)
//原来写法
Public   class   Stack
{
object[]   m_Items;
public   void   Push(object   item)
{...}
public   object   Pop()
{...}
}
Stack   stack   =   new   Stack();
stack.Push(1);
int   number   =   (int)stack.Pop();

//有了(jin)泛型?
Public   class   Stack <T>
{
T[]   m_Items;
public   void   Push(T   item)
{...}
public   T   Pop()
{...}
}
Stack <int>   stack   =   new   Stack <int> ();
stack.Push(1);
int   number   =   (int)stack.Pop();

三:(x)泛型的好?
1、一ơ性的开发、测试和部v代码Q通过Mcd来重用它
2、编译器支持和类型安?
3、不?x)强行对值类型进行装和取消装箱Q或者对引用cdq行向下强制cd转换Q所以性能得到显著提高?
注:(x)值类型大概可以提?00%Q引用类型大概ؓ(f)100%

四:(x)多个泛型
1、单个类型可以定义多个泛?

五:(x)泛型别名
1、在文g头部使用using   为特定类型取别名Q别名作用范围是整个文g
2、例?
using   List   =   LinkedList <int,string> ;
class   ListClient
{
static   void   Main(string[]   args)
{
List   list   =   new   List();
list.AddHead(123, "AAA ");
}
}

五:(x)泛型U束
(1)、派生约?
如:(x)
public   class   LinkedList <K,T>   where   K:IComparable
{
T   Find(K   key)
{
if   (str.Key.CompareTo(key)   ==   0)//只有实现q个接口才可比较
}
}

注意:
1、所有的zU束必须攑֜cȝ实际z列表之后
如:(x)public   class   LinkedList <K,T> :IEnumerable <T>   where   K:IComparable <K>
        {...}
2、一个泛型参C可以U束多个接口Q用逗号分隔Q?
public   class   LinkedList <K,T>   where   K:IComparable <K> ,IConvertible
3、在一个约束中最多只能用一个基c?
4、约束的基类不能是密类或静(rn)态类
5、不能将System.Delegate或System.ArrayU束为基c?
6、可以同时约束一个基cM?qing)一个或多个接口Q但是该基类必须首先出现在派生约束列表中?
7、C#允许你将另一个泛型参数指定ؓ(f)U束
public   class   MyClass <T,U>   where   T:U
{...}
8、可以自己定义基cL接口q行泛型U束
9、自定义的接口或基类必须与泛型具有一致的可见?

(2)、构造函数约?
如:(x)
class   Node   <K,T>   where   T:new()
{
}
注意Q?
1、可以将构造函数的U束和派生约束结合v来,前提是构造函数的U束出现在约束列表中的最?

(3)、引?值类型约?
1、可以用structU束泛型参数约束ؓ(f)值类?如int、bool、enum),或Q何自定义l构
2、同样可以用classU束泛型参数约束ؓ(f)引用cd
3、不能将引用/值类型约束与基类U束一起用,因ؓ(f)基类U束涉及(qing)到类
4、不能用结构和默认构造函数约束,因ؓ(f)默认构造函数约束也涉及(qing)到类
5、虽然?zhn)可以使用cd默认构造函数约束,但是q样做没有Q何h(hun)?
6、可以将引用/值类型约束与接口U束l合hQ前提是引用/值类型约束出现在U束列表的开?

六:(x)泛型和强制类型{?
1、C#~译器只允许泛型参数隐式{换到Object或约束指定的cd
如:(x)
interface   IS{...}
class   BaseClass{...}
class   MyClass <T>   where   T:BaseClass,IS
{
void   SomeMethod(T   t)
{
IS   obj1   =   t;
BaseClass   obj2   =   t;
object   obj3   =   t;
}
}
2、编译器允许你将泛型参数昄强制转换到其他Q何借口Q但不能其转换到类
interface   IS{...}
class   SomeClass{...}
class   MyClass   <T>   //没有U束
{
void   SomeMethod(T   t)
{
IS   obj1   =   (IS)t;   //可以
SomeClass   obj2   =   (SomeClass)t   //不可?
}
}
3、可以用(f)时的Object变量Q将泛型参数强制转换到其他Q何类?
class   SomeClass{...}
class   MyClass   <T>  
{
void   SomeMethod(T   t)
{
object   temp   =   t;
SomeClass   obj   =   (SomeClass)temp;//可以
}
}
注意Q这里只是告诉你q样写是可以的,但是要不要这样写Q不要这样写Q因为如果t实没有l承SomeClass~译没错但是q行׃(x)出错
4、解决上面强制{换问题,可以使用is和asq算W进行判?
public   class   MyClass <T>
{
public   void   SomeMethod <T   t>
{
if   (t   is   int   ){...}
if   (t   is   LinkedList <int,string> ){...}
//如果泛型参数的类型是所查询的类型,则isq算W返回true
string   str   =   t   as   string;
//如果q写cd兼容Q则as执行强制类型{换,否则返回null
if   (str   !=   null){...}
LinkedList <int,string>   list   =   t   as   LinkedList <int,string> ;
if   (list   !=   null){...}
}
}

七:(x)l承和泛?
1、在从泛型基cL生,可以提供cd实参Q而不是基cL型参?
public   class   BaseClass <T> {...}
public   class   SubClass:BaseClass <int>
2、如果子cL泛型Q而非具体的类型实参,则可以用子cL型参C为泛型基cȝ指定cd
public   class   BaseClass <TT> {...}
public   class   SubClass <T> :BaseClass <T> {...}
3、在使用子类泛型参数Ӟ必须在子cȝ别重复在基类U别规定的Q何约?
4、基cd以定义其{֐使用泛型参数的虚C方法,在重写它们时Q子cddҎ(gu){֐中提供相应的cd?
如:(x)
public   class   BaseClass <T>
{
public   virtual   T   SomeMethod()
{...}
}
public   class   SubClass:BaseClass <int>
{
public   override   int   SomeMethod()
{...}
}
5、如果该子类是泛型,则它q可以在重写时用它自己的泛型参?
public   class   SubClass <T> :BaseClass <T>
{
public   override   T   SomeMethod()
{...}
}
6、你可以定义泛型接口、泛型抽象类Q甚x(chng)型抽象方法?
7、不能对泛型参数使用+?=之类的运符
public   class   Calculator <T>
{
public   T   Add   (T   arg1,T   arg2)
{
return   arg1   +   arg2;//错误
}
}
但是我们可以通过泛型抽象cR接口来实现在个功能Q因为实现泛型抽象类、接口我们就已经明确传一个参C(jin)Q就可以执行诸如+q样的操作?

八:(x)泛型Ҏ(gu)
1、方法可以定义特定于其执行范围的泛型参数
public   class   MyClass <T>
{
public   void   MyMethod <X> (X   x)
{...}
}
2、即使各包含cL本不使用泛型Q你也可以定义方法特定的泛型参数
public   class   MyClass
{
public   void   MyMethod <T> (T   t)
{...}
}
注意Q该功能只用于Ҏ(gu)Q属性,索引器只能用在cȝ作用范围中定义的泛型参数?
3、调用泛型方?
MyClass   obj   =   new   MyClass();
obj.MyMethod <int> (3);
也可以这P(x)
MyClass   obj   =   new   MyClass();
obj.MyMethod(3);   //该功能称为泛型推?
4、泛型方法也可以有自q泛型参数U束
pubic   class   MyClass
{
public   void   SomeMethod <T> (T   t)   where   T:IComparable <T>
{...}
}
5、子cL法实C能重复在父别出现的U束
public   class   BaseClass
{
public   virtual   void   SomeMethod <T> (T   t)where   T:new()
{...}
}
pubic   class   SubClass:BaseClass
{
public   override   void   SomeMethod <T> (T   t)//不能再有U束
{...}
}
6、静(rn)态方?
?rn)态方法可以定义特定的泛型参数和约?
public   class   MyClass <T>
{
public   static   T   SomeMethod <X> (T   t,X   x)
{...}
}
int   number   =   MyClass <int> .SomeMethod <string> (3, "AAA ");
或者:(x)int   mumber   =   MyClass <int> .SomeMethod(3, "AAA ");

?ji)?x)泛型委托
1、在某个cM定义的委托可以利用该cȝ泛型参数
2、委托(sh)可以定义自己的泛型参?/strong>

]]>
毅的验证码http://www.aygfsteel.com/xiaoyi/articles/228185.html可爱的小?/dc:creator>可爱的小?/author>Wed, 10 Sep 2008 08:42:00 GMThttp://www.aygfsteel.com/xiaoyi/articles/228185.htmlhttp://www.aygfsteel.com/xiaoyi/comments/228185.htmlhttp://www.aygfsteel.com/xiaoyi/articles/228185.html#Feedback0http://www.aygfsteel.com/xiaoyi/comments/commentRss/228185.htmlhttp://www.aygfsteel.com/xiaoyi/services/trackbacks/228185.htmlcheckCode.java
package com.yz.checkcode;

import java.io.IOException;    
import java.io.PrintWriter;

import javax.servlet.ServletException;    
import javax.servlet.ServletOutputStream;    
   
import javax.servlet.http.HttpServlet;    
import javax.servlet.http.HttpServletRequest;    
import javax.servlet.http.HttpServletResponse;    
import javax.servlet.http.HttpSession;    
   
import com.sun.image.codec.jpeg.JPEGCodec;    
import com.sun.image.codec.jpeg.JPEGImageEncoder;    
   
import java.awt.*;    
import java.awt.image.*;    
import java.util.*;    
   
public class checkCode    
    extends HttpServlet {    
   
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws   
       ServletException, IOException {    
     response.reset();    
     response.setContentType("image/jpeg");    
     response.setHeader("Pragma","No-cache");
     response.setHeader("Cache-Control","no-cache");
     response.setHeader("Expires",   "Tues,   01   Jan   1980   00:00:00   GMT");   
    
   
//在内存(sh)创徏图象    
    int width = 58, height = 18;    
     BufferedImage image = new BufferedImage(width, height,    
                                             BufferedImage.TYPE_INT_RGB);    
   
//获取囑Ş上下?nbsp;   
     Graphics g = image.getGraphics();    
   
//生成随机c?nbsp;   
     Random random = new Random();    
   
//讑֮背景?nbsp;   
     g.setColor(new Color(201 + random.nextInt(50), 201 + random.nextInt(50),    
                         201 + random.nextInt(50)));    
     g.fillRect(0, 0, width, height);    
   
//讑֮字体    
     g.setFont(new Font("Times new Roman", Font.PLAIN, 18));    
   
//画边?nbsp;   
g.setColor(new Color(255,140,0));    
g.drawRect(0,0,width-1,height-1);    
   
//随机产生155条干扰线Q图象中的认证码不易被其它E序探测?nbsp;   
     g.setColor(new Color(160 + random.nextInt(41), 160 + random.nextInt(41),    
                         160 + random.nextInt(41)));    
    for (int i = 0; i 
< 155
; i++) {    
      int x 
= random.nextInt(width);    
      
int y 
= random.nextInt(height);    
      
int xl 
= random.nextInt(12);    
      
int yl 
= random.nextInt(12);    
       
g.drawLine(x, y, x + xl, y + yl);    
     }    
   
//取随Z生的认证?br />     String src 
= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKMNOPQRSTUVWXYZ0123456789"
;
     String sRand 
= ""
;    
    for (int i 
= 0; 
i < 4; i++) {    
        int position
=random.nextInt(src.length());
        
String radomChar
=src.charAt(position)+"";
       
sRand +
= radomChar;    
   
//认证码昄到图象中    
       g.setColor(new Color(20 + random.nextInt(111), 20 + random.nextInt(111),    
                           20 + random.nextInt(111)));    
   
//调用函数出来的颜色相同,可能是因为种子太接近Q所以只能直接生?nbsp;   
       g.drawString(  radomChar, 13 * i + 6, 16);    
     }    
    
//图象生效    
     g.dispose(); 
     HttpSession session 
= request.getSession(true);  
     
     
//认证码存入SESSION    
      session.setAttribute("checkCode", sRand);
   
//输出图象到页?nbsp;    
     ServletOutputStream out 
= response.getOutputStream();    
     
JPEGImageEncoder encoder 
= JPEGCodec.createJPEGEncoder(out);    
     
encoder.encode(image);    
     System.out.println("验证码:(x)\t"+sRand);
     out.println(sRand);
     out.flush();
     out.close();
   }    
}    

getKey.java
package com.yz.checkcode;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class getKey extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        this.doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/html");
        response.setCharacterEncoding("utf-8");
        PrintWriter out = response.getWriter();    
        String key=request.getSession().getAttribute("checkCode").toString();
        out.println(key);
        out.flush();
        out.close();
    }
}


]]>
毅议Java字符?/title><link>http://www.aygfsteel.com/xiaoyi/articles/224118.html</link><dc:creator>可爱的小?/dc:creator><author>可爱的小?/author><pubDate>Mon, 25 Aug 2008 04:22:00 GMT</pubDate><guid>http://www.aygfsteel.com/xiaoyi/articles/224118.html</guid><wfw:comment>http://www.aygfsteel.com/xiaoyi/comments/224118.html</wfw:comment><comments>http://www.aygfsteel.com/xiaoyi/articles/224118.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/xiaoyi/comments/commentRss/224118.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/xiaoyi/services/trackbacks/224118.html</trackback:ping><description><![CDATA[<strong>首先我们来看以个例子:(x)<br /> </strong> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><strong><img id="Codehighlighter1_18_200_Open_Image" onclick="this.style.display='none'; Codehighlighter1_18_200_Open_Text.style.display='none'; Codehighlighter1_18_200_Closed_Image.style.display='inline'; Codehighlighter1_18_200_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_18_200_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_18_200_Closed_Text.style.display='none'; Codehighlighter1_18_200_Open_Image.style.display='inline'; Codehighlighter1_18_200_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> Test </span><span id="Codehighlighter1_18_200_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span></strong><span id="Codehighlighter1_18_200_Open_Text"><strong><span style="color: #000000">{<br /> <img id="Codehighlighter1_62_84_Open_Image" onclick="this.style.display='none'; Codehighlighter1_62_84_Open_Text.style.display='none'; Codehighlighter1_62_84_Closed_Image.style.display='inline'; Codehighlighter1_62_84_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_62_84_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_62_84_Closed_Text.style.display='none'; Codehighlighter1_62_84_Open_Image.style.display='inline'; Codehighlighter1_62_84_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> changeStr(String str) </span><span id="Codehighlighter1_62_84_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span></strong><span id="Codehighlighter1_62_84_Open_Text"><strong><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        str </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">welcome</span><span style="color: #000000">"</span></strong><span style="color: #000000"><strong>;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</strong></span></span><span style="color: #000000"><br /> <strong><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img id="Codehighlighter1_127_198_Open_Image" onclick="this.style.display='none'; Codehighlighter1_127_198_Open_Text.style.display='none'; Codehighlighter1_127_198_Closed_Image.style.display='inline'; Codehighlighter1_127_198_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_127_198_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_127_198_Closed_Text.style.display='none'; Codehighlighter1_127_198_Open_Image.style.display='inline'; Codehighlighter1_127_198_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </strong></span><strong><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> main(String[] args) </span><span id="Codehighlighter1_127_198_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span></strong><span id="Codehighlighter1_127_198_Open_Text"><strong><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        String str </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">1234</span><span style="color: #000000">"</span></strong><span style="color: #000000"><strong>;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        changeStr(str);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        System.out.println(str);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</strong></span></span><span style="color: #000000"><br /> <strong><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</strong></span></span></div> <span style="color: #0000ff; background-color: #ffffff"><strong>输出l果是什么?wecome?<span style="color: #ff0000">你错?jin),?1234  Z么呢Q原因如下:(x)<br /> <br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #008000"><!--</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />    对象Q一个对象可以被很多引用兌 <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />引用Q一个引用只能关联一个对?br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />Ojbect xiaoyi1; Ojbect xiaoyi1; Ojbect xiaoyi1; q里创徏?jin)三个引?nbsp;q没有创建对?br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />xiaoyi xy = new xiaoyi();<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />xy是一个引用, new xiaoyi()q个在内存(sh)创徏?jin)一个对象,q个对象?nbsp;xyq个引用所兌<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />引用好比一个句柄对象,通过xyq个引用Q句柄对象)(j) 可以操作 new xiaoyi()对象<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />引用也是一个|只不q他的D录了(jin)其关联对象的地址信息而已?br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />public void test(String s1){ <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />只要是参数在Ҏ(gu)内用时Q都?x)生参数的副本?Cq一点,无论javaQC#,C,C++?nbsp;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />1>String temp = s1;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />q里s1只是一个引用的副本Q是实际S1引用的一副本Q好比你mainҎ(gu)内str实际引用的副?br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />2>s1="welcome";<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />在这里进行交换的时候你交换的仅仅是副本而已Q虽然S1和mainҎ(gu)的str指向同一个对象,但是你交换的是mainҎ(gu)str引用的副本而已<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />另外QString str="XIAOYI";<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />str.toLowerCase() ;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />System.out.println(str);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />l果是什么?xiaoyi? 那么你又错了(jin)。?br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />因ؓ(f)在你调用toLowerCase(Q方法是?x)新开辟内存来保存转换完成的对象,而你q没有把原来对象的引用重新关联被转换后的对象Q所以输出的仍然是{换前的对?nbsp;XIAOYI,要想改变l果怎么办?<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />重新兌:str=str.toLowerCase();  q样可以了(jin)<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #008000">--></span></div> <br /> 关于  Java字符串池(String pool)<br /> <p>public   class   Sub{   <br /> String   str=new   String( "good ");   <span style="color: #008080">//一个地址的传?new出来的对象,在内存(sh)已经开辟了(jin)I间<br /> </span> <br /> public   static   void   main(String   args[]){   <br /> Sub   ex=new   Sub();   <br /> ex.change(ex.str);   <br /> System.out.println(ex.str);   <br /> }   <br /> public   void   change(String   bb){   <br /> bb= "test   ok " }</p> <p><font color="#ff0000"><span style="color: #008080"><font color="#ff0000">问题Q?/font>String   str=new   String( "good ") 和String str="good"的区别?</span></font></p> <p><font color="#ff0000">体会(x)1Q?/font><clk><span style="color: #008080">str是一个Stringcd的对象引用,他是Subcȝcd量。当ex对象引用使用changeҎ(gu)时。bb是str引用的拷贝。可以通过bb讉K原str的对象。而方法里当bb="test ok"的时候他把bb指向?jin)一个新的对象中。这时候我们就要引?nobr oncontextmenu="return false" onmousemove="kwM(0)" id="clickeyekey0" onmouseover="kwE(event,0, this)" style="border-bottom: #6600ff 1px dotted; background-color: transparent; text-decoration: underline" onclick="kwC(event,0)" onmouseout="kwL(event,this)">java</nobr>字符串的概念?jin)?/span></clk></p> <p><font color="#ff0000">体会(x)2Q?/font><span style="color: #008080">字符串池Q{Q?/span><font face="Courier New, Courier, Monospace, Simsun" color="#0000ff">String a = "Hello";<br /> String b = "Hello";<br /> String c = new<strong><font color="#000000"> </font></strong>String("Hello");<br /> String d = new String("Hello");<br /> System.out.println(a == b);<br /> System.out.println(b == c);<br /> System.out.println(c == d);<br /> System.out.println(a.equals(b));<br /> System.out.println(b.equals(c));<br /> System.out.println(c.equals(d));</font></p> <p><span style="color: #008080">l果是trueQfalseQfalseQtrueQtrueQtrue。这里就涉及(qing)到字W串池?#8220;字符串池”Q是JavaZ(jin)提高内存利用率而采用的措施Q?/span></p> <p><span style="color: #008080">当遇到String a = "Hello"; q样的语句时QJava?x)先在字W串池中L是否已经存在"Hello"q个字符?如果没有Q则建立字符?Hello"对象Q然后变?a 指向q个地址Q然后遇到语句String b = "Hello"Q这时字W串池中已经?"Hello"?jin),所以直接让变量b也指向这个地址Q省M(jin)重新分配的麻?ch)。而在Java中,操作W?#8220;==”对于两个基本型来_(d)是判断其内容是否相同Q对于两个对象来_(d)则是判断其地址是否相同Q所以a == bq回 true?/span></p> <p><span style="color: #008080">那么String c = new String("Hello")又如何处理呢Q如果是q种写法Q则不会(x)去访问字W串池,而是先ؓ(f)变量 c 开辟空_(d)然后值写入空间。所以a == cq回falseQc == d同样q回false?/span></p> <p><span style="color: #008080">至于String的equalsҎ(gu)Q因为它比较的不是对象的地址Q而是对象的|所以都q回true׃奇怪了(jin)?/span></p> <p><span style="color: #008080">Java虚拟机有一个字W串池,保存着几乎所有的字符串对象。字W串表达式L指向字符串池中的一个对象。用new操作创徏的字W串对象不指向字W串池中的对象但是可以用internҎ(gu)使其指向字符串池中的对象.Q注Q如果池中已l有相同的字W串--使用equalsҎ(gu)定Q则直接q回池中的字W串Q否则先字W串d到池中,再返回)(j)。池中两个相{的字符串如果?#8220;==”来比较将q回真?/span></p> <p><span style="color: #008080"><font color="#ff0000">ȝQ?/font>也就是在changeq个Ҏ(gu)中,bb已经写入strI间。而bb在等?#8220;test ok”的时候是q用字符串池创徏?jin)对象中了(jin)。所以不能赋倹{可以这?bb="test ok"; this.str=bb;</span></p> <p><span style="color: #008080">理解有错误,希望看到的高手可以告诉我Q以便我可以更好的修改,谢谢?jin)?/span></p> <br /> </span></strong></span> <img src ="http://www.aygfsteel.com/xiaoyi/aggbug/224118.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/xiaoyi/" target="_blank">可爱的小?/a> 2008-08-25 12:22 <a href="http://www.aygfsteel.com/xiaoyi/articles/224118.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">¡</a>| <a href="http://" target="_blank">º</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ƺ</a>| <a href="http://" target="_blank">ָɽ</a>| <a href="http://" target="_blank">ȫ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ն</a>| <a href="http://" target="_blank">ȫ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank">̩</a>| <a href="http://" target="_blank">ˮ</a>| <a href="http://" target="_blank">ľ˹</a>| <a href="http://" target="_blank">˳</a>| <a href="http://" target="_blank">â</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ĭ</a>| <a href="http://" target="_blank">ѳ</a>| <a href="http://" target="_blank">żҸ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ԫ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">̨</a>| <a href="http://" target="_blank">״</a>| <a href="http://" target="_blank"></a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>