﻿{"id":1011,"date":"2015-03-22T11:36:57","date_gmt":"2015-03-22T03:36:57","guid":{"rendered":"http:\/\/zerobox.org\/notes\/?p=1011"},"modified":"2016-06-02T19:36:51","modified_gmt":"2016-06-02T11:36:51","slug":"java%e6%80%a7%e8%83%bd%e4%bc%98%e5%8c%96","status":"publish","type":"post","link":"http:\/\/zerobox.org\/notes\/1011.html","title":{"rendered":"Java\u6027\u80fd\u4f18\u5316"},"content":{"rendered":"<div id=\"cnblogs_post_body\">\n<div id=\"article_content\">\u4f5c\u8005\uff1a\u7985\u697c\u671b\u6708\uff08<a href=\"http:\/\/www.cnblogs.com\/yaoyinglong\">http:\/\/www.cnblogs.com\/yaoyinglong<\/a>\uff09<\/div>\n<p>\u6ce8\uff1a\u91cc\u9762\u7684\u6d4b\u8bd5\u7ed3\u679c\u4f1a\u56e0\u7535\u8111\u914d\u7f6e\u7684\u4e0d\u540c\u800c\u6709\u6240\u5dee\u5f02\uff01\uff01\uff01<\/p>\n<h1><a name=\"t0\"><\/a>1. \u4e3a\u4e00\u4e9b\u96c6\u5408\u5b9a\u4e49\u521d\u59cb\u5316\u5927\u5c0f<\/h1>\n<p>List\u3001Set\u3001Map\u90fd\u4f1a\u6709\u6709\u4e00\u4e2a\u9ed8\u8ba4\u7684\u521d\u59cb\u5316\u5927\u5c0f\uff0c\u4f46\u662f\u8fd9\u4e2a\u503c\u5f80\u5f80\u4e0d\u591f\u6211\u4eec\u4f7f\u7528\uff0c\u8fd9\u65f6\u5019JVM\u4fbf\u4f1a\u7533\u8bf7\u66f4\u5927\u7684\u4e00\u5757\u5185\u5b58\u7ed9\u96c6\u5408\uff0c\u7136\u540e\u5c06\u539f\u96c6\u5408\u4e2d\u7684\u6570\u636e\u590d\u5236\u8fc7\u6765\uff0c\u6700\u540e\u539f\u96c6\u5408\u7b49\u5f85\u88ab\u4f5c\u4e3a\u5783\u573e\u800c\u56de\u6536\u3002\u53ef\u89c1\u6269\u5bb9\u662f\u4e00\u4ef6\u6bd4\u8f83\u8d39\u4e8b\u7684\u4e8b\u60c5\uff0c\u6240\u4ee5\u6700\u597d\u80fd\u51c6\u786e\u7684\u4f30\u8ba1\u4f60\u6240\u9700\u8981\u7684\u6700\u4f73\u5927\u5c0f\u3002<\/p>\n<div id=\"code\">\n<div><span id=\"codeHead1\">[+]<\/span>view code<\/div>\n<\/div>\n<p>\u4f18\u5316\u540e\uff1a<\/p>\n<div id=\"code\">\n<div><span id=\"codeHead2\">[+]<\/span>view code<\/div>\n<\/div>\n<p>\u8fd9\u6837\u79ef\u5c11\u6210\u591a\uff0c\u6548\u679c\u8fd8\u662f\u633a\u53ef\u89c2\u7684\u3002<\/p>\n<h1><a name=\"t1\"><\/a>2. \u590d\u5236\u6570\u7ec4\u7684\u65f6\u5019\u4f7f\u7528System.arraycopy\u6765\u4ee3\u66ff\u5faa\u73afcopy\uff0c\u5b83\u7684\u6548\u7387\u66f4\u9ad8\u66f4\u7b80\u6d01\u3002<\/h1>\n<div id=\"code\">\n<div><span id=\"codeHead3\">[+]<\/span>view code<\/div>\n<\/div>\n<h1><a name=\"t2\"><\/a>3. \u907f\u514d\u4e0d\u9700\u8981\u7684instanceof\u64cd\u4f5c<\/h1>\n<p>\u5982\u679c\u5de6\u8fb9\u7684\u5bf9\u8c61\u7684\u9759\u6001\u7c7b\u578b\u7b49\u4e8e\u53f3\u8fb9\u7684\uff0cinstanceof\u8868\u8fbe\u5f0f\u8fd4\u56de\u6c38\u8fdc\u4e3atrue\u3002<\/p>\n<div id=\"code\">\n<div><span id=\"codeHead4\">[+]<\/span>view code<\/div>\n<\/div>\n<h1><a name=\"t3\"><\/a>4. \u907f\u514d\u4e0d\u9700\u8981\u7684\u9020\u578b\u64cd\u4f5c<\/h1>\n<p>\u6240\u6709\u7684\u7c7b\u90fd\u662f\u76f4\u63a5\u6216\u8005\u95f4\u63a5\u7ee7\u627f\u81eaobject\u3002\u540c\u6837\uff0c\u6240\u6709\u7684\u5b50\u7c7b\u4e5f\u90fd\u9690\u542b\u7684\u201c\u7b49\u4e8e\u201d\u5176\u7236\u7c7b\u3002\u90a3\u4e48\uff0c\u7531\u5b50\u7c7b\u9020\u578b\u81f3\u7236\u7c7b\u7684\u64cd\u4f5c\u5c31\u662f\u4e0d\u5fc5\u8981\u7684\u4e86\u3002\u5982\uff1a<\/p>\n<p>class dog extends unc<\/p>\n<p>dog dog = new dog ();<\/p>\n<p>unc animal = (unc)dog; \/\/ not necessary<\/p>\n<p>object o = (object)dog; \/\/ not necessary<\/p>\n<h1><a name=\"t4\"><\/a>5. \u5982\u679c\u53ea\u662f\u67e5\u627e\u5355\u4e2a\u5b57\u7b26\u7684\u8bdd\uff0c\u7528charAt()\u4ee3\u66ffstartsWith<\/h1>\n<div id=\"code\">\n<div><span id=\"codeHead5\">[+]<\/span>view code<\/div>\n<\/div>\n<p>\u5c06&#8217;startsWith&#8217; \u66ff\u6362\u6210&#8217;charAt()&#8217;<\/p>\n<div id=\"code\">\n<div><span id=\"codeHead6\">[+]<\/span>view code<\/div>\n<\/div>\n<h1><a name=\"t5\"><\/a>6. \u4f7f\u7528\u79fb\u4f4d\u64cd\u4f5c\u6765\u4ee3\u66ff&#8217;a \/ b&#8217;\u548c&#8217;a * b&#8217;\u64cd\u4f5c<\/h1>\n<p>&#8220;\/&#8221;\u548c&#8221;*&#8221;\u90fd\u662f\u4e00\u4e2a\u5f88\u201c\u6602\u8d35\u201d\u7684\u64cd\u4f5c\uff0c\u4f7f\u7528\u79fb\u4f4d\u64cd\u4f5c\u5c06\u4f1a\u66f4\u5feb\u66f4\u6709\u6548\u3002<\/p>\n<div id=\"code\">\n<div><span id=\"codeHead7\">[+]<\/span>view code<\/div>\n<\/div>\n<p>\u6ce8\uff1a\u9664\u975e\u662f\u5728\u4e00\u4e2a\u975e\u5e38\u5927\u7684\u5faa\u73af\u5185\uff0c\u6027\u80fd\u975e\u5e38\u91cd\u8981\uff0c\u800c\u4e14\u4f60\u5f88\u6e05\u695a\u4f60\u81ea\u5df1\u5728\u505a\u4ec0\u4e48\uff0c\u65b9\u53ef\u4f7f\u7528\u8fd9\u79cd\u65b9\u6cd5\u3002\u5426\u5219\u63d0\u9ad8\u6027\u80fd\u6240\u5e26\u6765\u7684\u7a0b\u5e8f\u53ef\u8bfb\u6027\u7684\u964d\u4f4e\u5c06\u662f\u4e0d\u5408\u7b97\u7684\u3002<\/p>\n<h1><a name=\"t6\"><\/a>7. \u4e0d\u8981\u5728\u5faa\u73af\u4e2d\u8c03\u7528<strong>synchronized<\/strong>\u00a0(\u540c\u6b65)\u65b9\u6cd5<\/h1>\n<p>\u65b9\u6cd5\u7684\u540c\u6b65\u9700\u8981\u6d88\u8017\u76f8\u5f53\u5927\u7684\u8d44\u6e90\uff0c\u5728\u4e00\u4e2a\u5faa\u73af\u4e2d\u8c03\u7528\u5b83\u7edd\u5bf9\u4e0d\u662f\u4e00\u4e2a\u597d\u4e3b\u610f\u3002<\/p>\n<div id=\"code\">\n<div><span id=\"codeHead8\">[+]<\/span>view code<\/div>\n<\/div>\n<p>\u66f4\u6b63\uff1a\u4e0d\u8981\u5728\u5faa\u73af\u4f53\u4e2d\u8c03\u7528\u540c\u6b65\u65b9\u6cd5\uff0c\u5982\u679c\u5fc5\u987b\u540c\u6b65\u7684\u8bdd\uff0c\u63a8\u8350\u4ee5\u4e0b\u65b9\u5f0f\uff1a<\/p>\n<div id=\"code\">\n<div><span id=\"codeHead9\">[+]<\/span>view code<\/div>\n<\/div>\n<h1><a name=\"t7\"><\/a>8. \u5c06try\/catch\u5757\u79fb\u51fa\u5faa\u73af<\/h1>\n<p>\u628atry\/catch\u5757\u653e\u5165\u5faa\u73af\u4f53\u5185\uff0c\u4f1a\u6781\u5927\u7684\u5f71\u54cd\u6027\u80fd\uff0c\u5982\u679c\u7f16\u8bd1jit\u88ab\u5173\u95ed\u6216\u8005\u4f60\u6240\u4f7f\u7528\u7684\u662f\u4e00\u4e2a\u4e0d\u5e26jit\u7684jvm\uff0c\u6027\u80fd\u4f1a\u5c06\u4e0b\u964d21%\u4e4b\u591a!<\/p>\n<div id=\"code\">\n<div><span id=\"codeHead10\">[+]<\/span>view code<\/div>\n<\/div>\n<h1><a name=\"t8\"><\/a>9. \u5bf9\u4e8eboolean\u503c\uff0c\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u7b49\u5f0f\u5224\u65ad<\/h1>\n<p>\u5c06\u4e00\u4e2aboolean\u503c\u4e0e\u4e00\u4e2atrue\u6bd4\u8f83\u662f\u4e00\u4e2a\u6052\u7b49\u64cd\u4f5c(\u76f4\u63a5\u8fd4\u56de\u8be5boolean\u53d8\u91cf\u7684\u503c). \u79fb\u8d70\u5bf9\u4e8eboolean\u7684\u4e0d\u5fc5\u8981\u64cd\u4f5c\u81f3\u5c11\u4f1a\u5e26\u67652\u4e2a\u597d\u5904\uff1a<\/p>\n<p>1)\u4ee3\u7801\u6267\u884c\u7684\u66f4\u5feb (\u751f\u6210\u7684\u5b57\u8282\u7801\u5c11\u4e865\u4e2a\u5b57\u8282)\uff1b<br \/>\n2)\u4ee3\u7801\u4e5f\u4f1a\u66f4\u52a0\u5e72\u51c0\u3002<\/p>\n<div id=\"code\">\n<div><span id=\"codeHead11\">[+]<\/span>view code<\/div>\n<\/div>\n<h1><a name=\"t9\"><\/a>10. \u5bf9\u4e8e\u5e38\u91cf\u5b57\u7b26\u4e32\uff0c\u7528&#8217;string&#8217; \u4ee3\u66ff &#8216;stringbuffer&#8217;<\/h1>\n<p>\u5e38\u91cf\u5b57\u7b26\u4e32\u5e76\u4e0d\u9700\u8981\u52a8\u6001\u6539\u53d8\u957f\u5ea6\u3002\u628astringbuffer\u6362\u6210string\uff0c\u5982\u679c\u786e\u5b9a\u8fd9\u4e2astring\u4e0d\u4f1a\u518d\u53d8\u7684\u8bdd\uff0c\u8fd9\u5c06\u4f1a\u51cf\u5c11\u8fd0\u884c\u5f00\u9500\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n<h1><a name=\"t10\"><\/a>11. \u7528&#8217;StringTokenizer&#8217; \u4ee3\u66ff &#8216;indexof()&#8217; \u548c&#8217;substring()&#8217;<\/h1>\n<p>\u5b57\u7b26\u4e32\u7684\u5206\u6790\u5728\u5f88\u591a\u5e94\u7528\u4e2d\u90fd\u662f\u5e38\u89c1\u7684\u3002\u4f7f\u7528substring()\u6765\u5206\u6790\u5b57\u7b26\u4e32\u5bb9\u6613\u5bfc\u81f4java.lang.StringIndexOutOfBoundsException\u3002\u800c\u4f7f\u7528StringTokenizer\u7c7b\u6765\u5206\u6790\u5b57\u7b26\u4e32\u5219\u4f1a\u5bb9\u6613\u4e00\u4e9b\uff0c\u6548\u7387\u4e5f\u4f1a\u9ad8\u4e00\u4e9b\u3002<\/p>\n<h1><a name=\"t11\"><\/a>12. \u4f7f\u7528\u4e09\u5143\u8fd0\u7b97\u8868\u8fbe\u5f0f\u66ff\u4ee3&#8221;if (cond) XXX; else XXX;&#8221; \u7ed3\u6784\u3002<\/h1>\n<h1><a name=\"t12\"><\/a>13. \u5c3d\u91cf\u4e0d\u8981\u5728\u5faa\u73af\u4f53\u4e2d\u5b9e\u4f8b\u5316\u53d8\u91cf<\/h1>\n<p>\u5728\u5faa\u73af\u4f53\u4e2d\u5b9e\u4f8b\u5316\u4e34\u65f6\u53d8\u91cf\u5c06\u4f1a\u589e\u52a0\u5185\u5b58\u6d88\u8017<\/p>\n<h1><a name=\"t13\"><\/a>14. \u5c3d\u53ef\u80fd\u7684\u4f7f\u7528\u6808\u53d8\u91cf<\/h1>\n<p>\u5982\u679c\u4e00\u4e2a\u53d8\u91cf\u9700\u8981\u7ecf\u5e38\u8bbf\u95ee\uff0c\u90a3\u4e48\u4f60\u5c31\u9700\u8981\u8003\u8651\u8fd9\u4e2a\u53d8\u91cf\u7684\u4f5c\u7528\u57df\u4e86\u3002static? local?\u8fd8\u662f\u5b9e\u4f8b\u53d8\u91cf\uff1f\u8bbf\u95ee\u9759\u6001\u53d8\u91cf\u548c\u5b9e\u4f8b\u53d8\u91cf\u5c06\u4f1a\u6bd4\u8bbf\u95ee\u5c40\u90e8\u53d8\u91cf\u8dd1\u7684\u8def\u5f84\u8981\u957f\u7684\u591a\u3002<\/p>\n<div id=\"code\">\n<div><span id=\"codeHead13\">[+]<\/span>view code<\/div>\n<\/div>\n<p>\u66f4\u6b63\uff1a\u5982\u679c\u53ef\u80fd\uff0c\u8bf7\u4f7f\u7528\u5c40\u90e8\u53d8\u91cf\u4f5c\u4e3a\u4f60\u7ecf\u5e38\u8bbf\u95ee\u7684\u53d8\u91cf\u3002\u53ef\u4ee5\u6309\u4e0b\u9762\u7684\u65b9\u6cd5\u6765\u4fee\u6539getsum()\u65b9\u6cd5\uff1a<\/p>\n<div id=\"code\">\n<div><span id=\"codeHead14\">[+]<\/span>view code<\/div>\n<\/div>\n<h1><a name=\"t14\"><\/a>15. \u4e0e\u4e00\u4e2a\u63a5\u53e3 \u8fdb\u884cinstanceof\u64cd\u4f5c<\/h1>\n<p>\u57fa\u4e8e\u63a5\u53e3\u7684\u8bbe\u8ba1\u901a\u5e38\u662f\u4ef6\u597d\u4e8b\uff0c\u56e0\u4e3a\u5b83\u5141\u8bb8\u6709\u4e0d\u540c\u7684\u5b9e\u73b0\uff0c\u800c\u53c8\u4fdd\u6301\u7075\u6d3b\u3002\u53ea\u8981\u53ef\u80fd\uff0c\u5bf9\u4e00\u4e2a\u5bf9\u8c61\u8fdb\u884cinstanceof\u64cd\u4f5c\uff0c\u4ee5\u5224\u65ad\u5b83\u662f\u5426\u67d0\u4e00\u63a5\u53e3\u8981\u6bd4\u662f\u5426\u67d0\u4e00\u4e2a\u7c7b\u8981\u5feb\u3002<\/p>\n<h1><a name=\"t15\"><\/a>16. \u5c3d\u91cf\u51cf\u5c11\u5bf9\u53d8\u91cf\u7684\u91cd\u590d\u8ba1\u7b97<\/h1>\n<p>\u6bd4\u5982<\/p>\n<p>for(int i=0;i&lt;list.size();i++)<\/p>\n<p>\u5e94\u4fee\u6539\u4e3a<\/p>\n<p>for(int i=0,len=list.size();i&lt;len;i++)<\/p>\n<h1><a name=\"t16\"><\/a>17. \u8003\u8651\u4f7f\u7528\u9759\u6001\u65b9\u6cd5<\/h1>\n<p>\u5982\u679c\u4f60\u6ca1\u6709\u5fc5\u8981\u53bb\u8bbf\u95ee\u5bf9\u8c61\u7684\u5916\u90e8\uff0c\u90a3\u4e48\u5c31\u4f7f\u4f60\u7684\u65b9\u6cd5\u6210\u4e3a\u9759\u6001\u65b9\u6cd5\u3002\u5979\u4f1a\u88ab\u66f4\u5feb\u5730\u8c03\u7528\uff0c\u56e0\u4e3a\u5979\u4e0d\u9700\u8981\u4e00\u4e2a\u865a\u62df\u51fd\u6570\u5bfc\u5411\u8868\u3002\u8fd9\u540c\u65f6\u4e5f\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u5b9e\u8df5\uff0c\u56e0\u4e3a\u5979\u544a\u8bc9\u4f60\u5982\u4f55\u533a\u5206\u65b9\u6cd5\u7684\u6027\u8d28\uff0c\u8c03\u7528\u8fd9\u4e2a\u65b9\u6cd5\u4e0d\u4f1a\u6539\u53d8\u5bf9\u8c61\u7684\u72b6\u6001\u3002<\/p>\n<\/div>\n<div id=\"MySignature\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u8005\uff1a\u7985\u697c\u671b\u6708\uff08http:\/\/www.cnblogs.com\/yaoyinglo &hellip;<\/p>\n<p class=\"read-more\"><a href=\"http:\/\/zerobox.org\/notes\/1011.html\">\u7ee7\u7eed\u9605\u8bfb &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[96],"class_list":["post-1011","post","type-post","status-publish","format-standard","hentry","tag-java"],"views":474,"_links":{"self":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/posts\/1011","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/comments?post=1011"}],"version-history":[{"count":0,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/posts\/1011\/revisions"}],"wp:attachment":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/media?parent=1011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/categories?post=1011"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/tags?post=1011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}