锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久亚洲精品成人,日韩亚洲国产综合高清,亚洲AV日韩AV无码污污网站http://www.tkk7.com/fhtdy2004/category/39225.html緇忛獙嫻呰杽錛岃愬績縐瘡錛涜鎬т笉濂斤紝璁拌鏂囧瓧zh-cnSat, 18 Jun 2011 22:12:44 GMTSat, 18 Jun 2011 22:12:44 GMT60t.interrupt(),t.isInterrupted(),Thread.interrupted()http://www.tkk7.com/fhtdy2004/archive/2009/08/22/292181.htmlFrank_FangFrank_FangSat, 22 Aug 2009 03:07:00 GMThttp://www.tkk7.com/fhtdy2004/archive/2009/08/22/292181.htmlhttp://www.tkk7.com/fhtdy2004/comments/292181.htmlhttp://www.tkk7.com/fhtdy2004/archive/2009/08/22/292181.html#Feedback0http://www.tkk7.com/fhtdy2004/comments/commentRss/292181.htmlhttp://www.tkk7.com/fhtdy2004/services/trackbacks/292181.html闃呰鍏ㄦ枃

Frank_Fang 2009-08-22 11:07 鍙戣〃璇勮
]]>
銆愯漿銆戠嚎紼嬩腑鐨勯粯璁ゅ紓甯稿鐞?/title><link>http://www.tkk7.com/fhtdy2004/archive/2009/08/07/290215.html</link><dc:creator>Frank_Fang</dc:creator><author>Frank_Fang</author><pubDate>Fri, 07 Aug 2009 05:15:00 GMT</pubDate><guid>http://www.tkk7.com/fhtdy2004/archive/2009/08/07/290215.html</guid><wfw:comment>http://www.tkk7.com/fhtdy2004/comments/290215.html</wfw:comment><comments>http://www.tkk7.com/fhtdy2004/archive/2009/08/07/290215.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/fhtdy2004/comments/commentRss/290215.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/fhtdy2004/services/trackbacks/290215.html</trackback:ping><description><![CDATA[<blockquote> <p>http://www.ibm.com/developerworks/cn/java/j-tiger08104/</p> <p>璺熻釜鏃犳硶棰勬湡鐨勮繍琛屾椂寮傚父鍙兘鏄竴浠跺張鎱㈠張璐瑰姏鐨勪簨鎯咃紝鍙幏寰楅粯璁ょ嚎紼嬪悕縐板拰鍫嗘爤璺熻釜閫氬父鏄笉澶熺殑銆傚湪 <em>椹湇 Tiger</em> 榪欎竴鏈熶笓鏍忎腑錛孞ava 寮鍙戜漢鍛?John Zukowski 鍚戞偍灞曠ず浜嗗浣曢氳繃鏇夸唬榛樿琛屼負鏉ュ畾鍒惰緭鍑恒備粬榪樺姣斾簡閫氳繃緇嗗垎 <code>ThreadGroup</code> 瀹氬埗杈撳嚭鐨勮佹柟娉曚笌閫氳繃鎻愪緵鑷繁鐨?<code>UncaughtExceptionHandler</code> 瀹氬埗杈撳嚭鐨勬柊鏂規硶銆?</p> </blockquote><!--start RESERVED FOR FUTURE USE INCLUDE FILES--><!-- include java script once we verify teams wants to use this and it will work on dbcs and cyrillic characters --><!--end RESERVED FOR FUTURE USE INCLUDE FILES--> <p>铏界劧鎴戜滑涓嶆兂鍒涘緩鍦ㄦ棤娉曢鏈熸椂鎶涘嚭榪愯鏃跺紓甯哥殑紼嬪簭錛屼絾榪欑鎯呭喌榪樻槸浼氬彂鐢熲斺斿挨鍏舵槸絎竴嬈¤繍琛屽鏉傜▼搴忔椂銆傞氬父鏄嬌鐢ㄩ粯璁よ涓恒佹墦鍗板爢鏍堟孩鍑哄拰緇撴潫綰跨▼鐨勭敓鍛芥潵澶勭悊榪欎簺寮傚父銆?/p> <p>浠庡摢閲屽彂鐜伴粯璁よ涓猴紵姣忎釜綰跨▼閮藉睘浜庝竴涓敱 <code>java.lang.ThreadGroup</code> 綾昏〃紺虹殑綰跨▼緇勩傞【鍚嶆濅箟錛岀嚎紼嬬粍鍏佽鎮ㄥ皢綰跨▼緇勫悎鍦ㄤ竴璧楓傛偍鍙兘鏄負浜嗘柟渚胯屽皢綰跨▼緇勫悎錛屼緥濡傦紝涓涓嚎紼嬫睜涓殑鎵鏈夌嚎紼嬮兘灞炰簬緇?X錛岃屽彟涓涓睜鐨勬墍鏈夌嚎紼嬪垯灞炰簬緇?Y錛屾垨鑰呮槸涓轟簡璁塊棶鎺у埗鑰屽皢綰跨▼榪涜緇勫悎銆傜粍 X 涓殑綰跨▼鏃犳潈璁塊棶鎴栨敼鍙樼粍 Y 涓殑綰跨▼錛岄櫎闈炲畠浠兘鍦ㄥ悓涓綰跨▼緇勫唴錛堟垨鍦ㄤ竴涓瓙緇勫唴錛夈?</p> <p>鍦?Tiger 涔嬪墠錛?<code>ThreadGroup</code> 綾繪彁渚涗簡涓縐嶅鐞嗘湭鎹曡幏寮傚父鐨勬柟娉曪細 <code>ThreadGroup</code> 鐨?<code>uncaughtException()</code> 鏂規硶銆傚鏋滃紓甯鎬笉鏄?<code>ThreadDeath</code> 錛屽垯灝嗙嚎紼嬬殑鍚嶇О鍜屽爢鏍堝洖婧紙stack backtrace錛夊彂閫佸埌 <code>System.err</code> 銆備絾鏄?Tiger 娣誨姞浜嗗彟涓縐嶆柟娉曪細 <code>Thread.UncaughtExceptionHandler</code> 鎺ュ彛銆傜粏鍒?<code>ThreadGroup</code> 鎴栧畨瑁呰鏂版帴鍙g殑瀹炵幇閮藉厑璁告偍鏇存敼榛樿琛屼負銆傛垜浠皢瀵?Tiger 涔嬪墠鍜屼箣鍚庢彁渚涚殑鏂規硶閮借繘琛岀爺絀躲?</p> <p><a name="1.0"><span id="6666161" class="atitle">浣跨敤 ThreadGroup 鐨勫畾鍒惰涓?/span></a></p> <p>鍙戠敓鏈崟鑾風殑寮傚父鏃訛紝榛樿琛屼負鏄皢鍫嗘爤婧㈠嚭鎵撳嵃杈撳嚭鍒扮郴緇熼敊璇紙 <code>System.err</code> 錛変腑錛屽娓呭崟 1 涓墍紺恒備笉闇瑕佷嬌鐢ㄤ換浣曞懡浠ゅ弬鏁版潵鍚姩紼嬪簭銆?</p> <br /> <a name="list1"><strong>娓呭崟 1. 綰跨▼婧㈠嚭紺轟緥</strong></a><br /> <table cellspacing="0" cellpadding="0" width="500" border="0" sizset="36" sizcache="2"> <tbody sizset="36" sizcache="1"> <tr> <td class="code-outline"> <pre class="displaycode">public class SimpleDump { public static void main(String args[]) { System.out.println(args[0]); } } </pre> </td> </tr> </tbody> </table> <br /> <p>涓嶄嬌鐢ㄤ換浣曞弬鏁拌繍琛岃紼嬪簭灝嗙敓鎴愭竻鍗?2 涓殑杈撳嚭銆傚敖綆″畠涓嶆槸涓涓緢闀跨殑鍫嗘爤璺熻釜錛屼絾瀹冩槸涓涓畬鏁寸殑鍫嗘爤璺熻釜銆?/p> <br /> <a name="list2"><strong>娓呭崟 2. 榛樿綰跨▼婧㈠嚭杈撳嚭</strong></a><br /> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizset="37" sizcache="2"> <tbody sizset="37" sizcache="1"> <tr> <td class="code-outline"> <pre class="displaycode">Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at SimpleDump.main(SimpleDump.java:3) </pre> </td> </tr> </tbody> </table> <br /> <p>姝e Java 騫沖彴鐨勮澶氫笢瑗夸竴鏍鳳紝濡傛灉涓嶅枩嬈㈤粯璁よ涓猴紝鎮ㄥ彲浠ュ鍏惰繘琛屾洿鏀廣傚湪 Java 騫沖彴鐨?Tiger 鐗堜互鍓嶇殑鐗堟湰涓紝涓嶈兘鏇夸唬鎵鏈夌嚎紼嬬殑榛樿琛屼負錛屼絾鏄彲浠ュ垱寤轟竴涓柊鐨?<code>ThreadGroup</code> 錛屽茍鏇存敼鍦ㄨ緇勫唴鍒涘緩鐨勪換浣曠嚎紼嬬殑榛樿琛屼負銆傛偍鍙互閲嶅啓 <code>uncaughtException(Thread t, Throwable e)</code> 鏂規硶鏉ュ畾鍒惰琛屼負銆傜劧鍚庯紝褰撳彂鐢熸湭棰勬枡鐨勮繍琛屾椂寮傚父鏃訛紝璇ョ嚎紼嬬粍鍐呭垱寤虹殑浠諱綍綰跨▼閮藉皢鑾峰緱鏂扮殑琛屼負銆備笉榪囷紝鏈濂芥槸淇鍩虹闂錛屾垜灝嗘彁渚涗竴涓畝鍗曠殑紺轟緥錛岃鏄庢洿鏀歸粯璁よ涓烘墍蹇呴渶鐨勬楠ゃ傛竻鍗?3 灞曠ず浜嗗皢鎵ц浠g爜鏀懼叆鏂扮嚎紼嬬殑璋冩暣榪囩殑嫻嬭瘯紼嬪簭錛?</p> <br /> <a name="list3"><strong>娓呭崟 3. 璋冩暣榪囩殑綰跨▼婧㈠嚭紺轟緥</strong></a><br /> <table cellspacing="0" cellpadding="0" width="600" border="0" sizset="38" sizcache="2"> <tbody sizset="38" sizcache="1"> <tr> <td class="code-outline"> <pre class="displaycode">public class WindowDump { public static void main(String args[]) throws Exception { ThreadGroup group = new LoggingThreadGroup("Logger"); new Thread(group, "myThread") { public void run() { System.out.println(1 / 0); } }.start(); } } </pre> </td> </tr> </tbody> </table> <br /> <p><code>LoggingThreadGroup</code> 綾繪槸涓涓柊鐨勫唴瀹癸紝娓呭崟 4 涓樉紺轟簡瀹冪殑瀹氫箟銆備負浜嗚繘琛岃鏄庯紝閫氳繃閲嶅啓 <code>uncaughtException()</code> 鏂規硶瀹炵幇鐨勭壒孌婅涓哄皢鍦ㄤ竴涓脊鍑虹獥鍙d腑鏄劇ず璇ュ紓甯革紝榪欓」鎿嶄綔鏄湪鐗規畩 <code>Handler</code> 鐨勫府鍔╀笅浣跨敤 Java Logging API 鏉ュ畬鎴愮殑銆?</p> <br /> <a name="list4"><strong>娓呭崟 4. LoggingThreadGroup 鐨勫畾涔?/strong></a><br /> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizset="39" sizcache="2"> <tbody sizset="39" sizcache="1"> <tr> <td class="code-outline"> <pre class="displaycode">import java.util.logging.*; public class LoggingThreadGroup extends ThreadGroup { private static Logger logger; public LoggingThreadGroup(String name) { super(name); } public void uncaughtException(Thread t, Throwable e) { // Initialize logger once if (logger == null) { logger = Logger.getLogger("example"); Handler handler = LoggingWindowHandler.getInstance(); logger.addHandler(handler); } logger.log(Level.WARNING, t.getName(), e); } } </pre> </td> </tr> </tbody> </table> <br /> <p>榪欓噷鍒涘緩鐨勫畾鍒?<code>Handler</code> 鐨勭被鍨嬩負 <code>LoggingWindowHandler</code> 錛岃綾誨瀷鐨勫畾涔夊湪娓呭崟 5 涓傚鐞嗙▼搴忎嬌鐢ㄤ簡涓涓敮鎸佺被 <code>LoggingWindow</code> 錛岃綾誨皢寮傚父鏄劇ず鍦ㄥ睆騫曚笂銆?<a cmimpressionsent="1">娓呭崟 6</a> 涓樉紺轟簡璇ョ被鐨勫畾涔夈?<code>Handler</code> 鐨?<code>public void publish(LogRecord record)</code> 鏂規硶瀹炵幇浜嗕竴浜涢噸瑕佹搷浣溿傚叾浣欐搷浣滃ぇ閮ㄥ垎鍙笌閰嶇疆鏈夊叧銆?</p> <br /> <a name="list5"><strong>娓呭崟 5. LoggingWindowHandler 鐨勫畾涔?/strong></a><br /> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizset="40" sizcache="2"> <tbody sizset="40" sizcache="1"> <tr> <td class="code-outline"> <pre class="displaycode">import java.util.logging.*; public class LoggingWindowHandler extends Handler { private static LoggingWindow window; private static LoggingWindowHandler handler; private LoggingWindowHandler() { configure(); window = new LoggingWindow("Logging window...", 400, 200); } public static synchronized LoggingWindowHandler getInstance() { if (handler == null) { handler = new LoggingWindowHandler(); } return handler; } /** * Get any configuration properties set */ private void configure() { LogManager manager = LogManager.getLogManager(); String className = getClass().getName(); String level = manager.getProperty(className + ".level"); setLevel((level == null) ? Level.INFO : Level.parse(level)); String filter = manager.getProperty(className + ".filter"); setFilter(makeFilter(filter)); String formatter = manager.getProperty(className + ".formatter"); setFormatter(makeFormatter(formatter)); } private Filter makeFilter(String name) { Filter f = null; try { Class c = Class.forName(name); f = (Filter)c.newInstance(); } catch (Exception e) { if (name != null) { System.err.println("Unable to load filter: " + name); } } return f; } private Formatter makeFormatter(String name) { Formatter f = null; try { Class c = Class.forName(name); f = (Formatter)c.newInstance(); } catch (Exception e) { f = new SimpleFormatter(); } return f; } // Overridden abstract Handler methods public void close() { } public void flush() { } /** * If record is loggable, format it and add it to window */ public void publish(LogRecord record) { String message = null; if (isLoggable(record)) { try { message = getFormatter().format(record); } catch (Exception e) { reportError(null, e, ErrorManager.FORMAT_FAILURE); return; } try { window.addLogInfo(message); } catch (Exception e) { reportError(null, e, ErrorManager.WRITE_FAILURE); } } } } </pre> </td> </tr> </tbody> </table> <br /> <br /> <br /> <br /> <a name="list6"><strong>娓呭崟 6. LoggingWindow 鐨勫畾涔?/strong></a><br /> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizset="41" sizcache="2"> <tbody sizset="41" sizcache="1"> <tr> <td class="code-outline"> <pre class="displaycode">import java.awt.*; import javax.swing.*; public class LoggingWindow extends JFrame { private JTextArea textArea; public LoggingWindow(String title, final int width, final int height) { super(title); EventQueue.invokeLater(new Runnable() { public void run() { setSize(width, height); textArea = new JTextArea(); JScrollPane pane = new JScrollPane(textArea); textArea.setEditable(false); getContentPane().add(pane); setVisible(true); } }); } public void addLogInfo(final String data) { EventQueue.invokeLater(new Runnable() { public void run() { textArea.append(data); } }); } } </pre> </td> </tr> </tbody> </table> <br /> <p>鎵ц <a cmimpressionsent="1">娓呭崟 3</a> 涓殑 <code>WindowDump</code> 紼嬪簭灝嗗嚭鐜板浘 1 涓殑灞忓箷銆傚洜涓烘病鏈変粠 <code>Logger</code> 涓垹闄ゆ帶鍒跺彴澶勭悊紼嬪簭錛屾墍浠ュ爢鏍堟孩鍑轟粛灝嗗嚭鐜板湪鎺у埗鍙頒笂銆?</p> <br /> <a name="N10145"><strong>鍥?1. 璁板綍鐨勫爢鏍堣窡韙?/strong></a><br /> <img height="200" alt="璁板綍鐨勫爢鏍堣窡韙? src="http://www.ibm.com/developerworks/cn/java/j-tiger08104/stack.jpg" width="400" /> <br /> <p>鍙戠敓榪愯鏃跺紓甯告椂錛屽彲鑳借鍋氳澶氬伐浣滄潵鏇存敼鍙戠敓鐨勯棶棰樸傝浠g爜鐨勫ぇ閮ㄥ垎閮芥槸 Logging Handler錛屼絾鏄紝瑕佹墽琛屾洿鏀癸紝灝卞繀欏葷粏鍒?<code>ThreadGroup</code> 錛岄噸鍐?<code>uncaughtException()</code> 錛岀劧鍚庡湪璇ョ嚎紼嬬粍涓墽琛屾偍鐨勭嚎紼嬨備笉榪囷紝璁╂垜浠氳繃鍙畨瑁?<code>Thread.UncaughtExceptionHandler</code> 錛屾潵鐪嬩竴鐪?Tiger 鐨勫鐞嗘柟寮忋?</p> <br /> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizset="42" sizcache="2"> <tbody sizset="42" sizcache="1"> <tr> <td><img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" /><br /> <img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" /></td> </tr> </tbody> </table> <table class="no-print" cellspacing="0" cellpadding="0" align="right" sizset="43" sizcache="2"> <tbody sizset="44" sizcache="2"> <tr align="right" sizset="44" sizcache="2"> <td sizset="44" sizcache="2"><img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" /><br /> <table cellspacing="0" cellpadding="0" border="0" sizset="44" sizcache="2"> <tbody sizset="44" sizcache="1"> <tr> <td valign="middle"><img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" /><br /> </td> <td valign="top" align="right"><a class="fbox" cmimpressionsent="1"><strong>鍥為〉棣?/strong></a></td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <br /> <br /> <p><a name="2.0"><span id="6666666" class="atitle">浣跨敤 UncaughtExceptionHandler 鐨勫畾鍒惰涓?/span></a></p> <p>瀵逛簬 Tiger錛?<code>Thread</code> 綾誨畾涔変腑娣誨姞浜嗕竴涓柊鐨勫叕鍏卞唴閮ㄧ被 <code>UncaughtExceptionHandler</code> 錛屾洿瀹屾暣鐨勫悕縐頒負 <code>Thread.UncaughtExceptionHandler</code> 錛堝叾浠栫被璁塊棶鍐呴儴綾繪椂闇瑕佷嬌鐢ㄥ畬鏁村悕縐幫級銆傛帴鍙g殑瀹氫箟鏄竴涓柟娉曪紝濡傚浘 7 涓墍紺猴細 </p> <br /> <a name="list7"><strong>娓呭崟 7. UncaughtExceptionHandler 鐨勫畾涔?/strong></a><br /> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizset="45" sizcache="2"> <tbody sizset="45" sizcache="1"> <tr> <td class="code-outline"> <pre class="displaycode">public interface Thread.UncaughtExceptionHandler { public void uncaughtException(Thread, Throwable); } </pre> </td> </tr> </tbody> </table> <br /> <p>鎮ㄥ彲鑳芥病鏈夋敞鎰忓埌錛屾竻鍗?7 涓殑鏂規硶涓庢垜浠墠闈㈤噸鍐欑殑 <code>ThreadGroup</code> 鐨勬柟娉曠浉鍚屻傚疄闄呬笂錛岀幇鍦ㄧ敱 <code>ThreadGroup</code> 綾誨疄鐜拌鎺ュ彛銆?</p> <p>鏂扮殑鍐呴儴綾誨彲浠ュ府鍔╂垜浠簡瑙d笅鍒椾袱瀵規柊鏂規硶錛屽茍鏈夊姪浜庢垜浠湪 <code>Thread</code> 涓嬌鐢ㄥ畠浠細 </p> <ul> <li><code>getUncaughtExceptionHandler()</code> 鍜?<code>setUncaughtExceptionHandler()</code> 銆? <li><code>getDefaultUncaughtExceptionHandler()</code> 鍜?<code>setDefaultUncaughtExceptionHandler()</code> 銆?</li> </ul> <p>絎竴瀵規柟娉曟槸 <code>getUncaughtExceptionHandler()</code> 鍜?<code>setUncaughtExceptionHandler()</code> 錛屽畠浠厑璁告偍涓哄綋鍓嶇嚎紼嬪強鍏跺悗浠e畾鍒惰涓猴紝浠庤屽厑璁鎬簩鍗佹垨鏇村鐨勭嚎紼嬫嫢鏈夎嚜宸辯殑瀹氬埗琛屼負銆備笉榪囷紝鎮ㄦ洿鍙兘浣跨敤絎簩瀵規柟娉?<code>getDefaultUncaughtExceptionHandler()</code> 鍜?<code>setDefaultUncaughtExceptionHandler()</code> 銆傚鏋滀嬌鐢ㄧ浜屽鏂規硶璁劇疆榛樿澶勭悊紼嬪簭錛岄偅涔堟病鏈夎嚜宸辯殑寮傚父澶勭悊紼嬪簭鐨勬墍鏈夌嚎紼嬮兘灝嗕嬌鐢ㄩ粯璁ゅ鐞嗙▼搴忋?</p> <p>鍚搗鏉ュソ鍍忓緢綆鍗曘備負浜嗚繘琛岃鏄庯紝娓呭崟 8 杞崲浜?<a cmimpressionsent="1">娓呭崟 3</a> 涓殑 <code>ThreadGroup</code> 鍙嬪ソ鐨勭▼搴忥紝浣跨敤鏂扮殑 <code>UncaughtExceptionHandler</code> 鎺ュ彛錛?</p> <br /> <a name="list8"><strong>娓呭崟 8. UncaughtExceptionHandler 紺轟緥</strong></a><br /> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizset="46" sizcache="2"> <tbody sizset="46" sizcache="1"> <tr> <td class="code-outline"> <pre class="displaycode">public class HandlerDump { public static void main(String args[]) throws Exception { Thread.UncaughtExceptionHandler handler = new LoggingThreadGroup("Logger"); Thread.currentThread().setUncaughtExceptionHandler(handler); System.out.println(1 / 0); } } </pre> </td> </tr> </tbody> </table> <br /> <p>璇ョ▼搴忓彧鏄皢 <code>LoggingThreadGroup</code> 閲嶇敤涓?<code>UncaughtExceptionHandler</code> 錛屽茍娌℃湁鍒涘緩鏂扮殑澶勭悊紼嬪簭瀹炵幇銆傝娉ㄦ剰錛屼笌鍘熸潵鐨勪唬鐮佺浉姣旓紝鏂頒唬鐮佽綆媧佸緱澶氥?</p> <br /> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizset="47" sizcache="2"> <tbody sizset="47" sizcache="1"> <tr> <td><img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" /><br /> <img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" /></td> </tr> </tbody> </table> <table class="no-print" cellspacing="0" cellpadding="0" align="right" sizset="48" sizcache="2"> <tbody sizset="49" sizcache="2"> <tr align="right" sizset="49" sizcache="2"> <td sizset="49" sizcache="2"><img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" /><br /> <table cellspacing="0" cellpadding="0" border="0" sizset="49" sizcache="2"> <tbody sizset="49" sizcache="1"> <tr> <td valign="middle"><img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" /><br /> </td> <td valign="top" align="right"><a class="fbox" cmimpressionsent="1"><strong>鍥為〉棣?/strong></a></td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <br /> <br /> <p><a name="3.0"><span id="6616166" class="atitle">鍏朵粬綰跨▼鏇存敼</span></a></p> <p><code>Thread</code> 綾諱笉浠呮敮鎸佷嬌鐢?Tiger 娣誨姞鐨勬湭鎹曡幏寮傚父澶勭悊紼嬪簭錛屽畠榪樻敮鎸佷嬌鐢?<code>getAllStackTraces()</code> 鑾峰緱鎵鏈夋湁鏁堢嚎紼嬬殑鍫嗘爤璺熻釜錛屾垨鑰呮敮鎸佷嬌鐢?<code>getStackTrace()</code> 鏉ュ彧鑾峰緱褰撳墠綰跨▼鐨勫爢鏍堣窡韙傝繖涓ょ鍫嗘爤璺熻釜閮借繑鍥炵被鍨嬩負 <code>java.lang.StackTraceElement</code> 鐨勫璞★紝 <code>java.lang.StackTraceElement</code> 鏄?Java 1.4 騫沖彴涓坊鍔犵殑涓涓被錛屽畠鍙互璁╂偍鐢熸垚鑷繁鐨勫爢鏍堣窡韙傚悓鏃訛紝Java 5 騫沖彴鏂版坊鍔犵殑鍔熻兘鏄竴涓儫涓綰跨▼鏍囪瘑絎︼紙鍙互浣跨敤 <code>getId()</code> 鑾峰緱璇ユ爣璇嗙錛夊拰涓涓柊鐨?<code>Thread.State</code> 綾伙紝浠ュ強涓庤綾葷浉鍏崇殑 <code>getThreadState()</code> 鏂規硶銆傛渶鍚庝竴涓嚎紼嬫洿鏀規槸涓涓姸鎬佹灇涓捐〃錛岃琛ㄦ槸鐢ㄦ潵鐩戣緋葷粺鐘舵侊紝鑰屼笉鏄敤鏉ュ悓姝ョ姸鎬佺殑銆?</p> <br /> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizset="50" sizcache="2"> <tbody sizset="50" sizcache="1"> <tr> <td><img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" /><br /> <img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" /></td> </tr> </tbody> </table> <table class="no-print" cellspacing="0" cellpadding="0" align="right" sizset="51" sizcache="2"> <tbody sizset="52" sizcache="2"> <tr align="right" sizset="52" sizcache="2"> <td sizset="52" sizcache="2"><img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" /><br /> <table cellspacing="0" cellpadding="0" border="0" sizset="52" sizcache="2"> <tbody sizset="52" sizcache="1"> <tr> <td valign="middle"><img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" /><br /> </td> <td valign="top" align="right"><a class="fbox" cmimpressionsent="1"><strong>鍥為〉棣?/strong></a></td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <br /> <br /> <p><a name="4.0"><span id="6116616" class="atitle">緇撴潫璇?/span></a></p> <p>鍍忔坊鍔犳湭鎹曡幏鐨勫紓甯稿鐞嗙▼搴忚繖鏍風殑綆鍗曞簱鏇存敼錛屽彲浠ユ瀬澶у湴澧炲姞鍘熶唬鐮佺殑鍙悊瑙fс傝櫧鐒跺湪綰跨▼緇勭駭鍒笂錛屾柊鐨勫簱浠g爜鐨勫姛鑳戒笌鍘熸潵搴撲唬鐮佺殑鐩稿悓錛屼絾鏂版ā鍨嬩腑鐨勬槗鐢ㄦу拰鐏墊椿鎬ц繙榪滆秴鍑轟簡灝嗕唬鐮佽皟鏁翠負鏇存柊鐨勬柟寮忔墍闇鐨勬椂闂淬傚綋鐒訛紝鑰佹柟娉曚粛鐒跺彲浠ヤ嬌鐢紝浣嗘渶濂藉皢浠g爜鏇存柊涓烘渶鏂扮殑搴撳姛鑳姐?/p> <img src ="http://www.tkk7.com/fhtdy2004/aggbug/290215.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/fhtdy2004/" target="_blank">Frank_Fang</a> 2009-08-07 13:15 <a href="http://www.tkk7.com/fhtdy2004/archive/2009/08/07/290215.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Java涓富綰跨▼濡備綍鎹曡幏瀛愮嚎紼嬫姏鍑虹殑寮傚父http://www.tkk7.com/fhtdy2004/archive/2009/08/07/290210.htmlFrank_FangFrank_FangFri, 07 Aug 2009 04:38:00 GMThttp://www.tkk7.com/fhtdy2004/archive/2009/08/07/290210.htmlhttp://www.tkk7.com/fhtdy2004/comments/290210.htmlhttp://www.tkk7.com/fhtdy2004/archive/2009/08/07/290210.html#Feedback0http://www.tkk7.com/fhtdy2004/comments/commentRss/290210.htmlhttp://www.tkk7.com/fhtdy2004/services/trackbacks/290210.html   <<  
          public   void   run();  
  >>  
  鑰屾墍鏈夌殑鍏蜂綋綰跨▼閮藉疄鐜拌繖涓柟娉曪紝鎵浠ヨ繖閲屽氨鏄庣‘浜嗕竴鐐癸紝綰跨▼浠g爜涓嶈兘鎶涘嚭浠諱綍checked寮傚父銆傛墍鏈夌殑綰跨▼涓殑checked寮傚父閮藉彧鑳借綰跨▼鏈韓娑堝寲鎺夈?)   榪欐牱鏈韓涔熸槸絎﹀悎綰跨▼鐨勮璁$悊蹇電殑錛岀嚎紼嬫湰韜氨鏄鐪嬩綔鐙珛鐨勬墽琛岀墖鏂紝瀹冨簲璇ュ鑷繁璐熻矗錛屾墍浠ョ敱瀹冩潵娑堝寲鎵鏈夌殑checked寮傚父鏄緢姝e父鐨勩? 
  榪欐牱灝卞洖絳斾簡妤間富鐨勭涓涓棶棰橈細checked寮傚父涓瀹氳鍦ㄧ嚎紼嬪唴閮ㄦ秷鍖栥? 
   
  浣嗘槸錛岀嚎紼嬩唬鐮佷腑鏄彲浠ユ姏鍑洪敊璇?Error)鍜岃繍琛岀駭鍒紓甯?RuntimeException)鐨勩侲rror淇轟滑鍙互蹇界暐錛屽洜涓洪氬父Error鏄簲璇ョ暀緇檝m鐨勶紝鑰孯untimeException紜槸姣旇緝姝e父鐨勶紝濡傛灉鍦ㄨ繍琛岃繃紼嬩腑婊¤凍浜嗘煇縐嶆潯浠跺鑷寸嚎紼嬪繀欏諱腑鏂紝鍙互閫夋嫨浣跨敤鎶涘嚭榪愯綰у埆寮傚父鏉ュ鐞嗭紝濡備笅錛? 
  <<  
          public   void   run()   {  
                if   (...)   throw   new   RuntimeException();  
          }  
  >>  
  褰撶嚎紼嬩唬鐮佹姏鍑鴻繍琛岀駭鍒紓甯鎬箣鍚庯紝綰跨▼浼氫腑鏂?)榪欑偣java涓В閲婂緱寰堟竻妤氾細  
  <<   @see   Thread  
  All   threads   that   are   not   daemon   threads   have   died,   either   by   returning   from   the   call   to   the   run   method   or   "by   throwing   an   exception   that   propagates   beyond   the   run   method".    
  >>  
  浣嗘槸瀵逛簬invoke姝ょ嚎紼嬬殑涓葷嚎紼嬩細浜х敓浠涔堝獎鍝嶅憿錛熶富綰跨▼涓嶅彈榪欎釜褰卞搷錛屼笉浼氬鐞嗚繖涓猂untimeException錛岃屼笖鏍規湰涓嶈兘catch鍒拌繖涓紓甯搞備細緇х畫鎵ц鑷繁鐨勪唬鐮?  :)  
  鎵浠ュ緱鍒扮粨璁猴細綰跨▼鏂規硶鐨勫紓甯稿彧鑳借嚜宸辨潵澶勭悊銆? 
   
  鍏充簬鏈鍚庝竴鐐癸紝涓嶇浉淇$殑璇濆ぇ瀹跺彲浠ュ仛榪欎箞涓涓瘯楠岋細  
  <<  
  public   class   TestThreadException   extends   Thread   {  
          public   void   run()   {  
                  throw   new   RuntimeException();  
          }  
   
          public   static   void   main(String[]   args)   throws   InterruptedException   {  
                  try   {  
                          new   TestThreadException().start();  
                  }   catch(RuntimeException   ex)   {  
                          //   鐪嬬湅鑳戒笉鑳藉埌杈捐繖閲岋紵   :)  
                  }  
                   
                  Thread.sleep(1000);  
                  //   鐪嬬湅鑳戒笉鑳藉埌杈捐繖閲岋紵   :)  
          }  
  }  
  >>  


璁頒笉寰楀湪鍝噷鐪嬪埌鐨勪唬鐮侊紝鍙互澶勭悊鍒扮嚎紼嬩腑鎶涘嚭鐨凴untimeException錛? 
   
  public   class   ApplicationLoader   extends   ThreadGroup  
  {  
          private   ApplicationLoader()  
          {  
   
                  super("ApplicationLoader");  
   
          }  
   
          public   static   void   main(String[]   args)  
          {  
   
                  Runnable   appStarter   =   new   Runnable()  
                  {  
   
                          public   void   run()  
                          {  
                                  //invoke   your   application   (i.e.MySystem.main(args)  
   
                                  throw   new   NullPointerException();   //example,   throw   a   runtime   exception  
                          }  
                  };  
   
                  new   Thread(new   ApplicationLoader(),   appStarter).start();  
          }  
   
          //We   overload   this   method   from   our   parent  
          //ThreadGroup   ,   which   will   make   sure   that   it  
          //gets   called   when   it   needs   to   be.     This   is    
          //where   the   magic   occurs.  
          public   void   uncaughtException(Thread   thread,   Throwable   exception)  
          {  
                  //Handle   the   error/exception.  
                  //Typical   operations   might   be   displaying   a  
                  //useful   dialog,   writing   to   an   event   log,   etc.  
   
                  exception.printStackTrace();//example,   print   stack   trace  
          }  
  }  


鍛靛懙錛寀ncaughtException濂藉儚鏄敮涓鑳藉澶勭悊綰跨▼鎶涘嚭鐨剈ncaught寮傚父鐨勫叆鍙c傜湅鏉ヨ繕鏄湁緇嗗績浜哄晩銆傜‘瀹炲姝わ紝閫氳繃ThreadGroup鐨剈ncaughtException鏂規硶榪樻槸鏈夊鐞嗙殑鏈轟細銆傚綋綰跨▼鎶涘嚭uncaughtException鐨勬椂鍊欙紝JVM浼氳皟鐢═hreadGroup鐨勬鏂規硶銆傞粯璁ょ殑澶勭悊濡備笅錛? 
  <<  
          public   void   uncaughtException(Thread   t,   Throwable   e)   {  
  if   (parent   !=   null)   {  
          parent.uncaughtException(t,   e);  
  }   else   if   (!(e   instanceof   ThreadDeath))   {  
          e.printStackTrace(System.err);  
  }  
          }  
  >>  
  姣忎釜Thread閮戒細鏈変竴涓猅hreadGroup瀵硅薄錛屽彲浠ラ氳繃Thread.getThreadGroup()鏂規硶寰楀埌錛屾彁渚涗簡涓婅堪榛樿鐨剈ncaught寮傚父澶勭悊鏂規硶銆? 
  涓婇潰娌℃湁鎻愯繖鐐癸紝鍥犱負淇鴻涓哄湪姝e父鐨勬儏鍐典笅錛岃繖涓柟娉曠殑澶勭悊鎯呭喌灝卞凡緇忚凍澶熶簡銆傝繕鏄偅涓嚎紼嬭璁$殑鐞嗗康錛?#8220;綰跨▼鐨勯棶棰樺簲璇ョ嚎紼嬭嚜宸辨湰韜潵瑙e喅錛岃屼笉瑕佸鎵樺埌澶栭儴銆?#8221;閫氬父鎯呭喌涓嬶紝澶栭儴涓嶉渶瑕佸鐞嗙嚎紼嬬殑寮傚父銆傚綋鐒朵篃鏈変緥澶栥?)  

Frank_Fang 2009-08-07 12:38 鍙戣〃璇勮
]]>
銆愯漿銆慗ava1.5娉涘瀷鎸囧崡涓枃鐗?Java1.5 Generic Tutorial) http://www.tkk7.com/fhtdy2004/archive/2009/07/27/288633.htmlFrank_FangFrank_FangMon, 27 Jul 2009 12:50:00 GMThttp://www.tkk7.com/fhtdy2004/archive/2009/07/27/288633.htmlhttp://www.tkk7.com/fhtdy2004/comments/288633.htmlhttp://www.tkk7.com/fhtdy2004/archive/2009/07/27/288633.html#Feedback0http://www.tkk7.com/fhtdy2004/comments/commentRss/288633.htmlhttp://www.tkk7.com/fhtdy2004/services/trackbacks/288633.html闃呰鍏ㄦ枃

Frank_Fang 2009-07-27 20:50 鍙戣〃璇勮
]]>
Java闆嗗悎綾誨皬緇?/title><link>http://www.tkk7.com/fhtdy2004/archive/2009/07/16/286932.html</link><dc:creator>Frank_Fang</dc:creator><author>Frank_Fang</author><pubDate>Wed, 15 Jul 2009 16:01:00 GMT</pubDate><guid>http://www.tkk7.com/fhtdy2004/archive/2009/07/16/286932.html</guid><wfw:comment>http://www.tkk7.com/fhtdy2004/comments/286932.html</wfw:comment><comments>http://www.tkk7.com/fhtdy2004/archive/2009/07/16/286932.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/fhtdy2004/comments/commentRss/286932.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/fhtdy2004/services/trackbacks/286932.html</trackback:ping><description><![CDATA[Java闆嗗悎綾誨皬緇? <img src ="http://www.tkk7.com/fhtdy2004/aggbug/286932.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/fhtdy2004/" target="_blank">Frank_Fang</a> 2009-07-16 00:01 <a href="http://www.tkk7.com/fhtdy2004/archive/2009/07/16/286932.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Java鍙嶅皠鏈哄埗瀛︿範灝忕粨http://www.tkk7.com/fhtdy2004/archive/2009/07/09/286024.htmlFrank_FangFrank_FangThu, 09 Jul 2009 02:08:00 GMThttp://www.tkk7.com/fhtdy2004/archive/2009/07/09/286024.htmlhttp://www.tkk7.com/fhtdy2004/comments/286024.htmlhttp://www.tkk7.com/fhtdy2004/archive/2009/07/09/286024.html#Feedback0http://www.tkk7.com/fhtdy2004/comments/commentRss/286024.htmlhttp://www.tkk7.com/fhtdy2004/services/trackbacks/286024.html鍏堢暀鐫



Frank_Fang 2009-07-09 10:08 鍙戣〃璇勮
]]>
Java Hashtable鍒嗘瀽http://www.tkk7.com/fhtdy2004/archive/2009/07/03/285330.htmlFrank_FangFrank_FangFri, 03 Jul 2009 05:24:00 GMThttp://www.tkk7.com/fhtdy2004/archive/2009/07/03/285330.htmlhttp://www.tkk7.com/fhtdy2004/comments/285330.htmlhttp://www.tkk7.com/fhtdy2004/archive/2009/07/03/285330.html#Feedback1http://www.tkk7.com/fhtdy2004/comments/commentRss/285330.htmlhttp://www.tkk7.com/fhtdy2004/services/trackbacks/285330.html闃呰鍏ㄦ枃

Frank_Fang 2009-07-03 13:24 鍙戣〃璇勮
]]>
Java 鍐呭瓨妯″瀷鍙?volatile鍏抽敭瀛楄涔?/title><link>http://www.tkk7.com/fhtdy2004/archive/2009/06/28/284435.html</link><dc:creator>Frank_Fang</dc:creator><author>Frank_Fang</author><pubDate>Sat, 27 Jun 2009 16:50:00 GMT</pubDate><guid>http://www.tkk7.com/fhtdy2004/archive/2009/06/28/284435.html</guid><wfw:comment>http://www.tkk7.com/fhtdy2004/comments/284435.html</wfw:comment><comments>http://www.tkk7.com/fhtdy2004/archive/2009/06/28/284435.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.tkk7.com/fhtdy2004/comments/commentRss/284435.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/fhtdy2004/services/trackbacks/284435.html</trackback:ping><description><![CDATA[<p>http://www.javaeye.com/topic/109150<br /> <br /> http://itchaser.javaeye.com/blog/440335<br /> <br /> http://www.javaeye.com/topic/11315<br /> <br /> <br /> 榪樺緱浜嗚В涓涓婮ava鍐呭瓨妯″瀷銆傘傘?br /> <br /> 鐪嬩簡涓涓婮ava铏氭嫙鏈鴻鑼冿紝灝辨瘮杈冩竻妤氫簡<br /> <br /> </p> <img src ="http://www.tkk7.com/fhtdy2004/aggbug/284435.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/fhtdy2004/" target="_blank">Frank_Fang</a> 2009-06-28 00:50 <a href="http://www.tkk7.com/fhtdy2004/archive/2009/06/28/284435.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>[杞琞J2EE欏圭洰寮傚父澶勭悊http://www.tkk7.com/fhtdy2004/archive/2009/06/24/283881.htmlFrank_FangFrank_FangWed, 24 Jun 2009 02:29:00 GMThttp://www.tkk7.com/fhtdy2004/archive/2009/06/24/283881.htmlhttp://www.tkk7.com/fhtdy2004/comments/283881.htmlhttp://www.tkk7.com/fhtdy2004/archive/2009/06/24/283881.html#Feedback4http://www.tkk7.com/fhtdy2004/comments/commentRss/283881.htmlhttp://www.tkk7.com/fhtdy2004/services/trackbacks/283881.html闃呰鍏ㄦ枃

Frank_Fang 2009-06-24 10:29 鍙戣〃璇勮
]]>
Java transient鍏抽敭瀛?/title><link>http://www.tkk7.com/fhtdy2004/archive/2009/06/20/286112.html</link><dc:creator>Frank_Fang</dc:creator><author>Frank_Fang</author><pubDate>Sat, 20 Jun 2009 10:23:00 GMT</pubDate><guid>http://www.tkk7.com/fhtdy2004/archive/2009/06/20/286112.html</guid><wfw:comment>http://www.tkk7.com/fhtdy2004/comments/286112.html</wfw:comment><comments>http://www.tkk7.com/fhtdy2004/archive/2009/06/20/286112.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.tkk7.com/fhtdy2004/comments/commentRss/286112.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/fhtdy2004/services/trackbacks/286112.html</trackback:ping><description><![CDATA[<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #000000">Volatile淇グ鐨勬垚鍛樺彉閲忓湪姣忔琚嚎紼嬭闂椂錛岄兘寮鴻揩浠庝富鍐呭瓨涓噸璇昏鎴愬憳鍙橀噺鐨勫箋傝屼笖錛屽綋鎴愬憳鍙橀噺鍙戠敓鍙樺寲鏃訛紝寮鴻揩綰跨▼灝嗗彉鍖栧煎洖鍐欏埌涓誨唴瀛樸傝繖鏍峰湪浠諱綍鏃跺埢錛屼袱涓笉鍚岀殑綰跨▼鎬繪槸鐪嬪埌鏌愪釜鎴愬憳鍙橀噺鐨勫悓涓涓箋?nbsp;  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />Java璇█瑙勮寖涓寚鍑猴細涓轟簡鑾峰緱鏈浣抽熷害錛屽厑璁哥嚎紼嬩繚瀛樺叡浜垚鍛樺彉閲忕殑縐佹湁鎷瘋礉錛岃屼笖鍙綋綰跨▼榪涘叆鎴栬呯寮鍚屾浠g爜鍧楁椂鎵嶄笌鍏變韓鎴愬憳鍙橀噺鐨勫師濮嬪煎姣斻?nbsp;  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />榪欐牱褰撳涓嚎紼嬪悓鏃朵笌鏌愪釜瀵硅薄浜や簰鏃訛紝灝卞繀欏昏娉ㄦ剰鍒拌璁╃嚎紼嬪強鏃剁殑寰楀埌鍏變韓鎴愬憳鍙橀噺鐨勫彉鍖栥?nbsp;  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />鑰寁olatile鍏抽敭瀛楀氨鏄彁紺篤M錛氬浜庤繖涓垚鍛樺彉閲忎笉鑳戒繚瀛樺畠鐨勭鏈夋嫹璐濓紝鑰屽簲鐩存帴涓庡叡浜垚鍛樺彉閲忎氦浜掋?nbsp;  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />浣跨敤寤鴻錛氬湪涓や釜鎴栬呮洿澶氱殑綰跨▼璁塊棶鐨勬垚鍛樺彉閲忎笂浣跨敤volatile銆傚綋瑕佽闂殑鍙橀噺宸插湪synchronized浠g爜鍧椾腑錛屾垨鑰呬負甯擱噺鏃訛紝涓嶅繀浣跨敤銆?nbsp;  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />鐢變簬浣跨敤volatile灞忚斀鎺変簡VM涓繀瑕佺殑浠g爜浼樺寲錛屾墍浠ュ湪鏁堢巼涓婃瘮杈冧綆錛屽洜姝や竴瀹氬湪蹇呰鏃舵墠浣跨敤姝ゅ叧閿瓧銆?nbsp;  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  <br /> <strong><span style="color: red"><strong><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />java鍏抽敭瀛桾ransient</strong>   </span></strong><br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />杞嚜http:</span><span style="color: #008000">//</span><span style="color: #008000">horst.sun.blog.163.com/blog/static/348849612007614494492/   </span><span style="color: #008000"><br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #000000">  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />緲昏瘧鑷猦ttp:</span><span style="color: #008000">//</span><span style="color: #008000">www.devx.com/tips/Tip/13726銆?nbsp;  </span><span style="color: #008000"><br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #000000">  <br /> <span style="color: red"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />Java鐨剆erialization鎻愪緵浜嗕竴縐嶆寔涔呭寲瀵硅薄瀹炰緥鐨勬満鍒躲傚綋鎸佷箙鍖栧璞℃椂錛屽彲鑳芥湁涓涓壒孌婄殑瀵硅薄鏁版嵁鎴愬憳錛屾垜浠笉鎯?nbsp;  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />鐢╯erialization鏈哄埗鏉ヤ繚瀛樺畠銆備負浜嗗湪涓涓壒瀹氬璞$殑涓涓煙涓婂叧闂璼erialization錛屽彲浠ュ湪榪欎釜鍩熷墠鍔犱笂鍏抽敭瀛梩ransient銆?nbsp;  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />transient鏄疛ava璇█鐨勫叧閿瓧錛岀敤鏉ヨ〃紺轟竴涓煙涓嶆槸璇ュ璞′覆琛屽寲鐨勪竴閮ㄥ垎銆傚綋涓涓璞¤涓茶鍖栫殑鏃跺欙紝transient鍨嬪彉閲忕殑鍊間笉鍖呮嫭鍦ㄤ覆琛屽寲鐨勮〃紺轟腑錛岀劧鑰岄潪transient鍨嬬殑鍙橀噺鏄鍖呮嫭榪涘幓鐨勩?nbsp; <br /> </span><span style="color: red"><strong style="color: red"><span style="color: #000000"><strong>娉ㄦ剰static鍙橀噺涔熸槸鍙互涓茶鍖栫殑 </strong><br /> </span></strong></span><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />棣栧厛錛岃鎴戜滑鐪嬩竴浜汮ava serialization鐨勪唬鐮侊細   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> LoggingInfo </span><span style="color: #0000ff">implements</span><span style="color: #000000"> java.io.Serializable   <br /> <img id="Codehighlighter1_929_1579_Open_Image" onclick="this.style.display='none'; Codehighlighter1_929_1579_Open_Text.style.display='none'; Codehighlighter1_929_1579_Closed_Image.style.display='inline'; Codehighlighter1_929_1579_Closed_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_929_1579_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_929_1579_Closed_Text.style.display='none'; Codehighlighter1_929_1579_Open_Image.style.display='inline'; Codehighlighter1_929_1579_Open_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_929_1579_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.tkk7.com/Images/dot.gif" /></span><span id="Codehighlighter1_929_1579_Open_Text"><span style="color: #000000">{   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">private</span><span style="color: #000000"> Date loggingDate </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Date();   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">private</span><span style="color: #000000"> String uid;   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">transient</span><span style="color: #000000"> String pwd;   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />      <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />    LoggingInfo(String user, String password)   <br /> <img id="Codehighlighter1_1104_1163_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1104_1163_Open_Text.style.display='none'; Codehighlighter1_1104_1163_Closed_Image.style.display='inline'; Codehighlighter1_1104_1163_Closed_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1104_1163_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1104_1163_Closed_Text.style.display='none'; Codehighlighter1_1104_1163_Open_Image.style.display='inline'; Codehighlighter1_1104_1163_Open_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_1104_1163_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.tkk7.com/Images/dot.gif" /></span><span id="Codehighlighter1_1104_1163_Open_Text"><span style="color: #000000">{   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        uid </span><span style="color: #000000">=</span><span style="color: #000000"> user;   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        pwd </span><span style="color: #000000">=</span><span style="color: #000000"> password;   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000">   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> String toString()   <br /> <img id="Codehighlighter1_1204_1574_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1204_1574_Open_Text.style.display='none'; Codehighlighter1_1204_1574_Closed_Image.style.display='inline'; Codehighlighter1_1204_1574_Closed_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1204_1574_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1204_1574_Closed_Text.style.display='none'; Codehighlighter1_1204_1574_Open_Image.style.display='inline'; Codehighlighter1_1204_1574_Open_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_1204_1574_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.tkk7.com/Images/dot.gif" /></span><span id="Codehighlighter1_1204_1574_Open_Text"><span style="color: #000000">{   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        String password</span><span style="color: #000000">=</span><span style="color: #0000ff">null</span><span style="color: #000000">;   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: #0000ff">if</span><span style="color: #000000">(pwd </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">)   <br /> <img id="Codehighlighter1_1277_1323_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1277_1323_Open_Text.style.display='none'; Codehighlighter1_1277_1323_Closed_Image.style.display='inline'; Codehighlighter1_1277_1323_Closed_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1277_1323_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1277_1323_Closed_Text.style.display='none'; Codehighlighter1_1277_1323_Open_Image.style.display='inline'; Codehighlighter1_1277_1323_Open_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_1277_1323_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.tkk7.com/Images/dot.gif" /></span><span id="Codehighlighter1_1277_1323_Open_Text"><span style="color: #000000">{   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        password </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">NOT SET</span><span style="color: #000000">"</span><span style="color: #000000">;   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="color: #000000">   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: #0000ff">else</span><span style="color: #000000">  <br /> <img id="Codehighlighter1_1351_1395_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1351_1395_Open_Text.style.display='none'; Codehighlighter1_1351_1395_Closed_Image.style.display='inline'; Codehighlighter1_1351_1395_Closed_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1351_1395_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1351_1395_Closed_Text.style.display='none'; Codehighlighter1_1351_1395_Open_Image.style.display='inline'; Codehighlighter1_1351_1395_Open_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_1351_1395_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.tkk7.com/Images/dot.gif" /></span><span id="Codehighlighter1_1351_1395_Open_Text"><span style="color: #000000">{   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />            password </span><span style="color: #000000">=</span><span style="color: #000000"> pwd;   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="color: #000000">   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">logon info: \n   </span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">user: </span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> uid </span><span style="color: #000000">+</span><span style="color: #000000">   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="color: #000000">"</span><span style="color: #000000">\n   logging date : </span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> loggingDate.toString() </span><span style="color: #000000">+</span><span style="color: #000000">   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="color: #000000">"</span><span style="color: #000000">\n   password: </span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> password;   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000">   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: #000000">   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />鐜板湪鎴戜滑鍒涘緩涓涓繖涓被鐨勫疄渚嬶紝騫朵笖涓茶鍖?serialize)瀹?nbsp;,鐒跺悗灝嗚繖涓覆琛屽寲瀵硅薄鍐欏紓佺洏銆?nbsp;  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />LoggingInfo logInfo </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> LoggingInfo(</span><span style="color: #000000">"</span><span style="color: #000000">MIKE</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000">MECHANICS</span><span style="color: #000000">"</span><span style="color: #000000">);   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />System.out.println(logInfo.toString());   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">try</span><span style="color: #000000">  <br /> <img id="Codehighlighter1_1755_1917_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1755_1917_Open_Text.style.display='none'; Codehighlighter1_1755_1917_Closed_Image.style.display='inline'; Codehighlighter1_1755_1917_Closed_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1755_1917_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1755_1917_Closed_Text.style.display='none'; Codehighlighter1_1755_1917_Open_Image.style.display='inline'; Codehighlighter1_1755_1917_Open_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_1755_1917_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.tkk7.com/Images/dot.gif" /></span><span id="Codehighlighter1_1755_1917_Open_Text"><span style="color: #000000">{   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />   ObjectOutputStream o </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> ObjectOutputStream(   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span><span style="color: #0000ff">new</span><span style="color: #000000"> FileOutputStream(</span><span style="color: #000000">"</span><span style="color: #000000">logInfo.out</span><span style="color: #000000">"</span><span style="color: #000000">));   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />   o.writeObject(logInfo);   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />   o.close();   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: #000000">   <br /> <img id="Codehighlighter1_1941_3009_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1941_3009_Open_Text.style.display='none'; Codehighlighter1_1941_3009_Closed_Image.style.display='inline'; Codehighlighter1_1941_3009_Closed_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1941_3009_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1941_3009_Closed_Text.style.display='none'; Codehighlighter1_1941_3009_Open_Image.style.display='inline'; Codehighlighter1_1941_3009_Open_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="color: #0000ff">catch</span><span style="color: #000000">(Exception e) </span><span id="Codehighlighter1_1941_3009_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.tkk7.com/Images/dot.gif" /></span><span id="Codehighlighter1_1941_3009_Open_Text"><span style="color: #000000">{</span><span style="color: #008000">//</span><span style="color: #008000">deal with exception}   </span><span style="color: #008000"><br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000">  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />To read the object back, we can write   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #0000ff">try</span><span style="color: #000000">  <br /> <img id="Codehighlighter1_2021_2237_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2021_2237_Open_Text.style.display='none'; Codehighlighter1_2021_2237_Closed_Image.style.display='inline'; Codehighlighter1_2021_2237_Closed_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_2021_2237_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_2021_2237_Closed_Text.style.display='none'; Codehighlighter1_2021_2237_Open_Image.style.display='inline'; Codehighlighter1_2021_2237_Open_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /></span><span id="Codehighlighter1_2021_2237_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.tkk7.com/Images/dot.gif" /></span><span id="Codehighlighter1_2021_2237_Open_Text"><span style="color: #000000">{   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />   ObjectInputStream in </span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> ObjectInputStream(   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span><span style="color: #0000ff">new</span><span style="color: #000000"> FileInputStream(</span><span style="color: #000000">"</span><span style="color: #000000">logInfo.out</span><span style="color: #000000">"</span><span style="color: #000000">));   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />   LoggingInfo logInfo </span><span style="color: #000000">=</span><span style="color: #000000"> (LoggingInfo)in.readObject();   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />   System.out.println(logInfo.toString());   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />}</span></span><span style="color: #000000">   <br /> <img id="Codehighlighter1_2261_3009_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2261_3009_Open_Text.style.display='none'; Codehighlighter1_2261_3009_Closed_Image.style.display='inline'; Codehighlighter1_2261_3009_Closed_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_2261_3009_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_2261_3009_Closed_Text.style.display='none'; Codehighlighter1_2261_3009_Open_Image.style.display='inline'; Codehighlighter1_2261_3009_Open_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /></span><span style="color: #0000ff">catch</span><span style="color: #000000">(Exception e) </span><span id="Codehighlighter1_2261_3009_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.tkk7.com/Images/dot.gif" /></span><span id="Codehighlighter1_2261_3009_Open_Text"><span style="color: #000000">{</span><span style="color: #008000">//</span><span style="color: #008000">deal with exception}   </span><span style="color: #008000"><br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000">  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />濡傛灉鎴戜滑榪愯榪欐浠g爜錛屾垜浠細娉ㄦ剰鍒頒粠紓佺洏涓鍥?read鈥斺攂ack (de</span><span style="color: #000000">-</span><span style="color: #000000">serializing))鐨勫璞℃墦鍗皃assword涓?/span><span style="color: #000000">"</span><span style="color: #000000">NOT SET</span><span style="color: #000000">"</span><span style="color: #000000">銆傝繖鏄綋鎴戜滑瀹氫箟pwd鍩熶負transient鏃訛紝鎵鏈熸湜鐨勬紜粨鏋溿?nbsp;  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />鐜板湪錛岃鎴戜滑鏉ョ湅涓涓嬬矖蹇冨寰卼ransient鍩熷彲鑳藉紩璧風殑娼滃湪闂銆傚亣璁炬垜浠慨鏀逛簡綾誨畾涔夛紝鎻愪緵緇檛ransient鍩熶竴涓粯璁ゅ鹼紝   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />浠g爜濡備笅錛?nbsp;  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />  <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> GuestLoggingInfo </span><span style="color: #0000ff">implements</span><span style="color: #000000"> java.io.Serializable   <br /> <img id="Codehighlighter1_2548_2844_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2548_2844_Open_Text.style.display='none'; Codehighlighter1_2548_2844_Closed_Image.style.display='inline'; Codehighlighter1_2548_2844_Closed_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_2548_2844_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_2548_2844_Closed_Text.style.display='none'; Codehighlighter1_2548_2844_Open_Image.style.display='inline'; Codehighlighter1_2548_2844_Open_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /></span><span id="Codehighlighter1_2548_2844_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.tkk7.com/Images/dot.gif" /></span><span id="Codehighlighter1_2548_2844_Open_Text"><span style="color: #000000">{   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">private</span><span style="color: #000000"> Date loggingDate </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Date();   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">private</span><span style="color: #000000"> String uid;   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">transient</span><span style="color: #000000"> String pwd;   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />      <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />    GuestLoggingInfo()   <br /> <img id="Codehighlighter1_2700_2761_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2700_2761_Open_Text.style.display='none'; Codehighlighter1_2700_2761_Closed_Image.style.display='inline'; Codehighlighter1_2700_2761_Closed_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_2700_2761_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_2700_2761_Closed_Text.style.display='none'; Codehighlighter1_2700_2761_Open_Image.style.display='inline'; Codehighlighter1_2700_2761_Open_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_2700_2761_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.tkk7.com/Images/dot.gif" /></span><span id="Codehighlighter1_2700_2761_Open_Text"><span style="color: #000000">{   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        uid </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">guest</span><span style="color: #000000">"</span><span style="color: #000000">;   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        pwd </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">guest</span><span style="color: #000000">"</span><span style="color: #000000">;   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000">   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> String toString()   <br /> <img id="Codehighlighter1_2802_2839_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2802_2839_Open_Text.style.display='none'; Codehighlighter1_2802_2839_Closed_Image.style.display='inline'; Codehighlighter1_2802_2839_Closed_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_2802_2839_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_2802_2839_Closed_Text.style.display='none'; Codehighlighter1_2802_2839_Open_Image.style.display='inline'; Codehighlighter1_2802_2839_Open_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_2802_2839_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.tkk7.com/Images/dot.gif" /></span><span id="Codehighlighter1_2802_2839_Open_Text"><span style="color: #000000">{   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: #008000">//</span><span style="color: #008000">same as above   </span><span style="color: #008000"><br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /></span><span style="color: #000000">     }</span></span><span style="color: #000000">   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />}</span></span><span style="color: #000000">   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" /><strong>鐜板湪錛屽鏋滄垜浠┛琛屽寲GuestLoggingInfo鐨勪竴涓疄渚嬶紝灝嗗畠鍐欏叆紓佺洏錛屽茍涓斿啀灝嗗畠浠庣鐩樹腑璇誨嚭錛屾垜浠粛鐒剁湅鍒拌鍥炵殑瀵硅薄鎵撳嵃password 涓?nbsp;</strong></span><strong><span style="color: #000000">"</span><span style="color: #000000">NOT SET</span><span style="color: #000000">"</span></strong><span style="color: #000000"><strong>銆傚綋浠庣鐩樹腑璇誨嚭鏌愪釜綾葷殑瀹炰緥鏃訛紝瀹為檯涓婂茍涓嶄細鎵ц榪欎釜綾葷殑鏋勯犲嚱鏁幫紝   <br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />鑰屾槸杞藉叆浜嗕竴涓綾誨璞$殑鎸佷箙鍖栫姸鎬侊紝騫跺皢榪欎釜鐘舵佽祴鍊肩粰璇ョ被鐨勫彟涓涓璞°?nbsp; <br /> </strong><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" /></span></div> </span></span> <img src ="http://www.tkk7.com/fhtdy2004/aggbug/286112.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/fhtdy2004/" target="_blank">Frank_Fang</a> 2009-06-20 18:23 <a href="http://www.tkk7.com/fhtdy2004/archive/2009/06/20/286112.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Java Serializable灝忕粨http://www.tkk7.com/fhtdy2004/archive/2009/06/20/286933.htmlFrank_FangFrank_FangSat, 20 Jun 2009 10:00:00 GMThttp://www.tkk7.com/fhtdy2004/archive/2009/06/20/286933.htmlhttp://www.tkk7.com/fhtdy2004/comments/286933.htmlhttp://www.tkk7.com/fhtdy2004/archive/2009/06/20/286933.html#Feedback0http://www.tkk7.com/fhtdy2004/comments/commentRss/286933.htmlhttp://www.tkk7.com/fhtdy2004/services/trackbacks/286933.html

Frank_Fang 2009-06-20 18:00 鍙戣〃璇勮
]]>
java.io.Serializable涓巎ava.io.Externalizable鐨勬瘮杈?/title><link>http://www.tkk7.com/fhtdy2004/archive/2009/06/20/283372.html</link><dc:creator>Frank_Fang</dc:creator><author>Frank_Fang</author><pubDate>Sat, 20 Jun 2009 09:43:00 GMT</pubDate><guid>http://www.tkk7.com/fhtdy2004/archive/2009/06/20/283372.html</guid><wfw:comment>http://www.tkk7.com/fhtdy2004/comments/283372.html</wfw:comment><comments>http://www.tkk7.com/fhtdy2004/archive/2009/06/20/283372.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.tkk7.com/fhtdy2004/comments/commentRss/283372.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/fhtdy2004/services/trackbacks/283372.html</trackback:ping><description><![CDATA[     鎽樿:       褰撲袱涓繘紼嬪湪榪涜榪滅▼閫氫俊鏃訛紝鏃犺鏄綍縐嶇被鍨嬬殑鏁版嵁錛岄兘浼氫互浜岃繘鍒跺簭鍒楃殑褰㈠紡鍦ㄧ綉緇滀笂浼犻併傚彂閫佹柟闇瑕佹妸榪欎釜Java瀵硅薄杞崲涓哄瓧鑺傚簭鍒楋紝鎵嶈兘鍦ㄧ綉緇滀笂浼犻侊紝縐頒負瀵硅薄鐨勫簭鍒楀寲錛涙帴鏀舵柟鍒欓渶瑕佹妸瀛楄妭搴忓垪鍐嶆仮澶嶄負Java瀵硅薄錛岀О涓哄璞$殑鍙嶅簭鍒楀寲銆?鍙湁瀹炵幇浜哠erializable鍜孍xternalizable鎺ュ彛鐨勭被鐨勫璞℃墠鑳借搴忓垪鍖栵紝鑰孍xtern...  <a href='http://www.tkk7.com/fhtdy2004/archive/2009/06/20/283372.html'>闃呰鍏ㄦ枃</a><img src ="http://www.tkk7.com/fhtdy2004/aggbug/283372.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/fhtdy2004/" target="_blank">Frank_Fang</a> 2009-06-20 17:43 <a href="http://www.tkk7.com/fhtdy2004/archive/2009/06/20/283372.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>銆愯漿銆戦伩鍏嶅湪Java涓嬌鐢–hecked Exceptionhttp://www.tkk7.com/fhtdy2004/archive/2009/06/20/283358.htmlFrank_FangFrank_FangSat, 20 Jun 2009 07:49:00 GMThttp://www.tkk7.com/fhtdy2004/archive/2009/06/20/283358.htmlhttp://www.tkk7.com/fhtdy2004/comments/283358.htmlhttp://www.tkk7.com/fhtdy2004/archive/2009/06/20/283358.html#Feedback0http://www.tkk7.com/fhtdy2004/comments/commentRss/283358.htmlhttp://www.tkk7.com/fhtdy2004/services/trackbacks/283358.html

Java 鎻愪緵浜嗕袱縐岴xception 鐨勬ā寮忥紝涓縐嶆槸鎵ц鐨勬椂鍊欐墍浜х敓鐨凟xception (Runtime Exception)錛屽彟澶栦竴縐嶅垯鏄彈鎺у埗鐨凟xception (Checked Exception)銆?/span>

鎵鏈夌殑Checked Exception 鍧囦粠java.lang.Exception 緇ф壙鑰屾潵錛岃孯untime Exception 鍒欑戶鎵縥ava.lang.RuntimeException 鎴杍ava.lang.Error (瀹為檯涓妀ava.lang.RuntimeException 鐨勪笂涓灞備篃鏄痡ava.lang.Exception錛岃繖璇存槑浣滀負exception涓よ呭茍娌℃湁鏈川鐨勫尯鍒紝鍙槸java璇█鏈韓浠庡姛鑳借冭檻鏈夋墍鍖哄垎錛岃繖鎵嶅鑷翠笅闈㈡彁鍒扮殑涓嶅悓鐐?銆?/span>

涓涓嚱鏁板鏋滀細鎶涘嚭Checked Exception 錛岋紙榪欓噷鍖呭惈涓ょ鎯呭喌錛屼竴涓槸鍑芥暟鏈韓鎶涘嚭錛屽彟澶栦竴縐嶆槸瀹冭皟鐢ㄧ殑鍑芥暟浼氭姏鍑篊hecked Exception 浣嗘槸瀹冨茍娌℃湁鍘籧atch榪欎釜exception錛夛紝閭e湪澹版槑姝ゅ嚱鏁扮殑鏃跺欏繀欏繪爣鏄巘hrows XXXException()銆傝孯untime Exception涓嶉渶瑕佸姝ゅ0鏄庛?/span>

閫昏緫涓婄湅錛孯untime Exception 涓嶤hecked Exception 浣跨敤鐩殑涓嶄竴鏍楓備竴鑸岃█錛孋hecked Exception 琛ㄧず榪欎釜Exception 蹇呴』瑕佽澶勭悊錛屼篃灝辨槸璇寸▼搴忚璁¤呭簲璇ュ凡緇忕煡閬撳彲鑳戒細鏀跺埌鏌愪釜Exception(鍥犱負瑕乼ry catch浣? 錛屾墍浠ョ▼搴忚璁¤呭簲璇ヨ兘涔熷繀欏伙紙鎴栬呮爣鏄巘hrows XXXException()緇х畫鎶涘嚭鍘伙紝鎴栬卼ry catch澶勭悊錛屼笉鐒舵槸緙栬瘧涓嶈繃鐨勶級閽堝榪欎簺涓嶅悓鐨凜hecked Exception 鍋氬嚭涓嶅悓鐨勫鐞嗐傝孯untime Exception 閫氬父浼氭殫紺虹潃紼嬪簭涓婄殑閿欒錛岃繖縐嶉敊璇細瀵艱嚧紼嬪簭璁捐鑰呮棤娉曞鐞嗭紝鑰岄犳垚紼嬪簭鏃犳硶緇х畫鎵ц涓嬪幓錛堝彲浠ry catch澶勭悊鑰岄伩鍏嶇▼搴忔寕鎺夛紝浣嗘槸榪欏父甯鎬細鎺╃洊闂鎵鍦級銆?/span>


checked exception鐢變簬蹇呴』琚鐞嗭紝浼氱粰紼嬪簭鍛樺甫鏉ラ澶栫殑楹葷儲錛岃瘯鎯充竴涓嚱鏁癮錛屽畠浼氳皟鐢ㄥ埌b1錛宐2...錛宐9涓鍏?涓嚱鏁幫紝榪欎簺鍑芥暟姣忎釜閮戒細鎶涘嚭checked exception錛岃宎鍑芥暟閲岄潰鍙堟病鏈夊姙娉曞鐞嗚繖浜沞xception錛岄偅鍦ㄥ0鏄巃鍑芥暟鐨勬椂鍊欏氨蹇呴』榪炲啓9涓猼hrow xxxException錛屽绱殑錛侊紒鐒惰岃繖浠呬粎鏄棶棰樼殑涓涓柟闈紝鎵浠ヤ笅闈㈣繖綃囨枃绔犺瘯鍥捐鏈嶆垜浠敖閲忎嬌鐢╮untime exception鏇夸唬checked exception(鍓嶉潰鎻愬埌鍙互try catch澶勭悊runtime exception錛岃岄伩鍏嶇▼搴忔寕鎺夛紝榪欎篃鏄繖鏍峰仛鐨勪竴涓墠鎻?銆?/span>

榪欑瘒鏂囩珷鎸囧嚭浜咼ava涓璫hecked Exception鐨勪竴浜涚己鐐癸紝鎻愬嚭搴旇鍦ㄧ▼搴忚璁′腑閬垮厤浣跨敤checked Exception,瀵逛簬闇瑕佸鐞哻hecked Exception鐨勪唬鐮侊紝鍙互浣跨敤ExceptionAdapter榪欎釜綾誨checked Exception榪涜鍖呰銆傝繖綃囨枃绔犵殑姒傚康鍜孍xceptionAdapter榪欎釜綾誨潎婧愯嚜Bruce Eckel鐨凞oes Java need Checked Exception銆?br />

Java
鐨?font face="Arial">Exception
鍒嗕負涓ょ被錛屼竴綾繪槸RuntimeException鍙婂叾瀛愮被錛屽彟澶栦竴綾誨氨鏄?font face="Arial">checked Exception銆?font face="Arial">Java瑕佹眰鍑芥暟瀵規病鏈夎catch澶勭悊鎺夌殑checked Exception錛岄渶瑕佸皢鍏跺啓鍦ㄥ嚱鏁扮殑澹版槑閮ㄥ垎銆傜劧鑰岋紝榪欎竴瑕佹眰甯稿父緇欑▼搴忓憳甯︽潵涓浜涗笉蹇呰鐨勮礋鎷呫?/font>

涓轟簡閬垮厤鍦ㄥ嚱鏁板0鏄庝腑鍐?font face="Arial">throws閮ㄥ垎錛屽湪Java欏圭洰閲岄潰甯稿父鍙互鐪嬪埌浠ヤ笅浠g爜鐢ㄦ潵‘鍚炴帀’Exception錛?br />

 try {
  
// 
 }
 catch (Exception ex) {
           ex.printStackTrace();
  }


榪欐樉鐒朵笉鏄竴涓ソ鐨勫鐞?font face="Arial">Exception鍔炴硶錛屼簨瀹炰笂錛?font face="Arial">catch騫跺鐞嗕竴涓?font face="Arial">Exception鎰忓懗鐫璁╃▼搴忎粠鍙戠敓鐨勯敊璇?font face="Arial">(Exception)涓仮澶嶈繃鏉ャ備粠榪欑鎰忎箟涓婅錛屽凡涓婄殑浠g爜鍙彲鑳藉湪涓浜涘緢綆鍗曠殑鎯呭喌涓嬪伐浣滆屼笉甯︽潵闂銆?/font>

瀵逛簬寰堝Exception錛屽線寰娌℃湁鍘誨鐞嗗畠騫惰紼嬪簭浠庨敊璇腑鎭㈠鍑烘潵鐨勫姙娉曪紝榪欐椂鍞竴鑳藉仛鐨勪簨鎯呭彲鑳藉氨鏄湪鐣岄潰涓婃樉紺轟竴浜涙彁紺轟俊鎭粰鐢ㄦ埛銆傝繖縐嶆儏鍐典笅璁╃▼搴忔姏鍑洪亣鍒扮殑Exception鏄洿涓哄悎鐞嗙殑鍋氭硶銆傜劧鑰岋紝榪欐牱鍋氫細浣垮緱涓浜涘嚱鏁扮殑澹版槑鎬ュ墽鑶ㄨ儉銆備竴涓嚱鏁板彲鑳介渶瑕佸0鏄庝細鎶涘嚭鐨?font face="Arial">7銆?font face="Arial">8涓?font face="Arial">checked Exception錛岃屼笖姣忎釜璋冪敤瀹冪殑鍑芥暟涔熼渶瑕佸悓鏍風殑澹版槑銆?/font>

姣旇繖鏇寸碂緋曠殑鏄紝榪欐湁鍙兘鐮村潖綾昏璁$殑open-close鍘熷垯銆傜畝鍗曟潵璇達紝open-close鍘熷垯鏄寚褰撴墿灞曚竴涓ā鍧楃殑鏃跺欙紝鍙互涓嶅獎鍝嶅叾鐜版湁鐨?font face="Arial">client銆?font face="Arial">open-close鍘熷垯鏄氳繃緇ф壙鏉ュ疄鐜扮殑錛屽綋緇ф壙涓涓被鐨勬椂鍊欙紝鎴戜滑鏃㈡墿灞曚簡榪欎釜綾伙紝涔熶笉浼氬獎鍝嶅師鏈夌殑client錛堝洜涓哄榪欎釜綾繪病鏈夋敼鍔級銆?/font>

鐜板湪鑰冭檻涓嬮潰榪欑鎯呭喌錛屾湁涓涓埗綾?font face="Arial">Base錛?/font>

 

public class Base {
    
public void foo() throws ExceptionA {
       
// 
    }

}

 

 

鐜板湪闇瑕佺戶鎵?font face="Arial">Base榪欎釜綾誨茍閲嶈澆foo榪欎釜鏂規硶錛屽湪鏂扮殑瀹炵幇涓紝foo鍙兘鎶涘嚭ExceptionB錛?br />

public class Extend extends Base {
    
public void foo() throws ExceptionB {
       
// 
    }

}

 


鐒惰岋紝榪欐牱鍐欏湪Java閲岄潰鏄笉鍚堟硶鐨勶紝灝界Java涓嶄細鎶涘嚭鐨?font face="Arial">Exception鐪嬩綔鍑芥暟鐗瑰緛鐨勪竴閮ㄥ垎錛屼絾瀛愮被澹版槑鎶涘嚭鐨?font face="Arial">Exception蹇呴』鏄埗綾葷殑瀛愰泦銆?br /> 鍙互鍦?font face="Arial">Base綾葷殑foo鏂規硶涓姞鍏ユ姏鍑?font face="Arial">ExceptionB鐨勫0鏄庯紝鐒惰岋紝榪欐牱灝辯牬鍧忎簡open-close鍘熷垯銆傝屼笖錛屾湁鏃舵垜浠病鏈夊姙娉曞幓淇敼鐖剁被錛屾瘮濡傚綋閲嶈澆涓涓?font face="Arial">Jdk閲岀殑綾葷殑鏃跺欍?/font>

鍙︿竴涓彲鑳界殑鍋氭硶鏄湪Extend鐨?font face="Arial">foo鏂規硶涓?font face="Arial">catch浣?font face="Arial">ExceptionB錛岀劧鍚庢瀯閫犱竴涓?font face="Arial">ExceptionA騫舵姏鍑恒傝繖鏄釜鍙鐨勫姙娉曚絾涔熷彧鏄竴涓潈瀹滀箣璁°?/font>

濡傛灉浣跨敤RuntimeException錛岃繖浜涢棶棰橀兘涓嶄細瀛樺湪銆傝繖璇存槑checked Exception騫朵笉鏄竴涓緢瀹炵敤鐨勬蹇碉紝涔熸剰鍛崇潃鍦ㄧ▼搴忚璁$殑鏃跺欙紝鎴戜滑搴旇璁╄嚜宸辯殑Exception綾葷戶鎵?font face="Arial">RuntimeException鑰屼笉鏄?font face="Arial">Exception銆傦紙榪欏拰JDK鐨勫緩璁濂界浉鍙嶏紝浣嗗疄璺佃瘉鏄庤繖鏍峰仛浠g爜鐨勮川閲忔洿濂姐傦級

瀵逛簬閭d簺闇瑕佸鐞?font face="Arial">checked Exception鐨勪唬鐮侊紝鍙互鍒╃敤涓涓?font face="Arial">ExceptionAdapter鐨勭被鎶?font face="Arial">checked Exception鍖呰鎴愪竴涓?font face="Arial">RuntimeException鎶涘嚭銆?font face="Arial">ExceptionAdapter鏉ヨ嚜Bruce Eckel鐨?font face="Arial">Does Java need Checked Exception榪欑瘒鏂囩珷錛?br />

public class ExceptionAdapter extends RuntimeException {

    
public ExceptionAdapter(Exception ex) {

       
super(ex);

    }


    
public void printStackTrace(java.io.PrintStream s) 

       getCause().printStackTrace(s); 

    }


    
public void printStackTrace(java.io.PrintWriter s) 
       getCause().printStackTrace(s);

    }


    
// rethrow()鐨勪綔鐢ㄦ槸鎶婅鍖呰鐨凟xception鍐嶆鎶涘嚭銆?/span>

    
public void rethrow() 
       
throws Exception
    
{
       
throw (Exception) getCause();
    }

}




Frank_Fang 2009-06-20 15:49 鍙戣〃璇勮
]]>
Java Exception灝忕粨(浜?http://www.tkk7.com/fhtdy2004/archive/2009/06/18/286768.htmlFrank_FangFrank_FangThu, 18 Jun 2009 15:40:00 GMThttp://www.tkk7.com/fhtdy2004/archive/2009/06/18/286768.htmlhttp://www.tkk7.com/fhtdy2004/comments/286768.htmlhttp://www.tkk7.com/fhtdy2004/archive/2009/06/18/286768.html#Feedback0http://www.tkk7.com/fhtdy2004/comments/commentRss/286768.htmlhttp://www.tkk7.com/fhtdy2004/services/trackbacks/286768.html闃呰鍏ㄦ枃

Frank_Fang 2009-06-18 23:40 鍙戣〃璇勮
]]>
Java Exception灝忕粨http://www.tkk7.com/fhtdy2004/archive/2009/06/18/283133.htmlFrank_FangFrank_FangThu, 18 Jun 2009 15:36:00 GMThttp://www.tkk7.com/fhtdy2004/archive/2009/06/18/283133.htmlhttp://www.tkk7.com/fhtdy2004/comments/283133.htmlhttp://www.tkk7.com/fhtdy2004/archive/2009/06/18/283133.html#Feedback1http://www.tkk7.com/fhtdy2004/comments/commentRss/283133.htmlhttp://www.tkk7.com/fhtdy2004/services/trackbacks/283133.html鍞夛紝浠婂ぉibm闈㈣瘯鐪嬫潵鏄閯欒浜嗭紝闂強寮傚父涓嶇煡閬撴槸瑕侀棶CheckedException鍜孶ncheckedException
thinking in java鐪嬬殑鏃╁繕浜嗐?br /> 鐪嬩簡濂藉嚑綃囧笘瀛愶紝榪樻槸鐞嗚В涓嶅娣卞埢
http://www.javaeye.com/topic/2038       涓婚錛氫負浠涔?Java 涓浣跨敤 Checked Exceptions
http://www.javaeye.com/topic/14082     涓婚錛氭垜瀵笴hecked Exceptions鐨勭湅娉?(緇負浠涔坖ava寮曞叆Checked Ex...
http://www.javaeye.com/topic/10482     涓婚錛氭垜瀵笴hecked Exception瑙傜偣鐨勫彉鍖?/a>
http://www.javaeye.com/topic/72170     涓婚錛欽2EE欏圭洰寮傚父澶勭悊
http://www.ibm.com/developerworks/cn/java/j-jtp05254/index.html

http://www.onjava.com/pub/a/onjava/2006/01/11/exception-handling-framework-for-j2ee.html?page=6&x-order=date



http://www.onjava.com/pub/a/onjava/2003/11/19/exceptions.html?page=2

鏈枃鏄疎xception澶勭悊鐨勪竴綃囦笉閿欑殑鏂囩珷錛屼粠Java Exception鐨勬蹇典粙緇嶈搗錛屼緷嬈¤瑙d簡Exception鐨勭被鍨嬶紙Checked/Unchecked錛夛紝Exception澶勭悊鐨勬渶浣沖疄鐜幫細
1錛?閫夋嫨Checked榪樻槸Unchecked鐨勫嚑涓粡鍏鎬緷鎹?br /> 2錛?Exception鐨勫皝瑁呴棶棰?br /> 3錛?濡傛棤蹇呰涓嶈鍒涘緩鑷繁鐨凟xception
4錛?涓嶈鐢‥xception鏉ヤ綔嫻佺▼鎺у埗
5錛?涓嶈杞繪槗鐨勫拷鐣ユ崟鑾風殑Exception
6錛?涓嶈綆鍗曞湴鎹曡幏欏跺眰鐨凟xception
鍘熸枃鍦板潃錛?br /> http://www.onjava.com/pub/a/onjava/2003/11/19/exceptions.html


鍏充簬寮傚父澶勭悊鐨勪竴涓棶棰樺氨鏄瀵逛綍鏃訛紙when錛夊拰濡備綍錛坔ow錛変嬌鐢ㄥ畠浠仛鍒頒簡鐒朵簬蹇冦傚湪鏈枃涓垜灝嗕粙緇嶄竴浜涘叧浜庡紓甯稿鐞嗙殑鏈浣沖疄璺碉紝鍚屾椂鎴戜篃浼氭秹鍙婂埌鏈榪戜簤璁哄崄鍒嗘縺鐑堢殑checked Exception鐨勪嬌鐢ㄩ棶棰樸?br />
浣滀負寮鍙戝憳錛屾垜浠兘甯屾湜鑳藉啓鍑鴻В鍐抽棶棰樺茍涓旀槸楂樿川閲忕殑浠g爜銆備笉騫哥殑鏄紝涓浜涘壇浣滅敤錛坰ide effects錛変即闅忕潃寮傚父鍦ㄦ垜浠殑浠g爜涓參鎱㈡粙鐢熴傛棤搴哥疆鐤戯紝娌℃湁浜哄枩嬈㈠壇浣滅敤錛坰ide effects錛?鎵浠ユ垜浠緢蹇氨鐢ㄦ垜浠嚜宸辯殑鏂瑰紡鏉ラ伩鍏嶅畠錛屾垜鏇劇粡鐪嬪埌涓浜涜仾鏄庣殑紼嬪簭鍛樼敤涓嬮潰鐨勬柟寮忔潵澶勭悊寮傚父錛?br />
public void consumeAndForgetAllExceptions(){
try {
...some code that throws exceptions
} catch (Exception ex){
ex.printStacktrace();
}
}

涓婅竟鐨勪唬鐮佹湁浠涔堥棶棰樹箞錛?br />
鍦ㄥ洖絳斾互鍓嶈鎴戜滑鎯蟲兂鎬庢牱鎵嶆槸姝g‘鐨勶紵鏄殑錛屼竴鏃︾▼搴忕鍒板紓甯革紝瀹冨氨璇ユ寕璧風▼搴忚?鍋?鐐逛粈涔堛傞偅涔堜笂杈圭殑浠g爜鏄繖鏍峰瓙鐨勪箞錛熺湅鍚э紝瀹冮殣鐬掍簡浠涔堬紵瀹冩妸鎵鏈夌殑"鑻︽按"寰鑲氶噷鍜斤紙鍦ㄦ帶鍒跺彴鎵撳嵃鍑哄紓甯鎬俊鎭級錛岀劧鍚庝竴鍒囩戶緇紝浠庤〃闈笂鐪嬪氨鍍忎粈涔堥兘娌℃湁鍙戠敓榪囦竴鏍?.....錛屽緢鏄劇劧錛屼笂杈逛唬鐮佽揪鍒扮殑鏁堟灉騫朵笉鏄垜浠墍鏈熸湜鐨勩?br />
鍚庢潵鍙堟庢牱錛?br />
public void someMethod() throws Exception{
}

涓婅竟鐨勪唬鐮佸張鏈変粈涔堥棶棰橈紵

寰堟槑鏄撅紝涓婅竟鐨勬柟娉曚綋鏄┖鐨勶紝瀹冧笉瀹炵幇浠諱綍鐨勫姛鑳斤紙娌℃湁涓鍙ヤ唬鐮侊級錛岃瘯闂竴涓┖鏂規硶浣撹兘鎶涘嚭浠涔堝紓甯革紵褰撶劧Java騫朵笉闃繪浣犺繖涔堝共銆傛渶榪戯紝鎴戜篃閬囧埌綾諱技鐨勬儏鏅紝鏂規硶澹版槑浼氭姏鍑哄紓甯革紝浣嗘槸浠g爜涓茍娌℃湁浠諱綍"鏈轟細"鏉?灞曠ず"寮傚父銆傚綋鎴戦棶寮鍙戝憳涓轟粈涔堣榪欐牱鍋氱殑鏃跺欙紝浠栧洖絳旀垜璇?鎴戠煡閬擄紝瀹冪‘瀹炴湁鐐歸偅涓紝浣嗘垜浠ュ墠灝辨槸榪欎箞騫茬殑騫朵笖瀹冪‘瀹炶兘涓烘垜宸ヤ綔銆?

鍦–++紺懼尯鏇劇粡鑺變簡鏁板勾瀹炶返鏉ュ疄璺靛浣曚嬌鐢ㄥ紓甯革紝鍏充簬姝ょ被鐨勪簤璁哄湪 java紺懼尯鎵嶅垰鍒氬紑濮嬨傛垜鏇劇粡鐪嬪埌璁稿Java紼嬪簭鍛橀拡瀵逛嬌鐢ㄥ紓甯哥殑闂榪涜浜夎銆傚鏋滃浜庡紓甯稿鐞嗕笉褰撶殑璇濓紝寮傚父鍙互澶уぇ鍑忔參搴旂敤紼嬪簭鐨勬墽琛岄熷害錛屽洜涓哄畠灝嗘秷鑰楀唴瀛樺拰CPU鏉ュ垱寤恒佹姏鍑哄茍鎹曡幏寮傚父銆傚鏋滆繃鍒嗙殑渚濊禆寮傚父澶勭悊錛屼唬鐮佸鏄撹鍜屾槗浣跨敤榪欎袱鏂歸潰浜х敓褰卞搷錛屼互鑷充簬浼氳鎴戜滑鍐欏嚭涓婅竟涓ゅ"緋熺硶"浠g爜銆?br />
寮傚父鍘熺悊

澶т綋涓婅錛屾湁涓夌涓嶅悓鐨?鎯呮櫙"浼氬鑷村紓甯哥殑鎶涘嚭錛?br />
l 緙栫▼閿欒瀵艱嚧寮傚父錛圗xception due Programming errors錛? 榪欑鎯呮櫙涓嬶紝寮傚父寰寰澶勪簬緙栫▼閿欒錛堝錛歂ullPointerException 鎴栬?IllegalArgumentException錛?榪欐椂寮傚父涓鏃︽姏鍑猴紝瀹㈡埛绔皢鍙樺緱鏃犺兘涓哄姏銆?br />
l 瀹㈡埛绔唬鐮侀敊璇鑷村紓甯革紙Exception due client code errors錛? 璇寸櫧鐐瑰氨鏄鎴風璇曞浘璋冪敤API涓嶅厑璁哥殑鎿嶄綔銆?br />
l 璧勬簮澶辮觸瀵艱嚧寮傚父錛圗xception due to resource failures錛? 濡傚唴瀛樹笉瓚蟲垨緗戠粶榪炴帴澶辮觸瀵艱嚧鍑虹幇寮傚父絳夈傝繖浜涘紓甯哥殑鍑虹幇瀹㈡埛绔彲浠ラ噰鍙栫浉搴旂殑鎺柦鏉ユ仮澶嶅簲鐢ㄧ▼搴忕殑緇х畫榪愯銆?br />
Java涓紓甯哥殑綾誨瀷

Java 涓畾涔変簡涓ょ被寮傚父錛?br />
l Checked exception: 榪欑被寮傚父閮芥槸Exception鐨勫瓙綾?br />
l Unchecked exception: 榪欑被寮傚父閮芥槸RuntimeException鐨勫瓙綾伙紝铏界劧RuntimeException鍚屾牱涔熸槸Exception鐨勫瓙綾伙紝浣嗘槸瀹冧滑鏄壒孌婄殑錛屽畠浠笉鑳介氳繃client code鏉ヨ瘯鍥捐В鍐籌紝鎵浠ョО涓篣nchecked exception

涓句釜渚嬪瓙錛屼笅鍥句負NullPointerException鐨勭戶鎵垮叧緋伙細


鍥句腑錛孨ullPointerException緇ф壙鑷猂untimeException錛屾墍浠ュ畠鏄疷nchecked exception.

浠ュ線鎴戦兘鏄簲鐢╟hecked exception澶氫簬Unchecked exception錛屾渶榪戯紝鍦╦ava紺懼尯嬋璧蜂簡涓鍦哄叧浜巆hecked exception鍜屼嬌鐢ㄥ畠浠殑浠峰肩殑浜夎銆傝繖鍦轟簤璁鴻搗婧愪簬JAVA鏄涓涓嫢鏈塁hecked exception鐨勪富嫻丱O璇█榪欐牱涓涓簨瀹烇紝鑰孋++鍜孋#閮芥槸鏍規湰娌℃湁Checked exception錛屽畠浠墍鏈夌殑寮傚父閮芥槸unchecked銆?/em>

涓涓猚hecked exception寮鴻揩瀹冪殑瀹㈡埛绔彲浠ユ姏鍑哄茍鎹曡幏瀹冿紝涓鏃﹀鎴風涓嶈兘鏈夋晥鍦板鐞嗚繖浜涜鎶涘嚭鐨勫紓甯稿氨浼氱粰紼嬪簭鐨勬墽琛屽甫鏉ヤ笉鏈熸湜鐨勮礋鎷呫?br /> Checked exception榪樺彲鑳藉甫鏉ュ皝瑁呮硠婕忥紝鐪嬩笅闈㈢殑浠g爜錛?br />
public List getAllAccounts() throws
FileNotFoundException, SQLException{
...
}

涓婅竟鐨勬柟娉曟姏鍑轟袱涓紓甯搞傚鎴風蹇呴』鏄劇ず鐨勫榪欎袱縐嶅紓甯歌繘琛屾崟鑾峰拰澶勭悊鍗充嬌鏄湪瀹屽叏涓嶇煡閬撹繖縐嶅紓甯稿埌搴曟槸鍥犱負鏂囦歡榪樻槸鏁版嵁搴撴搷浣滃紩璧風殑鎯呭喌涓嬨傚洜姝わ紝姝ゆ椂鐨勫紓甯稿鐞嗗皢瀵艱嚧涓縐嶆柟娉曞拰璋冪敤涔嬮棿涓嶅悎閫傜殑鑰﹀悎銆?br />


鎺ヤ笅鏉ユ垜浼氱粰鍑哄嚑縐嶈璁″紓甯哥殑鏈浣沖疄璺?錛圔est Practises for Designing the API錛?br />
1錛?褰撹鍐沖畾鏄噰鐢╟hecked exception榪樻槸Unchecked exception鐨勬椂鍊欙紝浣犺闂嚜宸變竴涓棶棰橈紝"濡傛灉榪欑寮傚父涓鏃︽姏鍑猴紝瀹㈡埛绔細鍋氭庢牱鐨勮ˉ鏁戯紵"
濡傛灉瀹㈡埛绔彲浠ラ氳繃鍏朵粬鐨勬柟娉曟仮澶嶅紓甯革紝閭d箞榪欑寮傚父灝辨槸checked exception錛涘鏋滃鎴風瀵瑰嚭鐜扮殑榪欑寮傚父鏃犺兘涓哄姏錛岄偅涔堣繖縐嶅紓甯稿氨鏄疷nchecked exception錛涗粠浣跨敤涓婅錛屽綋寮傚父鍑虹幇鐨勬椂鍊欒鍋氫竴浜涜瘯鍥炬仮澶嶅畠鐨勫姩浣滆屼笉瑕佷粎浠呯殑鎵撳嵃瀹冪殑淇℃伅錛屾繪潵鐨勬潵璇達紝鐪嬩笅琛細

Client's reaction when exception happens
Exception type

Client code cannot do anything
Make it an unchecked exception

Client code will take some useful recovery action based on information in exception
Make it a checked exception


姝ゅ錛屽敖閲忎嬌鐢╱nchecked exception鏉ュ鐞嗙紪紼嬮敊璇細鍥犱負unchecked exception涓嶇敤浣垮鎴風浠g爜鏄劇ず鐨勫鐞嗗畠浠紝瀹冧滑鑷繁浼氬湪鍑虹幇鐨勫湴鏂規寕璧風▼搴忓茍鎵撳嵃鍑哄紓甯鎬俊鎭侸ava API涓彁渚涗簡涓板瘜鐨剈nchecked excetpion錛岃濡傦細NullPointerException , IllegalArgumentException 鍜?IllegalStateException絳夛紝鍥犳鎴戜竴鑸嬌鐢ㄨ繖浜涙爣鍑嗙殑寮傚父綾昏屼笉鎰夸翰鑷垱寤烘柊鐨勫紓甯哥被錛岃繖鏍蜂嬌鎴戠殑浠g爜鏄撲簬鐞嗚В騫墮伩鍏嶇殑榪囧鐨勬秷鑰楀唴瀛樸?br />
2錛?淇濇姢灝佽鎬э紙Preserve encapsulation錛?br />
涓嶈璁╀綘瑕佹姏鍑虹殑checked exception鍗囩駭鍒拌緝楂樼殑灞傛銆備緥濡傦紝涓嶈璁㏒QLException寤朵幾鍒頒笟鍔″眰銆備笟鍔″眰騫朵笉闇瑕侊紙涓嶅叧蹇冿紵錛塖QLException銆備綘鏈変袱縐嶆柟娉曟潵瑙e喅榪欑闂錛?br />
l 杞彉SQLException涓哄彟澶栦竴涓猚hecked exception錛屽鏋滃鎴風騫朵笉闇瑕佹仮澶嶈繖縐嶅紓甯哥殑璇濓紱

l 杞彉SQLException涓轟竴涓猽nchecked exception錛屽鏋滃鎴風瀵硅繖縐嶅紓甯告棤鑳戒負鍔涚殑璇濓紱

澶氭暟鎯呭喌涓嬶紝瀹㈡埛绔唬鐮侀兘鏄SQLException鏃犺兘涓哄姏鐨勶紝鍥犳浣犺姣笉鐘硅鮑鐨勬妸瀹冭漿鍙樹負涓涓猽nchecked exception錛岀湅鐪嬩笅杈圭殑浠g爜錛?br /> public void dataAccessCode(){
try{
..some code that throws SQLException
}catch(SQLException ex){
ex.printStacktrace();
}
}


涓婅竟鐨刢atch鍧楃揣绱ф墦鍗板紓甯鎬俊鎭屾病鏈変換浣曠殑鐩存帴鎿嶄綔錛岃繖鏄儏鏈夊彲鍘熺殑錛屽洜涓哄浜嶴QLException浣犺繕濂㈡湜瀹㈡埛绔仛浜涗粈涔堝憿錛燂紙浣嗘槸鏄劇劧榪欑灝辮薄浠涔堜簨鎯呴兘娌″彂鐢熶竴鏍風殑鍋氭硶鏄笉鍙彇鐨勶級閭d箞鏈夋病鏈夊彟澶栦竴縐嶆洿鍔犲彲琛岀殑鏂規硶鍛紵

public void dataAccessCode(){
try{
..some code that throws SQLException
}catch(SQLException ex){
throw new RuntimeException(ex);
}
}

涓婅竟鐨勫仛娉曟槸鎶奡QLException杞崲涓篟untimeException錛屼竴鏃QLException琚姏鍑猴紝閭d箞紼嬪簭灝嗘姏鍑篟untimeException,姝ゆ椂紼嬪簭琚寕璧峰茍榪斿洖瀹㈡埛绔紓甯鎬俊鎭?br />
濡傛灉浣犳湁瓚沖鐨勪俊蹇冩仮澶嶅畠褰揝QLException琚姏鍑虹殑鏃跺欙紝閭d箞浣犱篃鍙互鎶婂畠杞崲涓轟竴涓湁鎰忎箟鐨刢hecked exception, 浣嗘槸鎴戝彂鐜板湪澶у鏃跺欐姏鍑篟untimeException宸茬粡瓚沖鐢ㄤ簡銆?br />
3錛?涓嶈鍒涘緩娌℃湁鎰忎箟鐨勫紓甯革紙Try not to create new custom exceptions if they do not have useful information for client code.錛?br />
鐪嬬湅涓嬮潰鐨勪唬鐮佹湁浠涔堥棶棰橈紵

public class DuplicateUsernameException
extends Exception {}


瀹冮櫎浜嗘湁涓涓?鎰忎箟鏄庣‘"鐨勫悕瀛椾互澶栨病鏈変換浣曟湁鐢ㄧ殑淇℃伅浜嗐備笉瑕佸繕璁癊xception璺熷叾浠栫殑Java綾諱竴鏍鳳紝瀹㈡埛绔彲浠ヨ皟鐢ㄥ叾涓殑鏂規硶鏉ュ緱鍒版洿澶氱殑淇℃伅銆?br />
鎴戜滑鍙互涓哄叾娣誨姞涓浜涘繀瑕佺殑鏂規硶錛屽涓嬶細

public class DuplicateUsernameException
extends Exception {
public DuplicateUsernameException
(String username){....}
public String requestedUsername(){...}
public String[] availableNames(){...}
}



鍦ㄦ柊鐨勪唬鐮佷腑鏈変袱涓湁鐢ㄧ殑鏂規硶錛歳eqeuestedUsername(),瀹㈡埛浣嗗彲浠ラ氳繃瀹冨緱鍒拌姹傜殑鍚嶇О錛沘vailableNames(),瀹㈡埛绔彲浠ラ氳繃瀹冨緱鍒頒竴緇勬湁鐢ㄧ殑usernames銆傝繖鏍峰鎴風鍦ㄥ緱鍒板叾榪斿洖鐨勪俊鎭潵鏄庣‘鑷繁鐨勬搷浣滃け璐ョ殑鍘熷洜銆備絾鏄鏋滀綘涓嶆兂娣誨姞鏇村鐨勪俊鎭紝閭d箞浣犲彲浠ユ姏鍑轟竴涓爣鍑嗙殑Exception:

throw new Exception("Username already taken");
鏇寸敋鐨勬儏鍐碉紝濡傛灉浣犺涓哄鎴風騫朵笉鎯崇敤榪囧鐨勬搷浣滆屼粎浠呮兂鐪嬪埌寮傚父淇℃伅錛屼綘鍙互鎶涘嚭涓涓猽nchecked exception:

throw new RuntimeException("Username already taken");

鍙﹀錛屼綘鍙互鎻愪緵涓涓柟娉曟潵楠岃瘉璇sername鏄惁琚崰鐢ㄣ?br />
寰堟湁蹇呰鍐嶉噸鐢充竴涓嬶紝checked exception搴旇璁╁鎴風浠庝腑寰楀埌涓板瘜鐨勪俊鎭傝鎯寵浣犵殑浠g爜鏇村姞鏄撹錛岃鍊懼悜浜庣敤unchecked excetpion鏉ュ鐞嗙▼搴忎腑鐨勯敊璇紙Prefer unchecked exceptions for all programmatic errors錛夈?br />
4錛?Document exceptions.

浣犲彲浠ラ氳繃Javadoc's @throws 鏍囩鏉ヨ鏄庯紙document錛変綘鐨凙PI涓鎶涘嚭checked exception鎴栬卽nchecked exception銆傜劧鑰岋紝鎴戞洿鍊懼悜浜庝嬌鐢ㄦ潵鍗曞厓嫻嬭瘯鏉ヨ鏄庯紙document錛夊紓甯搞備笉綆′綘閲囩敤鍝腑鏂瑰紡錛屼綘瑕佽瀹㈡埛绔唬鐮佺煡閬撲綘鐨凙PI涓墍瑕佹姏鍑虹殑寮傚父銆傝繖閲屾湁涓涓敤鍗曞厓嫻嬭瘯鏉ユ祴璇旾ndexOutOfBoundsException鐨勪緥瀛愶細

public void testIndexOutOfBoundsException() {
ArrayList blankList = new ArrayList();
try {
blankList.get(10);
fail("Should raise an IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException success) {}
}



涓婅竟鐨勪唬鐮佸湪璇鋒眰blankList.get(10)鐨勬椂鍊欎細鎶涘嚭IndexOutOfBoundsException,濡傛灉娌℃湁琚姏鍑猴紝灝唂ail ("Should raise an IndexOutOfBoundsException")鏄劇ず璇存槑璇ユ祴璇曞け璐ャ傞氳繃涔﹀啓嫻嬭瘯寮傚父鐨勫崟鍏冩祴璇曪紝浣犱笉浣嗗彲浠ョ湅鍒板紓甯告槸鎬庢牱鐨勫伐浣滅殑錛岃屼笖浣犲彲浠ヨ浣犵殑浠g爜鍙樺緱瓚婃潵瓚婂仴澹?br />

涓嬮潰浣滆呭皢浠嬬粛鐣屼腑浣跨敤寮傚父鐨勬渶浣沖疄璺碉紙Best Practices for Using Exceptions錛?br /> 1錛?鎬繪槸瑕佸仛涓浜涙竻鐞嗗伐浣滐紙Always clean up after yourself錛?br />
濡傛灉浣犱嬌鐢ㄤ竴浜涜祫婧愪緥濡傛暟鎹簱榪炴帴鎴栬呯綉緇滆繛鎺ワ紝璇瘋浣忚鍋氫竴浜涙竻鐞嗗伐浣滐紙濡傚叧闂暟鎹簱榪炴帴鎴栬呯綉緇滆繛鎺ワ級錛屽鏋滀綘鐨凙PI鎶涘嚭Unchecked exception錛岄偅涔堜綘瑕佺敤try-finally鏉ュ仛蹇呰鐨勬竻鐞嗗伐浣滐細
public void dataAccessCode(){    
Connection conn 
= null;    
try{    
conn 
= getConnection();    
..some code that 
throws SQLException    
}
catch(SQLException ex){    
ex.printStacktrace();    
}
 finally{    
DBUtil.closeConnection(conn);    
}
    
}
    
   
class DBUtil{    
public static void closeConnection    
(Connection conn)
{    
try{    
conn.close();    
}
 catch(SQLException ex){    
logger.error(
"Cannot close connection");    
throw new RuntimeException(ex);    
}
    
}
    
}
    

DBUtil鏄竴涓伐鍏風被鏉ュ叧闂瑿onnection.鏈夊繀瑕佺殑璇寸殑浣跨敤鐨刦inally鐨勯噸瑕佹ф槸涓嶇紼嬪簭鏄惁紕板埌寮傚父錛屽畠閮戒細琚墽琛屻傚湪涓婅竟鐨勪緥瀛愪腑錛宖inally涓叧闂繛鎺ワ紝濡傛灉鍦ㄥ叧闂繛鎺ョ殑鏃跺欏嚭鐜伴敊璇氨鎶涘嚭RuntimeException.



2錛?涓嶈浣跨敤寮傚父鏉ユ帶鍒舵祦紼嬶紙Never use exceptions for flow control錛?br />
涓嬭竟浠g爜涓紝MaximumCountReachedException琚敤浜庢帶鍒舵祦紼嬶細

public void useExceptionsForFlowControl() {    
try {    
while (true{    
increaseCount();    
}
    
}
 catch (MaximumCountReachedException ex) {    
}
    
//Continue execution    
}
    
   
public void increaseCount()    
throws MaximumCountReachedException {    
if (count >= 5000)    
throw new MaximumCountReachedException();    
}
     

涓婅竟鐨剈seExceptionsForFlowControl()鐢ㄤ竴涓棤闄愬驚鐜潵澧炲姞count鐩村埌鎶涘嚭寮傚父錛岃繖縐嶅仛娉曞茍娌℃湁璇磋浠g爜涓嶆槗璇伙紝浣嗘槸瀹冩槸紼嬪簭鎵ц鏁堢巼闄嶄綆銆?br />
璁頒綇錛屽彧鍦ㄨ浼氭姏鍑哄紓甯哥殑鍦版柟榪涜寮傚父澶勭悊銆?br />


3錛?涓嶈蹇界暐寮傚父

褰撴湁寮傚父琚姏鍑虹殑鏃跺欙紝濡傛灉浣犱笉鎯蟲仮澶嶅畠錛岄偅涔堜綘瑕佹涓嶇姽璞殑灝嗗叾杞崲涓簎nchecked exception錛岃屼笉鏄敤涓涓┖鐨刢atch鍧楁垨鑰呬粈涔堜篃涓嶅仛鏉ュ拷鐣ュ畠錛屼互鑷充簬浠庤〃闈㈡潵鐪嬭薄鏄粈涔堜篃娌℃湁鍙戠敓涓鏍楓?br />


4錛?涓嶈鎹曡幏欏跺眰鐨凟xception

unchecked exception閮芥槸RuntimeException鐨勫瓙綾伙紝RuntimeException鍙堢戶鎵縀xception,鍥犳錛屽鏋滃崟綰殑鎹曡幏Exception,閭d箞浣犲悓鏍蜂篃鎹曡幏浜哛untimeException,濡備笅浠g爜錛?br />
try{
..
}catch(Exception ex){
}
涓鏃︿綘鍐欏嚭浜嗕笂杈圭殑浠g爜錛堟敞鎰廲atch鍧楁槸絀虹殑錛夛紝瀹冨皢蹇界暐鎵鏈夌殑寮傚父錛屽寘鎷瑄nchecked exception.

5錛?Log exceptions just once

Logging the same exception stack trace more than once can confuse the programmer examining the stack trace about the original source of exception. So just log it once.



]]>
[杞琞涓轟粈涔堜笉榧撳姳浣跨敤 Thread.stop銆乀hread.suspend鍜?Thread.resume鍙婅В鍐蟲柟娉?/title><link>http://www.tkk7.com/fhtdy2004/archive/2009/06/10/281315.html</link><dc:creator>Frank_Fang</dc:creator><author>Frank_Fang</author><pubDate>Wed, 10 Jun 2009 13:57:00 GMT</pubDate><guid>http://www.tkk7.com/fhtdy2004/archive/2009/06/10/281315.html</guid><wfw:comment>http://www.tkk7.com/fhtdy2004/comments/281315.html</wfw:comment><comments>http://www.tkk7.com/fhtdy2004/archive/2009/06/10/281315.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.tkk7.com/fhtdy2004/comments/commentRss/281315.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/fhtdy2004/services/trackbacks/281315.html</trackback:ping><description><![CDATA[     鎽樿: 涓轟粈涔堜笉榧撳姳浣跨敤 Thread.stop銆乀hread.suspend鍜?Thread.resume鍙婅В鍐蟲柟娉?nbsp; <a href='http://www.tkk7.com/fhtdy2004/archive/2009/06/10/281315.html'>闃呰鍏ㄦ枃</a><img src ="http://www.tkk7.com/fhtdy2004/aggbug/281315.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/fhtdy2004/" target="_blank">Frank_Fang</a> 2009-06-10 21:57 <a href="http://www.tkk7.com/fhtdy2004/archive/2009/06/10/281315.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>OWL瀹炰緥鎻忚堪http://www.tkk7.com/fhtdy2004/archive/2009/06/10/281310.htmlFrank_FangFrank_FangWed, 10 Jun 2009 13:56:00 GMThttp://www.tkk7.com/fhtdy2004/archive/2009/06/10/281310.htmlhttp://www.tkk7.com/fhtdy2004/comments/281310.htmlhttp://www.tkk7.com/fhtdy2004/archive/2009/06/10/281310.html#Feedback0http://www.tkk7.com/fhtdy2004/comments/commentRss/281310.htmlhttp://www.tkk7.com/fhtdy2004/services/trackbacks/281310.html

http://www.transwiki.org/wiki/index.php/OWL%E6%8C%87%E5%8D%97_%E6%8E%A8%E8%8D%90%E6%A0%87%E5%87%86-4#equivalentClass.2C_equivalentProperty 錛堟湰浣撲粙緇嶏級

http://imarine.blog.163.com/blog/static/5138018320071119110889/錛堟湰浣撴煡璇級

http://bbs.w3china.org/dispbbs.asp?boardID=2&ID=74918/ (鏈綋鏌ヨ錛?br />

-------------------------------------------------------
rdfs:subClassOf 鎻忚堪

 <owl:Class rdf:ID="Wine">
   <rdfs:subClassOf rdf:resource="&food;PotableLiquid"/>
   <rdfs:label xml:lang="en">wine</rdfs:label>
   <rdfs:label xml:lang="fr">vin</rdfs:label>
 </owl:Class>

Wine PotableLiquid
--------------------------------------------------------
ObjectProperty   鎻忚堪 wine hasWinDescriptor WineDescriptor

 <owl:ObjectProperty rdf:ID="hasWineDescriptor">
   <rdfs:domain rdf:resource="#Wine" />
   <rdfs:range  rdf:resource="#WineDescriptor" />
 </owl:ObjectProperty>


-------------------------------------------------------
DatatypeProperty 鎻忚堪 VintageYear is 1998

  <owl:DatatypeProperty rdf:ID="yearValue">
    <rdfs:domain rdf:resource="#VintageYear" />   
    <rdfs:range  rdf:resource="&xsd;positiveInteger" />
  </owl:DatatypeProperty>
 
  <VintageYear rdf:ID="Year1998">
    <yearValue rdf:datatype="&xsd;positiveInteger">1998</yearValue>
  </VintageYear>

  <owl:ObjectProperty rdf:ID="hasVintageYear">
    <rdf:type rdf:resource="&owl;FunctionalProperty" />
    <rdfs:domain rdf:resource="#Vintage" />
    <rdfs:range  rdf:resource="#VintageYear" />
  </owl:ObjectProperty>

Vintage has VintageYear that is 1998 ------ 钁¤悇閰掔殑騫翠喚鏄?998 鎴?1998鐨勮憽钀勯厭

--------------------------------------------------------
涓綋(individual) 鎻忚堪

 <owl:Class rdf:ID="WineGrape">
   <rdfs:subClassOf rdf:resource="&food;Grape" />
 </owl:Class>
 <WineGrape rdf:ID="CabernetSauvignonGrape" />

CabernetSauvignonGrape is WineGrape ---- 璧ら湠鐝犺憽钀勬爲

----------------------灞炴х壒鎬?-----------------------
TransitiveProperty 鎻忚堪
SymmetricProperty  鎻忚堪

<owl:Class rdf:ID="Region" />

<owl:ObjectProperty rdf:ID="locatedIn">
   <rdf:type rdf:resource="&owl;TransitiveProperty" />
   <rdfs:domain rdf:resource="    <rdfs:range rdf:resource="#Region" />
</owl:ObjectProperty>

<owl:ObjectProperty rdf:ID="adjacentRegion">
  <rdf:type rdf:resource="&owl;SymmetricProperty" />
  <rdfs:domain rdf:resource="#Region" />
  <rdfs:range rdf:resource="#Region" />
</owl:ObjectProperty>

--------------------------------------------
FunctionalProperty   鎻忚堪 涓涓粰瀹氱殑 Vintage涓綋鍙兘浣跨敤hasVintageYear灞炴т笌鍗曠嫭涓涓勾浠界浉鍏寵仈

 <owl:Class rdf:ID="VintageYear" />
 <owl:ObjectProperty rdf:ID="hasVintageYear">
   <rdf:type rdf:resource="&owl;FunctionalProperty" />
   <rdfs:domain rdf:resource="#Vintage" />
   <rdfs:range  rdf:resource="#VintageYear" />
 </owl:ObjectProperty>
---------------------------------------------
 inverseOf  鎻忚堪 鍚勭钁¤悇閰掗兘鏈夊埗閫犲晢

 <owl:ObjectProperty rdf:ID="hasMaker">
   <rdf:type rdf:resource="&owl;FunctionalProperty" />
 </owl:ObjectProperty>  
 <owl:ObjectProperty rdf:ID="producesWine">
   <owl:inverseOf rdf:resource="#hasMaker" />
 </owl:ObjectProperty>

---------------------------------------------
 InverseFunctionalProperty 

 <owl:ObjectProperty rdf:ID="hasMaker" />
 <owl:ObjectProperty rdf:ID="producesWine">
   <rdf:type rdf:resource="&owl;InverseFunctionalProperty" />
   <owl:inverseOf rdf:resource="#hasMaker" />
 </owl:ObjectProperty>

 owl:InverseFunctional鎰忓懗鐫灞炴х殑鍊煎煙涓殑鍏冪礌涓哄畾涔夊煙涓殑姣忎釜鍏冪礌鎻愪緵浜嗕竴涓敮涓鐨勬爣璇?/p>


 ---灞炴ч檺鍒?-----
 -------------------------
 allValuesFrom   鎻忚堪 Wine鐨勫埗閫犲晢蹇呴』鏄疻inery銆?br />  owl:someValuesFrom鏇挎崲owl:allValuesFrom錛岄偅灝辨剰鍛崇潃鑷沖皯鏈変竴涓猈ine綾誨疄渚嬬殑hasMaker灞炴ф槸鎸囧悜涓涓猈inery綾葷殑涓綋鐨勩?/p>

 <owl:Class rdf:ID="Wine">
   <rdfs:subClassOf rdf:resource="&food;PotableLiquid" />
   ...
   <rdfs:subClassOf>
     <owl:Restriction>
       <owl:onProperty rdf:resource="#hasMaker" />
       <owl:allValuesFrom rdf:resource="#Winery" />
     </owl:Restriction>
   </rdfs:subClassOf>
  
   ...
 </owl:Class>

 -------------------------------------------------------
 owl:cardinality  鎻忚堪  鍏佽瀵逛竴涓叧緋諱腑鐨勫厓绱犳暟鐩綔鍑虹簿紜殑闄愬埗

  <owl:Class rdf:ID="Vintage">
   <rdfs:subClassOf>
     <owl:Restriction>
       <owl:onProperty rdf:resource="#hasVintageYear"/>
       <owl:cardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:cardinality>
     </owl:Restriction>
   </rdfs:subClassOf>
 </owl:Class>

 姣忕摱钁¤悇閰掑彧鏈変竴涓勾搴?/p>

 -------------------------------------------------------
 hasValue  鎻忚堪 涓涓釜浣撳彧瑕佽嚦灝戞湁“涓涓?#8221;灞炴у肩瓑浜巋asValue鐨勮祫婧愶紝榪欎竴涓綋灝辨槸璇ョ被鐨勬垚鍛樸?/p>

  <owl:Class rdf:ID="Burgundy">
   ...
   <rdfs:subClassOf>
     <owl:Restriction>
       <owl:onProperty rdf:resource="#hasSugar" />
       <owl:hasValue rdf:resource="#Dry" />
     </owl:Restriction>
   </rdfs:subClassOf>
 </owl:Class>

 鎵鏈夌殑Burgundy閰掗兘鏄共(dry)鐨勯厭銆備篃鍗籌紝瀹冧滑鐨刪asSugar灞炴у繀欏昏嚦灝戞湁涓涓槸鍊肩瓑浜嶥ry錛堝共鐨勶級

------------------------------------------------------
 鏈綋鏄犲皠
 綾誨拰灞炴т箣闂寸殑絳変環鍏崇郴錛嶏紞equivalentClass, equivalentProperty

 <owl:Class rdf:ID="TexasThings">
   <owl:equivalentClass>
     <owl:Restriction>
       <owl:onProperty rdf:resource="#locatedIn" />
       <owl:someValuesFrom rdf:resource="#TexasRegion" />
     </owl:Restriction>
   </owl:equivalentClass>
 </owl:Class>

 TexasThings鎸囩殑鏄偅浜涙伆濂戒綅浜嶵exasRegion鐨勪簨鐗┿備嬌鐢╫wl:equivalentClass 鍜屼嬌鐢╮dfs:subClassOf 鐨勪笉鍚屽氨鍍忓繀瑕佹潯浠跺拰鍏呰鏉′歡鐨勪笉鍚屼竴鏍楓傚鏋滄槸浣跨敤subClassOf鐨勮瘽錛屼綅浜嶵exasRegion鐨勪簨鐗╀笉涓瀹氭槸TexasThings銆備絾鏄紝濡傛灉浣跨敤owl:equivalentClass錛屼綅浜嶵exasRegion鐨勪簨鐗╀竴瀹氬睘浜嶵exasThings綾匯?/p>

------------------------------------------------------
涓綋闂寸殑鍚屼竴鎬?錛峴ameAs

 <Wine rdf:ID="MikesFavoriteWine>
     <owl:sameAs rdf:resource="#StGenevieveTexasWhite" />
 </Wine>

 淇グ錛堟垨寮曠敤錛変袱涓被鐢╯ameAs榪樻槸鐢╡quivalentClass鏁堟灉鏄笉鍚岀殑銆傜敤sameAs鐨勬椂鍊欙紝鎶婁竴涓被瑙i噴涓轟竴涓釜浣擄紝灝卞儚鍦∣WL Full涓竴鏍鳳紝榪欐湁鍒╀簬瀵規湰浣撹繘琛屽垎綾匯?/p>

-----------------------------------------------------
 涓嶅悓鐨勪釜浣?br /> ------------------------------------------------------
differentFrom

 <WineSugar rdf:ID="Dry" />
 
 <WineSugar rdf:ID="Sweet">
   <owl:differentFrom rdf:resource="#Dry"/> 
 </WineSugar>
 
 <WineSugar rdf:ID="OffDry">
   <owl:differentFrom rdf:resource="#Dry"/>
   <owl:differentFrom rdf:resource="#Sweet"/>
 </WineSugar>

 ---------------------------------------------------
AllDifferent

 <owl:AllDifferent>
   <owl:distinctMembers rdf:parseType="Collection">
     <vin:WineColor rdf:about="#Red" />
     <vin:WineColor rdf:about="#White" />
     <vin:WineColor rdf:about="#Rose" />
   </owl:distinctMembers>
 </owl:AllDifferent>

 owl:distinctMembers灞炴у0鏄庡彧鑳藉拰owl:AllDifferent灞炴у0鏄庝竴璧風粨鍚堜嬌鐢ㄣ?/p>

 -----------------------------------------------------
 intersectionOf

 <owl:Class rdf:ID="WhiteWine">
   <owl:intersectionOf rdf:parseType="Collection">
     <owl:Class rdf:about="#Wine" />
     <owl:Restriction>
       <owl:onProperty rdf:resource="#hasColor" />
       <owl:hasValue rdf:resource="#White" />
     </owl:Restriction>
   </owl:intersectionOf>
 </owl:Class>

 WhiteWine鎭板ソ鏄被Wine涓庢墍鏈夐鑹叉槸鐧借壊鐨勪簨鐗╃殑闆嗗悎鐨勪氦闆?/p>

 -----------------------------------------------------
 unionOf

 <owl:Class rdf:ID="Fruit">
   <owl:unionOf rdf:parseType="Collection">
     <owl:Class rdf:about="#SweetFruit" />
     <owl:Class rdf:about="#NonSweetFruit" />
   </owl:unionOf>
 </owl:Class>

 ------------------------------------------------------
 complementOf 浠庢煇涓鍩?domain of discourse)閫夊嚭涓嶅睘浜庢煇涓被鐨勬墍鏈変釜浣?/p>

 <owl:Class rdf:ID="NonFrenchWine">
   <owl:intersectionOf rdf:parseType="Collection">
     <owl:Class rdf:about="#Wine"/>
    
     <owl:Class>
       <owl:complementOf>
         <owl:Restriction>
           <owl:onProperty rdf:resource="#locatedIn" />
           <owl:hasValue rdf:resource="#FrenchRegion" />
         </owl:Restriction>
       </owl:complementOf>
     </owl:Class>
   </owl:intersectionOf>
 </owl:Class>

 -----------------------------------------------------------
 oneOf  鏋氫婦

 <owl:Class rdf:ID="WineColor">
   <rdfs:subClassOf rdf:resource="#WineDescriptor"/>
   <owl:oneOf rdf:parseType="Collection">
     <owl:Thing rdf:about="#White"/>
     <owl:Thing rdf:about="#Rose"/>
     <owl:Thing rdf:about="#Red"/>
   </owl:oneOf>
 </owl:Class>

 鏈夋晥鐨勪釜浣撳0鏄?/p>

 -----------------------------------------------------------
 disjointWith  涓嶇浉浜ょ被  淇濊瘉浜嗗睘浜庢煇涓涓被鐨勪釜浣撲笉鑳藉悓鏃跺張鏄彟涓涓寚瀹氱被鐨勫疄渚?/p>

 <owl:Class rdf:ID="Pasta">
   <rdfs:subClassOf rdf:resource="#EdibleThing"/>
   <owl:disjointWith rdf:resource="#Meat"/>
   <owl:disjointWith rdf:resource="#Fowl"/>
   <owl:disjointWith rdf:resource="#Seafood"/>
   <owl:disjointWith rdf:resource="#Dessert"/>
   <owl:disjointWith rdf:resource="#Fruit"/>
 </owl:Class>

Pasta涓庡叾瀹冩墍鏈夌被鏄笉鐩鎬氦鐨勩備緥濡傦紝瀹冨茍娌℃湁淇濊瘉Meat鍜孎ruit鏄笉鐩鎬氦鐨?/p>

]]>
Java澶氱嚎紼媠leep(),join(),interrupt(),wait(),notify()http://www.tkk7.com/fhtdy2004/archive/2009/06/08/280728.htmlFrank_FangFrank_FangMon, 08 Jun 2009 13:01:00 GMThttp://www.tkk7.com/fhtdy2004/archive/2009/06/08/280728.htmlhttp://www.tkk7.com/fhtdy2004/comments/280728.htmlhttp://www.tkk7.com/fhtdy2004/archive/2009/06/08/280728.html#Feedback5http://www.tkk7.com/fhtdy2004/comments/commentRss/280728.htmlhttp://www.tkk7.com/fhtdy2004/services/trackbacks/280728.html
浠ヤ笅鏄弬鑰?lt;<Java澶氱嚎紼嬫ā寮?gt;>鐨?
1. sleep() & interrupt()
    綰跨▼A姝e湪浣跨敤sleep()鏆傚仠鐫: Thread.sleep(100000);
    濡傛灉瑕佸彇娑堜粬鐨勭瓑寰呯姸鎬?鍙互鍦ㄦ鍦ㄦ墽琛岀殑綰跨▼閲?姣斿榪欓噷鏄疊)璋冪敤
        a.interrupt();
    浠ょ嚎紼婣鏀懼純鐫$湢鎿嶄綔,榪欓噷a鏄嚎紼婣瀵瑰簲鍒扮殑Thread瀹炰緥
    鎵цinterrupt()鏃?騫朵笉闇瑕佽幏鍙朤hread瀹炰緥鐨勯攣瀹?浠諱綍綰跨▼鍦ㄤ換浣曟椂鍒?閮藉彲浠ヨ皟鐢ㄥ叾浠栫嚎紼媔nterrupt().褰搒leep涓殑綰跨▼琚皟鐢╥nterrupt()鏃?灝變細鏀懼純鏆傚仠鐨勭姸鎬?騫舵姏鍑篒nterruptedException.涓㈠嚭寮傚父鐨?鏄疉綰跨▼.

2. wait() & interrupt()
    綰跨▼A璋冪敤浜唚ait()榪涘叆浜嗙瓑寰呯姸鎬?涔熷彲浠ョ敤interrupt()鍙栨秷.
    涓嶈繃榪欐椂鍊欒灝忓績閿佸畾鐨勯棶棰?綰跨▼鍦ㄨ繘鍏ョ瓑寰呭尯,浼氭妸閿佸畾瑙i櫎,褰撳絳夊緟涓殑綰跨▼璋冪敤interrupt()鏃?娉ㄦ剰鏄瓑寰呯殑綰跨▼璋冪敤鍏惰嚜宸辯殑interrupt()),浼氬厛閲嶆柊鑾峰彇閿佸畾,鍐嶆姏鍑哄紓甯?鍦ㄨ幏鍙栭攣瀹氫箣鍓?鏄棤娉曟姏鍑哄紓甯哥殑.

3. join() & interrupt()
    褰撶嚎紼嬩互join()絳夊緟鍏朵粬綰跨▼緇撴潫鏃?涓鏍峰彲浠ヤ嬌鐢╥nterrupt()鍙栨秷涔?鍥犱負璋冪敤join()涓嶉渶瑕佽幏鍙栭攣瀹?鏁呬笌sleep()鏃朵竴鏍?浼氶┈涓婅煩鍒癱atch鍧楅噷. 娉ㄦ剰鏄殢璋冪敤interrupt()鏂規硶,涓瀹氭槸闃誨鐨勭嚎紼嬫潵璋冪敤鍏惰嚜宸辯殑interrupt鏂規硶.濡傚湪綰跨▼a涓皟鐢ㄦ潵綰跨▼t.join().鍒檃浼氱瓑t鎵ц瀹屽悗鍦ㄦ墽琛宼.join鍚庣殑浠g爜,褰撳湪綰跨▼b涓皟鐢ㄦ潵a.interrupt()鏂規硶,鍒欎細鎶涘嚭InterruptedException

4. interrupt()鍙槸鏀瑰彉涓柇鐘舵佽屽凡
    interrupt()涓嶄細涓柇涓涓鍦ㄨ繍琛岀殑綰跨▼銆傝繖涓鏂規硶瀹為檯涓婂畬鎴愮殑鏄紝鍦ㄧ嚎紼嬪彈鍒伴樆濉炴椂鎶涘嚭涓涓腑鏂俊鍙鳳紝榪欐牱綰跨▼灝卞緱浠ラ鍑洪樆濉炵殑鐘舵併傛洿紜垏鐨勮錛屽鏋滅嚎紼嬭Object.wait, Thread.join鍜孴hread.sleep涓夌鏂規硶涔嬩竴闃誨錛岄偅涔堬紝瀹冨皢鎺ユ敹鍒頒竴涓腑鏂紓甯革紙InterruptedException錛夛紝浠庤屾彁鏃╁湴緇堢粨琚樆濉炵姸鎬併?
    濡傛灉綰跨▼娌℃湁琚樆濉烇紝榪欐椂璋冪敤interrupt()灝嗕笉璧蜂綔鐢紱鍚﹀垯錛岀嚎紼嬪氨灝嗗緱鍒板紓甯革紙璇ョ嚎紼嬪繀欏諱簨鍏堥澶囧ソ澶勭悊姝ょ姸鍐碉級錛屾帴鐫閫冪闃誨鐘舵併?
    綰跨▼A鍦ㄦ墽琛宻leep,wait,join鏃?綰跨▼B璋冪敤A鐨刬nterrupt鏂規硶,鐨勭‘榪欎竴涓椂鍊橝浼氭湁InterruptedException寮傚父鎶涘嚭鏉?浣嗚繖鍏跺疄鏄湪sleep,wait,join榪欎簺鏂規硶鍐呴儴浼氫笉鏂鏌ヤ腑鏂姸鎬佺殑鍊?鑰岃嚜宸辨姏鍑虹殑InterruptedException銆?
    濡傛灉綰跨▼A姝e湪鎵ц涓浜涙寚瀹氱殑鎿嶄綔鏃跺璧嬪?for,while,if,璋冪敤鏂規硶絳?閮戒笉浼氬幓媯鏌ヤ腑鏂姸鎬?鎵浠ョ嚎紼婣涓嶄細鎶涘嚭InterruptedException,鑰屼細涓鐩存墽琛岀潃鑷繁鐨勬搷浣?褰撶嚎紼婣緇堜簬鎵ц鍒皐ait(),sleep(),join()鏃?鎵嶉┈涓婁細鎶涘嚭InterruptedException.
    鑻ユ病鏈夎皟鐢╯leep(),wait(),join()榪欎簺鏂規硶,鎴栨槸娌℃湁鍦ㄧ嚎紼嬮噷鑷繁媯鏌ヤ腑鏂姸鎬佽嚜宸辨姏鍑篒nterruptedException鐨勮瘽,閭nterruptedException鏄笉浼氳鎶涘嚭鏉ョ殑.

欏轟究鍔犱釜涓嶵hread.sleep()鐩稿悓鏁堟灉鐨勪唬鐮?
public static void amethod(long x) throws InterruptedExcetion{
    if (x != 0) {
        Object o = new Object();
        synchronized (o) {
            o.wait(x);
        }
    }
}


]]>
姝g‘鐞嗚ВThreadLocalhttp://www.tkk7.com/fhtdy2004/archive/2009/06/02/279582.htmlFrank_FangFrank_FangTue, 02 Jun 2009 06:18:00 GMThttp://www.tkk7.com/fhtdy2004/archive/2009/06/02/279582.htmlhttp://www.tkk7.com/fhtdy2004/comments/279582.htmlhttp://www.tkk7.com/fhtdy2004/archive/2009/06/02/279582.html#Feedback3http://www.tkk7.com/fhtdy2004/comments/commentRss/279582.htmlhttp://www.tkk7.com/fhtdy2004/services/trackbacks/279582.html闃呰鍏ㄦ枃

]]>
ThreadLocal鍜宻ynchronizedhttp://www.tkk7.com/fhtdy2004/archive/2009/06/01/279469.htmlFrank_FangFrank_FangMon, 01 Jun 2009 13:57:00 GMThttp://www.tkk7.com/fhtdy2004/archive/2009/06/01/279469.htmlhttp://www.tkk7.com/fhtdy2004/comments/279469.htmlhttp://www.tkk7.com/fhtdy2004/archive/2009/06/01/279469.html#Feedback1http://www.tkk7.com/fhtdy2004/comments/commentRss/279469.htmlhttp://www.tkk7.com/fhtdy2004/services/trackbacks/279469.html闃呰鍏ㄦ枃

]]>
Java澶氱嚎紼嬪皬緇?/title><link>http://www.tkk7.com/fhtdy2004/archive/2009/06/01/279329.html</link><dc:creator>Frank_Fang</dc:creator><author>Frank_Fang</author><pubDate>Mon, 01 Jun 2009 01:31:00 GMT</pubDate><guid>http://www.tkk7.com/fhtdy2004/archive/2009/06/01/279329.html</guid><wfw:comment>http://www.tkk7.com/fhtdy2004/comments/279329.html</wfw:comment><comments>http://www.tkk7.com/fhtdy2004/archive/2009/06/01/279329.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.tkk7.com/fhtdy2004/comments/commentRss/279329.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/fhtdy2004/services/trackbacks/279329.html</trackback:ping><description><![CDATA[     鎽樿: Java澶氱嚎紼嬪皬緇?nbsp; <a href='http://www.tkk7.com/fhtdy2004/archive/2009/06/01/279329.html'>闃呰鍏ㄦ枃</a><img src ="http://www.tkk7.com/fhtdy2004/aggbug/279329.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/fhtdy2004/" target="_blank">Frank_Fang</a> 2009-06-01 09:31 <a href="http://www.tkk7.com/fhtdy2004/archive/2009/06/01/279329.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Java鍐呴儴綾?/title><link>http://www.tkk7.com/fhtdy2004/archive/2009/05/24/277741.html</link><dc:creator>Frank_Fang</dc:creator><author>Frank_Fang</author><pubDate>Sun, 24 May 2009 14:52:00 GMT</pubDate><guid>http://www.tkk7.com/fhtdy2004/archive/2009/05/24/277741.html</guid><description><![CDATA[     鎽樿: 閲嶇偣鐞嗚ВJava寮曞叆鍐呴儴綾葷殑鍘熷洜浠ュ強濂藉 鍐呴儴綾昏兘璁╀綘鍐嶉昏緫涓婂皢鐩鎬簰浠庡睘鐨勭被緇勭粐璧鋒潵錛屽茍涓斿湪綾葷殑鍐呴儴鎺у埗璁塊棶鏉冮檺銆備絾鏄垏璁幫紝鍐呴儴綾誨拰鍚堟垚鏃舵埅鐒朵笉鍚岀殑錛岃繖涓鐐歸潪甯擱噸瑕併? 鍑犱釜鏈変唬琛ㄦх殑浠g爜鍧?鎺ュ彛鍙互宓屽鍦ㄧ被鎴栧叾瀹冩帴鍙d腑 鎺ュ彛鐨勫祵濂?Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.Co...  <a href='http://www.tkk7.com/fhtdy2004/archive/2009/05/24/277741.html'>闃呰鍏ㄦ枃</a><img src ="http://www.tkk7.com/fhtdy2004/aggbug/277741.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/fhtdy2004/" target="_blank">Frank_Fang</a> 2009-05-24 22:52 <a href="http://www.tkk7.com/fhtdy2004/archive/2009/05/24/277741.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>java瀵硅薄鐨勫疄渚嬪寲榪囩▼,鎴愬憳鍙橀噺鐨勫垵濮嬪寲欏哄簭http://www.tkk7.com/fhtdy2004/archive/2009/05/11/270110.htmlFrank_FangFrank_FangMon, 11 May 2009 13:16:00 GMThttp://www.tkk7.com/fhtdy2004/archive/2009/05/11/270110.htmlhttp://www.tkk7.com/fhtdy2004/comments/270110.htmlhttp://www.tkk7.com/fhtdy2004/archive/2009/05/11/270110.html#Feedback0http://www.tkk7.com/fhtdy2004/comments/commentRss/270110.htmlhttp://www.tkk7.com/fhtdy2004/services/trackbacks/270110.htmlJAVA涓瓙綾誨璞$殑瀹炰緥鍖栬繃紼?/span>

 Person.java

class Person
{
 
public String name = "not know";//4
 public int age = -1 ;//5
 public Person()
 
{    
 }
 
public Person(String name , int age)//3
 {
  
this.name = name ;//6
  this.age = age;//7
 }
 
public void showInfo()
 
{
  System.out.println("Name is :"+name+" Age is :"+age);
 }
}
class Student extends Person
{
 
public String school = "not konwn";//8
    public Student()
    
{
     
super();    
    }
    
public Student (String name ,int age, String school)  //1
    {
     
super(name,age);  //2
     this.school = school;//9
    }
    
public void showInfo()
    
{
     
super.showInfo();
     System.out.println("School is :"+school);
    }
}

AllTest.java

class AllTest
{
 
public static void main(String[]args)
 
{
  Student stA = 
new Student("wanghao",20,"qinghuadaxue"); //0
 }
}

鍏惰鍙ョ殑鎵ц欏哄簭鏄庢牱鐨勫憿錛?/span>
java
涓紝鍦ㄤ嬌鐢?/span>new鎿嶄綔絎﹀垱寤轟竴涓被鐨勫疄渚嬪璞$殑鏃跺欙紝寮濮嬪垎閰嶇┖闂村茍灝嗘垚鍛樺彉閲忓垵濮嬪寲涓?/span>榛樿鐨?/span>鏁板?/span>錛屾敞鎰忚繖閲屽茍涓嶆槸鎸囧皢鍙橀噺鍒濆鍖栦負鍦ㄥ彉閲忓畾涔夊鐨勫垵濮嬪鹼紝鑰?strong>鏄粰鏁村艦璧嬪?/span>0錛岀粰瀛楃涓茶祴鍊?/span>null 榪欎竴鐐逛簬C++涓嶅悓錛岋紙student.name = null , student.age = 0 錛?/span>
鐒跺悗鍦ㄨ繘鍏ョ被鐨勬瀯閫犲嚱鏁般?/span>

鍦ㄦ瀯閫犲嚱鏁伴噷闈紝棣栧厛瑕佹鏌ユ槸鍚︽湁this鎴栬?/span>super璋冪敤錛?/span>this璋冪敤鏄畬鎴愭湰綾繪湰韜殑鏋勯犲嚱鏁頒箣闂寸殑璋冪敤錛?/span>super璋冪敤鏄畬鎴愬鐖剁被鐨勮皟鐢ㄣ?strong>浜岃呭彧鑳藉嚭鐜頒竴涓紝騫朵笖鍙兘浣滀負鏋勯犲嚱鏁扮殑絎竴鍙ュ嚭鐜般?/span>鍦ㄨ皟鐢?/span>this鍜?/span>super鐨勬椂鍊欏疄鐜扮▼搴忕殑璺寵漿錛岃漿鑰屾墽琛岃璋冪敤鐨?/span>this鏋勯犲嚱鏁版垨鑰?/span>super鏋勯犲嚱鏁般?/span>
鍦?/span>this鍜?/span>super鎵ц瀹屾瘯錛?strong>紼嬪簭杞屾墽琛屽湪綾誨畾涔夌殑鏃跺欒繘琛岀殑鍙橀噺鍒濆鍖栧伐浣?/span>銆?/span>
榪欎釜鎵ц瀹屾瘯錛屾墠鏄瀯閫犲嚱鏁頒腑鍓╀笅鐨勪唬鐮佺殑鎵ц銆?/span>
鎵ц欏哄簭宸茬粡鐢ㄧ豢鑹叉爣鍑恒?/span>

Order of initialization
Within a class, the order of initialization is determined by the order that the variables are defined within the class. The variable definitions may be scattered throughout and in between method definitions, but the variables are initialized before any methods can be called鈥攅ven the constructor. For example: Feedback
//: c04:OrderOfInitialization.java
// Demonstrates initialization order.
import com.bruceeckel.simpletest.*;

// When the constructor is called to create a
// Tag object, you'll see a message:
class Tag {
  Tag(int marker) {
    System.out.println("Tag(" + marker + ")");
  }
}

class Card {
  Tag t1 = new Tag(1); // Before constructor
  Card() {
    // Indicate we're in the constructor:
    System.out.println("Card()");
    t3 = new Tag(33); // Reinitialize t3
  }
  Tag t2 = new Tag(2); // After constructor
  void f() {
    System.out.println("f()");
  }
  Tag t3 = new Tag(3); // At end
}

public class OrderOfInitialization {
  static Test monitor = new Test();
  public static void main(String[] args) {
    Card t = new Card();
    t.f(); // Shows that construction is done
    monitor.expect(new String[] {
      "Tag(1)",
      "Tag(2)",
      "Tag(3)",
      "Card()",
      "Tag(33)",
      "f()"
    });
  }
} ///:~


//: c04:StaticInitialization.java
// Specifying initial values in a class definition.
class Bowl {
  Bowl(int marker) {
    System.out.println("Bowl(" + marker + ")");
  }
  void f(int marker) {
    System.out.println("f(" + marker + ")");
  }
}

class Table {
  static Bowl b1 = new Bowl(1);
  Table() {
    System.out.println("Table()");
    b2.f(1);
  }
  void f2(int marker) {
    System.out.println("f2(" + marker + ")");
  }
  static Bowl b2 = new Bowl(2);
}

class Cupboard {
  Bowl b3 = new Bowl(3);
  static Bowl b4 = new Bowl(4);
  Cupboard() {
    System.out.println("Cupboard()");
    b4.f(2);
  }
  void f3(int marker) {
    System.out.println("f3(" + marker + ")");
  }
  static Bowl b5 = new Bowl(5);
}

public class StaticInitialization {
  static Test monitor = new Test();
  public static void main(String[] args) {
    System.out.println("Creating new Cupboard() in main");
    new Cupboard();
    System.out.println("Creating new Cupboard() in main");
    new Cupboard();
    t2.f2(1);
    t3.f3(1);
    monitor.expect(new String[] {
      "Bowl(1)",
      "Bowl(2)",
      "Table()",
      "f(1)",
      "Bowl(4)",
      "Bowl(5)",
      "Bowl(3)",
      "Cupboard()",
      "f(2)",
      "Creating new Cupboard() in main",
      "Bowl(3)",
      "Cupboard()",
      "f(2)",
      "Creating new Cupboard() in main",
      "Bowl(3)",
      "Cupboard()",
      "f(2)",
      "f2(1)",
      "f3(1)"
    });
  }
  static Table t2 = new Table();
  static Cupboard t3 = new Cupboard();
} ///:~


緇ф壙鎯呭喌涓嬬殑鍒濆鍖?br /> 浜嗚В涓涓嬪寘鎷戶鎵垮湪鍐呯殑鍒濆鍖栫殑榪囩▼灝嗘槸闈炲父鏈夌泭鐨勶紝榪欐牱灝辮兘鏈変釜鎬?br /> 浣撶殑浜嗚В銆傜湅鐪嬩笅闈㈣繖孌典唬鐮侊細
//: c06:Beetle.java
// The full process of initialization.
class Insect {
  protected static Test monitor = new Test();
  private int i = 9;
  protected int j;
  Insect() {
    System.out.println("i = " + i + ", j = " + j);
    j = 39;
  }
  private static int x1 = print("static Insect.x1 initialized");
  static int print(String s) {
    System.out.println(s);
    return 47;
  }
}

public class Beetle extends Insect {
  private int k = print("Beetle.k initialized");
  public Beetle() {
    System.out.println("k = " + k);
    System.out.println("j = " + j);
  }
  private static int x2 = print("static Beetle.x2 initialized");
  public static void main(String[] args) {
    System.out.println("Beetle constructor");
    Beetle b = new Beetle();
    monitor.expect(new String[] {
      "static Insect.x1 initialized",
      "static Beetle.x2 initialized",
      "Beetle constructor",
      "i = 9, j = 0",
      "Beetle.k initialized",
      "k = 47",
      "j = 39"
    });
  }
} ///:~

褰撲綘鐢?/span>Java 榪愯Beetle 鐨勬椂鍊欙紝絎竴浠朵簨灝辨槸璁塊棶浜?/span>Beetel.main( )(榪欐槸涓涓?/span>static 鏂?span style="color: blue">娉?/span>)錛屼簬鏄杞藉櫒(loader)灝變細涓?/span>

浣犲鎵劇粡緙栬瘧鐨?/span>Beetle 綾葷殑浠g爜(涔熷氨鏄?/span>Beetle.class 鏂囦歡)銆傚湪瑁呰澆鐨勮繃紼嬩腑錛岃杞藉櫒娉ㄦ剰鍒板畠鏈変竴涓熀綾?/span>(涔熷氨鏄?/span>extends 鎵瑕佽〃紺虹殑鎰忔?/span>)錛屼簬鏄畠鍐嶈杞藉熀綾匯備笉綆′綘鍒涗笉鍒涘緩鍩虹被瀵硅薄錛岃繖涓繃紼嬫諱細鍙戠敓銆?/span>(璇曡瘯鐪嬶紝鎶婂垱寤哄璞$殑閭e彞娉ㄩ噴鎺夛紝鐪嬬湅浼氭湁浠涔堢粨鏋溿?/span>)濡傛灉鍩虹被榪樻湁鍩虹被錛岄偅涔堣繖絎簩涓熀綾諱篃浼氳瑁呰澆錛屼互姝ょ被鎺?span style="color: blue">銆?strong>涓嬩竴姝ワ紝瀹冧細鎵ц“鏍瑰熀綾?/strong>(root bas e class)(榪欓噷灝辨槸Insect)鐨?/span>static 鍒濆鍖栵紝鐒跺悗鏄笅涓涓淳鐢熺被鐨?/span>static 鍒濆鍖栵紝浠ユ綾繪帹銆傝繖涓『搴忛潪甯擱噸瑕侊紝鍥犱負媧劇敓綾葷殑“闈欐佸垵濮嬪寲(鍗沖墠闈㈣鐨?/span>static 鍒濆鍖?/span>)”鏈夊彲鑳借渚濊禆鍩虹被鎴愬憳鐨勬紜垵濮嬪寲銆?/span>

鐜板湪鎵鏈夊繀瑕佺殑綾婚兘宸茬粡瑁呰澆緇撴潫錛屽彲浠ュ垱寤哄璞′簡銆?/span>棣栧厛錛屽璞¢噷鐨勬墍鏈夌殑primitive 閮戒細琚鎴愬畠浠殑緙虹渷鍊鹼紝鑰?/span>reference 涔熶細琚鎴?/span>null鈥斺旇繖涓繃紼嬫槸涓鐬棿瀹屾垚鐨勶紝瀵硅薄鐨勫唴瀛樹細琚粺涓鍦拌緗垚“涓よ繘鍒剁殑闆?/span>(binary zero)”銆?strong>濡傛灉鏈夊鎴愬憳鍙橀噺璧嬪垵鍊鹼紝鍒欏鎴愬憳鍙橀噺榪涜璧嬪鹼紝鐒跺悗璋冪敤鍩虹被鐨勬瀯閫犲嚱鏁般傝皟鐢ㄦ槸鑷姩鍙戠敓鐨勶紝浣嗘槸浣犲彲浠ヤ嬌鐢?/span>super 鏉ユ寚瀹氳皟鐢ㄥ摢涓瀯閫犲嚱鏁?/span>(涔熷氨Beetle( )鏋勯犲嚱鏁版墍鍋氱殑絎竴浠朵簨)銆傚熀綾葷殑鏋勯犺繃紼嬩互鍙婃瀯閫犻『搴忥紝鍚屾淳鐢熺被鐨勭浉鍚屻傚熀綾繪瀯閫犲嚱鏁拌繍琛屽畬姣曚箣鍚庯紝浼氭寜鐓у悇涓彉閲忕殑瀛楅潰欏哄簭榪涜鍒濆鍖栥傛渶鍚庝細鎵ц鏋勯犲嚱鏁扮殑鍏朵綑閮ㄥ垎銆?/span>



]]>
C++铏氬嚱鏁板0鏄庝負private涔熷彲浠ュ疄鐜拌繍琛屾椂澶氭?/title><link>http://www.tkk7.com/fhtdy2004/archive/2009/05/07/269408.html</link><dc:creator>Frank_Fang</dc:creator><author>Frank_Fang</author><pubDate>Thu, 07 May 2009 06:02:00 GMT</pubDate><guid>http://www.tkk7.com/fhtdy2004/archive/2009/05/07/269408.html</guid><wfw:comment>http://www.tkk7.com/fhtdy2004/comments/269408.html</wfw:comment><comments>http://www.tkk7.com/fhtdy2004/archive/2009/05/07/269408.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/fhtdy2004/comments/commentRss/269408.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/fhtdy2004/services/trackbacks/269408.html</trackback:ping><description><![CDATA[    鍙湁娉ㄥ唽鐢ㄦ埛鐧誨綍鍚庢墠鑳介槄璇昏鏂囥?a href='http://www.tkk7.com/fhtdy2004/archive/2009/05/07/269408.html'>闃呰鍏ㄦ枃</a><img src ="http://www.tkk7.com/fhtdy2004/aggbug/269408.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/fhtdy2004/" target="_blank">Frank_Fang</a> 2009-05-07 14:02 <a href="http://www.tkk7.com/fhtdy2004/archive/2009/05/07/269408.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Java鏂規硶瑕嗙洊Overridehttp://www.tkk7.com/fhtdy2004/archive/2009/05/07/269407.htmlFrank_FangFrank_FangThu, 07 May 2009 05:56:00 GMThttp://www.tkk7.com/fhtdy2004/archive/2009/05/07/269407.htmlhttp://www.tkk7.com/fhtdy2004/comments/269407.htmlhttp://www.tkk7.com/fhtdy2004/archive/2009/05/07/269407.html#Feedback0http://www.tkk7.com/fhtdy2004/comments/commentRss/269407.htmlhttp://www.tkk7.com/fhtdy2004/services/trackbacks/269407.html闃呰鍏ㄦ枃

]]>
Java瀵硅薄鐨勫己銆佽蔣銆佸急鍜岃櫄寮曠敤http://www.tkk7.com/fhtdy2004/archive/2009/04/30/268412.htmlFrank_FangFrank_FangThu, 30 Apr 2009 10:10:00 GMThttp://www.tkk7.com/fhtdy2004/archive/2009/04/30/268412.htmlhttp://www.tkk7.com/fhtdy2004/comments/268412.htmlhttp://www.tkk7.com/fhtdy2004/archive/2009/04/30/268412.html#Feedback3http://www.tkk7.com/fhtdy2004/comments/commentRss/268412.htmlhttp://www.tkk7.com/fhtdy2004/services/trackbacks/268412.html闃呰鍏ㄦ枃

]]>
java try return finallyhttp://www.tkk7.com/fhtdy2004/archive/2009/04/30/268386.htmlFrank_FangFrank_FangThu, 30 Apr 2009 08:04:00 GMThttp://www.tkk7.com/fhtdy2004/archive/2009/04/30/268386.htmlhttp://www.tkk7.com/fhtdy2004/comments/268386.htmlhttp://www.tkk7.com/fhtdy2004/archive/2009/04/30/268386.html#Feedback3http://www.tkk7.com/fhtdy2004/comments/commentRss/268386.htmlhttp://www.tkk7.com/fhtdy2004/services/trackbacks/268386.html鐢變竴涓瑪璇曢鎯沖埌鐨?br /> try鏈塺eturn,catch涔熸湁return,涓旀湁finally鍧?br /> 騫朵笖finally涓resutl榪涜鐨勮祴鍊煎茍涓嶅獎鍝嶄箣鍓嶇殑宸茬粡return 鐨剅esult鍊?br /> 鏈鍚庤繑鍥炵殑result寮曠敤榪樻槸涔嬪墠鐨剅esult寮曠敤
finally鍏跺疄涔熷彲浠ユ湁return錛屼竴鑸琫clipse浼氭彁紺篺inally block does not complete normally,浣嗕笉浼氭姤閿?br /> 騫朵笖浼氬拷鐣ヤ箣鍓嶇殑榪斿洖鍜屾姏鍑虹殑寮傚父

package returnfinally;

public class TestReturnAfterFinally {

     
public static void main(String[] args) {
      
try {
       String result 
= testException();
       System.out.println();
       System.out.println(result);
      }
 catch (Exception e) {
      
// System.out.println(result);
       System.out.println(e.toString());
      }

     }

     
    
public static String testException() throws Exception {
      String result 
= "";
      
try {
       
// if (true) throw new MyException("寮傚父錛?);
       
//int i = 0;
       int i=0;
       
int b = 10 / i;
       
//鍑芥暟涓嶄細姝e父鐨勮繑鍥?鍦ㄨ繑鍥炲墠宸茬粡鎶涘嚭寮傚父浜嗭紝鎶涘嚭寮傚父鍗沖嚱鏁拌繑鍥炰簡
       /*
        * 鐩稿綋浜巆atch(Exception e){
        *    throw e;
        * }
        
*/

       
/*
       result="in try";
       return result;
       
*/

       
throw new Exception("h");
      }
catch(Exception e){
          System.out.println(e);
          Exception ee 
= e;
          
//throw ee;
          result="in catch";
          
return result;
      }

      
finally {
       result 
= "in finally錛?/span>";
       System.out.println(result);
       
//return result;
       
//throw new Exception("ex cretated in finally");
      }

      
      
//return result;
     }


    }




 



]]>
java鐨勫洖璋冩満鍒?/title><link>http://www.tkk7.com/fhtdy2004/archive/2009/04/29/268249.html</link><dc:creator>Frank_Fang</dc:creator><author>Frank_Fang</author><pubDate>Wed, 29 Apr 2009 14:31:00 GMT</pubDate><guid>http://www.tkk7.com/fhtdy2004/archive/2009/04/29/268249.html</guid><wfw:comment>http://www.tkk7.com/fhtdy2004/comments/268249.html</wfw:comment><comments>http://www.tkk7.com/fhtdy2004/archive/2009/04/29/268249.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/fhtdy2004/comments/commentRss/268249.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/fhtdy2004/services/trackbacks/268249.html</trackback:ping><description><![CDATA[    鍙湁娉ㄥ唽鐢ㄦ埛鐧誨綍鍚庢墠鑳介槄璇昏鏂囥?a href='http://www.tkk7.com/fhtdy2004/archive/2009/04/29/268249.html'>闃呰鍏ㄦ枃</a><img src ="http://www.tkk7.com/fhtdy2004/aggbug/268249.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/fhtdy2004/" target="_blank">Frank_Fang</a> 2009-04-29 22:31 <a href="http://www.tkk7.com/fhtdy2004/archive/2009/04/29/268249.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Java String絎旇瘯緇忓父閬囧埌鐨?/title><link>http://www.tkk7.com/fhtdy2004/archive/2009/04/29/268231.html</link><dc:creator>Frank_Fang</dc:creator><author>Frank_Fang</author><pubDate>Wed, 29 Apr 2009 13:04:00 GMT</pubDate><guid>http://www.tkk7.com/fhtdy2004/archive/2009/04/29/268231.html</guid><description><![CDATA[<p>java.lang.String鐨刬ntern()鏂規硶 <br /> "abc".intern()鏂規硶鐨勮繑鍥炲艱繕鏄瓧絎︿覆"abc"錛岃〃闈笂鐪嬭搗鏉ュソ鍍忚繖涓柟娉曟病浠涔堢敤澶勩備絾瀹為檯涓婏紝瀹冨仛浜嗕釜灝忓姩浣滐細 <br /> 媯鏌ュ瓧絎︿覆姹犻噷鏄惁瀛樺湪"abc"榪欎箞涓涓瓧絎︿覆錛屽鏋滃瓨鍦紝灝辮繑鍥炴睜閲岀殑瀛楃涓詫紱濡傛灉涓嶅瓨鍦紝璇ユ柟娉曚細鎶?abc"娣誨姞鍒板瓧絎︿覆姹犱腑錛岀劧鍚庡啀榪斿洖瀹冪殑寮曠敤銆?<br /> 鎴戜滑鍋氫釜嫻嬭瘯錛?<br />       String str1 = "a"; <br /> String str2 = "bc"; <br /> String str3 = "a"+"bc"; <br /> String str4 = str1+str2; <br />    <br /> System.out.println(str3==str4); <br /> str4 = (str1+str2).intern(); <br /> System.out.println(str3==str4); <br /> 杈撳嚭鐨勭粨鏋滃皢浼氭槸: <br /> false <br /> true <br /> JDK鐨刟pi鏂囨。鏄繖涔堣В閲婄殑錛?<br /> ======================================================================= <br /> 榪斿洖瀛楃涓插璞$殑瑙勮寖鍖栬〃紺哄艦寮忋?<br /> 涓涓垵濮嬫椂涓虹┖鐨勫瓧絎︿覆姹狅紝瀹冪敱綾?String 縐佹湁鍦扮淮鎶ゃ?<br /> 褰撹皟鐢?intern 鏂規硶鏃訛紝濡傛灉姹犲凡緇忓寘鍚竴涓瓑浜庢 String 瀵硅薄鐨勫瓧絎︿覆錛堣瀵硅薄鐢?equals(Object) 鏂規硶紜畾錛夛紝鍒欒繑鍥炴睜涓殑瀛楃涓層傚惁鍒欙紝灝嗘 String 瀵硅薄娣誨姞鍒版睜涓紝騫朵笖榪斿洖姝?String 瀵硅薄鐨勫紩鐢ㄣ?<br /> 瀹冮伒寰浜庝換浣曚袱涓瓧絎︿覆 s 鍜?t錛屽綋涓斾粎褰?s.equals(t) 涓?true 鏃訛紝s.intern() == t.intern() 鎵嶄負 true銆?<br /> 鎵鏈夊瓧闈㈠煎瓧絎︿覆鍜屽瓧絎︿覆璧嬪煎父閲忚〃杈懼紡閮芥槸鍐呴儴鐨勩傚瓧絎︿覆瀛楅潰鍊煎湪銆奐ava Language Specification銆嬬殑 §3.10.5 涓凡瀹氫箟銆?</p> <p>榪斿洖錛?<br /> 涓涓瓧絎︿覆錛屽唴瀹逛笌姝ゅ瓧絎︿覆鐩稿悓錛屼絾瀹冧繚璇佹潵鑷瓧絎︿覆姹犱腑銆?<br /> =======================================================================</p> <p>瀛楃涓插瓧闈㈡睜鎸囩殑鏄父閲忔睜.</p> <p>瀛楃涓插璞$殑鍒涘緩鏂瑰紡鏈変袱縐?/p> <p>濡備笅:</p> <p>String s1 = new String("");   //絎竴縐?/p> <p>String s2 = "";               //絎簩縐?/p> <p>絎竴縐嶅緇堜笉浼氬叆姹犵殑.</p> <p>絎簩縐嶈鐪嬫儏鍐佃屽畾(絳夊彿鍙寵竟濡傛灉鏄父閲忓垯鍏ユ睜,闈炲父閲忓垯涓嶅叆姹?</p> <p>渚?</p> <p>String s3 = "a" + "b"; //"a"鏄父閲?"b"鏄父閲?甯擱噺+甯擱噺=甯擱噺,鎵浠ヤ細鍏ユ睜.</p> <p>String s4 = s1 + "b";   //s1鏄彉閲?"b"鏄父閲?鍙橀噺+甯擱噺!=甯擱噺,鎵浠ヤ笉浼氬叆姹?<br /> 銆銆銆銆銆銆銆銆銆//閭e紩鐢╯4鎵鎸囩殑瀵硅薄鍦ㄥ摢閲屽垱寤??????</p> <p>涓鏃﹀叆姹犵殑璇?灝變細鍏堟煡鎵炬睜涓湁鏃犳瀵硅薄.濡傛灉鏈夋瀵硅薄,鍒欒瀵硅薄寮曠敤鎸囧悜姝ゅ璞?濡傛灉鏃犳瀵硅薄,鍒欏厛鍒涘緩姝ゅ璞?鍐嶈瀵硅薄寮曠敤鎸囧悜姝ゅ璞?</p> <p>渚?</p> <p>String s5 = "abc"; //鍏堝湪姹犱腑鏌ユ壘鏈夋棤"abc"瀵硅薄,濡傛灉鏈?鍒欒s5鎸囧悜姝ゅ璞?濡傛灉姹犱腑鏃?abc"瀵硅薄,鍒欏湪姹犱腑鍒涘緩涓涓?abc"瀵硅薄,鐒跺悗璁﹕5鎸囧悜璇ュ璞?琛ュ厖涓涓嬶細</p> <p>鐪嬩簡瀛楄妭鐮佸悗錛屽彂鐜?br /> String str ="a"+"b";<br /> 瀹屽叏絳夊悓浜?br /> String str="ab"; <br /> </p> <p><br />  -----------------------------------------------------------------------------------------------------------------------------<br /> <br /> Java铏氭嫙鏈烘湁涓涓瓧絎︿覆姹狅紝淇濆瓨鐫鍑犱箮鎵鏈夌殑瀛楃涓插父閲忋傚瓧絎︿覆琛ㄨ揪寮忔繪槸鎸囧悜瀛楃涓叉睜涓殑涓涓璞°?br /> public class Test...{<br />  public static void main(String[] args)...{<br />   String s1=new String("abc");<br />   String s2="abc";//鏀懼叆String姹犻噷<br />   String s3=new String("abc");<br />   System.out.println(s1==s2);//false<br />   System.out.println(s1==s3);//false<br />   System.out.println(s3==s2);//false<br />   System.out.println(s1==s1.intern());//s1.intern()鍒癝tring姹犻噷鎵撅紝鑰宻1鏄湪鍫嗕腑鎵浠ヨ繑鍥瀎alse<br />   System.out.println(s2==s2.intern());//true<br />   System.out.println(s1.intern()==s3.intern());//涓や釜瀛楃涓插悓鏃跺埌String姹犻噷鏌ユ壘錛岃繑鍥瀟rue<br />   <br />    //浠ヤ笅涓変釜閮芥斁鍒癝tring姹?br />   String hello="hello";<br />   String hel="hel";<br />   String lo="lo";<br />   System.out.println(hello=="hel"+"lo");//瀛楃涓茬浉鍔犱互鍚庯紝浼氬埌String姹犻噷鎵撅紝鏈変笉浜х敓錛屾墍浠ヨ繑鍥瀟rue<br />   System.out.println(hello=="hello");//鐩存帴鍒癝tring姹犻噷鎵撅紝榪斿洖true<br />   System.out.println(hello=="hel"+lo);//瀛楃涓插姞涓涓紩鐢紝灝嗕駭鐢熶竴涓柊鐨勫璞★紝鎵浠ヨ繑鍥瀎alse<br />   System.out.println(hello==(hel+lo));//綾諱技涓婇潰錛岃繑鍥瀎alse<br />   System.out.println(hello==(hel+lo).intern());//浜х敓鏂扮殑瀵硅薄錛屼絾鏄湁intern()鏂規硶錛屽皢鍒癝tring姹犱腑鎵撅紝榪斿洖true<br />  }<br /> }<br /> <br /> </p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080"> 1</span><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #0000ff">package</span><span style="color: #000000"> com._6617.fhs.weatherservice;<br /> </span><span style="color: #008080"> 2</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /> </span><span style="color: #008080"> 3</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> java.util.HashSet;<br /> </span><span style="color: #008080"> 4</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> java.util.Set;<br /> </span><span style="color: #008080"> 5</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /> </span><span style="color: #008080"> 6</span><span style="color: #000000"><img id="Codehighlighter1_106_2030_Open_Image" onclick="this.style.display='none'; Codehighlighter1_106_2030_Open_Text.style.display='none'; Codehighlighter1_106_2030_Closed_Image.style.display='inline'; Codehighlighter1_106_2030_Closed_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_106_2030_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_106_2030_Closed_Text.style.display='none'; Codehighlighter1_106_2030_Open_Image.style.display='inline'; Codehighlighter1_106_2030_Open_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> Test </span><span id="Codehighlighter1_106_2030_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.tkk7.com/Images/dot.gif" /></span><span id="Codehighlighter1_106_2030_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080"> 7</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> </span><span style="color: #008080"> 8</span><span style="color: #000000"><img id="Codehighlighter1_110_133_Open_Image" onclick="this.style.display='none'; Codehighlighter1_110_133_Open_Text.style.display='none'; Codehighlighter1_110_133_Closed_Image.style.display='inline'; Codehighlighter1_110_133_Closed_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_110_133_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_110_133_Closed_Text.style.display='none'; Codehighlighter1_110_133_Open_Image.style.display='inline'; Codehighlighter1_110_133_Open_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_110_133_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/** */</span><span id="Codehighlighter1_110_133_Open_Text"><span style="color: #008000">/**</span><span style="color: #008000"><br /> </span><span style="color: #008080"> 9</span><span style="color: #008000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />     * </span><span style="color: #808080">@param</span><span style="color: #008000"> args<br /> </span><span style="color: #008080">10</span><span style="color: #008000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />     </span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">11</span><span style="color: #000000"><img id="Codehighlighter1_174_2027_Open_Image" onclick="this.style.display='none'; Codehighlighter1_174_2027_Open_Text.style.display='none'; Codehighlighter1_174_2027_Closed_Image.style.display='inline'; Codehighlighter1_174_2027_Closed_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_174_2027_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_174_2027_Closed_Text.style.display='none'; Codehighlighter1_174_2027_Open_Image.style.display='inline'; Codehighlighter1_174_2027_Open_Text.style.display='inline';" alt="" src="http://www.tkk7.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> main(String[] args)</span><span id="Codehighlighter1_174_2027_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.tkk7.com/Images/dot.gif" /></span><span id="Codehighlighter1_174_2027_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">37</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        <br /> </span><span style="color: #008080">38</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        Set set </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> HashSet();<br /> </span><span style="color: #008080">39</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        set.add(</span><span style="color: #0000ff">new</span><span style="color: #000000"> A());<br /> </span><span style="color: #008080">40</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        set.add(</span><span style="color: #0000ff">new</span><span style="color: #000000"> A());<br /> </span><span style="color: #008080">41</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        set.add(</span><span style="color: #0000ff">new</span><span style="color: #000000"> A());<br /> </span><span style="color: #008080">42</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        System.out.println(set.size());<br />                 //涓昏鏄湅綾籄鏄惁鑷繁瀹炵幇浜唄ashcode鍜宔quals鏂規硶<br /> </span><span style="color: #008080">43</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        <br /> </span><span style="color: #008080">44</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        String s </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> String(</span><span style="color: #000000">"</span><span style="color: #000000">abc</span><span style="color: #000000">"</span><span style="color: #000000">);<br /> </span><span style="color: #008080">45</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        System.out.println(s</span><span style="color: #000000">==</span><span style="color: #000000">"</span><span style="color: #000000">abc</span><span style="color: #000000">"</span><span style="color: #000000">);</span><span style="color: #008000">//</span><span style="color: #008000">f</span><span style="color: #008000"><br /> </span><span style="color: #008080">46</span><span style="color: #008000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000">        System.out.println(s</span><span style="color: #000000">==</span><span style="color: #000000">"</span><span style="color: #000000">a</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000">"</span><span style="color: #000000">bc</span><span style="color: #000000">"</span><span style="color: #000000">);</span><span style="color: #008000">//</span><span style="color: #008000">f</span><span style="color: #008000"><br /> </span><span style="color: #008080">47</span><span style="color: #008000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000">        String t </span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">abc</span><span style="color: #000000">"</span><span style="color: #000000">;<br /> </span><span style="color: #008080">48</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        System.out.println(s</span><span style="color: #000000">==</span><span style="color: #000000">t);</span><span style="color: #008000">//</span><span style="color: #008000">f</span><span style="color: #008000"><br /> </span><span style="color: #008080">49</span><span style="color: #008000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000">        String r </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">a</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000">"</span><span style="color: #000000">bc</span><span style="color: #000000">"</span><span style="color: #000000">;<br /> </span><span style="color: #008080">50</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        System.out.println(s</span><span style="color: #000000">==</span><span style="color: #000000">r);</span><span style="color: #008000">//</span><span style="color: #008000">f</span><span style="color: #008000"><br /> </span><span style="color: #008080">51</span><span style="color: #008000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000">        System.out.println(t</span><span style="color: #000000">==</span><span style="color: #000000">r);</span><span style="color: #008000">//</span><span style="color: #008000">t</span><span style="color: #008000"><br /> </span><span style="color: #008080">52</span><span style="color: #008000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000">        String u </span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">a</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #0000ff">new</span><span style="color: #000000"> String(</span><span style="color: #000000">"</span><span style="color: #000000">bc</span><span style="color: #000000">"</span><span style="color: #000000">);<br /> </span><span style="color: #008080">53</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        System.out.println(s</span><span style="color: #000000">==</span><span style="color: #000000">u);</span><span style="color: #008000">//</span><span style="color: #008000">f</span><span style="color: #008000"><br /> </span><span style="color: #008080">54</span><span style="color: #008000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000">        System.out.println(r</span><span style="color: #000000">==</span><span style="color: #000000">u);</span><span style="color: #008000">//</span><span style="color: #008000">f<br /> </span><span style="color: #008080">55</span><span style="color: #008000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        <br /> </span><span style="color: #008080">56</span><span style="color: #008000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: #008000">//</span><span style="color: #008000">String[] s = new String[3,4];</span><span style="color: #008000"><br /> </span><span style="color: #008080">57</span><span style="color: #008000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000">        System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">--------------</span><span style="color: #000000">"</span><span style="color: #000000">);<br /> </span><span style="color: #008080">58</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        String str1 </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">a</span><span style="color: #000000">"</span><span style="color: #000000">; <br /> </span><span style="color: #008080">59</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        String str2 </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">bc</span><span style="color: #000000">"</span><span style="color: #000000">; <br /> </span><span style="color: #008080">60</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        String str3 </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">a</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000">"</span><span style="color: #000000">bc</span><span style="color: #000000">"</span><span style="color: #000000">; <br /> </span><span style="color: #008080">61</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        String str4 </span><span style="color: #000000">=</span><span style="color: #000000"> str1</span><span style="color: #000000">+</span><span style="color: #000000">str2; <br /> </span><span style="color: #008080">62</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        String str5 </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">a</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000">str2;<br /> </span><span style="color: #008080">63</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />           <br /> </span><span style="color: #008080">64</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        System.out.println(str3</span><span style="color: #000000">==</span><span style="color: #000000">str4); </span><span style="color: #008000">//</span><span style="color: #008000">f</span><span style="color: #008000"><br /> </span><span style="color: #008080">65</span><span style="color: #008000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000">        System.out.println(str3</span><span style="color: #000000">==</span><span style="color: #000000">str5); </span><span style="color: #008000">//</span><span style="color: #008000">f</span><span style="color: #008000"><br /> </span><span style="color: #008080">66</span><span style="color: #008000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000">        System.out.println(str3</span><span style="color: #000000">==</span><span style="color: #000000">str5); </span><span style="color: #008000">//</span><span style="color: #008000">f</span><span style="color: #008000"><br /> </span><span style="color: #008080">67</span><span style="color: #008000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000">        str4 </span><span style="color: #000000">=</span><span style="color: #000000"> (str1</span><span style="color: #000000">+</span><span style="color: #000000">str2).intern(); <br /> </span><span style="color: #008080">68</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" />        System.out.println(str3</span><span style="color: #000000">==</span><span style="color: #000000">str4); </span><span style="color: #008000">//</span><span style="color: #008000">t</span><span style="color: #008000"><br /> </span><span style="color: #008080">69</span><span style="color: #008000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000">        System.out.println(str3</span><span style="color: #000000">==</span><span style="color: #000000">str5.intern());</span><span style="color: #008000">//</span><span style="color: #008000">t</span><span style="color: #008000"><br /> </span><span style="color: #008080">70</span><span style="color: #008000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000">        </span><span style="color: #000000"><br /> </span><span style="color: #008080">73</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> </span><span style="color: #008080">74</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">75</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> </span><span style="color: #008080">76</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">77</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /> </span><span style="color: #008080">78</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /> </span><span style="color: #008080">79</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /> </span><span style="color: #008080">80</span><span style="color: #000000"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /></span></div> <br /> <br /><img src ="http://www.tkk7.com/fhtdy2004/aggbug/268231.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/fhtdy2004/" target="_blank">Frank_Fang</a> 2009-04-29 21:04 <a href="http://www.tkk7.com/fhtdy2004/archive/2009/04/29/268231.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p> <a href="http://www.tkk7.com/" title="亚洲av成人片在线观看">亚洲av成人片在线观看</a> <div class="friend-links"> </div> </div> </footer> 主站蜘蛛池模板: <a href="http://yctbhb.com" target="_blank">一个人看的www视频免费在线观看</a>| <a href="http://wwwtoutoulu.com" target="_blank">国产福利在线观看永久免费</a>| <a href="http://aabbcc567.com" target="_blank">相泽南亚洲一区二区在线播放</a>| <a href="http://tianmao920.com" target="_blank">永久免费精品影视网站</a>| <a href="http://cqtchtwq.com" target="_blank">麻豆国产入口在线观看免费 </a>| <a href="http://345504.com" target="_blank">亚洲人成网77777亚洲色</a>| <a href="http://gztzbj.com" target="_blank">亚洲日本在线播放</a>| <a href="http://xxnxgay.com" target="_blank">18禁美女黄网站色大片免费观看 </a>| <a href="http://bcz123.com" target="_blank">97在线观看永久免费视频</a>| <a href="http://djllgs.com" target="_blank">亚洲电影在线免费观看</a>| <a href="http://ytsp88.com" target="_blank">国产精品爱啪在线线免费观看</a>| <a href="http://6123fa.com" target="_blank">亚洲毛片免费观看</a>| <a href="http://626632.com" target="_blank">18禁无遮挡无码网站免费</a>| <a href="http://18yinren.com" target="_blank">亚洲国产精品无码中文lv</a>| <a href="http://igao4.com" target="_blank">四只虎免费永久观看</a>| <a href="http://kingco-glaze.com" target="_blank">一区二区三区AV高清免费波多</a>| <a href="http://whknd.com" target="_blank">综合亚洲伊人午夜网</a>| <a href="http://wjjccw.com" target="_blank">在线观看亚洲网站</a>| <a href="http://gs168sz.com" target="_blank">亚洲av无码国产精品色在线看不卡</a>| <a href="http://gayhh.com" target="_blank">成人免费网站久久久</a>| <a href="http://sqmdjz.com" target="_blank">亚洲AV永久青草无码精品</a>| <a href="http://zgdhuibao.com" target="_blank">最近免费中文字幕mv电影</a>| <a href="http://jhmydxx.com" target="_blank">亚洲午夜精品一区二区麻豆</a>| <a href="http://044242.com" target="_blank">免费一级毛片清高播放</a>| <a href="http://wua72.com" target="_blank">精品成人一区二区三区免费视频</a>| <a href="http://87fulitv.com" target="_blank">天堂亚洲免费视频</a>| <a href="http://963315.com" target="_blank">视频一区二区三区免费观看</a>| <a href="http://w9366.com" target="_blank">亚洲日本一区二区一本一道</a>| <a href="http://www8x5188x.com" target="_blank">青青草原1769久久免费播放</a>| <a href="http://wcnmgb.com" target="_blank">久久久久久a亚洲欧洲aⅴ</a>| <a href="http://wcnmgb.com" target="_blank">国产一级一毛免费黄片</a>| <a href="http://cz655.com" target="_blank">亚洲综合在线成人一区</a>| <a href="http://tedegold.com" target="_blank">国产一级高清视频免费看</a>| <a href="http://www431234.com" target="_blank">a成人毛片免费观看</a>| <a href="http://airou08.com" target="_blank">啊灬啊灬别停啊灬用力啊免费看</a>| <a href="http://565636.com" target="_blank">香蕉视频在线免费看</a>| <a href="http://wyj4.com" target="_blank">亚洲一区二区三区免费在线观看</a>| <a href="http://cuuka.com" target="_blank">免费v片在线观看</a>| <a href="http://zgdhuibao.com" target="_blank">久久国产精品免费专区</a>| <a href="http://www44414.com" target="_blank">国内精品久久久久影院亚洲</a>| <a href="http://bxd888.com" 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>