??xml version="1.0" encoding="utf-8" standalone="yes"?>日韩在线无毛,依依成人在线,91福利精品第一导航http://www.aygfsteel.com/danxy2008/&nbsp;&nbsp;&nbsp;&nbsp;客观条g受制于hQƈ不惧。重要的是,我们拥有选择的自由,可以对现实环境积极回应,<br/> &nbsp;&nbsp;&nbsp;&nbsp;为生命负责,己创造有利的ZQ做一个“真正”操之在我的人!<br/>zh-cnWed, 18 Jun 2025 10:09:20 GMTWed, 18 Jun 2025 10:09:20 GMT60《Practical Java》学习笔讎ͼ一Q?/title><link>http://www.aygfsteel.com/danxy2008/archive/2006/11/23/83095.html</link><dc:creator>蒋利?/dc:creator><author>蒋利?/author><pubDate>Thu, 23 Nov 2006 10:50:00 GMT</pubDate><guid>http://www.aygfsteel.com/danxy2008/archive/2006/11/23/83095.html</guid><wfw:comment>http://www.aygfsteel.com/danxy2008/comments/83095.html</wfw:comment><comments>http://www.aygfsteel.com/danxy2008/archive/2006/11/23/83095.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/danxy2008/comments/commentRss/83095.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/danxy2008/services/trackbacks/83095.html</trackback:ping><description><![CDATA[<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <font size="2"> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"> </span> </font> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: -21pt; mso-list: l1 level1 lfo1; tab-stops: list 21.0pt"> <font size="2"> <strong> <span lang="EN-US" style="mso-bidi-font-family: 宋体"> <span style="mso-list: Ignore">一?/span> </span> <span lang="EN-US">General Techniques</span> </strong> </font> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo2; tab-stops: list 39.0pt"> <font size="2"> <span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore">1?span style="FONT: 7pt 'Times New Roman'">  </span></span> </span> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">引数?/span> <span lang="EN-US">by value </span> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方式而非</span> <span lang="EN-US"> by reference </span> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方式传?/span> </font> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo2; tab-stops: list 39.0pt"> <font size="2"> <span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore">2?span style="FONT: 7pt 'Times New Roman'">  </span></span> </span> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对于不变?/span> <span lang="EN-US">data</span> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">?/span> <span lang="EN-US">object reference</span> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">使用</span> <span lang="EN-US">final ,final</span> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">仅仅?/span> <span lang="EN-US">object reference</span> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">自n成ؓ不变量,但ƈ不限制它所指向对象的改?/span> </font> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo2; tab-stops: list 39.0pt"> <font size="2"> <span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore">3?span style="FONT: 7pt 'Times New Roman'">  </span></span> </span> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">~省情况下,所?/span> <span lang="EN-US">non-static</span> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">都可以被覆写Q不?/span> <span lang="EN-US">,</span> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">则用</span> <span lang="EN-US">final</span> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">防止覆写</span> </font> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo2; tab-stops: list 39.0pt"> <font size="2"> <span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore">4?span style="FONT: 7pt 'Times New Roman'">  </span></span> </span> <span lang="EN-US">vector</span> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">容器包含的是对象Q与</span> <span lang="EN-US">arrays</span> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">要区别,但我认ؓ</span> <span lang="EN-US">Vector</span> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的功能实际上有些像跟</span> <span lang="EN-US">Array List</span> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">差不多,只是</span> <span lang="EN-US">vector</span> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">现在不经怋?/span> </font> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo2; tab-stops: list 39.0pt"> <font size="2"> <span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore">5?span style="FONT: 7pt 'Times New Roman'">  </span></span> </span> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">多态优?/span> <span lang="EN-US">instanceof</span> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q只有在不得已的情况下?/span> </font> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt"> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"> <font size="2">“如果你Ҏ(gu)对象的型别来触发行ؓQ那改l自׃个耛_?/font> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt"> <font size="2"> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">例如Q当你必M一?/span> <span lang="EN-US">base type</span> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">做向下{型ؓ</span> <span lang="EN-US">derived type</span> <span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的时候,必须使用?/span> </font> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt"> <span lang="EN-US">?</span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt">Vector shapeVector = new Vector(10);<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?><o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt">shapeVector.add(new Triangle());<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt">shapeVector.add(new Triangle());<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt">shapeVector.add(new Circle());<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">    </span>//...<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">    </span>//Assume many Triangles and Circles are added and removed<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">    </span>//...<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">    </span>int size = shapeVector.size();<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">    </span>for (int i=0; i<size; i++)<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">    </span>{<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">      </span>Object o = shapeVector.get(i);<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">      </span>if (o instanceof Triangle)<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">      </span>{<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">        </span>if (((Triangle)o).isRightTriangle())<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">        </span>{<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">          </span>//...<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">        </span>}<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">      </span>}<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">      </span>else if (o instanceof Circle)<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">      </span>{<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">        </span>double rad = ((Circle)o).radius();<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">        </span>//...<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">      </span>}<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39.1pt; TEXT-INDENT: 18pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt">}<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-tab-count: 1">         </span> <span style="COLOR: #3366ff">6</span> </span> <span style="FONT-SIZE: 9pt; COLOR: #3366ff; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、一旦不需要对象的引用Q就它设ؓ</span> <span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #3366ff">null</span> <span style="FONT-SIZE: 9pt; COLOR: #3366ff; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q?/span> <span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #3366ff"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #3366ff"> <span style="mso-spacerun: yes">       </span> </span> <span style="FONT-SIZE: 9pt; COLOR: #3366ff; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">管?/span> <span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #3366ff">GC,</span> <span style="FONT-SIZE: 9pt; COLOR: #3366ff; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">你还是要x的你的代码如何运用内存;</span> <span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #3366ff"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-tab-count: 1">         </span> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: -21pt; LINE-HEIGHT: 12pt; mso-list: l1 level1 lfo1; tab-stops: list 21.0pt; mso-line-height-rule: exactly"> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; mso-bidi-font-family: 宋体"> <span style="mso-list: Ignore">二?span style="FONT: 7pt 'Times New Roman'">  </span></span> </span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象与相{?/span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt">7</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、区?/span> <span lang="EN-US" style="FONT-SIZE: 9pt">reference type</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">?/span> <span lang="EN-US" style="FONT-SIZE: 9pt">primitive type</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q理解他们的差异Q你会在q用他们时候做出明智的</span> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">选择Q?/span> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-tab-count: 1">         </span>Boolean(boolean)<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-tab-count: 1">         </span>Character(char)<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 18pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt">Byte(byte)<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 18pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt">Integer(int)<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 18pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt">Float(float) <o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 18pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt">Long(long)<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 18pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt">Short(short)<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 18pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt">Double(double)<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 18pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">基本型别相等Q只要是值相{就可以拉,不管是不是同一cdQ而引用类型必d按照引用的比较方式来比较Q譬?/span> <span lang="EN-US" style="FONT-SIZE: 9pt">equals();<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 18pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt">8</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">?/span> <span lang="EN-US" style="FONT-SIZE: 9pt">java.lang.object</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">提供?/span> <span lang="EN-US" style="FONT-SIZE: 9pt">equals()</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Ҏ(gu)很多时候不是你惌的,你需要自己写一些比较的Ҏ(gu)</span> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt">public boolean equals(Object obj)<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">  </span>{<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">    </span>if (this == obj)<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">      </span>return true;<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">    </span>if (obj != null && getClass() == obj.getClass())<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">    </span>{<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">      </span>Golfball gb = (Golfball)obj;<span style="mso-spacerun: yes">  </span>//Classes are equal, downcast.<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">      </span>if (brand.equals(gb.brand()) &&<span style="mso-spacerun: yes">  </span>//Compare attributes.<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">          </span>make.equals(gb.make()) &&<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">          </span>compression == gb.compression())<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">      </span>{<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">        </span>return true;<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">      </span>}<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">    </span>}<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">    </span>return false;<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <span style="mso-spacerun: yes">  </span>}<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: -21pt; LINE-HEIGHT: 12pt; mso-list: l1 level1 lfo1; tab-stops: list 21.0pt; mso-line-height-rule: exactly"> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; mso-bidi-font-family: 宋体"> <span style="mso-list: Ignore">三?span style="FONT: 7pt 'Times New Roman'">  </span></span> </span> <span lang="EN-US" style="FONT-SIZE: 9pt">java</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">异常</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -18pt; LINE-HEIGHT: 12pt; mso-list: l1 level2 lfo1; tab-stops: list 39.0pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt; mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore">1?span style="FONT: 7pt 'Times New Roman'">   </span></span> </span> <span lang="EN-US" style="FONT-SIZE: 9pt">try,cacth,finally<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不要?/span> <span lang="EN-US" style="FONT-SIZE: 9pt">catch</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的异常覆盖掉Q在q样的情况下Q我们要专门把异怿存下来,如用一?/span> <span lang="EN-US" style="FONT-SIZE: 9pt">vector</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">保存Q?/span> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不要忽略M一个异常,因ؓ异常一旦出玎ͼ抛出异常的那个线E将会终止;</span> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一个异常加入到</span> <span lang="EN-US" style="FONT-SIZE: 9pt">throw</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">子句Q会影响到调用它的所有函?/span> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">使用</span> <span lang="EN-US" style="FONT-SIZE: 9pt">finally</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">防止资源泄露Q譬如在q接数据库的时候在</span> <span lang="EN-US" style="FONT-SIZE: 9pt">finally</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中关闭连接;</span> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不要?/span> <span lang="EN-US" style="FONT-SIZE: 9pt">try</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">字段中返回;</span> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不要?/span> <span lang="EN-US" style="FONT-SIZE: 9pt">try</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">?/span> <span lang="EN-US" style="FONT-SIZE: 9pt">catch</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">用于程控制</span> <span lang="EN-US" style="FONT-SIZE: 9pt">;<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不要每逢出错的使用</span> <span lang="EN-US" style="FONT-SIZE: 9pt">try</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">?/span> <span lang="EN-US" style="FONT-SIZE: 9pt">catch;<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不要在构造函C抛出异常Q?/span> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; LINE-HEIGHT: 12pt; mso-line-height-rule: exactly"> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">抛出异常前,请将对象|ؓ有效状态;</span> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: -21pt; LINE-HEIGHT: 12pt; mso-list: l1 level1 lfo1; tab-stops: list 21.0pt; mso-line-height-rule: exactly"> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; mso-bidi-font-family: 宋体"> <span style="mso-list: Ignore">四?span style="FONT: 7pt 'Times New Roman'">  </span></span> </span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">性能</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -18pt; LINE-HEIGHT: 12pt; mso-list: l1 level2 lfo1; tab-stops: list 39.0pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt; mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore">1?span style="FONT: 7pt 'Times New Roman'">   </span></span> </span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">先把焦点攑֜设计Q数据机构和法斚w</span> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -18pt; LINE-HEIGHT: 12pt; mso-list: l1 level2 lfo1; tab-stops: list 39.0pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt; mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore">2?span style="FONT: 7pt 'Times New Roman'">   </span></span> </span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果q行字符串的拼接Q用</span> <span lang="EN-US" style="FONT-SIZE: 9pt">String Buffer</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">?/span> <span lang="EN-US" style="FONT-SIZE: 9pt"> String </span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">快许多?/span> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -18pt; LINE-HEIGHT: 12pt; mso-list: l1 level2 lfo1; tab-stops: list 39.0pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt; mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore">3?span style="FONT: 7pt 'Times New Roman'">   </span></span> </span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在面向对象中Q对象的创徏是昂늚Q因此需要将对象的创建成本降到最低,减少一些没有必要的对象Q在非必要的时候,别生你的对?/span> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -18pt; LINE-HEIGHT: 12pt; mso-list: l1 level2 lfo1; tab-stops: list 39.0pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt; mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore">4?span style="FONT: 7pt 'Times New Roman'">   </span></span> </span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">同步减到最低,增加</span> <span lang="EN-US" style="FONT-SIZE: 9pt">stack</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的?/span> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -18pt; LINE-HEIGHT: 12pt; mso-list: l1 level2 lfo1; tab-stops: list 39.0pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt; mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore">5?span style="FONT: 7pt 'Times New Roman'">   </span></span> </span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">使用基本型别代码会更?/span> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -18pt; LINE-HEIGHT: 12pt; mso-list: l1 level2 lfo1; tab-stops: list 39.0pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt; mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore">6?span style="FONT: 7pt 'Times New Roman'">   </span></span> </span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在?/span> <span lang="EN-US" style="FONT-SIZE: 9pt">vector</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">时候,?/span> <span lang="EN-US" style="FONT-SIZE: 9pt">get()</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">来获取对象,而不?/span> <span lang="EN-US" style="FONT-SIZE: 9pt">Interator<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -18pt; LINE-HEIGHT: 12pt; mso-list: l1 level2 lfo1; tab-stops: list 39.0pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt; mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore">7?span style="FONT: 7pt 'Times New Roman'">   </span></span> </span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">优先使用</span> <span lang="EN-US" style="FONT-SIZE: 9pt">array,</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">再考虑</span> <span lang="EN-US" style="FONT-SIZE: 9pt">ArrayList</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">?/span> <span lang="EN-US" style="FONT-SIZE: 9pt">Vector</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q如果不需?/span> <span lang="EN-US" style="FONT-SIZE: 9pt">vector</span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的同步特性,考虑使用</span> <span lang="EN-US" style="FONT-SIZE: 9pt">ArrayList<o:p></o:p></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -18pt; LINE-HEIGHT: 12pt; mso-list: l1 level2 lfo1; tab-stops: list 39.0pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt; mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore">8?span style="FONT: 7pt 'Times New Roman'">   </span></span> </span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可能的重复使用对象Q这比重新创建对象更有效</span> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -18pt; LINE-HEIGHT: 12pt; mso-list: l1 level2 lfo1; tab-stops: list 39.0pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt; mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore">9?span style="FONT: 7pt 'Times New Roman'">   </span></span> </span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">使用~式评估Qgq计,不必要的计算永远都不要计?/span> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -18pt; LINE-HEIGHT: 12pt; mso-list: l1 level2 lfo1; tab-stops: list 39.0pt; mso-line-height-rule: exactly"> <span lang="EN-US" style="FONT-SIZE: 9pt; mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore">10?/span> </span> <span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">手动优化你的代码Q特别是执行的顺?/span> <span lang="EN-US" style="FONT-SIZE: 9pt"> <o:p> </o:p> </span> </p><img src ="http://www.aygfsteel.com/danxy2008/aggbug/83095.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/danxy2008/" target="_blank">蒋利?/a> 2006-11-23 18:50 <a href="http://www.aygfsteel.com/danxy2008/archive/2006/11/23/83095.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用JMeter试web目http://www.aygfsteel.com/danxy2008/archive/2006/11/23/83094.html蒋利?/dc:creator>蒋利?/author>Thu, 23 Nov 2006 10:37:00 GMThttp://www.aygfsteel.com/danxy2008/archive/2006/11/23/83094.htmlhttp://www.aygfsteel.com/danxy2008/comments/83094.htmlhttp://www.aygfsteel.com/danxy2008/archive/2006/11/23/83094.html#Feedback0http://www.aygfsteel.com/danxy2008/comments/commentRss/83094.htmlhttp://www.aygfsteel.com/danxy2008/services/trackbacks/83094.html

一?/span> ?/span>

          Apache JMeter ?/span> 100 Q的 Java 桌面应用E序。用于对软g做压力测试(例如 Web 应用Q?/span> 它可以用于测试静态何动态资源例如静态文件?/span> Java 服务程序?/span> CGI 脚本?/span> Java 对象、数据库Q?/span> FTP 服务?/span> , {等?/span> JMeter 可以用于Ҏ(gu)务器、网l或对象模拟巨大的负载,来在不同压力cd下测试它们的强度和分析整体性能?/span>

另外Q?/span> JMeter 能够对应用程序做衰退试Q通过创徏带有断言的脚本来验证你的E序q回了你期望的结果。ؓ了最大限度的灉|性, JMeter 允许使用正则表达式创建断a?/span>

来开发的主要目标是?/span> JMeter 可能地变成一个有用的衰退试工具Q而不损失 JMeter 地压力测试能力?/span>

衰退试Q通过回归试{方法来保证l过修改的代码没有衰退Q质量下降)?/font>

 

二?/span> 安装与配|?/span>

JMeter 的安装过E非常简单:

W一?/span> 安装 JDK Q这里?/span> JDK 1.5.0 Q?/span>

W二?/span> 下蝲 JMeter Qƈ解压

       官方下蝲地址Q?/span> http://jakarta.apache.org/site/downloads/downloads_jmeter.cgi Q下?/span>

jakarta-jmeter-2.2.zip 包,大小Q?/span> 9.52M

W三?/span> 配置环境变量

       JAVA_HOME = ?/font>

    JMeter = ?/font>

    CLASS_PATH=?JAVA_HOME%\bin;%JAVA_HOME%\lib\tools.jar;%JMeter\bin%?/font>

W四?/span> q行

       在命令行q行 jmeter.bat Q出现如下界面,说明安装成功Q?/span>

 

三?/span> 目应用

1.       目需?/span>

模拟 5 个用户ƈ发请求,每个用户h两次Q一ơ请求结束后Q发Z一个请求)Q得出各个请求样本的响应旉Qƈ得出一些统计性的数据?/span>

2.       建立试计划

首先Q添加一个线E组Q如下图Q?/font>

用户q发Cؓ 5 Q因Z个用戯求我们可以看作是一个请求线E,所以我们将U程数设|ؓ 5 。这里设|休眠时间ؓ 0 Q@环的ơ数?/span> 2 ?/span>

其次Q徏立默认的 HTTP q接属性,q样不用每次都重新输入参敎ͼ如下图:  

再次Q徏立要试?/span> Http hQ如下图

最后,建立查看l果形式Q我们采用表格数据记?/font>

   

       3 Q运行测试脚?/span>

              点击要测试的脚本Q然后执行菜单运?/span> ?/span> 》开始,试开始?/span>

       4 Q测试数据分?/span>

              试完成之后Q数据如下:
      

聚合数据分析l果如下Q?/font>

模拟 5 个用户ƈ发访?/span> http://10.36.32.5:8080/wwwncsl/default.htm 面Q每个用户@环访问一ơ,d 10 个样本数据。最大响应时间ؓ 10.355s Q最短响应时间ؓ 2.84s Q^均ؓ 6.572s

90% 的可能集中在响应旉?/span> 10.355s ?/span>



]]>
Tomcat 5.5 配置数据?/title><link>http://www.aygfsteel.com/danxy2008/archive/2006/10/17/75574.html</link><dc:creator>蒋利?/dc:creator><author>蒋利?/author><pubDate>Tue, 17 Oct 2006 04:32:00 GMT</pubDate><guid>http://www.aygfsteel.com/danxy2008/archive/2006/10/17/75574.html</guid><wfw:comment>http://www.aygfsteel.com/danxy2008/comments/75574.html</wfw:comment><comments>http://www.aygfsteel.com/danxy2008/archive/2006/10/17/75574.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/danxy2008/comments/commentRss/75574.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/danxy2008/services/trackbacks/75574.html</trackback:ping><description><![CDATA[<p> <br /> <strong>配置文gQ?/strong> <br /><Context path="/apple" docBase="D:\workspace\bolg\webdoc"<br />         privileged="true" antiResourceLocking="false" antiJARLocking="false"><br /> <Resource name="jdbc/blogdb" auth="Container" <br />    type="javax.sql.DataSource"<br />    maxActive="100" maxIdle="30" maxWait="10000"<br />    username="root" password="" <br />    driverClassName="com.mysql.jdbc.Driver"<br />    url="jdbc:mysql://localhost:3306/blogdb?autoReconnect=true"/><br /></Context><br /><br /><strong>调用方式:</strong><br /> Context ctx = null ;<br /> Connection conn = null;<br /> Statement stmt = null ;<br /> ResultSet rs = null;<br /> try{<br />  ctx = new InitialContext();<br />  if( ctx == null) throw new Exception("没有匚w的环?");<br />  DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/blogdb");<br />  if( ds == null ) throw new Exception("没有匚w的数据库!");<br />  conn = ds.getConnection();<br />  stmt = conn.createStatement();<br />  rs = stmt.executeQuery(" select * from tbl_blog");<br />  while(rs.next()){<br />   out.print(rs.getString(2));<br />  }<br />  <br /> }catch(Exception e){<br />  e.printStackTrace();<br /> }finally{<br />  if(rs!=null) rs.close();<br />  if(stmt!=null) stmt.close();<br />  if(conn!=null) conn.close();<br />  if(ctx!=null) ctx.close();<br /> }<br /><strong><br /></strong><br /><br /></p><img src ="http://www.aygfsteel.com/danxy2008/aggbug/75574.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/danxy2008/" target="_blank">蒋利?/a> 2006-10-17 12:32 <a href="http://www.aygfsteel.com/danxy2008/archive/2006/10/17/75574.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ĩ</a>| <a href="http://" target="_blank">׿</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ϳ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ʯ</a>| <a href="http://" target="_blank">˫</a>| <a href="http://" target="_blank">Ͷ</a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank">ߴ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">¤</a>| <a href="http://" target="_blank">᯹</a>| <a href="http://" target="_blank">ׯ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ҽ</a>| <a href="http://" target="_blank">̫</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">߶</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ԭ</a>| <a href="http://" target="_blank">ȫ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ʷ</a>| <a href="http://" target="_blank">̩</a>| <a href="http://" target="_blank">ų</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Դ</a>| <a href="http://" target="_blank"></a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>