﻿<?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/seosyw/</link><description>微商网</description><language>zh-cn</language><lastBuildDate>Sun, 12 Apr 2026 07:55:01 GMT</lastBuildDate><pubDate>Sun, 12 Apr 2026 07:55:01 GMT</pubDate><ttl>60</ttl><item><title>Java开发小技巧</title><link>http://www.blogjava.net/seosyw/archive/2015/01/01/422009.html</link><dc:creator>董超洪</dc:creator><author>董超洪</author><pubDate>Thu, 01 Jan 2015 14:35:00 GMT</pubDate><guid>http://www.blogjava.net/seosyw/archive/2015/01/01/422009.html</guid><wfw:comment>http://www.blogjava.net/seosyw/comments/422009.html</wfw:comment><comments>http://www.blogjava.net/seosyw/archive/2015/01/01/422009.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/seosyw/comments/commentRss/422009.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/seosyw/services/trackbacks/422009.html</trackback:ping><description><![CDATA[<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">1.在连接字符串的时候尽量避免使用String= "str"+"str2"; 而使用StringBuffer str = newStringBuffer("str");str.append("str2")代替</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　2. 多使用PreparedStatement代替Statement 这样可以避免在拼接字符串的时候出现"select* fromtablename where col = '"+col+"'"单引号过多的情况，3在拚接查询语句的时候加上"where1=1 "道理：当你有很多查询条件的时候，你不知道那些个会有，哪些个没有，如果一个没有的话，是不是就不用where 子句了呢</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　3.如果只有一个条件的话，是不是只要一个where 子句就搞定了呢?又如果有2 个以上，就需要用and 来连接了。。基于上诉的情况，勤劳的程序员们想出了一个好用的办法，加个where 1=1后面不管有多少个条件有则加and，没有的话就什么都不用做，相比较之前的3 中情况的判断来说，比较方便。这种sql 开关代码，可是编程中的大忌啊!首先这么写的目的是预留开关，给今后参数的改变带来方便，但这样同时会造成数据库对该条语句的explainplan 不能做到完全稳定不变，而且也会造成代码不能被sgaping 在内存里，如果是频繁被调用的代码会造成很严重的性能问题，深入的原理大家可以从dba 方面的书籍中找到。这种开关代码在10 来年前大行其道，但现在随着各公司水平的提高基本都能根据自身需要实现个性化的orm 层了，所以早已经被证明是不好的设计。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　4.多使用MessageFormat类</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　5.代码中尽量少出现"123".equals(str)这样的危险字符，而要public static final StringSTR = "123"; STR.equals(str)去代替.</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　6.方法的命名要能够表达出方法的功能在for 循环里要注意for(int i = 0; i &lt; 调用某个方法返回值;i++)这种写法要改成 int y = 调用某个方法返回值;for(int i = 0;i &lt; y;i++)</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　(1) 使用Integer.valueOf()代替new Integer();</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　(2) if (result.size() &gt; 0) return true;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　return false; 可以优化为returnreturn result.size()&gt;0</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　(3) 使用"const".eqauls(variable)代替variable.eqauls("const")避免nullpoint exception</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　(4) 在使用字串的拼接的时候,建议使用StringBuffer 代替String</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　(5) 在进行数据库操作的时候用PreparedStatement代替Statement,可以避免因为引号过多而引起的错误</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　(6) 在进行复杂查询语句的拼接的时候,建议加上"where 1=1",当然在不考虑数据库的性能.</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　(7)try{}catch(Exception e){}finally{if(conn!=null){conn.colse();conn==null}}在使用数据库操作的时候尽量多用finally 语句，进行资源的释放。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　(8) 在进行多异常捕获的时候，最后建议加上Exception异常做没有考虑到的异常捕获，比如try{}catch(OtherException e){}catch(Exception e){}finally{if(conn!=null){conn.colse();conn==null}}</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　(9) 给每个if(condition){}都加上大括号，即使里面只有一句话,加强程序的可读性</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　(10)能用常量的东西都要用常量来完成，避免使用硬编码,增加可维护性质。比如少用String str ="123"使用private static final CONST ="123" ; String str = CONST;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　(11) 定义的静态的常量用全大写，方法名开头用小写，类名用大写。在bean 中定义的变量名用小写，并且所有的名字命名要体现出业务的特性。呵呵，这里说到了规范。。。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　(12) 多看看Apache 下的一些Utils 包吧!方便实用，必备工具!</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　(13) 可以用for(inti= 100;i&gt;0;i--;)去代替for(inti = 0;i &lt;100;i++) 这样可以提高程序的运行速度</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　(14) 写注释有助于写出逻辑清晰的代码</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　(15) 用字符分隔多字符串时，为了防止字符串中有设定的分隔符，我采用如下字符进行分隔(c#的，<strong>JAVA</strong><span class="Apple-converted-space">&nbsp;</span>也差不多)char char2 = '\x0012';string strreg = ""; strreg += char2;</p><img src ="http://www.blogjava.net/seosyw/aggbug/422009.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/seosyw/" target="_blank">董超洪</a> 2015-01-01 22:35 <a href="http://www.blogjava.net/seosyw/archive/2015/01/01/422009.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>介绍J2ME编程中的几个重要概念</title><link>http://www.blogjava.net/seosyw/archive/2015/01/01/422007.html</link><dc:creator>董超洪</dc:creator><author>董超洪</author><pubDate>Thu, 01 Jan 2015 14:34:00 GMT</pubDate><guid>http://www.blogjava.net/seosyw/archive/2015/01/01/422007.html</guid><wfw:comment>http://www.blogjava.net/seosyw/comments/422007.html</wfw:comment><comments>http://www.blogjava.net/seosyw/archive/2015/01/01/422007.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/seosyw/comments/commentRss/422007.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/seosyw/services/trackbacks/422007.html</trackback:ping><description><![CDATA[<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">我们都知道，<strong>Java（<a style="color: rgb(11,59,140); font-size: 12px; text-decoration: underline" href="http://www.xinfengit.com/col34/" target="_blank">Java教程</a><span class="Apple-converted-space">&nbsp;</span><a style="color: rgb(11,59,140); font-size: 12px; text-decoration: underline" href="http://training.xinfengit.com/java/" target="_blank">Java培训</a><span class="Apple-converted-space">&nbsp;</span>）</strong><span class="Apple-converted-space">&nbsp;</span>ME 以往称作<strong>J2ME（<a style="color: rgb(11,59,140); font-size: 12px; text-decoration: underline" href="http://training.xinfengit.com/j2ee/" target="_blank">J2ME培训</a><span class="Apple-converted-space">&nbsp;</span>）</strong>(Java Platform，Micro Edition)，是为机顶盒、移动电话和PDA之类嵌入式消费电子设备提供的Java语言平台，包括虚拟机和一系列标准化的Java API。它和Java SE、Java EE一起构成Java技术的三大版本，并且同样是通过JCP(Java Community Process)制订的。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　J2ME平台中有几个重要的概念，例如内存、CLDC、MIDP等。初学J2ME往往对这些概念理解不深，甚至出现偏差。本文的目的在于对J2ME中的相关重要概念进行阐述。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　1. 内存</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　我们一直在强调，移动信息设备的内存非常小，使用起来应该加倍的珍惜，但是我们却很少知道这些内存是如何分类的，下面将做详细的介绍。事实上MIDP设备的内存分为三种，Programme Memory、Heap、persistent Storage。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Programme Memory是移动信息设备分配给MIDlet suite的空间，因为MIDlet suite是以jar文件进行发布的，所以这个文件的大小可以认为是Programme Memory的大小。一些厂商对Programme Memory的最大值是有限制的，例如我的Nokia 6108的最大值是 64k，超过的话将不能进行安装。减小MIDlet suite的大小非常重要，一个便捷的方法就是使用混淆器对应用程序进行混淆，这样可以减小jar文件的大小。在以后的文章中我会谈到如何使用 Proguard。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Heap是应用程序在运行过程中存放所创建的对象的存储空间，本地变量和成员变量也是放在Heap上的，MIDP设备中提供的Heap空间大概在几十k到几百K。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Persistent Storage的空间是用来实现MIDP应用程序的本地数据持久性存储的，在Record Management System从入门到精通中我做了详细的介绍这里就不再多说了。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　2. Connected Limited Device Configuration</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　CLDC包括一个<strong>Java</strong>虚拟机和一系列的基础类，J2ME的专家组经过对移动信息设备进行硬件抽象后得到他们的特点，然后设计并实现了在移动信息设备上运行的java虚拟机，通常我们把它叫做KVM。在CLDC1.0还同时提供了由java.io、java.lang、 javax.microediton.io、java.util组成的基础类。在CLDC1.1里面添加了java.lang.ref。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　3. Mobile Infomation Device Profile</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　MIDP是运行在CLDC基础之上的，在MIDP中定义了应用程序的生命周期、用户图形界面、数据管理系统等子集，从而构建起了J2ME平台。通常，<strong>J2ME</strong>平台由一个CLDC和一个或者多个Profile构成。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　希望通过以上内容的介绍，让你能更好的应用J2ME平台。</p><img src ="http://www.blogjava.net/seosyw/aggbug/422007.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/seosyw/" target="_blank">董超洪</a> 2015-01-01 22:34 <a href="http://www.blogjava.net/seosyw/archive/2015/01/01/422007.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java内存泄漏调试</title><link>http://www.blogjava.net/seosyw/archive/2014/11/21/420381.html</link><dc:creator>董超洪</dc:creator><author>董超洪</author><pubDate>Fri, 21 Nov 2014 01:06:00 GMT</pubDate><guid>http://www.blogjava.net/seosyw/archive/2014/11/21/420381.html</guid><wfw:comment>http://www.blogjava.net/seosyw/comments/420381.html</wfw:comment><comments>http://www.blogjava.net/seosyw/archive/2014/11/21/420381.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/seosyw/comments/commentRss/420381.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/seosyw/services/trackbacks/420381.html</trackback:ping><description><![CDATA[<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">JDK本身为调试内存泄漏问题提供了比较完善的工具。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　先用命令jps找出要调试的jvm的进程id(jps这个命令，就是ps命令前面加j，列出所有正在运行的jvm的进程id)。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　例如：jps</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　输出类似下面这样：15976<strong><span class="Apple-converted-space">&nbsp;</span>java</strong>_app.jar 7586 startup.jar 22476 Jps 12248 Main 5437 Bootstrap</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　假设我们要调试的进程id是15976.</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　如果只是想简单观察一下堆内存的使用情况，可以用命令jmap -histo：live 15976这个命令会输出指定的jvm上当前各个<strong>Java</strong>类的实例数、占用的内存大小和完整的类名。虚拟机内部类的类名前面有"*"标记。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　如果想得到堆内存使用的详细情况，可以用命令jmap -dump：live，format=b，file=/tmp/java_app-heap.bin 15976</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　这样在/tmp目录下得到一个java_app-heap.bin文件，其中保存的信息就是指定的jvm中堆内存的使用详情。这个二进制文件可以用JDK附带的jhat(Java Heap Analysis Tool)来分析：</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　jhat -J-Xmx326m /tmp/java_app-heap.bin</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　这个工具相当耗内存，如果出现了OutOfMemoryException的话，请加大-J-Xmx326m中指定的预留堆内存大小再试。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Jhat会解析堆内存信息转储文件(上面用jmap生成的。bin文件)，输出大概像下面这样：</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　lewis@mgr $ jhat -J-Xmx326m /tmp/java_app-heap.bin Reading from /tmp/java_app-heap.bin&#8230;&#8230;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Dump file created Thu Sep 08 20：08：14 CST 2011 Snapshot read， resolving&#8230;&#8230;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Resolving 71327 objects&#8230;&#8230;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Chasing references， expect 14 dots&#8230;&#8230;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Eliminating duplicate references&#8230;&#8230;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Snapshot resolved. Started HTTP server on port 7000 Server is ready.</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　注意最后两行：堆内存信息转储文件分析完毕后，jhat并不会将分析结果输出为一个静态文件。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　为了方便查找，以及在相关的类之间导航，jhat会启动一个服务，监听7000端口。这时候就可以用浏览器来浏览和分析结果了：在浏览器地址栏里输入：</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　http://localhost：7000</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　里面的各个页面都有很多链接，可以在相关的各个类及各种统计数据之间跳转，还是很方便的。</p><img src ="http://www.blogjava.net/seosyw/aggbug/420381.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/seosyw/" target="_blank">董超洪</a> 2014-11-21 09:06 <a href="http://www.blogjava.net/seosyw/archive/2014/11/21/420381.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>浅述Java枚举常见7种用法</title><link>http://www.blogjava.net/seosyw/archive/2014/11/21/420379.html</link><dc:creator>董超洪</dc:creator><author>董超洪</author><pubDate>Fri, 21 Nov 2014 01:03:00 GMT</pubDate><guid>http://www.blogjava.net/seosyw/archive/2014/11/21/420379.html</guid><wfw:comment>http://www.blogjava.net/seosyw/comments/420379.html</wfw:comment><comments>http://www.blogjava.net/seosyw/archive/2014/11/21/420379.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/seosyw/comments/commentRss/420379.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/seosyw/services/trackbacks/420379.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: DK1.5引入了新的类型&#8212;&#8212;枚举。在&nbsp;Java&nbsp;中它虽然算个&#8220;小&#8221;功能，却给我的开发带来了&#8220;大&#8221;方便。　　用法一：常量　　在JDK1.5 之前，我们定义常量都是： publicstaticfianl.... 。现在好了，有了枚举，可以把相关的常量分组到一个枚举类型里，而且枚举提供了比常量更多的方法。...&nbsp;&nbsp;<a href='http://www.blogjava.net/seosyw/archive/2014/11/21/420379.html'>阅读全文</a><img src ="http://www.blogjava.net/seosyw/aggbug/420379.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/seosyw/" target="_blank">董超洪</a> 2014-11-21 09:03 <a href="http://www.blogjava.net/seosyw/archive/2014/11/21/420379.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JAR文件操作基础</title><link>http://www.blogjava.net/seosyw/archive/2014/11/21/420377.html</link><dc:creator>董超洪</dc:creator><author>董超洪</author><pubDate>Fri, 21 Nov 2014 01:01:00 GMT</pubDate><guid>http://www.blogjava.net/seosyw/archive/2014/11/21/420377.html</guid><wfw:comment>http://www.blogjava.net/seosyw/comments/420377.html</wfw:comment><comments>http://www.blogjava.net/seosyw/archive/2014/11/21/420377.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/seosyw/comments/commentRss/420377.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/seosyw/services/trackbacks/420377.html</trackback:ping><description><![CDATA[<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">The<span class="Apple-converted-space">&nbsp;</span><strong>Java（<a style="color: rgb(11,59,140); font-size: 12px; text-decoration: underline" href="http://www.xinfengit.com/col34/" target="_blank">Java教程</a><span class="Apple-converted-space">&nbsp;</span><a style="color: rgb(11,59,140); font-size: 12px; text-decoration: underline" href="http://training.xinfengit.com/java/" target="_blank">Java培训</a><span class="Apple-converted-space">&nbsp;</span>）</strong><span class="Apple-converted-space">&nbsp;</span>Archive (JAR) File Format JAR文件是用ZIP文件格式打包的，所以你可以在一些类似ZIP的任务中使用它，进行压缩、解压、打包或者解开包。这些都是JAR文件最普遍的使用方式，你能发现许多JAR文件的优势都是源自这些基本的特点。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　即使你希望能够使用JAR中那些先进的功能比如电子签名，你也得先熟悉一些基本的操作方式。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　你可以使用<strong>Java</strong><span class="Apple-converted-space">&nbsp;</span>Archive Tool 来完成JAR文件操作。这个工具被包含在JDK中。因为Java Archive Tool 通过jar命令来调用，为了方便，我们也可以称它为jat tool.</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　下面是最基本的命令操作：</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　操作 命令创建一个JAR文件。 jar cf jar-file input-file(s)</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　查看JAR文件的内容 jar tf jar-file导出JAR文件 jar xf jar-file导出JAR文件中制定的文件包 jar xf jar-file archived-file(s)</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　运行JAR文件中的应用jre -cp app.jar MainClass运行用JAR格式打包的应用java -jar app.jar调用一个打包成JAR的applet<span class="Apple-converted-space">&nbsp;</span><applet archive="JarFileName.jar" code="AppletClassName.class" width="width" height="height"></applet>下面是一些详细的介绍：</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　创建JAR文件</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　jar -cf jar-file input-file(s)</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　其中c表示create，f表示file，后面紧跟jar-file.也可以增加一个v选项(verbose)，以显示详细信息 jar -cvf jar-file input-file(s)</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　其实这些命令跟常见的tar打包命令类似，方便记忆。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　另外，在1.2的版本中还设置了一种 -C 的选项。可以让某些文件夹中的文件直接被打包到根目录下，而没有原始的层次结构的束缚。如下例：jar cf ImageAudio.jar -C images * -C audio *结果是META-INF/MANIFEST.MF cross.gif nor.gif beep.au ding.au return.au yahoo1.au yahoo2.au</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　如果不用 -C选项，直接打包：</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　jar cf ImageAudio.jar images audio</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　结果如下：META-INF/MANIFEST.MF image/cross.gif image/nor.gif audio/beep.au audio/ding.au audio/return.au audio/yahoo1.au audio/yahoo2.au</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　查看JAR文件中的内容You can这时候并没有解压jar文件，直接查看文件内容。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　jar tvf TicTacToe.jar同样的，也可以增加 -v 选项(verbose)，显示详细的查看过程。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　解压JAR文件包</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　将jar文件包中的内容解压出来，在当前工作目录下(而不是jar文件包所在目录)创建解压文件包。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　当然，也可以定向的解压指定的文件。如下，其中仅有TicTacToe.class images/cross.gif将会被解压出来。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　jar xf TicTacToe.jar TicTacToe.class images/cross.gif</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　修改Manifest文件有不少修改Manifest文件的方法。这里介绍一种用jar指令修改的方法。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　有一个m选项，可以将用户自己编辑的manifest文件同其他文件夹一起打包为JAR文件。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　jar cmf manifest-addition jar-file input-file(s)</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　这里 manifest-addition 是用户自己编辑好的文本文件，文件名没有特殊要求，内容为需要写入JAR的manifest文件内容。其他的跟创建JAR文件一样。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　更新JAR文件</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　jar uf jar-file input-file(s)</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　当input-file(s)跟JAR文件中原有的文件同名时，则覆盖掉原来的文件。如果没有，则添加相应文件。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　添加修改Manifest文件的命令选项后，也可以实现对manifest的更新。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　jar umf manifest jar-file注意其中manifest为txt文件，内容是需要更新的manifest文件内容。jar-file则为对应的JAR文件。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Running JAR-Packaged Software</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　<strong>java</strong><span class="Apple-converted-space">&nbsp;</span>-jar jar-file</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　以上命令执行的条件是 JAR的Manifest文件中具有 Main-Class： 标记。这个标记标明了整个JAR为相应的主类服务，这个主类中必须含有static main 程序入口。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　理解Manifest文件</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　JAR文件能够支持许多功能，包括电子签名，版本控制，包加密，扩展等等。这些都是manifest文件的功劳!</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　manifest是一个特殊的文本文件，JAR文件包中所有文件的信息都可以包含在其中。通过在manifest中设置不同的值，你能给JAR包增添各种不同的特殊用途。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　在我们看各种不同的用途之前，先看看manifest的默认内容：文件的默认路径是</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　META-INF/MANIFEST.MF默认内容是</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Manifest-Version： 1.0这一行展示了manifest的基本的格式：键值对。键和值用"："分开。默认manifest中展示了版本号。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Manifest-Version： 1.0</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Name： java/math/BigDecimal.class</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　SHA1-Digest： TD1GZt8G11dXY2p4olSZPc5Rj64=</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　MD5-Digest： z6z8xPj2AW/Q9AKRSF0cg==</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Name：<span class="Apple-converted-space">&nbsp;</span><strong>java</strong>/math/BigInteger/class</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　SHA1-Digest：oB1GZt8G11dXY2p4olSZPc5Rj64=</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　MD5-Digest： z6z8xPj2AW/8HAKRSF0cg==</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　这里展示了JAR文件中，不同。class文件的不同属性。Name标记了不同的子文件，之后的SHA1_Digest则是对应文件的属性。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Main-Class： classname Mani-Class键标记了整个JAR文件运行的主类。即整个JAR作为一个应用运行时的程序入口。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Class-Path： servlet.jar infobus.jar acme/beans.jar Class-Path键标记了需要下载的扩展包。</p><img src ="http://www.blogjava.net/seosyw/aggbug/420377.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/seosyw/" target="_blank">董超洪</a> 2014-11-21 09:01 <a href="http://www.blogjava.net/seosyw/archive/2014/11/21/420377.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java线程安全总结</title><link>http://www.blogjava.net/seosyw/archive/2014/11/21/420378.html</link><dc:creator>董超洪</dc:creator><author>董超洪</author><pubDate>Fri, 21 Nov 2014 01:01:00 GMT</pubDate><guid>http://www.blogjava.net/seosyw/archive/2014/11/21/420378.html</guid><wfw:comment>http://www.blogjava.net/seosyw/comments/420378.html</wfw:comment><comments>http://www.blogjava.net/seosyw/archive/2014/11/21/420378.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/seosyw/comments/commentRss/420378.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/seosyw/services/trackbacks/420378.html</trackback:ping><description><![CDATA[<div style="text-align: left; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; -webkit-text-stroke-width: 0px" class="msgbody">
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">最近想将<strong>Java（<a style="color: rgb(11,59,140); font-size: 12px; text-decoration: underline" href="http://www.xinfengit.com/col34/" target="_blank">Java教程</a><span class="Apple-converted-space">&nbsp;</span><a style="color: rgb(11,59,140); font-size: 12px; text-decoration: underline" href="http://training.xinfengit.com/java/" target="_blank">Java培训</a><span class="Apple-converted-space">&nbsp;</span>）</strong>基础的一些东西都整理整理，写下来，这是对知识的总结，也是一种乐趣。已经拟好了提纲，大概分为这几个主题： java线程安全，java垃圾收集，java并发包详细介绍，java profile和jvm性能调优。慢慢写吧。本人jameswxx原创文章，转载请注明出处，我费了很多心血，多谢了。关于java线程安全，网上有很多资料，我只想从自己的角度总结对这方面的考虑，有时候写东西是很痛苦的，知道一些东西，但想用文字说清楚，却不是那么容易。我认为要认识java线程安全，必须了解两个主要的点：java的内存模型，java的线程同步机制。特别是内存模型，java的线程同步机制很大程度上都是基于内存模型而设定的。后面我还会写java并发包的文章，详细总结如何利用java并发包编写高效安全的多线程并发程序。暂时写得比较仓促，后面会慢慢补充完善。</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　浅谈<strong>java</strong>内存模型</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　不同的平台，内存模型是不一样的，但是jvm的内存模型规范是统一的。其实java的多线程并发问题最终都会反映在java的内存模型上，所谓线程安全无非是要控制多个线程对某个资源的有序访问或修改。总结java的内存模型，要解决两个主要的问题：可见性和有序性。我们都知道计算机有高速缓存的存在，处理器并不是每次处理数据都是取内存的。JVM定义了自己的内存模型，屏蔽了底层平台内存管理细节，对于java开发人员，要清楚在jvm内存模型的基础上，如果解决多线程的可见性和有序性。</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　那么，何谓可见性?多个线程之间是不能互相传递数据通信的，它们之间的沟通只能通过共享变量来进行。Java内存模型(JMM)规定了jvm有主内存，主内存是多个线程共享的。当new一个对象的时候，也是被分配在主内存中，每个线程都有自己的工作内存，工作内存存储了主存的某些对象的副本，当然线程的工作内存大小是有限制的。当线程操作某个对象时，执行顺序如下：</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　(1)从主存复制变量到当前工作内存(read and load)</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　(2)执行代码，改变共享变量值(use and assign)</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　(3)用工作内存数据刷新主存相关内容(store and write)</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　JVM规范定义了线程对主存的操作指令：read，load，use，assign，store，write.当一个共享变量在多个线程的工作内存中都有副本时，如果一个线程修改了这个共享变量，那么其他线程应该能够看到这个被修改后的值，这就是多线程的可见性问题。</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　那么，什么是有序性呢?线程在引用变量时不能直接从主内存中引用，如果线程工作内存中没有该变量，则会从主内存中拷贝一个副本到工作内存中，这个过程为read-load，完成后线程会引用该副本。当同一线程再度引用该字段时，有可能重新从主存中获取变量副本(read-load-use)，也有可能直接引用原来的副本(use)，也就是说 read，load，use顺序可以由JVM实现系统决定。</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　线程不能直接为主存中中字段赋值，它会将值指定给工作内存中的变量副本(assign)，完成后这个变量副本会同步到主存储区(store-write)，至于何时同步过去，根据JVM实现系统决定。有该字段，则会从主内存中将该字段赋值到工作内存中，这个过程为read-load，完成后线程会引用该变量副本，当同一线程多次重复对字段赋值时，比如：</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　Java代码</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　for(int i=0;i&lt;10;i++)</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　a++;线程有可能只对工作内存中的副本进行赋值，只到最后一次赋值后才同步到主存储区，所以assign，store，weite顺序可以由JVM实现系统决定。假设有一个共享变量x，线程a执行x=x+1.从上面的描述中可以知道x=x+1并不是一个原子操作，它的执行过程如下：</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　1、从主存中读取变量x副本到工作内存2、给x加1 3、将x加1后的值写回主 存</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　如果另外一个线程b执行x=x-1，执行过程如下：</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　1、从主存中读取变量x副本到工作内存2、给x减1 3、将x减1后的值写回主存</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　那么显然，最终的x的值是不可靠的。假设x现在为10，线程a加1，线程b减1，从表面上看，似乎最终x还是为10，但是多线程情况下会有这种情况发生：</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　1：线程a从主存读取x副本到工作内存，工作内存中x值为10 2：线程b从主存读取x副本到工作内存，工作内存中x值为10 3：线程a将工作内存中x加1，工作内存中x值为11 4：线程a将x提交主存中，主存中x为11 5：线程b将工作内存中x值减1，工作内存中x值为9 6：线程b将x提交到中主存中，主存中x为9</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　同样，x有可能为11，如果x是一个银行账户，线程a存款，线程b扣款，显然这样是有严重问题的，要解决这个问题，必须保证线程a和线程b是有序执行的，并且每个线程执行的加1或减1是一个原子操作。看看下面代码：</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　<strong>Java</strong>代码</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　public class Account {</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　private int balance;</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　public Account(int balance) { this.balance = balance;}</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　public int getBalance() { return balance;}</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　public void add(int num) { balance = balance + num;}</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　public void withdraw(int num) { balance = balance - num;}</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　public static void main(String[] args) throws InterruptedException { Account account = new Account(1000);Thread a = new Thread(new AddThread(account， 20)， "add");Thread b = new Thread(new WithdrawThread(account， 20)， "withdraw");a.start();b.start();a.join();b.join();System.out.println(account.getBalance());}</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　static class AddThread implements Runnable { Account account;int amount;</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　public AddThread(Account account， int amount) { this.account = account;this.amount = amount;}</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　public void run() { for (int i = 0; i &lt; 200000; i++) { account.add(amount);}</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　static class WithdrawThread implements Runnable { Account account;int amount;</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　public WithdrawThread(Account account， int amount) { this.account = account;this.amount = amount;}</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 25px; list-style-type: none; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-size: 14px; border-top: 0px; border-right: 0px; padding-top: 0px">　　public void run() { for (int i = 0; i &lt; 100000; i++) { account.withdraw(amount);}第一次执行结果为10200，第二次执行结果为1060，每次执行的结果都是不确定的，因为线程的执行顺序是不可预见的。这是java同步产生的根源，synchronized关键字保证了多个线程对于同步块是互斥的，synchronized作为一种同步手段，解决java多线程的执行有序性和内存可见性，而volatile关键字之解决多线程的内存可见性问题。后面将会详细介绍。</p></div><br class="Apple-interchange-newline" /><img src ="http://www.blogjava.net/seosyw/aggbug/420378.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/seosyw/" target="_blank">董超洪</a> 2014-11-21 09:01 <a href="http://www.blogjava.net/seosyw/archive/2014/11/21/420378.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>java的内存管理</title><link>http://www.blogjava.net/seosyw/archive/2014/11/21/420376.html</link><dc:creator>董超洪</dc:creator><author>董超洪</author><pubDate>Fri, 21 Nov 2014 01:00:00 GMT</pubDate><guid>http://www.blogjava.net/seosyw/archive/2014/11/21/420376.html</guid><wfw:comment>http://www.blogjava.net/seosyw/comments/420376.html</wfw:comment><comments>http://www.blogjava.net/seosyw/archive/2014/11/21/420376.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/seosyw/comments/commentRss/420376.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/seosyw/services/trackbacks/420376.html</trackback:ping><description><![CDATA[<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">1、<strong>Java</strong>的内存管理就是对象的分配和释放问题。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　在Java中，程序员需要通过关键字new为每个对象申请内存空间 (基本类型除外)，所有的对象都在堆 (Heap)中分配空间。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　对象的释放是由GC决定和执行的。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　在Java中，内存的分配是由程序完成的，而内存的释放是有GC完成的，这种收支两条线的方法简化了程序员的工作。但也加重了JVM的工作。这也是Java程序运行速度较慢的原因之一。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　GC释放空间方法：监控每一个对象的运行状态，包括对象的申请、引用、被引用、赋值等。当该对象不再被引用时，释放对象。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　2、内存管理结构Java使用有向图的方式进行内存管理，对于程序的每一个时刻，我们都有一个有向图表示JVM的内存分配情况。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　将对象考虑为有向图的顶点，将引用关系考虑为图的有向边，有向边从引用者指向被引对象。另外，每个线程对象可以作为一个图的起始顶点，例如大多程序从main进程开始执行，那么该图就是以main进程顶点开始的一棵根树。在这个有向图中，根顶点可达的对象都是有效对象，GC将不回收这些对象。如果某个对象 (连通子图)与这个根顶点不可达(注意，该图为有向图)，那么我们认为这个(这些)对象不再被引用，可以被GC回收。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　3、使用有向图方式管理内存的优缺点Java使用有向图的方式进行内存管理，可以消除引用循环的问题，例如有三个对象，相互引用，只要它们和根进程不可达的，那么GC也是可以回收它们的。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　这种方式的优点是管理内存的精度很高，但是效率较低。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　另外一种常用的内存管理技术是使用计数器，例如COM模型采用计数器方式管理构件，它与有向图相比，精度行低(很难处理循环引用的问题)，但执行效率很高。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　&#9733;<span class="Apple-converted-space">&nbsp;</span><strong>Java</strong>的内存泄露Java虽然由GC来回收内存，但也是存在泄露问题的，只是比C++小一点。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　1、与C++的比较c++所有对象的分配和回收都需要由用户来管理。即需要管理点，也需要管理边。若存在不可达的点，无法在回收分配给那个点的内存，导致内存泄露。存在无用的对象引用，自然也会导致内存泄露。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Java由GC来管理内存回收，GC将回收不可达的对象占用的内存空间。所以，Java需要考虑的内存泄露问题主要是那些被引用但无用的对象&#8212;&#8212;即指要管理边就可以。被引用但无用的对象，程序引用了该对象，但后续不会再使用它。它占用的内存空间就浪费了。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　如果存在对象的引用，这个对象就被定义为&#8220;活动的&#8221;，同时不会被释放。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　2、Java内存泄露处理处理Java的内存泄露问题：确认该对象不再会被使用。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　典型的做法&#8212;&#8212;把对象数据成员设为null从集合中移除该对象注意，当局部变量不需要时，不需明显的设为null，因为一个方法执行完毕时，这些引用会自动被清理。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　例子：view plain<span style="padding-bottom: 0px; line-height: 25px; padding-left: 5px; padding-right: 5px; float: left; height: 25px; padding-top: 0px">List myList=new ArrayList();for (int i=1;i&lt;100; i++)</span></p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　{ Object o=new Object();myList.add(o);o=null;} //此时，所有的Object对象都没有被释放，因为变量myList引用这些对象。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　当myList后来不再用到，将之设为null，释放所有它引用的对象。之后GC便会回收这些对象占用的内存。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　&#9733; 对GC操作对GC的操作并不一定能达到管理内存的效果。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　GC对于程序员来说基本是透明的，不可见的。我们只有几个函数可以访问GC，例如运行GC的函数System.gc()，System.。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　但是根据Java语言规范定义， System.gc()函数不保证JVM的垃圾收集器一定会执行。因为，不同的JVM实现者可能使用不同的算法管理GC.通常，GC的线程的优先级别较低。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　JVM调用GC的策略有很多种，有的是内存使用到达一定程度时，GC才开始工作，也有定时执行的，有的是平缓执行GC，有的是中断式执行GC.但通常来说，我们不需要关心这些。除非在一些特定的场合，GC的执行影响应用程序的性能，例如对于基于Web的实时系统，如网络游戏等，用户不希望GC突然中断应用程序执行而进行垃圾回收，那么我们需要调整GC的参数，让GC能够通过平缓的方式释放内存，例如将垃圾回收分解为一系列的小步骤执行，Sun提供的HotSpot JVM就支持这一特性。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　&#9733; 内存泄露检测市场上已有几种专业检查<strong>Java</strong>内存泄漏的工具，它们的基本工作原理大同小异，都是通过监测Java程序运行时，所有对象的申请、释放等动作，将内存管理的所有信息进行统计、分析、可视化。开发人员将根据这些信息判断程序是否有内存泄漏问题。这些工具包括Optimizeit Profiler，JProbe Profiler，JinSight ， Rational 公司的Purify等。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　在运行过程中，我们可以随时观察内存的使用情况，通过这种方式，我们可以很快找到那些长期不被释放，并且不再使用的对象。我们通过检查这些对象的生存周期，确认其是否为内存泄露。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　&#9733; 软引用特点：只有当内存不够的时候才回收这类内存，同时又保证在Java抛出OutOfMemory异常之前，被设置为null.保证最大限度的使用内存而不引起OutOfMemory异常。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　在某些时候对软引用的使用会降低应用的运行效率与性能，例如：应用软引用的对象的初始化过程较为耗时，或者对象的状态在程序的运行过程中发生了变化，都会给重新创建对象与初始化对象带来不同程度的麻烦。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　用途：可以用于实现一些常用资源的缓存，实现Cache的功能处理一些占用内存大而且声明周期较长，但使用并不频繁的对象时应尽量应用该技术&#9733; java程序设计中有关内存管理的经验1.最基本的建议是尽早释放无用对象的引用。如：view plain<span style="padding-bottom: 0px; line-height: 25px; padding-left: 5px; padding-right: 5px; float: left; height: 25px; padding-top: 0px">&#8230;&#8230;</span></p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　A a = new A();//应用a对象a = null; //当使用对象a之后主动将其设置为空&#8230;。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　注：如果a 是方法的返回值，不要做这样的处理，否则你从该方法中得到的返回值永远为空，而且这种错误不易被发现、排除2.尽量少用finalize函数。它会加大GC的工作量。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　3.如果需要使用经常用到的图片，可以使用soft应用类型。它尽可能把图片保存在内存中4.注意集合数据类型，包括数组、树、图、链表等数据结构，这些数据结构对GC来说，回收更为复杂。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　5.尽量避免在类的默认构造器中创建、初始化大量的对象，防止在调用其自类的构造器时造成不必要的内存资源浪费6.尽量避免强制系统做垃圾内存的回收，增长系统做垃圾回收的最终时间7.尽量避免显式申请数组空间8.尽量做远程方法调用类应用开发时使用瞬间值变量，除非远程调用端需要获取该瞬间值变量的值。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　9.尽量在合适的场景下使用对象池技术以提高系统性能。</p><img src ="http://www.blogjava.net/seosyw/aggbug/420376.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/seosyw/" target="_blank">董超洪</a> 2014-11-21 09:00 <a href="http://www.blogjava.net/seosyw/archive/2014/11/21/420376.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java程序连接各种数据库的方法</title><link>http://www.blogjava.net/seosyw/archive/2014/10/28/419145.html</link><dc:creator>董超洪</dc:creator><author>董超洪</author><pubDate>Tue, 28 Oct 2014 14:15:00 GMT</pubDate><guid>http://www.blogjava.net/seosyw/archive/2014/10/28/419145.html</guid><wfw:comment>http://www.blogjava.net/seosyw/comments/419145.html</wfw:comment><comments>http://www.blogjava.net/seosyw/archive/2014/10/28/419145.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/seosyw/comments/commentRss/419145.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/seosyw/services/trackbacks/419145.html</trackback:ping><description><![CDATA[<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">1、Oracle8/8i/9i数据库（<a style="color: rgb(11,59,140); font-size: 12px; text-decoration: underline" href="http://training.xinfengit.com/shujuku/" target="_blank">数据库培训</a><span class="Apple-converted-space">&nbsp;</span><a style="color: rgb(11,59,140); font-size: 12px; text-decoration: underline" href="http://cert.xinfengit.com/Database/" target="_blank">数据库认证</a><span class="Apple-converted-space">&nbsp;</span>）(thin模式)</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Class.forName(&#8220;oracle.jdbc.driver.OracleDriver&#8221;).newInstance();</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　String url=&#8220;jdbc:oracle:thin：@localhost:1521:orcl&#8221;; //orcl为数据库的SID</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　String user=&#8220;test&#8221;;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　String password=&#8220;test&#8221;;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Connection conn= DriverManager.getConnection(url，user，password);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　2、DB2数据库</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Class.forName(&#8220;com.ibm.db2.jdbc.app.DB2Driver &#8221;).newInstance();</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　String url=&#8220;jdbc:db2://localhost:5000/sample&#8221;; //sample为你的数据库名</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　String user=&#8220;admin&#8221;;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　String password=&#8220;&#8221;;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Connection conn= DriverManager.getConnection(url，user，password);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　3、SQL Server7.0/2000数据库</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Class.forName(&#8220;com.microsoft.jdbc.sqlserver.SQLServerDriver&#8221;).newInstance();</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　String url=&#8220;jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb&#8221;;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　//mydb为数据库</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　String user=&#8220;sa&#8221;;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　String password=&#8220;&#8221;;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Connection conn= DriverManager.getConnection(url，user，password);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　4、Sybase数据库</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Class.forName(&#8220;com.sybase.jdbc.SybDriver&#8221;).newInstance();</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　String url =&#8220; jdbc:sybase:Tds:localhost:5007/myDB&#8221;;//myDB为你的数据库名</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Properties sysProps = System.getProperties();</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　SysProps.put(&#8220;user&#8221;，&#8220;userid&#8221;);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　SysProps.put(&#8220;password&#8221;，&#8220;user_password&#8221;);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Connection conn= DriverManager.getConnection(url， SysProps);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　5、Informix数据库</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Class.forName(&#8220;com.informix.jdbc.IfxDriver&#8221;).newInstance();</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　String url = &#8220;jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　user=testuser;password=testpassword&#8221;; //myDB为数据库名</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Connection conn= DriverManager.getConnection(url);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　6、MySQL数据库</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Class.forName(&#8220;org.gjt.mm.mysql.Driver&#8221;).newInstance();</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　//或者Class.forName(&#8220;com.mysql.jdbc.Driver&#8221;);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　String url =&#8220;jdbc:mysql://localhost/myDB?</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　user=soft&amp;password=soft1234&amp;useUnicode=true&amp;characterEncoding=8859_1&#8221;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　//myDB为数据库名</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Connection conn= DriverManager.getConnection(url);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　7、PostgreSQL数据库</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Class.forName(&#8220;org.postgresql.Driver&#8221;).newInstance();</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　String url =&#8220;jdbc:postgresql://localhost/myDB&#8221; //myDB为数据库名</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　String user=&#8220;myuser&#8221;;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　String password=&#8220;mypassword&#8221;;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Connection conn= DriverManager.getConnection(url，user，password);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　8、access数据库直连用ODBC的</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Class.forName(&#8220;sun.jdbc.odbc.JdbcOdbcDriver&#8221;) ;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　String url=&#8220;jdbc:odbc:Driver={MicroSoft Access Driver</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　(*.mdb)};DBQ=&#8221;+application.getRealPath(&#8220;/Data/ReportDemo.mdb&#8221;);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Connection conn = DriverManager.getConnection(url，&#8220;&#8221;，&#8220;&#8221;);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Statement stmtNew=conn.createStatement() ;</p><img src ="http://www.blogjava.net/seosyw/aggbug/419145.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/seosyw/" target="_blank">董超洪</a> 2014-10-28 22:15 <a href="http://www.blogjava.net/seosyw/archive/2014/10/28/419145.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>实现鼠标画图的Java程序</title><link>http://www.blogjava.net/seosyw/archive/2014/10/28/419144.html</link><dc:creator>董超洪</dc:creator><author>董超洪</author><pubDate>Tue, 28 Oct 2014 14:14:00 GMT</pubDate><guid>http://www.blogjava.net/seosyw/archive/2014/10/28/419144.html</guid><wfw:comment>http://www.blogjava.net/seosyw/comments/419144.html</wfw:comment><comments>http://www.blogjava.net/seosyw/archive/2014/10/28/419144.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/seosyw/comments/commentRss/419144.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/seosyw/services/trackbacks/419144.html</trackback:ping><description><![CDATA[<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">import java.awt.Color;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　import java.awt.Frame;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　import java.awt.Graphics;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　import java.awt.Point;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　import java.awt.event.MouseAdapter;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　import java.awt.event.MouseEvent;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　import java.awt.event.MouseListener;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　import java.util.ArrayList;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　import java.util.Iterator;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　public class MyMouseAdapter {</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　public static void main(String[] args) {</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　new MyFrame5(&#8220;drawing&#8221;);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　}</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　}</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　class MyFrame5 extends Frame{</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　ArrayList points=null;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　MyFrame5(String s){</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　super(s);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　points=new ArrayList();</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　setLayout(null);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　setBounds(300，300，400，300);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　this.setBackground(new Color(204，204，255));</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　setVisible(true);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　this.addMouseListener(new Monitor5());</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　}</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　public void paint(Graphics g){</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Iterator i=points.iterator();</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　while(i.hasNext()){</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Point p=(Point)i.next();</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　g.setColor(Color.blue);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　g.fillOval(p.x，p.y， 10， 10);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　}</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　}</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　public void addPoint(Point p){</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　points.add(p);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　}</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　}</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　class Monitor5 extends MouseAdapter{ //MouseAdapter实现了MouseListener接口</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　public void mousePressed(MouseEvent e){</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　MyFrame5 f=(MyFrame5)e.getSource();</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　f.addPoint(new Point(e.getX()，e.getY()));</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　f.repaint(); //让Frame强制经行重画</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　}</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　}</p><img src ="http://www.blogjava.net/seosyw/aggbug/419144.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/seosyw/" target="_blank">董超洪</a> 2014-10-28 22:14 <a href="http://www.blogjava.net/seosyw/archive/2014/10/28/419144.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java设计模式之Visitor模式</title><link>http://www.blogjava.net/seosyw/archive/2014/10/28/419143.html</link><dc:creator>董超洪</dc:creator><author>董超洪</author><pubDate>Tue, 28 Oct 2014 14:13:00 GMT</pubDate><guid>http://www.blogjava.net/seosyw/archive/2014/10/28/419143.html</guid><wfw:comment>http://www.blogjava.net/seosyw/comments/419143.html</wfw:comment><comments>http://www.blogjava.net/seosyw/archive/2014/10/28/419143.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/seosyw/comments/commentRss/419143.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/seosyw/services/trackbacks/419143.html</trackback:ping><description><![CDATA[<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><strong>Visitor<span class="Apple-converted-space">&nbsp;</span></strong>定义</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　作用于某个对象群中各个对象的操作。 它可以使你在不改变这些对象本身的情况下，定义作用于这些对象的新操作。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　在Java（<a style="color: rgb(11,59,140); font-size: 12px; text-decoration: underline" href="http://www.xinfengit.com/col34/" target="_blank">Java教程</a><span class="Apple-converted-space">&nbsp;</span><a style="color: rgb(11,59,140); font-size: 12px; text-decoration: underline" href="http://training.xinfengit.com/java/" target="_blank">Java培训</a><span class="Apple-converted-space">&nbsp;</span>） 中，Visitor 模式实际上是分离了collection 结构中的元素和对这些元素进行操作的行为。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　为何使用Visitor?</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Java 的Collection(包括Vector 和Hashtable)是我们最经常使用的技术，可是Collection好象是个黑色大染缸，本来有各种鲜明类型特征的对象一旦放入后，再取出时，这些类型就消失了。那么我们势必要用If 来判断，如：</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Iterator iterator = collection.iterator()</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　while (iterator.hasNext()) {</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Object o = iterator.next();</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　if (o instanceof Collection)</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　messyPrintCollection((Collection)o);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　else if (o instanceof String)</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　System.out.println(&#8220;&#8216;&#8221;+o.toString()+&#8220;&#8217;&#8221;);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　else if (o instanceof Float)</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　System.out.println(o.toString()+&#8220;f&#8221;);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　else</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　System.out.println(o.toString());</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　}</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　在上例中，我们使用了 instanceof 来判断 o 的类型。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　很显然，这样做的缺点代码If else if 很繁琐。我们就可以使用Visitor 模式解决它。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　如何使用<strong>Visitor</strong>?</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　针对上例，我们设计一个接口visitor 访问者：</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　public interface Visitor</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　{</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　public void visitCollection(Collection collection);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　public void visitString(String string);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　public void visitFloat(Float float);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　}</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　在这个接口中，将我们认为Collection 有可能的类的类型放入其中。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　有了访问者，我们需要被访问者，被访问者就是我们Collection 的每个元素Element，我们要为这些Element 定义一个可以接受访问的接口(访问和被访问是互动的，只有访问者，被访问者如果表示不欢迎，访问者就不能访问)，我们定义这个接口叫Visitable， 用来定义一个Accept 操作，也就是说让Collection 每个元素具备可访问性。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　public interface Visitable</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　{</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　public void accept(Visitor visitor);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　}</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　好了，有了两个接口，我们就要定义他们的具体实现(Concrete class)：</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　public class ConcreteElement implements Visitable</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　{</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　private String value;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　public ConcreteElement(String string) {</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　value = string;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　}</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　//定义accept 的具体内容 这里是很简单的一句调用</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　public void accept(Visitor visitor) {</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　visitor.visitString(this);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　}</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　}</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　再看看访问者的Concrete 实现：</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　public class ConcreteVisitor implements Visitor</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　{</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　//在本方法中，我们实现了对Collection 的元素的成功访问</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　public void visitCollection(Collection collection) {</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Iterator iterator = collection.iterator()</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　while (iterator.hasNext()) {</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Object o = iterator.next();</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　if (o instanceof Visitable)</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　((Visitable)o).accept(this);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　}</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　public void visitString(String string) {</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　System.out.println(&#8220;&#8216;&#8221;+string+&#8220;&#8217;&#8221;);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　}</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　public void visitFloat(Float float) {</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　System.out.println(float.toString()+&#8220;f&#8221;);</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　}</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　}</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　}</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　在上面的visitCollection 我们实现了对Collection 每个元素访问，只使用了一个判断语句，只要判断其是否可以访问。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　至此，我们完成了Visitor 模式基本架构。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　使用<strong>Visitor</strong><span class="Apple-converted-space">&nbsp;</span>模式的前提</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　对象群结构中(Collection) 中的对象类型很少改变，也就是说访问者的身份类型很少改变，如上面中Visitor 中的类型很少改变，如果需要增加新的操作，比如上例中我们在ConcreteElement 具体实现外，还需要新的ConcreteElement2 ConcreteElement3.</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　可见使用Visitor 模式是有前提的，在两个接口Visitor 和Visitable 中，确保Visitor 很少变化，变化的是Visitable，这样使用Visitor 最方便。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　如果Visitor 也经常变化， 也就是说，对象群中的对象类型经常改变，一般建议是，不如在这些对象类中逐个定义操作。但是Java 的Reflect 技术解决了这个问题。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 20px 0px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/25px 宋体; white-space: normal; color: rgb(51,51,51); border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　Reflect 技术是在运行期间动态获取对象类型和方法的一种技术，具体实现参考Javaworld的英文原文.</p><img src ="http://www.blogjava.net/seosyw/aggbug/419143.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/seosyw/" target="_blank">董超洪</a> 2014-10-28 22:13 <a href="http://www.blogjava.net/seosyw/archive/2014/10/28/419143.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>