﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-日出而作兮勤于外，日落而归兮忙于内-随笔分类-学习记录</title><link>http://www.blogjava.net/cherishchen/category/24321.html</link><description>The art of living is to know when to hold fast and when to let go</description><language>zh-cn</language><lastBuildDate>Fri, 24 Aug 2007 02:30:49 GMT</lastBuildDate><pubDate>Fri, 24 Aug 2007 02:30:49 GMT</pubDate><ttl>60</ttl><item><title>也来写个struts2 CURD的例子-Move CRUD Operations into the same Action</title><link>http://www.blogjava.net/cherishchen/archive/2007/08/23/138760.html</link><dc:creator>凭栏观海</dc:creator><author>凭栏观海</author><pubDate>Thu, 23 Aug 2007 03:02:00 GMT</pubDate><guid>http://www.blogjava.net/cherishchen/archive/2007/08/23/138760.html</guid><wfw:comment>http://www.blogjava.net/cherishchen/comments/138760.html</wfw:comment><comments>http://www.blogjava.net/cherishchen/archive/2007/08/23/138760.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/cherishchen/comments/commentRss/138760.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/cherishchen/services/trackbacks/138760.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 最近读starting struts2 online，里面有一节Move CRUD Operations into the same Action，提供了Move CRUD Operations into the same Action大概的sample，于是进行了补充，记录下来，以备使用。 一、思路  在这本书里，lan roughley提到在结合preparable和ModenDriven拦截...&nbsp;&nbsp;<a href='http://www.blogjava.net/cherishchen/archive/2007/08/23/138760.html'>阅读全文</a><img src ="http://www.blogjava.net/cherishchen/aggbug/138760.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/cherishchen/" target="_blank">凭栏观海</a> 2007-08-23 11:02 <a href="http://www.blogjava.net/cherishchen/archive/2007/08/23/138760.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>java的数据类型（备用）</title><link>http://www.blogjava.net/cherishchen/archive/2007/07/27/132720.html</link><dc:creator>凭栏观海</dc:creator><author>凭栏观海</author><pubDate>Fri, 27 Jul 2007 03:11:00 GMT</pubDate><guid>http://www.blogjava.net/cherishchen/archive/2007/07/27/132720.html</guid><wfw:comment>http://www.blogjava.net/cherishchen/comments/132720.html</wfw:comment><comments>http://www.blogjava.net/cherishchen/archive/2007/07/27/132720.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/cherishchen/comments/commentRss/132720.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/cherishchen/services/trackbacks/132720.html</trackback:ping><description><![CDATA[&nbsp; 结合了前段时间看unicode的知识补补基础<br><br>
<ul>
    <li><strong>byte</strong>: The <code>byte</code> data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The <code>byte</code> data type can be useful for saving memory in large <a href="http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html">arrays</a>, where the memory savings actually matters. They can also be used in place of <code>int</code> where their limits help to clarify your code; the fact that a variable's range is limited can serve as a form of documentation.  </li>
    <li><strong>short</strong>: The <code>short</code> data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive). As with <code>byte</code>, the same guidelines apply: you can use a <code>short</code> to save memory in large arrays, in situations where the memory savings actually matters.  </li>
    <li><strong>int</strong>: The <code>int</code> data type is a 32-bit signed two's complement integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive). For integral values, this data type is generally the default choice unless there is a reason (like the above) to choose something else. This data type will most likely be large enough for the numbers your program will use, but if you need a wider range of values, use <code>long</code> instead.  </li>
    <li><strong>long</strong>: The <code>long</code> data type is a 64-bit signed two's complement integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive). Use this data type when you need a range of values wider than those provided by <code>int</code>.  </li>
    <li><strong>float</strong>: The <code>float</code> data type is a single-precision 32-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in section <a href="http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3">4.2.3</a> of the Java Language Specification. As with the recommendations for <code>byte</code> and <code>short</code>, use a <code>float</code> (instead of <code>double</code>) if you need to save memory in large arrays of floating point numbers. This data type should never be used for precise values, such as currency. For that, you will need to use the <a href="http://java.sun.com/javase/6/docs/api/java/math/BigDecimal.html">java.math.BigDecimal</a> class instead. <a href="http://java.sun.com/docs/books/tutorial/java/data/index.html">Numbers and Strings</a> covers <code>BigDecimal</code> and other useful classes provided by the Java platform.  </li>
    <li><strong>double</strong>: The <code>double</code> data type is a double-precision 64-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in section <a href="http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3">4.2.3</a> of the Java Language Specification. For decimal values, this data type is generally the default choice. As mentioned above, this data type should never be used for precise values, such as currency.  </li>
    <li><strong>boolean</strong>: The <code>boolean</code> data type has only two possible values: <code>true</code> and <code>false</code>. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its "size" isn't something that's precisely defined.  </li>
    <li><strong>char</strong>: The <code>char</code> data type is a single 16-bit Unicode character. It has a minimum value of <code>'\u0000'</code> (or 0) and a maximum value of <code>'\uffff'</code> (or 65,535 inclusive). </li>
</ul>
<p>&nbsp;</p>
<table unselectable="on" border="0" cellpadding="2" cellspacing="0" width="828">
    <tbody>
        <tr>
            <td valign="top" width="173">
            <p><strong>类型名称</strong></p>
            </td>
            <td valign="top" width="177"><strong>类型定义</strong></td>
            <td valign="top" width="474"><strong>类型取值</strong></td>
        </tr>
        <tr>
            <td valign="top" width="173"><em>boolean</em></td>
            <td valign="top" width="177">布尔值</td>
            <td valign="top" width="473"><em>true</em>, <em>false</em></td>
        </tr>
        <tr>
            <td valign="top" width="173"><em>byte</em></td>
            <td valign="top" width="177">8位<strong>有符号整数</strong></td>
            <td valign="top" width="473">最小值-128，最大值127</td>
        </tr>
        <tr>
            <td valign="top" width="173"><em>short</em></td>
            <td valign="top" width="177">16位<strong>有符号整数</strong></td>
            <td valign="top" width="472">
            <p>最小值-32768（-2<sup>15</sup>），最大值32767（2<sup>15</sup>-1）</p>
            </td>
        </tr>
        <tr>
            <td valign="top" width="173"><em>int</em></td>
            <td valign="top" width="177">32位<strong>有符号整数</strong></td>
            <td valign="top" width="472">最小值-2147483648（-2<sup>31</sup>），最大值2147483647（2<sup>31</sup>-1）</td>
        </tr>
        <tr>
            <td valign="top" width="173"><em>long</em></td>
            <td valign="top" width="177">64位<strong>有符号整数</strong></td>
            <td valign="top" width="472">
            <p>-2<sup>63</sup>~(2<sup>63</sup>-1)</p>
            </td>
        </tr>
        <tr>
            <td valign="top" width="173"><em>float</em></td>
            <td valign="top" width="177">32位浮点数</td>
            <td valign="top" width="472">
            <p>1.4E-45~3.4028235E38</p>
            </td>
        </tr>
        <tr>
            <td valign="top" width="173"><em>double</em></td>
            <td valign="top" width="177">64位浮点数</td>
            <td valign="top" width="472">4.9E-324~1.7976931348623157E308</td>
        </tr>
        <tr>
            <td valign="top" width="173">char</td>
            <td valign="top" width="177">16位Unicode字符</td>
            <td valign="top" width="472">&nbsp;</td>
        </tr>
        <tr>
            <td valign="top" width="173">&nbsp;</td>
            <td valign="top" width="177">&nbsp;</td>
            <td valign="top" width="472">&nbsp;</td>
        </tr>
    </tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div class="ad_in_page"> <script type="text/javascript"><!--
google_ad_client = "pub-7843511305731432";
google_ad_width =" 468;
google_ad_height" = 60;
google_ad_format =" "468x60_as";
google_ad_type" = "text_image";
//2007-07-22: test
google_ad_channel =" "2043099642";
google_color_border" = "ffffff";
google_color_bg =" "ffffff";
google_color_link" = "ffffff";
google_color_text =" "000000";
google_color_url" = "000033";
//-->
</script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script> </div><img src ="http://www.blogjava.net/cherishchen/aggbug/132720.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/cherishchen/" target="_blank">凭栏观海</a> 2007-07-27 11:11 <a href="http://www.blogjava.net/cherishchen/archive/2007/07/27/132720.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>hibernate 事务</title><link>http://www.blogjava.net/cherishchen/archive/2007/07/27/132719.html</link><dc:creator>凭栏观海</dc:creator><author>凭栏观海</author><pubDate>Fri, 27 Jul 2007 03:09:00 GMT</pubDate><guid>http://www.blogjava.net/cherishchen/archive/2007/07/27/132719.html</guid><wfw:comment>http://www.blogjava.net/cherishchen/comments/132719.html</wfw:comment><comments>http://www.blogjava.net/cherishchen/archive/2007/07/27/132719.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/cherishchen/comments/commentRss/132719.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/cherishchen/services/trackbacks/132719.html</trackback:ping><description><![CDATA[<p>Hibernate does not lock objects in memory. Your application can expect the behavior as defined by the isolation level of your database transactions. </p> <p><strong>Note that thanks to the Session, which is also a transaction-scoped cache, Hibernate provides <font color="#ff0000">repeatable reads</font> for lookup by identifier and entity queries (not reporting queries that return scalar values).</strong></p> <p><strong>Hibernate 没有提供在内存中对对象加锁的功能，因此应用的事务隔离级别是完全由数据库来提供的。</strong></p> <p><strong>借助于session，Hibernate 提供了可重复读的事务隔离级别，但是前提是</strong><strong>只有使用identifier and entity queries的可以，使用标量查询则不可以，其原因是hibernate的cache的对象需要是能够被唯一识别的实体对象，标量查询返回的结果是数组，不满足该要求，无法在session级别进行事务的cache</strong></p> <p><strong>在事务和并发性方面，hibernate不仅提供了基于版本的控制的自动乐观锁机制，同时还提供了API来实现悲观锁机制（通过SELECT FOR UPDATE 语法）</strong></p> <p>A SessionFactory is an expensive-to-create, threadsafe object intended to be shared by all application threads. It is created once, usually on application startup, from a Configuration instance.  <p>A Session is an inexpensive, non-threadsafe object that should be used once, for a single request, a conversation, single unit of work, and then discarded. A Session will not obtain a JDBC Connection (or a Datasource) unless it is needed, hence consume no resources until used.  <p>Database transactions are never optional, all communication with a database has to occur inside a transaction, no matter if you read or write data.  <p>事务并不是可有可无的，所有的数据库操作都是在事务环境下发生的，<strong>不管是read 操作</strong>还是write操作。这点一定要名明确，以前曾经误解。  <p>As explained, auto-commit behavior for reading data should be avoided, as many small transactions are unlikely to perform better than one clearly defined unit of work. The latter is also much more maintainable and extensible.  <p>最好关闭自动提交功能，因为使用大量的短数据库事务在性能上未必比一个清晰定义的unit work强，后者更加易于维护和扩展。（以前曾经误解）  <p>&nbsp;  <h4><strong>乐观锁的处理方式</strong></h4> <p>Hibernate checks instance versions at flush time, throwing an exception if concurrent modification is detected.It's up to the developer to catch and handle this exception (common options are the opportunity for the user to merge changes or to restart the business conversation with non-stale data).  <p>在flush的时候检查version，如果发现更改会抛出异常，开发人员可以捕捉该异常，并决定如何处理（要么合并修改，要么放弃修改）  <h4><strong>悲观锁的处理方式</strong></h4> <p>悲观锁基本上是靠数据库本身提供的机制来实现，通常只要为jdbc connection指定事务隔离的级别即可。The LockMode class defines the different lock levels that may be acquired by Hibernate.  <p>悲观锁会在读取数据之前获取，因此能够保证当前事务的数据就是最新数据。  <p>&nbsp;</p> <h3><strong>hibernate的查询分类：</strong></h3> <p><strong>1、标量查询（Scalar queries）：返回的记录数组的集合</strong></p> <p>标量是与数组相对的概念，是一种由单一的值来表征的量。所谓标量查询，就是直接使用原生sql语句的查询，也即返回的是裸数据（只不过hibernate使用<code>ResultSetMetaData将resultset中的每一条记录放到一个数组Object[]中</code>）。</p> <p>比如</p> <p>List list = session.createSQLQuery("select * from t_area_person").list();</p> <p>for (Object object : list) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Object[] ob = (Object[]) object;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; ob.length; i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.print("&nbsp; " +ob[i]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }  <p>&nbsp;  <p><strong>2、实体查询(Entity queries)：返回的是实体对象的集合</strong></p> <p><strong>3、Load方法：lookup by identifier ，返回的是该identifier 对应的对象</strong></p><img src ="http://www.blogjava.net/cherishchen/aggbug/132719.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/cherishchen/" target="_blank">凭栏观海</a> 2007-07-27 11:09 <a href="http://www.blogjava.net/cherishchen/archive/2007/07/27/132719.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>java语言中的bit 移位操作</title><link>http://www.blogjava.net/cherishchen/archive/2007/07/27/132717.html</link><dc:creator>凭栏观海</dc:creator><author>凭栏观海</author><pubDate>Fri, 27 Jul 2007 03:08:00 GMT</pubDate><guid>http://www.blogjava.net/cherishchen/archive/2007/07/27/132717.html</guid><wfw:comment>http://www.blogjava.net/cherishchen/comments/132717.html</wfw:comment><comments>http://www.blogjava.net/cherishchen/archive/2007/07/27/132717.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/cherishchen/comments/commentRss/132717.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/cherishchen/services/trackbacks/132717.html</trackback:ping><description><![CDATA[<div class="ad_in_page"> <script type="text/javascript"><!--
google_ad_client = "pub-7843511305731432";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
//2007-07-22: test
google_ad_channel = "2043099642";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "FFFFFF";
google_color_text = "000000";
google_color_url = "000033";
//-->
</script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script> </div>  <div class="ad_in_page">&nbsp;</div> <h4><strong>java 位操作符：</strong></h4> <p><strong>取反：</strong>~x<br>- flips each bit to the opposite value.  <p><b>与操作：AND</b>  <p>x &amp; y<br>- AND operation between the corresponding bits in x and y.  <p><b>或操作：OR</b><br>x | y<br>- OR operation between the corresponding bits in x and y.  <p><b>异或操作：XOR</b><br>x ^ y<br>- XOR operation between the corresponding bits in x and y.  <p><strong>左移操作：Shift left</strong><br>x &lt;&lt; y<br>- shifts x to the left by y bits. The high order bits are lost while zeros fill the right bits.  <p>将x左移y位，移动过程中，高位会丢失  <p><b>有符号数右移操作：Shift Right - Signed</b><br>x &gt;&gt; y<br>- shifts x to the right by y bits. The low order bits are lost while the sign bit value (0 for positive numbers, 1 for negative) fills in the left bits.  <p><b>无符号数右移：Shift Right - Unsigned</b><br>x &gt;&gt;&gt; y <br>- shifts x to the right by y bits. The low order bits are lost while zeros fill in the left bits regardless of the sign.  <h4><strong>例子：</strong></h4> <p>下面的例子显示如何将一个int数组通过移位操作压缩到一个int内保存，其原理是在java语言中，int类型使用4 bytes来保存，因此对于需要压缩的int数组，其中的每一个int值的大小不能超过255（2的8次方-1），因此这只是一个实例：</p> <p>&nbsp;&nbsp;int [] aRGB = {0x56, 0x78, 0x9A, 0xBC};&nbsp;&nbsp;&nbsp;//&nbsp;是用16进制保存的4种颜色值<br>&nbsp;&nbsp;int color_val = aRGB[3];&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;color_val = color_val | (aRGB[2] &lt;&lt; 8);&nbsp; //&nbsp;为了压缩，需要放置到color_val值的第二个字节位置上：将aRGB[2]&nbsp;左移到第二个byte，同时与color_val进行或操作，下面同理<br>&nbsp;&nbsp;color_val = color_val | (aRGB[1] &lt;&lt; 16);&nbsp;&nbsp;<br>&nbsp;&nbsp;color_val = color_val | (aRBG[0] &lt;&lt; 24);  <p>操作完的结果是56 78 9A BC  <p>如果要从colorVal 还原为int数组，或者得到数组中的某个值，只需要对colorVal 进行相应的右移操作即可：  <p>&nbsp;&nbsp;int alpha_val = (colorVal &gt;&gt;&gt; 24) &amp; 0xFF;<br>&nbsp;&nbsp;int red_val &nbsp;&nbsp;= (colorVal &gt;&gt;&gt; 16) &amp; 0xFF;<br>&nbsp;&nbsp;int green_val = (colorVal &gt;&gt;&gt; &nbsp;8) &amp; 0xFF;<br>&nbsp;&nbsp;int blue_val &nbsp;= &nbsp;colorVal &amp; 0xFF;  <p>参考资料：  <p><a href="http://www.particle.kth.se/%7Elindsey/JavaCourse/Book/Part1/Tech/Chapter10/bits.html" target="_blank">Bits in Java</a></p><img src ="http://www.blogjava.net/cherishchen/aggbug/132717.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/cherishchen/" target="_blank">凭栏观海</a> 2007-07-27 11:08 <a href="http://www.blogjava.net/cherishchen/archive/2007/07/27/132717.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>事务相关资料</title><link>http://www.blogjava.net/cherishchen/archive/2007/07/26/132554.html</link><dc:creator>凭栏观海</dc:creator><author>凭栏观海</author><pubDate>Thu, 26 Jul 2007 07:07:00 GMT</pubDate><guid>http://www.blogjava.net/cherishchen/archive/2007/07/26/132554.html</guid><wfw:comment>http://www.blogjava.net/cherishchen/comments/132554.html</wfw:comment><comments>http://www.blogjava.net/cherishchen/archive/2007/07/26/132554.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/cherishchen/comments/commentRss/132554.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/cherishchen/services/trackbacks/132554.html</trackback:ping><description><![CDATA[<p>ACID (原子性、一致性、孤立性和持久性)；  <p>&nbsp;  <p>事务级别：  <p>1&gt;.READ UNCOMMITTED&nbsp;&nbsp;&nbsp; 效率高,但可能会有脏数据(修改数据时不排他读);  <p>2&gt;.READ COMMITTED&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 避免了脏数据(修改数据时排他读);  <p>3&gt;. REPEATABLE READ&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 对满足条件的数据行集进行锁定，不允许其他事务修改和删除;  <p>4&gt;.SERIALABLE READ&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 最高级别,禁止对(数据行集甚至整个数据表）插入，因此能够防止幻影读的发生;  <p>&nbsp;  <p>常用的事务属性：</p> <p>1&gt;.Required 必须运行在事务中,没有现成的就新建一个;  <p>2&gt;.RequiresNew 指明每次运行都必须新建一个事务;  <p>3&gt;.Supports 如目前正处于事务中的话就加入到事务中去,没有就算了;  <p>4&gt;.Mandatory 必须有一个事务正在运行让其加入,否则抛出异常;  <p>5&gt;.NotSupported 不需要运行于任何事务中;  <p>6&gt;.Never 不但不会运行于任何事务中,如果发现运行在事务中会抛出异常。</p><img src ="http://www.blogjava.net/cherishchen/aggbug/132554.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/cherishchen/" target="_blank">凭栏观海</a> 2007-07-26 15:07 <a href="http://www.blogjava.net/cherishchen/archive/2007/07/26/132554.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Jakarta Commons Lang 功能</title><link>http://www.blogjava.net/cherishchen/archive/2007/07/26/132492.html</link><dc:creator>凭栏观海</dc:creator><author>凭栏观海</author><pubDate>Thu, 26 Jul 2007 04:14:00 GMT</pubDate><guid>http://www.blogjava.net/cherishchen/archive/2007/07/26/132492.html</guid><wfw:comment>http://www.blogjava.net/cherishchen/comments/132492.html</wfw:comment><comments>http://www.blogjava.net/cherishchen/archive/2007/07/26/132492.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/cherishchen/comments/commentRss/132492.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/cherishchen/services/trackbacks/132492.html</trackback:ping><description><![CDATA[<div class="ad_in_page"> <script type="text/javascript"><!--
google_ad_client = "pub-7843511305731432";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
//2007-07-22: test
google_ad_channel = "2043099642";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "FFFFFF";
google_color_text = "000000";
google_color_url = "000033";
//-->
</script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script> </div>  <p>今天看到Jakarta Commons Lang，发现提供了很多有用的功能,记录下来，留待以后查阅</p> <p>The Commons Lang library provides much needed additions to the standard JDK's java.lang package. Very generic, very reusable components for everyday use.</p> <h2>lang.*</h2> <h5><strong>String manipulation&nbsp;-StringUtils, StringEscapeUtils, RandomStringUtils, Tokenizer, WordUtils</strong></h5> <p>StringEscapeUtils contains methods to escape and unescape Java, JavaScript, HTML, XML and SQL.</p> <p>RandomStringUtils speaks for itself. It's provides ways in which to generate pieces of text, such as might be used for default passwords.</p> <h5><strong>Character handling - CharSetUtils, CharSet, CharRange, CharUtils</strong></h5> <p><strong>CharUtils</strong> exists for this purpose, while CharSetUtils exists for set-manipulation of Strings.Be careful, although CharSetUtils takes an argument of type String, it is only as a set of characters. For example, <code>CharSetUtils.delete("testtest", "tr")</code> will remove all t's and all r's from the String, not just the String "tr".</p> <h5><strong>JVM interaction - SystemUtils, CharEncoding</strong></h5> <p><strong>SystemUtils</strong> is a simple little class which makes it easy to find out information about which platform you are on。</p> <p>The CharEncoding class is also used to interact with the Java environment and may be used to see which character encodings are supported in a particular environment.</p> <h5><strong>Serialization - SerializationUtils, SerializationException</strong></h5> <p>&nbsp;</p> <h5><strong>Assorted functions - ObjectUtils, ClassUtils, ArrayUtils, BooleanUtils</strong></h5> <p>ClassUtils is largely a set of helper methods for reflection. Of special note are the comparators hidden away in ClassUtils, useful for sorting Class and Package objects by name。</p> <p>ArrayUtils. This is a big one with many methods and many overloads of these methods so it is probably worth an in depth look here. Before we begin, assume that every method mentioned is overloaded for all the primitives and for Object. Also, the short-hand 'xxx' implies a generic primitive type, but usually also includes Object.</p> <h5><strong>Flotsam - BitField, Validate</strong></h5> <p>On reaching the end of our package, we are left with a couple of classes that haven't fit any of the topics so far.  <p>The BitField class provides a wrapper class around the classic bitmask integer, whilst the Validate class may be used for assertions  <h2>lang.builder.*</h2> <p>HashCodeBuilder will save your day. It, and its buddies (EqualsBuilder, CompareToBuilder, ToStringBuilder), take care of the nasty bits while you focus on the important bits, like which fields will go into making up the hashcode.</p> <p>帮助提供equals、compare、toString方法</p> <h2>lang.enums.* (formerly lang.enum) </h2> <h2>lang.exception.*</h2> <h2>lang.math.*</h2> <p>These include classes to represent ranges of numbers, a Fraction class, various utilities for random numbers, and the flagship class, NumberUtils which contains a handful of classic number functions.</p> <h3>lang.mutable.*</h3> <p>mutable package provides mutable wrappers for primitive values (such as int, long, etc.) and Object. These wrappers are simiar to the wrappers provided by the Java API, but allow the wrapped value to <strong>be changed without needing to create a separate wrapper object.</strong></p> <h3>lang.text.*</h3> <p>It provides, amongst other classes, a replacement for StringBuffer named <code>StrBuilder</code>, a class for substituting variables within a String named <code>StrSubstitutor</code> and a replacement for StringTokenizer named <code>StrTokenizer</code>. While somewhat ungainly, the <code>Str</code> prefix has been used to ensure we don't clash with any current or future standard Java classes.</p> <h3>lang.time.*</h3> <p>These include a StopWatch for simple performance measurements and an optimised FastDateFormat class.</p><img src ="http://www.blogjava.net/cherishchen/aggbug/132492.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/cherishchen/" target="_blank">凭栏观海</a> 2007-07-26 12:14 <a href="http://www.blogjava.net/cherishchen/archive/2007/07/26/132492.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>