{"id":59758,"date":"2026-01-14T12:50:18","date_gmt":"2026-01-14T04:50:18","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/59758.html"},"modified":"2026-01-14T12:50:18","modified_gmt":"2026-01-14T04:50:18","slug":"java%e4%bb%8e%e5%85%a5%e9%97%a8%e5%88%b0%e7%b2%be%e9%80%9a-%e5%9f%ba%e7%a1%80%e7%af%87%ef%bc%88%e4%b8%80%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/59758.html","title":{"rendered":"java\u4ece\u5165\u95e8\u5230\u7cbe\u901a\u2014\u2014\u57fa\u7840\u7bc7\uff08\u4e00\uff09"},"content":{"rendered":"<h2>\u4e00\u3001\u521d\u8bc6java \u00a0<\/h2>\n<h3 id=\"java-\u4e00\u4e2a\u5e1d\u56fd\u7684\u8bde\u751f\">Java : \u4e00\u4e2a\u5e1d\u56fd\u7684\u8bde\u751f<\/h3>\n<h4 id=\"_1\u3001c\u8bed\u8a00\u5e1d\u56fd\u7684\u7edf\u6cbb\">1\u3001C\u8bed\u8a00\u5e1d\u56fd\u7684\u7edf\u6cbb<\/h4>\n<p>\u73b0\u5728\u662f\u516c\u51431995\u5e74&#xff0c; C\u8bed\u8a00\u5e1d\u56fd\u5df2\u7ecf\u7edf\u6cbb\u4e86\u6211\u4eec20\u591a\u5e74&#xff0c; \u5b9e\u5728\u662f\u592a\u4e45\u4e86\u3002<\/p>\n<p>1972\u5e74&#xff0c; \u968f\u7740C\u8bed\u8a00\u7684\u8bde\u751f\u548cUnix\u7684\u95ee\u4e16&#xff0c; \u5e1d\u56fd\u8fc5\u901f\u5efa\u7acb\u7edf\u6cbb&#xff0c; \u4ece\u5317\u7f8e\u5230\u6b27\u6d32&#xff0c; \u4ece\u6b27\u6d32\u5230\u4e9a\u6d32&#xff0c; \u65e0\u6570\u7a0b\u5e8f\u5458\u81e3\u670d\u5728\u4ed6\u7684\u811a\u4e0b\u3002<\/p>\n<p>\u5e1d\u56fd\u7ed9\u6211\u4eec\u63d0\u4f9b\u4e86\u6781\u597d\u7684\u798f\u5229&#xff1a;\u8d34\u8fd1\u786c\u4ef6&#xff0c; \u8fd0\u884c\u6781\u5feb&#xff0c; \u6548\u7387\u6781\u9ad8\u3002<\/p>\n<p>\u4f7f\u7528\u8fd9\u4e9b\u798f\u5229&#xff0c; \u7a0b\u5e8f\u5458\u4eec\u7528C \u5f00\u53d1\u4e86\u5f88\u591a\u7cfb\u7edf\u7ea7\u8f6f\u4ef6&#xff0c;\u64cd\u4f5c\u7cfb\u7edf&#xff0c; \u7f16\u8bd1\u5668&#xff0c; \u6570\u636e\u5e93&#xff0c;\u7f51\u7edc\u7cfb\u7edf&#8230;..<\/p>\n<p>\u4f46\u662f\u5e1d\u56fd\u4e5f\u7ed9\u6211\u4eec\u5b89\u4e0a\u4e86\u4e24\u4e2a\u6c89\u91cd\u7684\u67b7\u9501&#xff1a; \u6307\u9488\u548c\u5185\u5b58\u7ba1\u7406<\/p>\n<p>\u867d\u7136\u6307\u9488\u65e0\u6bd4\u5f3a\u5927&#xff0c; \u80fd\u76f4\u63a5\u64cd\u4f5c\u5185\u5b58&#xff0c; \u4f46\u662f\u5e1d\u56fd\u5374\u6ca1\u6709\u7ed9\u6211\u4eec\u5de5\u5177\u53bb\u505a\u8d8a\u754c\u7684\u68c0\u67e5&#xff0c; \u5bfc\u81f4\u5f88\u591a\u65b0\u624b\u7a0b\u5e8f\u5458\u8f7b\u6613\u72af\u9519\u3002<\/p>\n<p>\u81f3\u4e8e\u5185\u5b58\u7ba1\u7406&#xff0c; \u5e1d\u56fd\u66f4\u5b8c\u5168\u662f\u653e\u4efb\u7684\u6001\u5ea6&#xff1a; \u4f60\u81ea\u5df1\u5206\u914d\u7684\u7a7a\u95f4&#xff0c; \u81ea\u5df1\u53bb\u91ca\u653e &#xff01;<\/p>\n<p>\u66f4\u8981\u547d\u7684\u662f\u8fd9\u4e9b\u95ee\u9898\u5728\u7f16\u8bd1\u671f\u53d1\u73b0\u4e0d\u4e86&#xff0c; \u5728\u8fd0\u884c\u65f6\u624d\u4f1a\u7a81\u7136\u66b4\u9732&#xff0c; \u5e38\u5e38\u8ba9\u6211\u4eec\u624b\u5fd9\u811a\u4e71&#xff0c; \u660f\u5929\u9ed1\u5730\u53bb\u8c03\u8bd5\u3002<\/p>\n<p>\u6211\u4eec\u7684\u5927\u91cf\u65f6\u95f4\u548c\u5b9d\u8d35\u7684\u7cbe\u529b\u90fd\u88ab\u6d6a\u8d39\u5728\u5c0f\u5fc3\u7ffc\u7ffc\u7684\u5904\u7406\u6307\u9488\u548c\u5185\u5b58\u5206\u914d\u4e0a\u3002<\/p>\n<p>\u6bcf\u4e2a\u7a0b\u5e8f\u5458\u90fd\u88ab\u8fd9\u4e24\u4e2a\u4e1c\u897f\u641e\u7684\u7126\u5934\u70c2\u989d&#xff01;<\/p>\n<p>\u5e1d\u56fd\u5ba3\u79f0\u7684\u53ef\u79fb\u690d\u6027\u9a97\u4e86\u6211\u4eec&#xff0c;\u4ed6\u5ba3\u79f0\u6211\u4eec\u5728\u4e00\u4e2a\u673a\u5668\u4e0a\u5199\u7684\u7a0b\u5e8f&#xff0c; \u53ea\u8981\u5728\u53e6\u5916\u4e00\u4e2a\u673a\u5668\u4e0a\u7f16\u8bd1\u5c31\u53ef\u4ee5\u4e86&#xff0c; \u5b9e\u9645\u4e0a\u4e0d\u662f\u8fd9\u6837\u3002 \u4ed6\u8981\u6c42\u6211\u4eec\u5c3d\u91cf\u7528\u6807\u51c6\u7684C\u51fd\u6570\u5e93\u3002\u5176\u6b21&#xff0c;\u5982\u679c\u9047\u5230\u4e86\u4e00\u4e9b\u9488\u5bf9\u7279\u5b9a\u5e73\u53f0\u7684\u8c03\u7528&#xff0c; \u9700\u8981\u5bf9\u6bcf\u4e2a\u5e73\u53f0\u90fd\u5f97\u5199\u4e00\u4efd &#xff01; \u6709\u4e00\u70b9\u70b9\u5c0f\u9519\u8bef&#xff0c;\u90fd\u4f1a\u5bfc\u81f4\u7f16\u8bd1\u5931\u8d25\u3002<\/p>\n<p>1982\u5e74&#xff0c;\u5e1d\u56fd\u53c8\u63a8\u51fa\u4e86\u4e00\u95e8\u65b0\u7684\u8bed\u8a00C&#043;&#043;&#xff0c;\u6dfb\u52a0\u4e86\u9762\u5411\u5bf9\u8c61\u7684\u529f\u80fd&#xff0c;\u517c\u5bb9C&#xff0c;\u6709\u9759\u6001\u7c7b\u578b\u68c0\u67e5&#xff0c; \u6027\u80fd\u4e5f\u5f88\u597d\u3002<\/p>\n<p>\u4f46\u662f\u8fd9\u95e8\u65b0\u7684\u8bed\u8a00\u5b9e\u5728\u662f\u592a\u590d\u6742\u4e86&#xff0c; \u590d\u6742\u5230\u6bd4\u6211\u806a\u660e\u7684\u591a\u7684\u4eba\u90fd\u6ca1\u6709\u529e\u6cd5\u5b8c\u5168\u638c\u63e1\u8fd9\u95e8\u8bed\u8a00&#xff0c;\u5b83\u7684\u5f88\u591a\u7279\u6027\u590d\u6742\u7684\u8ba9\u4eba\u5403\u60ca\u3002<\/p>\n<p>C&#043;&#043;\u5728\u56fe\u5f62\u9886\u57df\u548c\u6e38\u620f\u4e0a\u53d6\u5f97\u4e86\u4e00\u4e9b\u6210\u529f&#xff0c; \u4f46\u662f\u6211\u4e00\u76f4\u5b66\u4e0d\u597d\u5b83\u3002<\/p>\n<h4 id=\"_2\u3001\u53cd\u6297\">2\u3001\u53cd\u6297<\/h4>\n<p>\u6211\u51b3\u5b9a\u53cd\u6297\u8fd9\u4e2a\u5e9e\u5927\u7684\u5e1d\u56fd&#xff0c; \u6211\u5077\u5077\u7684\u5e26\u9886\u7740\u4e00\u5e2e\u5fd7\u540c\u9053\u5408\u7684\u5144\u5f1f\u79bb\u5f00\u4e86&#xff0c;\u6211\u4eec\u8981\u65b0\u5efa\u4e00\u5757\u6e05\u65b0\u81ea\u7531\u7684\u9886\u5730\u3002<\/p>\n<p>\u4e3a\u4e86\u5438\u5f15\u66f4\u591a\u7684\u7a0b\u5e8f\u5458\u52a0\u5165\u6211\u4eec&#xff0c; \u6211\u4eec\u8981\u5efa\u7acb\u4e00\u4e2a\u65b0\u7684\u8bed\u8a00&#xff0c;\u8fd9\u4e2a\u8bed\u8a00\u5e94\u8be5\u6709\u8fd9\u6837\u7684\u7279\u6027&#xff1a;<\/p>\n<p>\u8bed\u6cd5\u6709\u70b9\u50cfC &#xff0c; \u8fd9\u6837\u5927\u5bb6\u5bb9\u6613\u63a5\u53d7<\/p>\n<p>\u6ca1\u6709C\u8bed\u8a00\u90a3\u6837\u7684\u6307\u9488<\/p>\n<p>\u518d\u4e5f\u4e0d\u8981\u8003\u8651\u5185\u5b58\u7ba1\u7406\u4e86&#xff0c; \u5b9e\u5728\u53d7\u4e0d\u4e86\u4e86<\/p>\n<p>\u771f\u6b63\u7684\u53ef\u79fb\u690d\u6027&#xff0c; \u7f16\u5199\u4e00\u6b21&#xff0c; \u5230\u5904\u8fd0\u884c<\/p>\n<p>\u9762\u5411\u5bf9\u8c61<\/p>\n<p>\u7c7b\u578b\u5b89\u5168<\/p>\n<p>\u8fd8\u6709&#xff0c;\u6211\u4eec\u8981\u63d0\u4f9b\u4e00\u5957\u9ad8\u8d28\u91cf\u7684\u7c7b\u5e93&#xff0c; \u968f\u8bed\u8a00\u53d1\u884c\u3002<\/p>\n<p>\u6211\u60f3\u628a\u8fd9\u4e2a\u8bed\u8a00\u547d\u540d\u4e3aC&#043;&#043;&#8211; &#xff0c;\u5373C&#043;&#043;\u51cf\u51cf&#xff0c; \u56e0\u4e3a\u6211\u60f3\u5728C&#043;&#043;\u7684\u57fa\u7840\u4e0a\u6539\u8fdb&#xff0c;\u628a\u5b83\u7b80\u5316\u3002<\/p>\n<p>\u540e\u6765\u53d1\u73b0\u4e0d\u884c&#xff0c; \u8bbe\u8ba1\u7406\u5ff5\u5dee\u522b\u592a\u5927\u3002<\/p>\n<p>\u5e72\u8106\u91cd\u542f\u7089\u7076\u3002<\/p>\n<p>\u6211\u770b\u5230\u95e8\u53e3\u7684\u4e00\u68f5\u6a61\u6811&#xff0c; \u5c31\u628a\u8fd9\u4e2a\u8bed\u8a00\u53eb\u505aOak\u3002<\/p>\n<p>\u4f46\u662f\u540e\u6765\u53d1\u5e03\u7684\u65f6\u5019&#xff0c; \u53d1\u73b0Oak\u5df2\u7ecf\u88ab\u522b\u4eba\u7528\u4e86&#xff0c; \u6211\u4eec\u8ba8\u8bba\u5f88\u4e45&#xff0c; \u6700\u7ec8\u51b3\u5b9a\u628a\u8fd9\u95e8\u65b0\u7684\u8bed\u8a00\u53eb\u505a Java\u3002<\/p>\n<p>\u4e3a\u4e86\u5b9e\u73b0\u8de8\u5e73\u53f0&#xff0c; \u6211\u4eec\u5728\u64cd\u4f5c\u7cfb\u7edf\u548c\u5e94\u7528\u7a0b\u5e8f\u4e4b\u95f4\u589e\u52a0\u4e86\u4e00\u4e2a\u62bd\u8c61\u5c42&#xff1a; Java \u865a\u62df\u673a<\/p>\n<p>\u7528Java\u5199\u7684\u7a0b\u5e8f\u90fd\u8dd1\u5728\u865a\u62df\u673a\u4e0a&#xff0c; \u9664\u975e\u4e2a\u522b\u60c5\u51b5&#xff0c; \u90fd\u4e0d\u7528\u770b\u5230\u64cd\u4f5c\u7cfb\u7edf\u3002<\/p>\n<h4 id=\"_3\u3001\u4e00\u9e23\u60ca\u4eba\">3\u3001\u4e00\u9e23\u60ca\u4eba<\/h4>\n<p>\u4e3a\u4e86\u5438\u5f15\u66f4\u591a\u7684\u4eba\u52a0\u5165\u6211\u4eec\u7684\u65b0\u9886\u5730&#xff0c; \u6211\u4eec\u51b3\u5b9a\u641e\u4e00\u4e2a\u6f14\u793a&#xff0c; \u5411\u5927\u5bb6\u5c55\u793aJava \u7684\u80fd\u529b\u3002<\/p>\n<p>\u51fa\u4e16\u672a\u4e45\u7684Java\u5176\u5b9e\u8fd8\u8fdc\u4e0d\u5b8c\u5584\u3002 \u641e\u70b9\u4ec0\u4e48\u597d\u5462&#xff1f;<\/p>\n<p>\u6211\u4eec\u628a\u773c\u5149\u76ef\u4e0a\u4e86\u521a\u521a\u5174\u8d77\u7684\u4e92\u8054\u7f51&#xff0c; 1995\u5e74\u7684\u7f51\u9875\u7b80\u5355\u800c\u7c97\u7cd9&#xff0c; \u7f3a\u4e4f\u4e92\u52a8\u6027\u3002 \u4e8e\u662f\u6211\u4eec\u5728\u6d4f\u89c8\u5668\u4e0a\u5f04\u4e86\u4e2a\u5c0f\u63d2\u4ef6&#xff0c; \u628ajava \u8fd0\u884c\u73af\u5883\u653e\u4e86\u4e0a\u53bb\u3002<\/p>\n<p>\u7136\u540e\u5728\u4e0a\u9762\u5f00\u53d1\u4e86\u4e00\u4e2a\u56fe\u5f62\u754c\u9762\u7684\u7a0b\u5e8f(Applet)&#xff0c; \u8ba9\u5b83\u770b\u8d77\u6765\u7f8e\u8f6e\u7f8e\u5942&#xff0c; \u9707\u64bc\u4eba\u5fc3\u3002<\/p>\n<p>\u6bcf\u4e00\u4e2a\u770b\u5230\u4ed6\u7684\u7a0b\u5e8f\u5458\u90fd\u4f1a\u53d1\u51fa\u201cWow\u201d\u7684\u60ca\u53f9 &#xff01;\u4e3a\u4e4b\u503e\u5012\u3002<\/p>\n<p>Java \u6d3b\u4e86&#xff01;<\/p>\n<p>\u901a\u8fc7Applet &#xff0c;\u65e0\u6570\u7684\u7a0b\u5e8f\u5458\u770b\u5230\u4e86Java\u8fd9\u95e8\u8bed\u8a00&#xff0c;\u4e86\u89e3\u4e86\u8fd9\u95e8\u8bed\u8a00\u7279\u6027\u4ee5\u540e&#xff0c; \u5f88\u591a\u65e0\u6cd5\u5fcd\u53d7C\u5e1d\u56fd\u66b4\u653f\u7684\u7a0b\u5e8f\u5458&#xff0c; \u5f88\u5feb\u52a0\u5165\u4e86\u6211\u4eec&#xff0c; \u6211\u4eec\u7684\u9886\u5730\u5f00\u59cb\u8fc5\u901f\u6269\u5927\u3002<\/p>\n<p>\u8fdeC\u8bed\u8a00\u5e1d\u56fd\u91cc\u7684\u4e00\u4e9b\u5546\u4e1a\u5de8\u5934\u4e5f\u7eb7\u7eb7\u6765\u548c\u6211\u4eec\u5408\u4f5c&#xff0c; \u5176\u4e2d\u5c31\u5305\u62ecOracle &#xff0c;\u5fae\u8f6f\u8fd9\u6837\u7684\u5de8\u5934 &#xff0c; \u5fae\u8f6f\u7684\u5934\u9886Bill Gates\u8fd8\u8bf4 &#xff1a;\u8fd9\u662f\u8fc4\u4eca\u4e3a\u6b62\u8bbe\u8ba1\u7684\u6700\u597d\u7684\u8bed\u8a00&#xff01;<\/p>\n<p>\u4f46\u662fBill Gates\u975e\u5e38\u7684\u4e0d\u5730\u9053&#xff0c; \u4e70\u4e86\u6211\u4eec\u7684Java \u8bb8\u53ef\u4ee5\u540e&#xff0c;\u867d\u7136\u5728\u81ea\u5bb6\u7684\u6d4f\u89c8\u5668\u4e0a\u4e5f\u652f\u6301Applet&#xff0c;\u4f46\u662f\u4ed6\u4eec\u5374\u5077\u5077\u7684\u8bd5\u56fe\u4fee\u6539Java &#xff0c; \u60f3\u628aJava\u7ed1\u6b7b\u5728\u81ea\u5bb6\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8d5a\u94b1&#xff0c; Java\u4f1a\u53d8\u7684\u4e0d\u53ef\u79fb\u690d\u3002<\/p>\n<p>\u8fd9\u662f\u6211\u4eec\u96be\u4e8e\u5fcd\u53d7\u7684&#xff0c; \u6211\u4eec\u548c\u5fae\u8f6f\u53d1\u8d77\u4e86\u4e00\u573a\u65f7\u65e5\u6301\u4e45\u7684\u6e38\u51fb\u6218\u4e89&#xff0c; \u903c\u7740\u5fae\u8f6f\u9000\u51fa\u4e86Java\u9886\u57df&#xff0c; \u5f00\u53d1\u4e86\u81ea\u5df1\u7684.NET &#xff0c;\u8fd9\u662f\u540e\u8bdd\u3002<\/p>\n<h4 id=\"_4\u3001\u5f00\u62d3\u7586\u571f\">4\u3001\u5f00\u62d3\u7586\u571f<\/h4>\n<p>\u4ece1995\u5e74\u52301997\u5e74&#xff0c;\u6211\u4eec\u4f9d\u9760 Java \u4e0d\u65ad\u7684\u653b\u57ce\u7565\u5730&#xff0c; \u5f00\u62d3\u7586\u571f&#xff0c;\u6211\u4eec\u738b\u56fd\u7684\u5b50\u6c11\u4e0d\u65ad\u589e\u52a0&#xff0c; \u8fbe\u5230\u4e86\u51e0\u5341\u4e07\u4e4b\u4f17&#xff0c; \u5df2\u7ecf\u662f\u4e00\u4e2a\u4e0d\u53ef\u5ffd\u89c6\u7684\u529b\u91cf\u4e86\u3002<\/p>\n<p>\u4f46\u662f\u5927\u5bb6\u53d1\u73b0&#xff0c; Java\u9664\u4e86Applet&#xff0c;\u4ee5\u53ca\u4e00\u4e9b\u5c0f\u7a0b\u5e8f\u4e4b\u5916&#xff0c; \u4f3c\u4e4e\u5e72\u4e0d\u4e86\u522b\u7684\u4e8b\u60c5\u3002<\/p>\n<p>C\u5e1d\u56fd\u7684\u4eba\u8fd8\u4e0d\u65ad\u7684\u5632\u7b11\u6211\u4eec\u6162&#xff0c; \u50cf\u4e2a\u73a9\u5177\u3002<\/p>\n<p>\u5230\u4e861998\u5e74&#xff0c; \u7ecf\u8fc7\u5bc6\u8c0b&#xff0c; \u6211\u4eecJava \u738b\u56fd\u51b3\u5b9a\u6d3e\u51fa\u4e09\u53ea\u519b\u961f\u5411\u5916\u6269\u5c55&#xff1a;<\/p>\n<p>Java 2 \u6807\u51c6\u7248(J2SE)&#xff1a; \u53bb\u5360\u9886\u684c\u9762<\/p>\n<p>Java 2 \u79fb\u52a8\u7248(J2ME)&#xff1a; \u53bb\u5360\u9886\u624b\u673a<\/p>\n<p>Java 2 \u4f01\u4e1a\u7248(J2EE)&#xff1a; \u53bb\u5360\u9886\u670d\u52a1\u5668<\/p>\n<p>\u5176\u4e2d\u7684\u4e24\u53ea\u5927\u519b\u5f88\u5feb\u8d25\u4e0b\u9635\u6765\u3002<\/p>\n<p>J2SE \u7684\u9996\u9886\u53d1\u73b0&#xff0c; \u5f00\u53d1\u684c\u9762\u5e94\u7528\u7684\u7a0b\u5e8f\u5458\u6839\u672c\u63a5\u53d7\u4e0d\u4e86Java&#xff0c; \u867d\u7136\u6211\u4eec\u6709\u505a\u7684\u5f88\u4f18\u96c5\u7684Swing \u53ef\u4ee5\u5f00\u53d1\u754c\u9762&#xff0c; \u4f46\u662f\u5f00\u53d1\u51fa\u7684\u754c\u9762\u975e\u5e38\u96be\u770b&#xff0c; \u548c\u539f\u751f\u7684\u684c\u9762\u5dee\u8ddd\u5f88\u5927\u3002 \u5c24\u5176\u662f\u4e3a\u4e86\u8fd0\u884c\u7a0b\u5e8f\u8fd8\u5f97\u5b89\u88c5\u4e00\u4e2a\u865a\u62df\u673a&#xff0c; \u5927\u5bb6\u90fd\u53d7\u4e0d\u4e86\u3002<\/p>\n<p>J2ME\u4e5f\u662f&#xff0c; \u4e00\u76f4\u4e0d\u53d7\u5f85\u89c1&#xff0c; \u5f53\u7136\u66f4\u91cd\u8981\u7684\u539f\u56e0\u662f\u4e54\u5e03\u65af\u8fd8\u6ca1\u6709\u91cd\u65b0\u53d1\u660e\u624b\u673a&#xff0c; \u79fb\u52a8\u4e92\u8054\u7f51\u8fd8\u6ca1\u6709\u542f\u52a8\u3002<\/p>\n<p>\u5931\u4e4b\u4e1c\u9685&#xff0c;\u6536\u4e4b\u6851\u6986&#xff0c; J2EE\u8d76\u4e0a\u4e86\u597d\u65f6\u5019&#xff0c; \u4e92\u8054\u7f51\u5927\u53d1\u5c55&#xff0c; \u5927\u5bb6\u5ffd\u7136\u53d1\u73b0&#xff0c; Java\u7b80\u76f4\u662f\u4e3a\u5199\u670d\u52a1\u5668\u7aef\u7a0b\u5e8f\u6240\u53d1\u660e\u7684&#xff01;<\/p>\n<p>\u5f3a\u5927&#xff0c; \u5065\u58ee&#xff0c; \u5b89\u5168&#xff0c; \u7b80\u5355&#xff0c; \u8de8\u5e73\u53f0 &#xff01;<\/p>\n<p>\u5728J2EE\u89c4\u8303\u7684\u6307\u5bfc\u4e0b&#xff0c; \u7279\u522b\u9002\u5408\u56e2\u961f\u5f00\u53d1\u590d\u6742\u7684\u5927\u578b\u9879\u76ee\u3002<\/p>\n<p>\u6211\u4eec\u6388\u6743BEA\u516c\u53f8\u7b2c\u4e00\u4e2a\u4f7f\u7528J2EE\u8bb8\u53ef\u8bc1&#xff0c; \u63a8\u51fa\u4e86Weblogic&#xff0c; \u51ed\u501f\u5176\u96c6\u7fa4\u529f\u80fd&#xff0c; \u7b2c\u4e00\u6b21\u5c55\u793a\u4e86\u590d\u6742\u5e94\u7528\u7684\u53ef\u6269\u5c55\u6027\u548c\u9ad8\u53ef\u7528\u6027\u3002<\/p>\n<p>\u8fd9\u4e2a\u540e\u6765\u88ab\u79f0\u4e3a\u4e2d\u95f4\u4ef6\u7684\u4e1c\u897f\u628a\u7a0b\u5e8f\u5458\u4ece\u4e8b\u52a1\u7ba1\u7406&#xff0c;\u5b89\u5168\u7ba1\u7406&#xff0c;\u6743\u9650\u7ba1\u7406\u7b49\u65b9\u9762\u89e3\u653e\u51fa\u6765&#xff0c; \u8ba9\u4ed6\u4eec\u4e13\u6ce8\u4e8e\u4e1a\u52a1\u5f00\u53d1\u3002 \u8fd9\u7acb\u523b\u6355\u83b7\u4e86\u5927\u91cf\u7a0b\u5e8f\u5458\u7684\u5fc3\u3002<\/p>\n<p>\u5f88\u5febJava \u738b\u56fd\u7684\u5b50\u6c11\u5c31\u8fbe\u5230\u6570\u767e\u4e07\u4e4b\u4f17\u3002<\/p>\n<p>\u699c\u6837\u7684\u529b\u91cf\u662f\u65e0\u7a77\u7684&#xff0c; \u5f88\u5feb\u5176\u4ed6\u5546\u4e1a\u5de8\u5934\u4e5f\u7eb7\u7eb7\u5165\u573a&#xff0c; \u5c24\u5176\u662fIBM&#xff0c;\u5728Java \u4e0a\u75af\u72c2\u6295\u5165&#xff0c;\u4e0d\u4ec5\u5f00\u53d1\u4e86\u81ea\u5df1\u7684\u5e94\u7528\u670d\u52a1\u5668 Websphere&#xff0c; \u8fd8\u63a8\u51fa\u4e86Eclipse\u8fd9\u4e2a\u6781\u5177\u9b45\u529b\u7684\u5f00\u6e90\u5f00\u53d1\u5e73\u53f0\u3002<\/p>\n<p>\u5f53\u7136IBM\u5229\u7528java \u83b7\u5f97\u4e86\u975e\u5e38\u53ef\u89c2\u7684\u6548\u76ca&#xff0c; \u8f6f\u4ef6&#043;\u786c\u4ef6&#043;\u670d\u52a1 \u4e09\u9a7e\u9a6c\u8f66\u6eda\u6eda\u5411\u524d&#xff0c; \u628aIBM\u63a8\u5411\u4e86\u4e00\u4e2a\u65b0\u7684\u9ad8\u5cf0\u3002<\/p>\n<h4 id=\"_5\u3001\u5e1d\u56fd\u7684\u8bde\u751f\">5\u3001\u5e1d\u56fd\u7684\u8bde\u751f<\/h4>\n<p>\u5927\u5bb6\u4e5f\u6ca1\u6709\u60f3\u5230&#xff0c;\u9664\u4e86\u5546\u4e1a\u5de8\u5934\u4ee5\u5916&#xff0c; \u7a0b\u5e8f\u5458\u4eec\u4e5f\u4f1a\u5bf9Java\u738b\u56fd \u8fd9\u4e48\u70ed\u7231&#xff0c; \u4ed6\u4eec\u57fa\u4e8eJava \u5f00\u53d1\u4e86\u5de8\u591a\u7684\u5e73\u53f0&#xff0c;\u7cfb\u7edf&#xff0c;\u5de5\u5177&#xff0c;\u4f8b\u5982&#xff1a;<\/p>\n<p>\u6784\u5efa\u5de5\u5177: Ant&#xff0c;Maven&#xff0c;Jekins<\/p>\n<p>\u5e94\u7528\u670d\u52a1\u5668&#xff1a; Tomcat&#xff0c;Jetty&#xff0c;Jboss&#xff0c;Websphere&#xff0c;weblogic<\/p>\n<p>Web\u5f00\u53d1&#xff1a; Struts,Spring,Hibernate&#xff0c;myBatis<\/p>\n<p>\u5f00\u53d1\u5de5\u5177&#xff1a; Eclipse&#xff0c;Netbean,intellij idea&#xff0c;Jbuilder<\/p>\n<p>\u3002\u3002\u3002\u3002\u7b49\u7b49\u7b49\u7b49\u3002\u3002\u3002\u3002<\/p>\n<p>\u5e76\u4e14\u7edd\u5927\u90e8\u5206\u90fd\u662f\u5f00\u6e90\u7684 &#xff01;<\/p>\n<p>\u5fae\u8f6f\u773c\u7741\u7741\u7684\u770b\u7740\u670d\u52a1\u5668\u7aef\u7684\u5e02\u573a\u88abJava \u738b\u56fd\u5360\u636e&#xff0c; \u5c82\u80fd\u5584\u7f62\u7518\u4f11&#xff1f; \u4ed6\u4eec\u8d76\u7d27\u63a8\u51fa.NET\u6765\u5bf9\u6297&#xff0c; \u4f46\u6211\u4eec\u5df2\u7ecf\u4e0d\u5728\u4e4e\u4e86&#xff0c; \u56e0\u4e3a\u4ed6\u7684\u7cfb\u7edf\u662f\u5c01\u95ed\u7684&#xff0c;\u6240\u6709\u7684\u8f6f\u4ef6\u90fd\u662f\u81ea\u5bb6\u7684&#xff1a;<\/p>\n<p>\u5f00\u53d1\u5de5\u5177\u662fVisual Studio&#xff0c;\u5e94\u7528\u670d\u52a1\u5668\u662fIIS&#xff0c;\u6570\u636e\u5e93\u662fSQL Server&#xff0c;\u53ea\u8981\u4f60\u7528.NET&#xff0c;\u57fa\u672c\u4e0a\u5c31\u4f1a\u7ed1\u5b9a\u5fae\u8f6f\u3002<\/p>\n<p>\u53e6\u5916\u4ed6\u4eec\u7684\u7cfb\u7edf\u53ea\u80fd\u8fd0\u884c\u5728Windows\u670d\u52a1\u5668\u4e0a&#xff0c; \u8fd9\u4e2a\u670d\u52a1\u5668\u5728\u9ad8\u7aef\u5e02\u573a\u7684\u5360\u6709\u7387\u5b9e\u5728\u662f\u592a\u4f4e\u4e86\u3002<\/p>\n<p>2005\u5e74\u5e95&#xff0c; \u4e00\u4e2a\u65b0\u7684\u738b\u56fd\u7a81\u7136\u5d1b\u8d77&#xff0c; \u4ed6\u4eec\u53f7\u79f0\u5f00\u53d1\u6548\u7387\u6bd4java \u5feb5-10\u500d&#xff0c; \u7531\u6b64\u5438\u5f15\u4e86\u5927\u6279\u7a0b\u5e8f\u5458\u524d\u5f80\u52a0\u76df\u3002<\/p>\n<p>\u8fd9\u4e2a\u65b0\u7684\u738b\u56fd\u53eb\u505aRuby on Rails&#xff0c;\u5b83\u7ed3\u5408\u4e86PHP\u4f53\u7cfb\u7684\u4f18\u70b9&#xff08;\u5feb\u901f\u5f00\u53d1&#xff09;\u548cJava\u4f53\u7cfb\u7684\u4f18\u70b9&#xff08;\u7a0b\u5e8f\u89c4\u6574&#xff09;&#xff0c; \u7279\u522b\u9002\u5408\u5feb\u901f\u7684\u5f00\u53d1\u7b80\u5355\u7684Web\u7f51\u7ad9\u3002<\/p>\n<p>\u867d\u7136\u53d1\u5c55\u5f88\u5feb&#xff0c; \u4f46\u6ca1\u6709\u5bf9Java \u738b\u56fd\u4ea7\u751f\u5b9e\u8d28\u6027\u7684\u5a01\u80c1&#xff0c; \u4f7f\u7528Ruby on Rails\u642d\u5efa\u5927\u578b\u5546\u4e1a\u7cfb\u7edf\u7684\u8fd8\u5f88\u5c11\u3002<\/p>\n<p>\u9664\u4e86Ruby on Rails &#xff0c;\u8fd8\u6709PHP&#xff0c; Python &#xff0c; \u90fd\u9002\u5408\u5feb\u901f\u5f00\u53d1\u4e0d\u592a\u590d\u6742\u7684Web\u7cfb\u7edf\u3002 \u4f46\u662f\u5173\u952e\u7684&#xff0c;\u590d\u6742\u7684\u5546\u4e1a\u7cfb\u7edf\u5f00\u53d1\u8fd8\u662fJava \u738b\u56fd\u7684\u7edf\u6cbb\u4e4b\u4e0b\u3002 \u6240\u4ee5\u6211\u4eec\u548c\u4ed6\u4eec\u76f8\u5b89\u65e0\u4e8b\u3002<\/p>\n<p>2006\u5e74&#xff0c; \u4e00\u53ea\u53ebHadoop\u7684\u519b\u961f\u8ba9Java\u738b\u56fd\u5165\u4fb5\u4e86\u5927\u6570\u636e\u9886\u57df&#xff0c; \u7531\u4e8e\u4f7f\u7528Java \u8bed\u8a00&#xff0c; \u7edd\u5927\u591a\u6570\u7a0b\u5e8f\u5458\u5728\u7406\u89e3\u4e86Map\/Reduce &#xff0c;\u5206\u5e03\u5f0f\u6587\u4ef6\u7cfb\u7edf\u5728Hadoop\u4e2d\u7684\u5b9e\u73b0\u4ee5\u540e&#xff0c; \u5f88\u5feb\u5c31\u80fd\u7f16\u5199\u5904\u7406\u5904\u7406\u6d77\u91cf\u6570\u636e\u7684\u7a0b\u5e8f&#xff0c; Java \u738b\u56fd\u7684\u9886\u5730\u5f97\u5230\u4e86\u6781\u5927\u7684\u6269\u5c55\u3002<\/p>\n<p>2008\u5e74&#xff0c; \u4e00\u4e2a\u540d\u53ebAndroid \u7684\u7cfb\u7edf\u6a2a\u7a7a\u51fa\u4e16&#xff0c; \u5e76\u4e14\u968f\u7740\u79fb\u52a8\u4e92\u8054\u7f51\u7684\u7206\u53d1\u8fc5\u901f\u666e\u53ca&#xff0c; \u8fd0\u884c\u5728Android\u4e4b\u4e0a\u7684\u6b63\u662fJava &#xff01;<\/p>\n<p>Java \u738b\u56fd\u5728Google\u7684\u652f\u6301\u4e0b&#xff0c; \u4ee5\u4e00\u79cd\u610f\u60f3\u4e0d\u5230\u7684\u65b9\u5f0f\u5360\u9886\u4e86\u624b\u673a\u7aef&#xff0c; \u5b8c\u6210\u4e86\u5f53\u5e74J2ME \u58ee\u5fd7\u672a\u916c\u7684\u4e8b\u4e1a &#xff01;<\/p>\n<p>\u5230\u4eca\u5e74\u4e3a\u6b62&#xff0c; \u5168\u4e16\u754c\u4f30\u8ba1\u67091000\u4e07\u7a0b\u5e8f\u5458\u52a0\u5165\u4e86Java\u738b\u56fd&#xff0c;\u5b83\u9886\u571f\u4e4b\u5e7f\u6cdb&#xff0c; \u5b9e\u529b\u4e4b\u5f3a\u5927&#xff0c; \u662f\u5176\u4ed6\u8bed\u8a00\u65e0\u6cd5\u6bd4\u62df\u7684\u3002<\/p>\n<p>Java \u5360\u636e\u4e86\u5927\u90e8\u5206\u7684\u670d\u52a1\u5668\u7aef\u5f00\u53d1&#xff0c;\u5c24\u5176\u662f\u5173\u952e\u7684\u590d\u6742\u7684\u7cfb\u7edf&#xff0c; \u7edd\u5927\u591a\u6570\u7684\u624b\u673a\u7aef&#xff0c; \u4ee5\u53ca\u5927\u90e8\u5206\u7684\u5927\u6570\u636e\u9886\u57df\u3002<\/p>\n<p>\u4e00\u4e2a\u4f1f\u5927\u7684\u5e1d\u56fd\u8bde\u751f\u4e86\u3002<\/p>\n<h3 id=\"java\u7684\u7279\u6027\u548c\u4f18\u52bf\">Java\u7684\u7279\u6027\u548c\u4f18\u52bf<\/h3>\n<h4 id=\"\u516b\u5927\u7279\u6027\">\u516b\u5927\u7279\u6027<\/h4>\n<p>1\u3001\u8de8\u5e73\u53f0\/\u53ef\u79fb\u690d\u6027<\/p>\n<p>\u8fd9\u662fJava\u7684\u6838\u5fc3\u4f18\u52bf\u3002Java\u5728\u8bbe\u8ba1\u65f6\u5c31\u5f88\u6ce8\u91cd\u79fb\u690d\u548c\u8de8\u5e73\u53f0\u6027\u3002\u6bd4\u5982&#xff1a;Java\u7684int\u6c38\u8fdc\u90fd\u662f32\u4f4d\u3002\u4e0d\u50cfC&#043;&#043;\u53ef\u80fd\u662f16&#xff0c;32&#xff0c;\u53ef\u80fd\u662f\u6839\u636e\u7f16\u8bd1\u5668\u5382\u5546\u89c4\u5b9a\u7684\u53d8\u5316\u3002\u8fd9\u6837\u7684\u8bdd\u7a0b\u5e8f\u7684\u79fb\u690d\u5c31\u4f1a\u975e\u5e38\u9ebb\u70e6\u3002<\/p>\n<p>2\u3001\u5b89\u5168\u6027<\/p>\n<p>Java\u9002\u5408\u4e8e\u7f51\u7edc\/\u5206\u5e03\u5f0f\u73af\u5883&#xff0c;\u4e3a\u4e86\u8fbe\u5230\u8fd9\u4e2a\u76ee\u6807&#xff0c;\u5728\u5b89\u5168\u6027\u65b9\u9762\u6295\u5165\u4e86\u5f88\u5927\u7684\u7cbe\u529b&#xff0c;\u4f7fJava\u53ef\u4ee5\u5f88\u5bb9\u6613\u6784\u5efa\u9632\u75c5\u6bd2&#xff0c;\u9632\u7be1\u6539\u7684\u7cfb\u7edf\u3002<\/p>\n<p>3\u3001\u9762\u5411\u5bf9\u8c61<\/p>\n<p>\u9762\u5411\u5bf9\u8c61\u662f\u4e00\u79cd\u7a0b\u5e8f\u8bbe\u8ba1\u6280\u672f&#xff0c;\u975e\u5e38\u9002\u5408\u5927\u578b\u8f6f\u4ef6\u7684\u8bbe\u8ba1\u548c\u5f00\u53d1\u3002\u7531\u4e8eC&#043;&#043;\u4e3a\u4e86\u7167\u987e\u5927\u91cfC\u8bed\u8a00\u4f7f\u7528\u8005\u800c\u517c\u5bb9\u4e86C&#xff0c;\u4f7f\u5f97\u81ea\u8eab\u4ec5\u4ec5\u6210\u4e3a\u4e86\u5e26\u7c7b\u7684C\u8bed\u8a00&#xff0c;\u591a\u5c11\u5f71\u54cd\u4e86\u5176\u9762\u5411\u5bf9\u8c61\u7684\u5f7b\u5e95\u6027&#xff01;<\/p>\n<p>Java\u5219\u662f\u5b8c\u5168\u7684\u9762\u5411\u5bf9\u8c61\u8bed\u8a00\u3002<\/p>\n<p>4\u3001\u7b80\u5355\u6027<\/p>\n<p>Java\u5c31\u662fC&#043;&#043;\u8bed\u6cd5\u7684\u7b80\u5316\u7248&#xff0c;\u6211\u4eec\u4e5f\u53ef\u4ee5\u5c06Java\u79f0\u4e4b\u4e3a\u201cC&#043;&#043;-\u201d\u3002\u8ddf\u6211\u5ff5\u201cC\u52a0\u52a0\u51cf\u201d&#xff0c;\u6307\u7684\u5c31\u662f\u5c06C&#043;&#043;\u7684\u4e00\u4e9b\u5185\u5bb9\u53bb\u6389&#xff1b;\u6bd4\u5982&#xff1a;\u5934\u6587\u4ef6&#xff0c;\u6307\u9488\u8fd0\u7b97&#xff0c;\u7ed3\u6784&#xff0c;\u8054\u5408&#xff0c;\u64cd\u4f5c\u7b26\u91cd\u8f7d&#xff0c;\u865a\u57fa\u7c7b\u7b49\u7b49\u3002<\/p>\n<p>\u540c\u65f6&#xff0c;\u7531\u4e8e\u8bed\u6cd5\u57fa\u4e8eC\u8bed\u8a00&#xff0c;\u56e0\u6b64\u5b66\u4e60\u8d77\u6765\u5b8c\u5168\u4e0d\u8d39\u529b\u3002<\/p>\n<p>5\u3001\u9ad8\u6027\u80fd<\/p>\n<p>Java\u6700\u521d\u53d1\u5c55\u9636\u6bb5&#xff0c;\u603b\u662f\u88ab\u4eba\u8bdf\u75c5\u201c\u6027\u80fd\u4f4e\u201d&#xff1b;\u5ba2\u89c2\u4e0a&#xff0c;\u9ad8\u7ea7\u8bed\u8a00\u8fd0\u884c\u6548\u7387\u603b\u662f\u4f4e\u4e8e\u4f4e\u7ea7\u8bed\u8a00\u7684&#xff0c;\u8fd9\u4e2a\u65e0\u6cd5\u907f\u514d\u3002Java\u8bed\u8a00\u672c\u8eab\u53d1\u5c55\u4e2d\u901a\u8fc7\u865a\u62df\u673a\u7684\u4f18\u5316\u63d0\u5347\u4e86\u51e0\u5341\u500d\u8fd0\u884c\u6548\u7387\u3002<\/p>\n<p>\u6bd4\u5982&#xff0c;\u901a\u8fc7JIT(JUST IN TIME)\u5373\u65f6\u7f16\u8bd1\u6280\u672f\u63d0\u9ad8\u8fd0\u884c\u6548\u7387\u3002 \u5c06\u4e00\u4e9b\u201c\u70ed\u70b9\u201d\u5b57\u8282\u7801\u7f16\u8bd1\u6210\u672c\u5730\u673a\u5668\u7801&#xff0c;\u5e76\u5c06\u7ed3\u679c\u7f13\u5b58\u8d77\u6765&#xff0c;\u5728\u9700\u8981\u7684\u65f6\u5019\u91cd\u65b0\u8c03\u7528\u3002\u8fd9\u6837\u7684\u8bdd&#xff0c;\u4f7fJava\u7a0b\u5e8f\u7684\u6267\u884c\u6548\u7387\u5927\u5927\u63d0\u9ad8&#xff0c;<\/p>\n<p>\u67d0\u4e9b\u4ee3\u7801\u751a\u81f3\u63a5\u5f85C&#043;&#043;\u7684\u6548\u7387\u3002\u56e0\u6b64&#xff0c;Java\u4f4e\u6027\u80fd\u7684\u77ed\u817f&#xff0c;\u5df2\u7ecf\u88ab\u5b8c\u5168\u89e3\u51b3\u4e86\u3002\u4e1a\u754c\u53d1\u5c55\u4e0a&#xff0c;\u6211\u4eec\u4e5f\u770b\u5230\u5f88\u591aC&#043;&#043;\u5e94\u7528\u8f6c\u5230Java\u5f00\u53d1&#xff0c;\u5f88\u591aC&#043;&#043;\u7a0b\u5e8f\u5458\u8f6c\u578b\u4e3aJava\u7a0b\u5e8f\u5458\u3002<\/p>\n<p>6\u3001\u5206\u5e03\u5f0f<\/p>\n<p>Java\u662f\u4e3aInternet\u7684\u5206\u5e03\u5f0f\u73af\u5883\u8bbe\u8ba1\u7684&#xff0c;\u56e0\u4e3a\u5b83\u80fd\u591f\u5904\u7406TCP\/IP\u534f\u8bae\u3002\u4e8b\u5b9e\u4e0a&#xff0c;\u901a\u8fc7URL\u8bbf\u95ee\u4e00\u4e2a\u7f51\u7edc\u8d44\u6e90\u548c\u8bbf\u95ee\u672c\u5730\u6587\u4ef6\u662f\u4e00\u6837\u7b80\u5355\u7684\u3002Java\u8fd8\u652f\u6301\u8fdc\u7a0b\u65b9\u6cd5\u8c03\u7528(RMI,Remote Method Invocation)&#xff0c;<\/p>\n<p>\u4f7f\u7a0b\u5e8f\u80fd\u591f\u901a\u8fc7\u7f51\u7edc\u8c03\u7528\u65b9\u6cd5\u3002<\/p>\n<p>7\u3001\u591a\u7ebf\u7a0b<\/p>\n<p>\u591a\u7ebf\u7a0b\u7684\u4f7f\u7528\u53ef\u4ee5\u5e26\u6765\u66f4\u597d\u7684\u4ea4\u4e92\u54cd\u5e94\u548c\u5b9e\u65f6\u884c\u4e3a\u3002 Java\u591a\u7ebf\u7a0b\u7684\u7b80\u5355\u6027\u662fJava\u6210\u4e3a\u4e3b\u6d41\u670d\u52a1\u5668\u7aef\u5f00\u53d1\u8bed\u8a00\u7684\u4e3b\u8981\u539f\u56e0\u4e4b\u4e00\u3002<\/p>\n<p>8\u3001\u5065\u58ee\u6027<\/p>\n<p>Java\u662f\u4e00\u79cd\u5065\u58ee\u7684\u8bed\u8a00&#xff0c;\u5438\u6536\u4e86C\/C&#043;&#043; \u8bed\u8a00\u7684\u4f18\u70b9&#xff0c;\u4f46\u53bb\u6389\u4e86\u5176\u5f71\u54cd\u7a0b\u5e8f\u5065\u58ee\u6027\u7684\u90e8\u5206&#xff08;\u5982&#xff1a;\u6307\u9488\u3001\u5185\u5b58\u7684\u7533\u8bf7\u4e0e\u91ca\u653e\u7b49&#xff09;\u3002Java\u7a0b\u5e8f\u4e0d\u53ef\u80fd\u9020\u6210\u8ba1\u7b97\u673a\u5d29\u6e83\u3002\u5373\u4f7fJava\u7a0b\u5e8f\u4e5f\u53ef\u80fd\u6709\u9519\u8bef\u3002<\/p>\n<p>\u5982\u679c\u51fa\u73b0\u67d0\u79cd\u51fa\u4e4e\u610f\u6599\u4e4b\u4e8b&#xff0c;\u7a0b\u5e8f\u4e5f\u4e0d\u4f1a\u5d29\u6e83&#xff0c;\u800c\u662f\u628a\u8be5\u5f02\u5e38\u629b\u51fa&#xff0c;\u518d\u901a\u8fc7\u5f02\u5e38\u5904\u7406\u673a\u5236\u52a0\u4ee5\u5904\u7406\u3002<\/p>\n<h4 id=\"\u6838\u5fc3\u4f18\u52bf\">\u6838\u5fc3\u4f18\u52bf<\/h4>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"258\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114045015-69672087b2de2.png\" width=\"518\" \/><\/p>\n<p>\u8de8\u5e73\u53f0\u662fJava\u8bed\u8a00\u7684\u6838\u5fc3\u4f18\u52bf&#xff0c;\u8d76\u4e0a\u6700\u521d\u4e92\u8054\u7f51\u7684\u53d1\u5c55&#xff0c;\u5e76\u968f\u7740\u4e92\u8054\u7f51\u7684\u53d1\u5c55\u800c\u53d1\u5c55&#xff0c;\u5efa\u7acb\u4e86\u5f3a\u5927\u7684\u751f\u6001\u4f53\u7cfb&#xff0c;\u76ee\u524d\u5df2\u7ecf\u8986\u76d6IT\u5404\u884c\u4e1a\u7684\u201c\u7b2c\u4e00\u5927\u8bed\u8a00\u201d&#xff0c;\u662f\u8ba1\u7b97\u673a\u754c\u7684\u201c\u82f1\u8bed\u201d\u3002<\/p>\n<p>\u867d\u7136&#xff0c;\u76ee\u524d\u4e5f\u6709\u5f88\u591a\u8de8\u5e73\u53f0\u7684\u8bed\u8a00&#xff0c;\u4f46\u662f\u5df2\u7ecf\u5931\u53bb\u5148\u673a&#xff0c;\u65e0\u6cd5\u548cJava\u5f3a\u5927\u7684\u751f\u6001\u4f53\u7cfb\u6297\u8861\u3002Java\u4ecd\u5c06\u5728\u672a\u6765\u51e0\u5341\u5e74\u6210\u4e3a\u7f16\u7a0b\u8bed\u8a00\u7684\u4e3b\u6d41\u8bed\u8a00\u3002<\/p>\n<p>JAVA\u865a\u62df\u673a\u662fJAVA\u5b9e\u73b0\u8de8\u5e73\u53f0\u7684\u6838\u5fc3\u3002\u4e8b\u5b9e\u4e0a&#xff0c;\u57fa\u4e8eJAVA\u865a\u62df\u673a(JVM)\u7684\u7f16\u7a0b\u8bed\u8a00\u8fd8\u6709\u5f88\u591a\u79cd&#xff1a;<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"340\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114045015-69672087cb7e6.png\" width=\"720\" \/><\/p>\n<p>\u57fa\u4e8eJAVA\u751f\u6001\u5efa\u7acb\u7684\u4ea7\u54c1\u5c06\u4f1a\u8d8a\u6765\u8d8a\u591a&#xff1b;\u57fa\u4e8eJAVA\u865a\u62df\u673a\u7684\u7f16\u7a0b\u8bed\u8a00\u4e5f\u5c06\u4f1a\u8d8a\u6765\u8d8a\u591a&#xff1b;\u751f\u6001\u7cfb\u7edf\u7684\u5f3a\u5927&#xff0c;\u662fJAVA\u80fd\u957f\u76db\u4e0d\u8870\u7684\u6839\u672c\u3002<\/p>\n<h3 id=\"java\u4e09\u5927\u7248\u672c\">Java\u4e09\u5927\u7248\u672c<\/h3>\n<p>JAVA\u6700\u5927\u7684\u7279\u70b9&#xff1a;<\/p>\n<p>Java\u7684\u4e3b\u8981\u4f18\u52bf\u5728\u4e8e\u5176\u505a\u51fa\u7684WORA&#xff1a;\u5373\u4e00\u6b21\u7f16\u5199&#xff08;Write Once&#xff09;\u3001\u968f\u5904\u8fd0\u884c&#xff08;Run Anywhere&#xff09;\u3002\u7b80\u5355\u6765\u8bb2&#xff0c;\u8fd9\u610f\u5473\u7740\u5f00\u53d1\u56e2\u961f\u80fd\u591f\u5229\u7528Java\u7f16\u5199\u4e00\u6b3e\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u5e76\u5c06\u5176\u7f16\u8bd1\u4e3a\u53ef\u6267\u884c\u5f62\u5f0f&#xff0c;\u800c\u540e\u5c06\u5176\u8fd0\u884c \u5728\u4efb\u4f55\u652f\u6301Java\u7684\u5e73\u53f0\u4e4b\u4e0a\u3002\u8fd9\u663e\u7136\u80fd\u591f\u6781\u5927\u63d0\u9ad8\u7f16\u7a0b\u5de5\u4f5c\u7684\u5b9e\u9645\u6548\u7387&#xff0c;\u8fd9\u79cd\u4f18\u52bf\u6765\u6e90\u4e8eJava Virtual Machine(JAVA\u865a\u62df\u673a\u7684\u7f29\u5199)&#xff0c;JVM\u662f\u4e00\u79cd\u7528\u4e8e\u8ba1\u7b97\u8bbe\u5907\u7684\u89c4\u8303&#xff0c;\u5b83\u662f\u4e00\u4e2a\u865a\u6784\u51fa\u6765\u7684\u8ba1\u7b97\u673a&#xff0c;\u662f\u901a\u8fc7\u5728 \u5b9e\u9645\u7684\u8ba1\u7b97\u673a\u4e0a\u4eff\u771f\u6a21\u62df\u5404\u79cd\u8ba1\u7b97\u673a\u529f\u80fd\u6765\u5b9e\u73b0\u7684\u3002JAVA\u8bed\u8a00\u7684\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u7279\u70b9\u5c31\u662f\u4e0e\u5e73\u53f0\u7684\u65e0\u5173 \u6027&#xff0c;\u800c\u4f7f\u7528Java\u865a\u62df\u673a\u662f\u5b9e\u73b0\u8fd9\u4e00\u7279\u70b9\u7684\u5173\u952e\u3002<\/p>\n<p>JAVA\u4e09\u5927\u7248\u672c&#xff1a;<\/p>\n<li>JAVA SE&#xff1a;\u5b83\u662fJAVA\u7684\u6807\u51c6\u7248&#xff0c;\u662f\u6574\u4e2aJAVA\u7684\u57fa\u7840\u548c\u6838\u5fc3&#xff0c;\u8fd9\u662f\u6211\u4eec\u4e3b\u8981\u5b66\u4e60\u7684\u4e00\u4e2a\u90e8\u5206&#xff0c;\u4e5f\u662f JAVAEE\u548cJAVAME\u6280\u672f\u7684\u57fa\u7840&#xff0c;\u4e3b\u8981\u7528\u4e8e\u5f00\u53d1\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002\u5b66\u4f1a\u540e\u53ef\u4ee5\u505a\u4e00\u4e9b\u7b80\u5355\u7684\u684c\u9762\u5e94\u7528 \u5982&#xff1a;\u626b\u96f7&#xff0c;\u8fde\u8fde\u770b\u7b49\u3002<\/li>\n<li>JAVA ME&#xff1a;\u5b83\u662fJAVA\u7684\u5fae\u7f29\u7248&#xff0c;\u4e3b\u8981\u5e94\u7528\u4e8e\u5d4c\u5165\u5f0f\u5f00\u53d1&#xff0c;\u6bd4\u5982\u624b\u673a\u7a0b\u5e8f\u7684\u5f00\u53d1\u3002\u76ee\u524d\u6765\u8bf4\u5c31\u4e1a\u8303\u56f4\u4e0d\u662f\u5f88\u5e7f&#xff0c;\u5728\u4e00\u4e9b\u57ce\u5e02\u53ef\u80fd\u76f8\u5bf9\u7684\u4e0d\u597d\u627e\u5de5\u4f5c\u3002<\/li>\n<li>JAVA EE&#xff1a;\u4e5f\u53ebJAVA\u7684\u4f01\u4e1a\u7248&#xff0c;\u5b83\u63d0\u4f9b\u4e86\u4f01\u4e1a\u7ea7\u5e94\u7528\u5f00\u53d1\u7684\u5b8c\u6574\u89e3\u51b3\u65b9\u6848&#xff0c;\u6bd4\u5982\u5f00\u53d1\u7f51\u7ad9&#xff0c;\u8fd8\u6709\u4f01\u4e1a\u7684\u4e00\u4e9b\u5e94\u7528\u7cfb\u7edf&#xff0c;\u662fJAVA\u6280\u672f\u5e94\u7528\u6700\u5e7f\u6cdb\u7684\u9886\u57df\u3002\u4e3b\u8981\u8fd8\u662f\u504f\u5411\u4e8eWEB\u7684\u5f00\u53d1&#xff0c;\u800cJAVA EE\u7684\u57fa\u7840\u5c31\u662fJAVA SE&#xff0c;\u6240\u4ee5\u6211\u4eec\u5728\u5b66\u4e60JAVA SE\u7684\u65f6\u5019&#xff0c;\u57fa\u7840\u4e00\u5b9a\u8981\u6253\u597d&#xff0c;\u56e0\u4e3a\u8fd9\u662f\u6700\u57fa\u672c\u7684&#xff0c;\u4e5f\u662f\u6700\u6838 \u5fc3\u7684\u3002<\/li>\n<h3 id=\"jdk-\u548c-jre\">JDK \u548c JRE<\/h3>\n<p>JDK<\/p>\n<p>Java 2 SDK (Development Kit)\u5305\u542b&#xff1a;JRE\u7684\u8d85\u96c6&#xff0c;\u5305\u542b\u7f16\u8bd1\u5668\u548c\u8c03\u8bd5\u5668\u7b49\u7528\u4e8e\u7a0b\u5e8f\u5f00\u53d1\u7684\u6587\u4ef6<\/p>\n<p>JRE<\/p>\n<p>Java Runtime Environment (JRE) \u5305\u542b&#xff1a;Java\u865a\u62df\u673a\u3001\u5e93\u51fd\u6570\u3001\u8fd0\u884cJava\u5e94\u7528\u7a0b\u5e8f\u548cApplet\u6240\u5fc5\u987b\u6587\u4ef6<\/p>\n<p>Java\u8fd0\u884c\u73af\u5883\u7684\u4e09\u9879\u4e3b\u8981\u529f\u80fd&#xff1a;<\/p>\n<ul>\n<li>\u52a0\u8f7d\u4ee3\u7801&#xff1a;\u7531class loader \u5b8c\u6210&#xff1b;<\/li>\n<li>\u6821\u9a8c\u4ee3\u7801&#xff1a;\u7531bytecode verifier \u5b8c\u6210&#xff1b;<\/li>\n<li>\u6267\u884c\u4ee3\u7801&#xff1a;\u7531 runtime interpreter\u5b8c\u6210\u3002<\/li>\n<\/ul>\n<p>\u533a\u522b\u548c\u8054\u7cfb&#xff1a;<\/p>\n<p>sdk&#xff08;\u4e5f\u5c31\u662fjdk&#xff09;\u662fjre\u7684\u8d85\u96c6&#xff0c;\u662f\u5728jre\u7684\u57fa\u7840\u4e0a\u589e\u52a0\u4e86\u7f16\u8bd1\u5668\u53ca\u5176\u4ed6\u4e00\u4e9b\u5f00\u53d1\u5de5\u5177\u3002<\/p>\n<p>jre\u5c31\u662fjava\u8fd0\u884c\u65f6\u73af\u5883&#xff0c;\u5305\u62ec\u4e86jvm\u548c\u5176\u5b83\u4e00\u4e9bjava\u6838\u5fc3api,\u4efb\u4f55\u4e00\u53f0\u7535\u8111&#xff0c;\u53ea\u6709\u5b89\u88c5\u4e86jre\u624d\u53ef\u4ee5\u884c java\u7a0b\u5e8f.<\/p>\n<p>\u5982\u679c\u53ea\u662f\u8981\u8fd0\u884cJAVA\u7a0b\u5e8f&#xff0c;\u4e4b\u9700\u8981JRE\u5c31\u53ef\u4ee5\u3002 JRE\u901a\u5e38\u975e\u5e38\u5c0f&#xff0c;\u4e5f\u5305\u542b\u4e86JVM.<\/p>\n<p>\u5982\u679c\u8981\u5f00\u53d1JAVA\u7a0b\u5e8f&#xff0c;\u5c31\u9700\u8981\u5b89\u88c5JDK\u3002<\/p>\n<h3 id=\"\u521d\u8bc6jvm\">\u521d\u8bc6JVM<\/h3>\n<p>JVM&#xff08;JAVA Virtual Machine&#xff09;<\/p>\n<p>JVM\u662f\u4e00\u79cd\u89c4\u8303&#xff0c;\u53ef\u4ee5\u4f7f\u7528\u8f6f\u4ef6\u6765\u5b9e\u73b0&#xff0c;\u4e5f\u53ef\u4ee5\u4f7f\u7528\u786c\u4ef6\u6765\u5b9e\u73b0&#xff0c;\u5c31\u662f\u4e00\u4e2a\u865a\u62df\u7684\u7528\u4e8e\u6267byte-codes \u5b57\u8282\u7801\u7684\u8ba1\u7b97\u673a\u3002\u4ed6\u4e5f\u5b9a\u4e49\u4e86\u6307\u4ee4\u96c6\u3001\u5bc4\u5b58\u5668\u96c6\u3001\u7ed3\u6784\u6808\u3001\u5783\u573e\u6536\u96c6\u5806\u3001\u5185\u5b58\u533a\u57df\u3002<\/p>\n<p>JVM\u8d1f\u8d23\u5c06java\u5b57\u8282\u7801\u89e3\u91ca\u8fd0\u884c&#xff0c;\u8fb9\u89e3\u91ca\u8fb9\u8fd0\u884c&#xff0c;\u8fd9\u6837&#xff0c;\u901f\u5ea6\u5c31\u4f1a\u53d7\u5230\u4e00\u5b9a\u7684\u5f71\u54cd\u3002JAVA\u63d0\u4f9b\u4e86\u53e6\u4e00\u79cd \u89e3\u91ca\u8fd0\u884c\u7684\u65b9\u6cd5JIT&#xff08;just in time&#xff09;&#xff0c;\u53ef\u4ee5\u4e00\u6b21\u89e3\u91ca\u5b8c&#xff0c;\u518d\u8fd0\u884c\u7279\u5b9a\u5e73\u53f0\u4e0a\u7684\u673a\u5668\u7801&#xff0c;\u9ad8\u7ea7\u7684JIT\u53ef\u4ee5\u53ea\u80fd \u5206\u6790\u70ed\u70b9\u4ee3\u7801&#xff0c;\u5e76\u5c06\u8fd9\u4e9b\u4ee3\u7801\u8f6c\u6210\u672c\u5730\u673a\u5668\u7801&#xff0c;\u5e76\u5c06\u7ed3\u679c\u7f13\u5b58\u8d77\u6765&#xff0c;\u4e0b\u6b21\u76f4\u63a5\u4ece\u5185\u5b58\u4e2d\u8c03\u7528&#xff0c;\u8fd9\u6837\u5c31\u5927 \u5927\u63d0\u9ad8\u4e86\u6267\u884cJAVA\u4ee3\u7801\u7684\u6548\u7387\u3002\u8fd9\u6837\u5c31\u5b9e\u73b0\u4e86\u8de8\u5e73\u53f0\u3001\u53ef\u79fb\u690d\u7684\u529f\u80fd\u3002<\/p>\n<li>\n<p>JVM\u662f\u6307\u5728\u4e00\u53f0\u8ba1\u7b97\u673a\u4e0a\u7531\u8f6f\u4ef6\u6216\u786c\u4ef6\u6a21\u62df\u7684\u8ba1\u7b97\u673a&#xff1b;\u5b83\u7c7b\u4f3c\u4e00\u4e2a\u5c0f\u5de7\u800c\u9ad8\u6548\u7684CPU\u3002<\/p>\n<\/li>\n<li>\n<p>byte-code\u4ee3\u7801\u662f\u4e0e\u5e73\u53f0\u65e0\u5173\u7684\u662f\u865a\u62df\u673a\u7684\u673a\u5668\u6307\u4ee4\u3002<\/p>\n<\/li>\n<li>\n<p>java\u5b57\u8282\u4ee3\u7801\u8fd0\u884c\u7684\u4e24\u79cd\u65b9\u5f0f:<\/p>\n<ul>\n<li>\n<p>interpreter(\u89e3\u91ca)<\/p>\n<p>\u8fd0\u884c\u671f\u89e3\u91ca\u5b57\u8282\u7801\u5e76\u6267\u884c<\/p>\n<\/li>\n<li>\n<p>Just-in-time(\u5373\u65f6\u7f16\u8bd1)<\/p>\n<p>\u7531\u4ee3\u7801\u751f\u6210\u5668\u5c06\u5b57\u8282\u4ee3\u7801\u8f6c\u6362\u6210\u672c\u673a\u7684\u673a\u5668\u4ee3\u7801,\u7136\u540e\u53ef\u4ee5\u4ee5\u8f83\u9ad8\u901f\u5ea6\u6267\u884c\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"504\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114045015-69672087de8bb.png\" width=\"905\" \/><\/p>\n<p>JAVA\u7684\u8de8\u5e73\u53f0\u5b9e\u73b0\u7684\u6838\u5fc3\u662f\u4e0d\u540c\u5e73\u53f0\u4f7f\u7528\u4e0d\u540c\u7684\u865a\u62df\u673a<\/p>\n<p>\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u6709\u4e0d\u540c\u7684\u865a\u62df\u673a\u3002Java \u865a\u62df\u673a\u673a\u5236\u5c4f\u853d\u4e86\u5e95\u5c42\u8fd0\u884c\u5e73\u53f0\u7684\u5dee\u522b&#xff0c;\u5b9e\u73b0\u4e86\u201c\u4e00\u6b21\u7f16\u8bd1&#xff0c;\u968f\u5904\u8fd0\u884c\u201d\u3002<\/p>\n<h3 id=\"java\u7a0b\u5e8f\u8fd0\u884c\u673a\u5236\">JAVA\u7a0b\u5e8f\u8fd0\u884c\u673a\u5236<\/h3>\n<p>\u8bf4\u5230Java\u7684\u8fd0\u884c\u673a\u5236&#xff0c;\u4e0d\u5f97\u4e0d\u63d0\u4e00\u4e0b\u4ec0\u4e48\u662f\u7f16\u8bd1\u578b\u8bed\u8a00&#xff0c;\u4ec0\u4e48\u662f\u89e3\u91ca\u578b\u8bed\u8a00\u3002<\/p>\n<h4 id=\"\u7f16\u8bd1\u578b\u8bed\u8a00\">\u7f16\u8bd1\u578b\u8bed\u8a00<\/h4>\n<p>\u7f16\u8bd1\u578b\u8bed\u8a00\u662f\u5148\u5c06\u6e90\u4ee3\u7801\u7f16\u8bd1\u6210\u673a\u5668\u8bed\u8a00&#xff08;\u673a\u5668\u53ef\u4ee5\u8bfb\u61c2\u7684\u8bed\u8a00&#xff09;&#xff0c;\u518d\u7531\u673a\u5668\u8fd0\u884c\u673a\u5668\u7801&#xff0c;\u8fd9\u6837\u6267\u884c\u7a0b\u5e8f\u7684\u6548\u7387\u6bd4\u8f83\u9ad8\u3002\u50cfC\u548cC&#043;&#043;\u5c31\u662f\u5178\u578b\u7684\u7f16\u8bd1\u578b\u8bed\u8a00\u3002<\/p>\n<h4 id=\"\u89e3\u91ca\u578b\u8bed\u8a00\">\u89e3\u91ca\u578b\u8bed\u8a00<\/h4>\n<p>\u5176\u5b9e\u89e3\u91ca\u578b\u8bed\u8a00\u662f\u76f8\u5bf9\u7f16\u8bd1\u578b\u8bed\u8a00\u5b58\u5728\u7684&#xff0c;\u89e3\u91ca\u578b\u8bed\u8a00\u662f\u5728\u8fd0\u884c\u7684\u65f6\u5019\u624d\u8fdb\u884c\u7f16\u8bd1&#xff0c;\u6bcf\u6b21\u8fd0\u884c\u90fd\u9700\u8981\u7f16\u8bd1&#xff0c;\u8fd9\u6837\u6548\u7387\u6bd4\u8f83\u4f4e\u3002\u50cfJavaScript&#xff0c;Python\u5c31\u662f\u5178\u578b\u7684\u89e3\u91ca\u578b\u8bed\u8a00<\/p>\n<h4 id=\"\u4e8c\u8005\u7684\u533a\u522b\">\u4e8c\u8005\u7684\u533a\u522b<\/h4>\n<p>\u7b80\u5355\u7684\u4e3e\u4e2a\u4f8b\u5b50&#xff1a;\u540c\u6837\u4e00\u672c\u82f1\u6587\u4e66&#xff0c;\u627e\u4eba\u7ffb\u8bd1\u6210\u4e2d\u6587\u7248\u7684\u4e66\u7136\u540e\u62ff\u7ed9\u4f60\u770b\u5c31\u662f\u7f16\u8bd1&#xff0c;\u627e\u4e00\u4e2a\u7ffb\u8bd1\u5458\u5728\u4f60\u65c1\u8fb9\u7ed9\u4f60\u89e3\u8bfb\u4e66\u7684\u542b\u4e49\u5c31\u662f\u89e3\u91ca\u3002\u4e24\u8005\u5404\u6709\u5229\u5f0a&#xff0c;\u7f16\u8bd1\u578b\u8bed\u8a00\u6267\u884c\u6548\u7387\u9ad8&#xff0c;\u7ffb\u8bd1\u4e00\u6b21\u53ef\u4ee5\u591a\u6b21\u8fd0\u884c\u3002\u89e3\u91ca\u6027\u8bed\u8a00\u6267\u884c\u6548\u7387\u4f4e&#xff0c;\u6bcf\u6b21\u8fd0\u884c\u90fd\u9700\u8981\u91cd\u65b0\u7ffb\u8bd1\u3002\u4f46\u662f\u89e3\u91ca\u578b\u7684\u8de8\u5e73\u53f0\u6027\u76f8\u5bf9\u8981\u597d&#xff0c;\u6bd4\u5982\u89e3\u91ca\u7ed9\u4e00\u4e2a\u61c2\u4e2d\u6587\u548c\u89e3\u91ca\u7ed9\u4e00\u4e2a\u61c2\u65e5\u6587\u7684\u4eba\u5c31\u53eb\u505a\u517c\u5bb9\u6027\u3002<\/p>\n<h4 id=\"java\u7684\u8fd0\u884c\u673a\u5236\">Java\u7684\u8fd0\u884c\u673a\u5236<\/h4>\n<p>Java\u5c5e\u4e8e\u4e24\u8005\u90fd\u6709&#xff0c;\u65e2\u6709\u7f16\u8bd1\u8fc7\u7a0b&#xff0c;\u53c8\u662f\u89e3\u91ca\u578b\u8bed\u8a00<\/p>\n<p>Java\u8bed\u8a00\u867d\u7136\u6bd4\u8f83\u63a5\u8fd1\u89e3\u91ca\u578b\u8bed\u8a00\u7684\u7279\u5f81&#xff0c;\u4f46\u5728\u6267\u884c\u4e4b\u524d\u5df2\u7ecf\u9884\u5148\u8fdb\u884c\u4e00\u6b21\u9884\u7f16\u8bd1&#xff0c;\u751f\u6210\u7684\u4ee3\u7801\u662f\u4ecb \u4e8e\u673a\u5668\u7801\u548cJava\u6e90\u4ee3\u7801\u4e4b\u95f4\u7684\u4e2d\u4ecb\u4ee3\u7801&#xff0c;\u8fd0\u884c\u7684\u65f6\u5019\u5219\u7531JVM&#xff08;Java\u7684\u865a\u62df\u673a\u5e73\u53f0&#xff0c;\u53ef\u89c6\u4e3a\u89e3\u91ca\u5668&#xff09;\u89e3 \u91ca\u6267\u884c\u3002\u5b83\u65e2\u4fdd\u7559\u4e86\u6e90\u4ee3\u7801\u7684\u9ad8\u62bd\u8c61\u3001\u53ef\u79fb\u690d\u7684\u7279\u70b9&#xff0c;\u53c8\u5df2\u7ecf\u5b8c\u6210\u4e86\u5bf9\u6e90\u4ee3\u7801\u7684\u5927\u90e8\u5206\u9884\u7f16\u8bd1\u5de5\u4f5c&#xff0c;\u6240\u4ee5 \u6267\u884c\u8d77\u6765\u6bd4\u201c\u7eaf\u89e3\u91ca\u578b\u201d\u7a0b\u5e8f\u8981\u5feb\u8bb8\u591a\u3002<\/p>\n<p>\u603b\u4e4b&#xff0c;\u968f\u7740\u8bbe\u8ba1\u6280\u672f\u4e0e\u786c\u4ef6\u7684\u4e0d\u65ad\u53d1\u5c55&#xff0c;\u7f16\u8bd1\u578b\u4e0e\u89e3\u91ca\u578b\u4e24\u79cd\u65b9\u5f0f\u7684\u754c\u9650\u6b63\u5728\u4e0d\u65ad\u53d8\u5f97\u6a21\u7cca\u3002<\/p>\n<p>TIP<\/p>\n<p>\u5229\u7528\u7f16\u8bd1\u5668&#xff08;javac&#xff09;\u5c06\u6e90\u7a0b\u5e8f\u7f16\u8bd1\u6210\u5b57\u8282\u7801\u00e0 \u5b57\u8282\u7801\u6587\u4ef6\u540d&#xff1a;\u6e90\u6587\u4ef6\u540d.class<\/p>\n<p>\u7b2c\u4e8c\u90e8&#xff1a;\u8fd0\u884c<\/p>\n<p>\u5229\u7528\u865a\u62df\u673a&#xff08;\u89e3\u91ca\u5668&#xff0c;java&#xff09;\u89e3\u91ca\u6267\u884cclass\u5b57\u8282\u7801\u6587\u4ef6\u3002<\/p>\n<h3 id=\"hello-world\">Hello World<\/h3>\n<p>\u9700\u8981\u5148\u914d\u7f6e\u597d\u5f00\u53d1\u73af\u5883<\/p>\n<p>\u53c2\u8003\u94fe\u63a5&#xff1a;https:\/\/www.runoob.com\/java\/java-environment-setup.html<\/p>\n<p>\u6d4b\u8bd5\u4ee3\u7801\u4e00\u5b9a\u8981\u5199HelloWorld&#xff01;\u4ee3\u8868\u4f60\u5411\u8fd9\u4e2a\u4e16\u754c\u7684\u5450\u558a&#xff0c;\u4eea\u5f0f\u611f\u5f88\u91cd\u8981&#xff0c;\u5c31\u50cf\u4f60\u751f\u6d3b \u4e2d\u548c\u5bb6\u4eba&#xff0c;\u670b\u53cb&#xff0c;\u59bb\u5b50\u5728\u8282\u65e5\u4e2d\u6216\u8005\u7eaa\u5ff5\u65e5\u4e00\u5b9a\u8981\u505a\u4e00\u4e9b\u4e8b\u60c5&#xff0c;\u8fd9\u5c31\u662f\u4eea\u5f0f\u611f\u3002<\/p>\n<li>\n<p>\u65b0\u5efa\u6587\u4ef6 Hello.java<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199\u6211\u4eec\u7684HelloWorld\u7a0b\u5e8f&#xff01;<\/p>\n<p> public class Hello{<br \/>\n    public static void main(String[] args){<br \/>\n        System.out.println(&#034;Hello,World!&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<\/li>\n<li>\n<p>\u4fdd\u5b58\u6587\u4ef6&#xff0c;cmd\u6253\u5f00\u547d\u4ee4\u884c&#xff0c;\u5229\u7528javac\u7f16\u8bd1&#xff01;<\/p>\n<p> javac Hello.java<br \/>\n# \u5982\u679c\u6ca1\u6709\u62a5\u9519&#xff0c;\u67e5\u770b\u6587\u4ef6\u5939\u4e0b\u662f\u5426\u6709\u65b0\u7684\u4e00\u4e2a\u6587\u4ef6<br \/>\n# Hello.class<br \/>\n# \u5982\u679c\u6ca1\u6709\u51fa\u73b0&#xff0c;\u606d\u559c&#xff01;\u8bf4\u660e\u4f60\u9047\u5230\u4e86\u4f60\u5728\u5b66Java\u5f53\u4e2d\u7684\u7b2c\u4e00\u4e2aBug <\/p>\n<\/li>\n<li>\n<p>java \u6267\u884c&#xff01;<\/p>\n<p> java Hello<br \/>\n# \u6210\u529f\u8f93\u51faHello&#xff0c;World&#xff01; <\/p>\n<\/li>\n<p>\u5982\u679c\u51fa\u73b0\u9519\u8bef&#xff0c;\u68c0\u67e5\u5b57\u6bcd\u5927\u5c0f\u5199\u662f\u5426\u6709\u9519\u8bef&#xff0c;\u6216\u8005\u662f\u5426\u6807\u70b9\u7b26\u53f7\u9519\u8bef&#xff0c;\u6587\u4ef6\u540d\u9519\u8bef\u7b49\u7b49&#xff0c;\u4e00\u5b9a\u8981\u786e\u4fdd\u6210\u529f\u8f93\u51fa<\/p>\n<p>\u7f16\u5199 Java \u7a0b\u5e8f\u65f6&#xff0c;\u5e94\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5927\u5c0f\u5199\u654f\u611f<\/p>\n<p>Java \u662f\u5927\u5c0f\u5199\u654f\u611f\u7684&#xff0c;\u8fd9\u5c31\u610f\u5473\u7740\u6807\u8bc6\u7b26 Hello \u4e0e hello \u662f\u4e0d\u540c\u7684\u3002<\/p>\n<\/li>\n<li>\n<p>\u7c7b\u540d<\/p>\n<p>\u5bf9\u4e8e\u6240\u6709\u7684\u7c7b\u6765\u8bf4&#xff0c;\u7c7b\u540d\u7684\u9996\u5b57\u6bcd\u5e94\u8be5\u5927\u5199\u3002\u5982\u679c\u7c7b\u540d\u7531\u82e5\u5e72\u5355\u8bcd\u7ec4\u6210&#xff0c;\u90a3\u4e48\u6bcf\u4e2a\u5355\u8bcd\u7684\u9996\u5b57\u6bcd\u5e94\u8be5\u5927\u5199&#xff0c;\u4f8b\u5982 MyFirstJavaClass \u3002<\/p>\n<\/li>\n<li>\n<p>\u65b9\u6cd5\u540d<\/p>\n<p>\u6240\u6709\u7684\u65b9\u6cd5\u540d\u90fd\u5e94\u8be5\u4ee5\u5c0f\u5199\u5b57\u6bcd\u5f00\u5934\u3002\u5982\u679c\u65b9\u6cd5\u540d\u542b\u6709\u82e5\u5e72\u5355\u8bcd&#xff0c;\u5219\u540e\u9762\u7684\u6bcf\u4e2a\u5355\u8bcd\u9996\u5b57 \u6bcd\u5927\u5199\u3002<\/p>\n<\/li>\n<li>\n<p>\u6e90\u6587\u4ef6\u540d<\/p>\n<p>\u6e90\u6587\u4ef6\u540d\u5fc5\u987b\u548c\u7c7b\u540d\u76f8\u540c\u3002\u5f53\u4fdd\u5b58\u6587\u4ef6\u7684\u65f6\u5019&#xff0c;\u4f60\u5e94\u8be5\u4f7f\u7528\u7c7b\u540d\u4f5c\u4e3a\u6587\u4ef6\u540d\u4fdd\u5b58&#xff08;\u5207\u8bb0 Java \u662f\u5927\u5c0f\u5199\u654f\u611f\u7684&#xff09;&#xff0c;\u6587\u4ef6\u540d\u7684\u540e\u7f00\u4e3a .java\u3002&#xff08;\u5982\u679c\u6587\u4ef6\u540d\u548c\u7c7b\u540d\u4e0d\u76f8\u540c\u5219\u4f1a\u5bfc\u81f4\u7f16\u8bd1\u9519\u8bef&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e3b\u65b9\u6cd5\u5165\u53e3<\/p>\n<p>\u6240\u6709\u7684 Java \u7a0b\u5e8f\u7531\u00a0public static void main(String []args)\u00a0\u65b9\u6cd5\u5f00\u59cb\u6267\u884c\u3002<\/p>\n<\/li>\n<\/ul>\n<h2>\u4e8c\u3001\u6ce8\u91ca \u00a0<\/h2>\n<p>\u5e73\u65f6\u6211\u4eec\u7f16\u5199\u4ee3\u7801&#xff0c;\u5728\u4ee3\u7801\u91cf\u6bd4\u8f83\u5c11\u7684\u65f6\u5019&#xff0c;\u6211\u4eec\u8fd8\u53ef\u4ee5\u770b\u61c2\u81ea\u5df1\u5199\u7684&#xff0c;\u4f46\u662f\u5f53\u9879\u76ee\u7ed3\u6784\u4e00\u65e6\u590d\u6742\u8d77\u6765&#xff0c;\u6211\u4eec\u5c31\u9700\u8981\u7528\u5230\u4e00\u4e2a\u6ce8\u91ca\u4e86&#xff0c;\u6ce8\u91ca\u5c31\u7c7b\u4f3c\u4e8e\u6211\u4eec\u4e0a\u5b66\u65f6\u5019\u5199\u7684\u7b14\u8bb0&#xff0c;\u6211\u4eec\u770b\u7740\u7b14\u8bb0\u5c31\u77e5\u9053\u81ea\u5df1\u5199\u7684 \u4ec0\u4e48\u4e1c\u897f\u4e86&#xff01;\u5728\u7a0b\u5e8f\u4e2d\u4e5f\u662f\u5982\u6b64\u3002\u6211\u4eec\u6765\u770b\u4e00\u4e0bJava\u4e2d\u7684\u6ce8\u91ca\u600e\u4e48\u5199&#xff0c;\u770b\u4ee5\u4e0b\u4ee3\u7801&#xff1a;<\/p>\n<\/p>\n<p>\/*<br \/>\n* &#064;Description HelloWorld\u7c7b<br \/>\n**\/<br \/>\npublic class HelloWorld {<br \/>\n    \/*<br \/>\n    \u8fd9\u662f\u6211\u4eecJava\u7a0b\u5e8f\u7684\u4e3b\u5165\u53e3&#xff0c;<br \/>\n    main\u65b9\u6cd5\u4e5f\u662f\u7a0b\u5e8f\u7684\u4e3b\u7ebf\u7a0b\u3002<br \/>\n    *\/<br \/>\n    public static void main(String[] args) {<br \/>\n        \/\/\u8f93\u51faHelloWorld&#xff01;<br \/>\n        System.out.println(&#034;Hello,World!&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u6ce8\u91ca\u5e76\u4e0d\u4f1a\u88ab\u6267\u884c&#xff0c;\u662f\u7ed9\u6211\u4eec\u5199\u4ee3\u7801\u7684\u4eba\u770b\u7684&#xff0c;\u4e66\u5199\u6ce8\u91ca\u662f\u4e00\u4e2a\u975e\u5e38\u597d\u7684\u4e60\u60ef\u3002<\/p>\n<p>Java\u4e2d\u7684\u6ce8\u91ca\u6709\u4e09\u79cd&#xff1a;<\/p>\n<p>\u5355\u884c\u6ce8\u91ca&#xff1a;\u53ea\u80fd\u6ce8\u91ca\u5f53\u524d\u884c&#xff0c;\u4ee5\/\/\u5f00\u59cb&#xff0c;\u76f4\u5230\u884c\u7ed3\u675f<\/p>\n<\/p>\n<p>\/\/\u8f93\u51faHelloWorld&#xff01; <\/p>\n<p>\u591a\u884c\u6ce8\u91ca&#xff1a;\u6ce8\u91ca\u4e00\u6bb5\u6587\u5b57&#xff0c;\u4ee5\/*\u5f00\u59cb&#xff0c; *\/\u7ed3\u675f&#xff01;<\/p>\n<\/p>\n<p>\/*<br \/>\n    \u8fd9\u662f\u6211\u4eecJava\u7a0b\u5e8f\u7684\u4e3b\u5165\u53e3&#xff0c;<br \/>\n    main\u65b9\u6cd5\u4e5f\u662f\u7a0b\u5e8f\u7684\u4e3b\u7ebf\u7a0b\u3002<br \/>\n*\/ <\/p>\n<p>\u6587\u6863\u6ce8\u91ca&#xff1a;\u7528\u4e8e\u751f\u4ea7API\u6587\u6863&#xff0c;\u914d\u5408JavaDoc\u3002<\/p>\n<\/p>\n<p>\/*<br \/>\n* &#064;Description HelloWorld\u7c7b<br \/>\n* &#064;Author Diamond \u72c2\u795e<br \/>\n**\/ <\/p>\n<h2>\u4e09\u3001\u6807\u8bc6\u7b26 \u00a0<\/h2>\n<p>\u6bcf\u4e2a\u4eba\u4ece\u51fa\u751f\u5f00\u59cb\u5c31\u6709\u4e00\u4e2a\u540d\u5b57&#xff0c;\u548b\u4eec\u751f\u6d3b\u4e2d\u7684\u6240\u6709\u4e8b\u7269\u4e5f\u90fd\u6709\u540d\u5b57&#xff0c;\u8fd9\u540d\u5b57\u662f\u8c01\u89c4\u5b9a\u5462&#xff1f;\u56de\u7b54\u662f&#xff1a;\u9020\u7269\u4e3b&#xff0c;\u8c01\u751f\u4ea7\u51fa\u6765\u7684\u8c01\u89c4\u5b9a\u540d\u5b57&#xff0c;\u5728\u6211\u4eec\u7684\u7a0b\u5e8f\u4e2d\u4e5f\u4e0d\u4f8b\u5916\u3002<\/p>\n<p>\u6211\u4eec\u4f5c\u4e3a\u9020\u7269\u4e3b&#xff0c;\u9700\u8981\u7ed9\u6240\u6709\u7684\u4e1c\u897f\u7ed9\u4e0a\u4e00\u4e2a\u540d\u5b57&#xff0c;\u6bd4\u5982\u6211\u4eec\u7684HelloWorld\u7a0b\u5e8f&#xff1a;<\/p>\n<p>HelloWorld\u662f\u7c7b\u540d&#xff0c;\u4e5f\u662f\u6211\u4eec\u7684\u6587\u4ef6\u540d\u3002\u5b83\u524d\u9762\u7684 public class\u662f\u5173\u952e\u5b57&#xff0c;\u4e0d\u8fc7\u662f\u641eJava\u90a3\u7fa4\u4eba\u5df2\u7ecf\u5b9a \u4e49\u597d\u7684\u6709\u7279\u6b8a\u4f5c\u7528\u7684&#xff0c;\u4e0b\u9762\u7684\u6bcf\u4e00\u4e2a\u4ee3\u7801\u90fd\u6709\u81ea\u5df1\u7684\u610f\u601d\u548c\u540d\u5b57\u5bf9\u5427&#xff0c;\u5c31\u662f\u7528\u6765\u4f5c\u533a\u5206&#xff01;\u548c\u6211\u4eec\u7684\u540d\u5b57 \u4e00\u6837&#xff0c;\u62ff\u6765\u88ab\u53eb\u6216\u8005\u79f0\u547c\u7684&#xff0c;\u7a0b\u5e8f\u4e00\u5207\u90fd\u6e90\u81ea\u4e8e\u751f\u6d3b&#xff0c;\u4e00\u5b9a\u8981\u628a\u5b66\u7a0b\u5e8f\u548c\u751f\u6d3b\u4e2d\u7684\u4e00\u5207\u8054\u7cfb\u8d77\u6765&#xff0c;\u4f60\u4f1a\u53d1\u73b0\u8fd9\u4e00\u5207\u90fd\u662f\u606f\u606f\u76f8\u5173\u7684\u3002<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"helloword\" height=\"157\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114045016-6967208817320.png\" width=\"508\" \/><\/p>\n<p>\u6211\u4eec\u6765\u770b\u770b\u6709\u54ea\u4e9b\u662fJava\u81ea\u5df1\u5b9a\u4e49\u597d\u7684\u5173\u952e\u5b57\u5462&#xff1f;<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\u5173\u952e\u8bcd\" height=\"354\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114045016-6967208825792.png\" width=\"537\" \/><\/p>\n<p>\u6211\u4eec\u81ea\u5df1\u8d77\u540d\u5b57\u6709\u54ea\u4e9b\u8981\u6c42\u5462&#xff1f;<\/p>\n<p>\u8868\u793a\u7c7b\u540d\u7684\u6807\u8bc6\u7b26\u7528\u5927\u5199\u5b57\u6bcd\u5f00\u59cb\u3002<\/p>\n<p>\u5982&#xff1a;Man&#xff0c;GoodMan<\/p>\n<p>\u8868\u793a\u65b9\u6cd5\u548c\u53d8\u91cf\u7684\u6807\u8bc6\u7b26\u7528\u5c0f\u5199\u5b57\u6bcd\u5f00\u59cb&#xff0c;\u540e\u9762\u7684\u63cf\u8ff0\u6027\u8bcd\u4ee5\u5927\u5199\u5f00\u59cb\u3002<\/p>\n<p>\u5982&#xff1a;eat(),eatFood()<\/p>\n<p>\u5177\u4f53\u53ef\u53c2\u8003\u300a\u963f\u91cc\u5df4\u5df4Java\u5f00\u53d1\u624b\u518c\u300b<\/p>\n<p>\u5173\u4e8e Java \u6807\u8bc6\u7b26&#xff0c;\u6709\u4ee5\u4e0b\u51e0\u70b9\u9700\u8981\u6ce8\u610f&#xff1a;<\/p>\n<ul>\n<li>\u6240\u6709\u7684\u6807\u8bc6\u7b26\u90fd\u5e94\u8be5\u4ee5\u5b57\u6bcd&#xff08;A-Z \u6216\u8005 a-z&#xff09;\u7f8e\u5143\u7b26&#xff08;$&#xff09;\u6216\u8005\u4e0b\u5212\u7ebf&#xff08;_&#xff09;\u5f00\u59cb<\/li>\n<li>\u9996\u5b57\u7b26\u4e4b\u540e\u53ef\u4ee5\u662f\u5b57\u6bcd&#xff08;A-Z \u6216\u8005 a-z&#xff09;\u7f8e\u5143\u7b26&#xff08;$&#xff09;\u4e0b\u5212\u7ebf&#xff08;_&#xff09;\u6216\u6570\u5b57\u7684\u4efb\u4f55\u5b57\u7b26\u7ec4\u5408<\/li>\n<li>\u4e0d\u80fd\u4f7f\u7528\u5173\u952e\u5b57\u4f5c\u4e3a\u53d8\u91cf\u540d\u6216\u65b9\u6cd5\u540d\u3002<\/li>\n<li>\u6807\u8bc6\u7b26\u662f\u5927\u5c0f\u5199\u654f\u611f\u7684<\/li>\n<li>\u5408\u6cd5\u6807\u8bc6\u7b26\u4e3e\u4f8b&#xff1a;age\u3001$salary\u3001_value\u3001__1_value<\/li>\n<li>\u975e\u6cd5\u6807\u8bc6\u7b26\u4e3e\u4f8b&#xff1a;123abc\u3001-salary\u3001#abc<\/li>\n<\/ul>\n<p>JAVA\u4e0d\u91c7\u7528\u901a\u5e38\u8bed\u8a00\u4f7f\u7528\u7684ASCII\u5b57\u7b26\u96c6&#xff0c;\u800c\u662f\u91c7\u7528unicode\u8fd9\u6837\u7684\u6807\u51c6\u7684\u56fd\u9645\u5b57\u7b26\u96c6\u3002\u56e0\u6b64&#xff0c;\u8fd9\u91cc\u7684 \u5b57\u6bcd\u7684\u542b\u4e49&#xff1a;\u53ef\u4ee5\u8868\u793a\u82f1\u6587\u3001\u6c49\u5b57\u7b49\u7b49\u3002<\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u4e2d\u6587\u547d\u540d&#xff0c;\u4f46\u662f\u4e00\u822c\u4e0d\u5efa\u8bae\u8fd9\u6837\u53bb\u4f7f\u7528&#xff0c;\u4e5f\u4e0d\u5efa\u8bae\u4f7f\u7528\u62fc\u97f3&#xff0c;\u5f88Low<\/p>\n<h2>\u56db\u3001\u6570\u636e\u7c7b\u578b \u00a0<\/h2>\n<p>Java\u662f\u4e00\u79cd\u5f3a\u7c7b\u578b\u8bed\u8a00&#xff0c;\u6bcf\u4e2a\u53d8\u91cf\u90fd\u5fc5\u987b\u58f0\u660e\u5176\u7c7b\u578b\u3002<\/p>\n<p>\u6269\u5c55&#xff1a;\u5404\u79cd\u5b57\u7b26\u96c6\u548c\u7f16\u7801\u8be6\u89e3(https:\/\/youmoxiang.blog.csdn.net\/article\/details\/156784190)<\/p>\n<h4 id=\"_1\u3001\u5f3a\u5f31\u7c7b\u578b\u8bed\u8a00\">1\u3001\u5f3a\u5f31\u7c7b\u578b\u8bed\u8a00<\/h4>\n<ul>\n<li>\n<p>\u5f3a\u7c7b\u578b\u8bed\u8a00<\/p>\n<p>\u5f3a\u7c7b\u578b\u8bed\u8a00\u662f\u4e00\u79cd\u5f3a\u5236\u7c7b\u578b\u5b9a\u4e49\u7684\u8bed\u8a00&#xff0c;\u4e00\u65e6\u67d0\u4e00\u4e2a\u53d8\u91cf\u88ab\u5b9a\u4e49\u7c7b\u578b&#xff0c;\u5982\u679c\u4e0d\u7ecf\u8fc7\u5f3a\u5236\u8f6c\u6362&#xff0c;\u5219\u5b83\u6c38\u8fdc\u5c31\u662f\u8be5\u6570\u636e\u7c7b\u578b\u4e86&#xff0c;\u5f3a\u7c7b\u578b\u8bed\u8a00\u5305\u62ecJava\u3001.net \u3001Python\u3001C&#043;&#043;\u7b49\u8bed\u8a00\u3002<\/p>\n<p>\u4e3e\u4e2a\u4f8b\u5b50&#xff1a;\u5b9a\u4e49\u4e86\u4e00\u4e2a\u6574\u6570&#xff0c;\u5982\u679c\u4e0d\u8fdb\u884c\u5f3a\u5236\u7684\u7c7b\u578b\u8f6c\u6362&#xff0c;\u5219\u4e0d\u53ef\u4ee5\u5c06\u8be5\u6574\u6570\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32\u3002<\/p>\n<\/li>\n<li>\n<p>\u5f31\u7c7b\u578b\u8bed\u8a00<\/p>\n<p>\u5f31\u7c7b\u578b\u8bed\u8a00\u662f\u4e00\u79cd\u5f31\u7c7b\u578b\u5b9a\u4e49\u7684\u8bed\u8a00&#xff0c;\u67d0\u4e00\u4e2a\u53d8\u91cf\u88ab\u5b9a\u4e49\u7c7b\u578b&#xff0c;\u8be5\u53d8\u91cf\u53ef\u4ee5\u6839\u636e\u73af\u5883\u53d8\u5316\u81ea\u52a8\u8fdb\u884c\u8f6c\u6362&#xff0c;\u4e0d\u9700\u8981\u7ecf\u8fc7\u663e\u6027\u5f3a\u5236\u8f6c\u6362\u3002\u5f31\u7c7b\u578b\u8bed\u8a00\u5305\u62ecvb \u3001PHP\u3001javascript\u7b49\u8bed\u8a00\u3002<\/p>\n<p>\u5728VB Script\u4e2d&#xff0c;\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u201812\u2019\u548c\u6574\u65703\u8fdb\u884c\u8fde\u63a5\u5f97\u5230\u5b57\u7b26\u4e32\u2018123\u2019&#xff0c;\u4e5f\u53ef\u4ee5\u628a\u5b83\u770b\u6210\u6574\u6570123&#xff0c;\u800c\u4e0d\u9700 \u8981\u663e\u793a\u8f6c\u6362\u3002\u662f\u4e0d\u662f\u5341\u5206\u7684\u968f\u4fbf&#xff0c;\u6211\u4eecJava\u5c31\u4e0d\u662f\u8fd9\u6837\u7684\u3002<\/p>\n<\/li>\n<li>\n<p>\u533a\u522b<\/p>\n<p>\u65e0\u8bba\u662f\u5f3a\u7c7b\u578b\u8bed\u8a00\u8fd8\u662f\u5f31\u7c7b\u578b\u8bed\u8a00&#xff0c;\u5224\u522b\u7684\u6839\u672c\u662f\u662f\u5426\u4f1a\u9690\u6027\u7684\u8fdb\u884c\u8bed\u8a00\u7c7b\u578b\u8f6c\u53d8\u3002\u5f3a\u7c7b\u578b\u8bed\u8a00\u5728\u901f\u5ea6\u4e0a\u7565\u900a\u4e8e\u5f31\u7c7b\u578b\u8bed\u8a00&#xff0c;\u4f46\u662f\u5f3a\u7c7b\u578b\u5b9a\u4e49\u8bed\u8a00\u5e26\u6765\u7684\u4e25\u8c28\u6027\u53c8\u80fd\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u9519\u8bef\u3002<\/p>\n<\/li>\n<\/ul>\n<h4 id=\"_2\u3001\u6570\u636e\u7c7b\u578b\">2\u3001\u6570\u636e\u7c7b\u578b<\/h4>\n<p>Java\u7684\u6570\u636e\u7c7b\u578b\u5206\u4e3a\u4e24\u5927\u7c7b&#xff1a;\u57fa\u672c\u7c7b\u578b&#xff08;primitive type&#xff09;\u548c\u5f15\u7528\u7c7b\u578b &#xff08;reference type&#xff09;<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"385\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114045016-69672088375a2.png\" width=\"1068\" \/><\/p>\n<p>\u3010\u6ce8&#xff1a;\u5f15\u7528\u6570\u636e\u7c7b\u578b\u7684\u5927\u5c0f\u7edf\u4e00\u4e3a4\u4e2a\u5b57\u8282&#xff0c;\u8bb0\u5f55\u7684\u662f\u5176\u5f15\u7528\u5bf9\u8c61\u7684\u5730\u5740&#xff01;\u3011<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"621\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114045016-6967208873097.png\" width=\"981\" \/><\/p>\n<p>\u5982\u679c\u4f60\u770b\u5230\u8fd9\u4e00\u5806\u5934\u75bc\u7684\u8bdd&#xff0c;\u6ca1\u5173\u7cfb&#xff0c;\u4e0d\u7528\u8bb0&#xff0c;JDK\u4e2d\u7c7b\u578b\u5bf9\u5e94\u7684\u5305\u88c5\u7c7b\u90fd\u5e2e\u5fd9\u5199\u597d\u4e86&#xff0c;\u6211\u4eec\u9700\u8981\u65f6\u5019\u53ef \u4ee5\u76f4\u63a5\u770b\u5230&#xff01;\u53ef\u4ee5\u628a\u4ee5\u4e0b\u4ee3\u7801\u62f7\u8d1d\u8fdb\u884c\u67e5\u770b\u7ed3\u679c&#xff1a;<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    \/\/ byte<br \/>\n    System.out.println(&#034;\u57fa\u672c\u7c7b\u578b&#xff1a;byte \u4e8c\u8fdb\u5236\u4f4d\u6570&#xff1a;&#034; &#043; Byte.SIZE);<br \/>\n    System.out.println(&#034;\u5305\u88c5\u7c7b&#xff1a;java.lang.Byte&#034;);<br \/>\n    System.out.println(&#034;\u6700\u5c0f\u503c&#xff1a;Byte.MIN_VALUE&#061;&#034; &#043; Byte.MIN_VALUE);<br \/>\n    System.out.println(&#034;\u6700\u5927\u503c&#xff1a;Byte.MAX_VALUE&#061;&#034; &#043; Byte.MAX_VALUE);<br \/>\n    System.out.println();<br \/>\n    \/\/ short<br \/>\n    System.out.println(&#034;\u57fa\u672c\u7c7b\u578b&#xff1a;short \u4e8c\u8fdb\u5236\u4f4d\u6570&#xff1a;&#034; &#043; Short.SIZE);<br \/>\n    System.out.println(&#034;\u5305\u88c5\u7c7b&#xff1a;java.lang.Short&#034;);<br \/>\n    System.out.println(&#034;\u6700\u5c0f\u503c&#xff1a;Short.MIN_VALUE&#061;&#034; &#043; Short.MIN_VALUE);<br \/>\n    System.out.println(&#034;\u6700\u5927\u503c&#xff1a;Short.MAX_VALUE&#061;&#034; &#043; Short.MAX_VALUE);<br \/>\n    System.out.println();<br \/>\n    \/\/ int<br \/>\n    System.out.println(&#034;\u57fa\u672c\u7c7b\u578b&#xff1a;int \u4e8c\u8fdb\u5236\u4f4d\u6570&#xff1a;&#034; &#043; Integer.SIZE);<br \/>\n    System.out.println(&#034;\u5305\u88c5\u7c7b&#xff1a;java.lang.Integer&#034;);<br \/>\n    System.out.println(&#034;\u6700\u5c0f\u503c&#xff1a;Integer.MIN_VALUE&#061;&#034; &#043; Integer.MIN_VALUE);<br \/>\n    System.out.println(&#034;\u6700\u5927\u503c&#xff1a;Integer.MAX_VALUE&#061;&#034; &#043; Integer.MAX_VALUE);<br \/>\n    System.out.println();<br \/>\n    \/\/ long<br \/>\n    System.out.println(&#034;\u57fa\u672c\u7c7b\u578b&#xff1a;long \u4e8c\u8fdb\u5236\u4f4d\u6570&#xff1a;&#034; &#043; Long.SIZE);<br \/>\n    System.out.println(&#034;\u5305\u88c5\u7c7b&#xff1a;java.lang.Long&#034;);<br \/>\n    System.out.println(&#034;\u6700\u5c0f\u503c&#xff1a;Long.MIN_VALUE&#061;&#034; &#043; Long.MIN_VALUE);<br \/>\n    System.out.println(&#034;\u6700\u5927\u503c&#xff1a;Long.MAX_VALUE&#061;&#034; &#043; Long.MAX_VALUE);<br \/>\n    System.out.println();<br \/>\n    \/\/ float<br \/>\n    System.out.println(&#034;\u57fa\u672c\u7c7b\u578b&#xff1a;float \u4e8c\u8fdb\u5236\u4f4d\u6570&#xff1a;&#034; &#043; Float.SIZE);<br \/>\n    System.out.println(&#034;\u5305\u88c5\u7c7b&#xff1a;java.lang.Float&#034;);<br \/>\n    System.out.println(&#034;\u6700\u5c0f\u503c&#xff1a;Float.MIN_VALUE&#061;&#034; &#043; Float.MIN_VALUE);<br \/>\n    System.out.println(&#034;\u6700\u5927\u503c&#xff1a;Float.MAX_VALUE&#061;&#034; &#043; Float.MAX_VALUE);<br \/>\n    System.out.println();<br \/>\n    \/\/ double<br \/>\n    System.out.println(&#034;\u57fa\u672c\u7c7b\u578b&#xff1a;double \u4e8c\u8fdb\u5236\u4f4d\u6570&#xff1a;&#034; &#043; Double.SIZE);<br \/>\n    System.out.println(&#034;\u5305\u88c5\u7c7b&#xff1a;java.lang.Double&#034;);<br \/>\n    System.out.println(&#034;\u6700\u5c0f\u503c&#xff1a;Double.MIN_VALUE&#061;&#034; &#043; Double.MIN_VALUE);<br \/>\n    System.out.println(&#034;\u6700\u5927\u503c&#xff1a;Double.MAX_VALUE&#061;&#034; &#043; Double.MAX_VALUE);<br \/>\n    System.out.println();<br \/>\n    \/\/ char<br \/>\n    System.out.println(&#034;\u57fa\u672c\u7c7b\u578b&#xff1a;char \u4e8c\u8fdb\u5236\u4f4d\u6570&#xff1a;&#034; &#043; Character.SIZE);<br \/>\n    System.out.println(&#034;\u5305\u88c5\u7c7b&#xff1a;java.lang.Character&#034;);<br \/>\n    \/\/ \u4ee5\u6570\u503c\u5f62\u5f0f\u800c\u4e0d\u662f\u5b57\u7b26\u5f62\u5f0f\u5c06Character.MIN_VALUE\u8f93\u51fa\u5230\u63a7\u5236\u53f0<br \/>\n    System.out.println(&#034;\u6700\u5c0f\u503c&#xff1a;Character.MIN_VALUE&#061;&#034;&#043; (int) Character.MIN_VALUE);<br \/>\n    \/\/ \u4ee5\u6570\u503c\u5f62\u5f0f\u800c\u4e0d\u662f\u5b57\u7b26\u5f62\u5f0f\u5c06Character.MAX_VALUE\u8f93\u51fa\u5230\u63a7\u5236\u53f0<br \/>\n    System.out.println(&#034;\u6700\u5927\u503c&#xff1a;Character.MAX_VALUE&#061;&#034;&#043; (int) Character.MAX_VALUE);<br \/>\n} <\/p>\n<p>\u5b57\u8282\u76f8\u5173\u77e5\u8bc6&#xff1a;<\/p>\n<p>\u4f4d&#xff08;bit&#xff09;&#xff1a;\u662f\u8ba1\u7b97\u673a \u5185\u90e8\u6570\u636e \u50a8\u5b58\u7684\u6700\u5c0f\u5355\u4f4d&#xff0c;11001100\u662f\u4e00\u4e2a\u516b\u4f4d\u4e8c\u8fdb\u5236\u6570\u3002<\/p>\n<p>\u5b57\u8282&#xff08;byte&#xff09;&#xff1a;\u662f\u8ba1\u7b97\u673a\u4e2d \u6570\u636e\u5904\u7406 \u7684\u57fa\u672c\u5355\u4f4d&#xff0c;\u4e60\u60ef\u4e0a\u7528\u5927\u5199 B \u6765\u8868\u793a\u3002<\/p>\n<p>\u200b 1B&#xff08;byte,\u5b57\u8282&#xff09;&#061; 8bit&#xff08;\u4f4d&#xff09;<\/p>\n<p>\u5b57\u7b26&#xff1a;\u662f\u6307\u8ba1\u7b97\u673a\u4e2d\u4f7f\u7528\u7684\u5b57\u6bcd\u3001\u6570\u5b57\u3001\u5b57\u548c\u7b26\u53f7<\/p>\n<p>ASCIIS\u7801&#xff1a;<\/p>\n<table>\n<tr>\u5185\u5bb9\u5360\u7528\u5927\u5c0f<\/tr>\n<tbody>\n<tr>\n<td>1\u4e2a\u82f1\u6587\u5b57\u7b26&#xff08;\u4e0d\u5206\u5927\u5c0f\u5199&#xff09;<\/td>\n<td>1\u4e2a\u5b57\u8282<\/td>\n<\/tr>\n<tr>\n<td>1\u4e2a\u4e2d\u6587\u6c49\u5b57<\/td>\n<td>2\u4e2a\u5b57\u8282<\/td>\n<\/tr>\n<tr>\n<td>1\u4e2aASCII\u7801<\/td>\n<td>1\u4e2a\u5b57\u8282<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>UTF-8\u7f16\u7801&#xff1a;<\/p>\n<table>\n<tr>\u5185\u5bb9\u5360\u7528\u5927\u5c0f<\/tr>\n<tbody>\n<tr>\n<td>1\u4e2a\u82f1\u6587\u5b57\u7b26<\/td>\n<td>1\u4e2a\u5b57\u8282<\/td>\n<\/tr>\n<tr>\n<td>\u82f1\u6587\u6807\u70b9<\/td>\n<td>1\u4e2a\u5b57\u8282<\/td>\n<\/tr>\n<tr>\n<td>1\u4e2a\u4e2d\u6587&#xff08;\u542b\u7e41\u4f53<\/td>\n<td>3\u4e2a\u5b57\u8282<\/td>\n<\/tr>\n<tr>\n<td>\u4e2d\u6587\u6807\u70b9<\/td>\n<td>3\u4e2a\u5b57\u8282<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Unicode\u7f16\u7801&#xff1a;<\/p>\n<table>\n<tr>\u5185\u5bb9\u5360\u7528\u5927\u5c0f<\/tr>\n<tbody>\n<tr>\n<td>1\u4e2a\u82f1\u6587\u5b57\u7b26<\/td>\n<td>2\u4e2a\u5b57\u8282<\/td>\n<\/tr>\n<tr>\n<td>\u82f1\u6587\u6807\u70b9<\/td>\n<td>2\u4e2a\u5b57\u8282<\/td>\n<\/tr>\n<tr>\n<td>1\u4e2a\u4e2d\u6587&#xff08;\u542b\u7e41\u4f53<\/td>\n<td>2\u4e2a\u5b57\u8282<\/td>\n<\/tr>\n<tr>\n<td>\u4e2d\u6587\u6807\u70b9<\/td>\n<td>2\u4e2a\u5b57\u8282<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>1bit\u8868\u793a1\u4f4d 1Byte\u8868\u793a\u4e00\u4e2a\u5b57\u8282<\/p>\n<p>1B&#061;8b 1024B&#061;1KB 1024KB&#061;1M 1024M&#061;1G<\/p>\n<hr \/>\n<p>\u90a3\u6709\u4eba\u4f1a\u95ee&#xff1a;\u7535\u8111\u768432\u4f4d\u548c64\u4f4d\u7684\u533a\u522b\u662f\u4ec0\u4e48\u5462&#xff1f;<\/p>\n<ul>\n<li>\n<p>32\u4f4d\u64cd\u4f5c\u7cfb\u7edf\u53ea\u53ef\u4ee5\u4f7f\u752832\u4f4d\u7684cpu&#xff0c;\u800c64\u4f4d\u7684CPU\u65e2\u53ef\u4ee5\u5b89\u88c532\u4f4d\u64cd\u4f5c\u7cfb\u7edf\u4e5f\u53ef\u4ee5\u5b89\u88c564\u4f4d\u64cd\u4f5c \u7cfb\u7edf\u3002<\/p>\n<\/li>\n<li>\n<p>\u5bfb\u5740\u80fd\u529b\u7b80\u5355\u70b9\u8bf4\u5c31\u662f\u652f\u6301\u7684\u5185\u5b58\u5927\u5c0f\u80fd\u529b&#xff0c;64\u4f4d\u7cfb\u7edf\u6700\u591a\u53ef\u4ee5\u652f\u8fbe128 GB\u7684\u5185\u5b58&#xff0c;\u800c32\u4f4d\u7cfb\u7edf\u6700 \u591a\u53ea\u53ef\u4ee5\u652f\u63014G\u5185\u5b58\u3002<\/p>\n<\/li>\n<li>\n<p>32\u4f4d\u64cd\u4f5c\u7cfb\u7edf\u53ea\u53ef\u4ee5\u5b89\u88c5\u4f7f\u752832\u4f4d\u67b6\u6784\u8bbe\u8ba1\u7684\u8f6f\u4ef6&#xff0c;\u800c64\u4f4d\u7684CPU\u65e2\u53ef\u4ee5\u5b89\u88c5\u4f7f\u752832\u4f4d\u8f6f\u4ef6\u4e5f\u53ef\u4ee5 \u5b89\u88c5\u4f7f\u752864\u4f4d\u8f6f\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p>\u73b0\u5728\u7684\u7535\u8111\u90fd\u662f64\u4f4d\u4e86&#xff01;<\/p>\n<\/li>\n<\/ul>\n<p>\u56de\u5230\u6b63\u9898&#xff0c;\u6211\u4eec\u4e86\u89e3\u4e86\u8fd9\u4e9b\u77e5\u8bc6\u540e&#xff0c;\u6211\u4eec\u81ea\u5df1\u5b9a\u4e49\u4e00\u4e9b\u53d8\u91cf\u6765\u770b&#xff01;<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    \/\/\u6574\u578b<br \/>\n    int i1&#061;100;<br \/>\n    \/\/\u957f\u6574\u578b<br \/>\n    long i2&#061;998877665544332211L;<br \/>\n    \/\/\u77ed\u6574\u578b<br \/>\n    short i3&#061;235;<br \/>\n    \/\/\u6d6e\u70b9\u578b<br \/>\n    double d1&#061;3.5; \/\/\u53cc\u7cbe\u5ea6<br \/>\n    double d2&#061;3;<br \/>\n    float f1&#061;(float)3.5; \/\/\u5355\u7cbe\u5ea6<br \/>\n    float f2&#061;3.5f; \/\/\u5355\u7cbe\u5ea6<br \/>\n    \/\/\u5e03\u5c14\u7c7b\u578b boolean true\u771f\/false\u5047<br \/>\n    boolean isPass&#061;true;<br \/>\n    boolean isOk&#061;false;<br \/>\n    boolean isBig&#061;5&gt;8;<br \/>\n    if(isPass){<br \/>\n    System.out.println(&#034;\u901a\u8fc7\u4e86&#034;);<br \/>\n    }else{<br \/>\n    System.out.println(&#034;\u672a\u901a\u8fc7&#034;);<br \/>\n    }<br \/>\n    \/\/\u5355\u5b57\u7b26<br \/>\n    char f&#061;&#039;\u5973&#039;;<br \/>\n    char m&#061;&#039;\u7537&#039;;<br \/>\n} <\/p>\n<p>Java\u8bed\u8a00\u7684\u6574\u578b\u5e38\u6570\u9ed8\u8ba4\u4e3aint\u578b&#xff0c;\u6d6e\u70b9\u6570\u9ed8\u8ba4\u662fDouble<\/p>\n<h4 id=\"_3\u3001\u6574\u578b\u62d3\u5c55\">3\u3001\u6574\u578b\u62d3\u5c55<\/h4>\n<p>\u5728\u6211\u4eec\u8ba1\u7b97\u673a\u4e2d\u5b58\u5728\u5f88\u591a\u8fdb\u5236\u95ee\u9898&#xff0c;\u5341\u8fdb\u5236&#xff0c;\u516b\u8fdb\u5236&#xff0c;\u5341\u516d\u8fdb\u5236\u7b49\u7b49\u7684\u95ee\u9898&#xff0c;\u4ed6\u4eec\u600e\u4e48\u8868\u793a\u5462&#xff1f;<\/p>\n<ul>\n<li>\n<p>\u5341\u8fdb\u5236\u6574\u6570&#xff0c;\u5982&#xff1a;99&#xff0c;-500&#xff0c;0\u3002<\/p>\n<\/li>\n<li>\n<p>\u516b\u8fdb\u5236\u6574\u6570&#xff0c;\u8981\u6c42\u4ee5 0 \u5f00\u5934&#xff0c;\u5982&#xff1a;015\u3002<\/p>\n<\/li>\n<li>\n<p>\u5341\u516d\u8fdb\u5236\u6570&#xff0c;\u8981\u6c42 0x \u6216 0X \u5f00\u5934&#xff0c;\u5982&#xff1a;0x15 \u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u6f14\u793a&#xff1a;<\/p>\n<\/p>\n<p>\/\/\u6574\u578b<br \/>\nint i&#061; 10;<br \/>\nint i2&#061; 010;<br \/>\nint i3&#061; 0x10;<br \/>\nSystem.out.println(i); \/\/10<br \/>\nSystem.out.println(i2); \/\/8<br \/>\nSystem.out.println(i3); \/\/16 <\/p>\n<h4 id=\"_4\u3001\u6d6e\u70b9\u578b\u62d3\u5c55\">4\u3001\u6d6e\u70b9\u578b\u62d3\u5c55<\/h4>\n<p>\u3010\u91d1\u878d\u9762\u8bd5\u95ee&#xff1a;\u94f6\u884c\u91d1\u878d\u4e1a\u52a1\u7528\u4ec0\u4e48\u7c7b\u578b\u8868\u793a&#xff1f;\u3011<\/p>\n<p>\u6d6e\u70b9\u7c7b\u578bfloat&#xff0c;double\u7684\u6570\u636e\u4e0d\u9002\u5408\u5728\u4e0d\u5bb9\u8bb8\u820d\u5165\u8bef\u5dee\u7684\u91d1\u878d\u8ba1\u7b97\u9886\u57df\u3002<\/p>\n<p>\u5982\u679c\u9700\u8981\u8fdb\u884c\u4e0d\u4ea7\u751f\u820d\u5165\u8bef\u5dee\u7684\u7cbe\u786e\u6570\u5b57\u8ba1\u7b97&#xff0c;\u9700\u8981\u4f7f\u7528BigDecimal\u7c7b\u3002<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    float f &#061; 0.1f;<br \/>\n    double d &#061; 1.0\/10;<br \/>\n    System.out.println(f&#061;&#061;d); \/\/false<\/p>\n<p>    float d1 &#061; 2131231231f;<br \/>\n    float d2 &#061; d1&#043;1;<br \/>\n    if(d1&#061;&#061;d2){<br \/>\n        System.out.println(&#034;d1&#061;&#061;d2&#034;);<br \/>\n    }else{<br \/>\n        System.out.println(&#034;d1!&#061;d2&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u6700\u540e\u8fd0\u884c\u7ed3\u679c&#xff1a;<\/p>\n<p>false d1&#061;&#061;d2<\/p>\n<p>\u4e3b\u8981\u7406\u7531&#xff1a;<\/p>\n<p>\u7531\u4e8e\u5b57\u957f\u6709\u9650&#xff0c;\u6d6e\u70b9\u6570\u80fd\u591f\u7cbe\u786e\u8868\u793a\u7684\u6570\u662f\u6709\u9650\u7684&#xff0c;\u56e0\u800c\u4e5f\u662f\u79bb\u6563\u7684\u3002\u6d6e\u70b9\u6570\u4e00\u822c\u90fd\u5b58\u5728\u820d\u5165\u8bef\u5dee&#xff0c;\u5f88 \u591a\u6570\u5b57\u65e0\u6cd5\u7cbe\u786e\u8868\u793a&#xff0c;\u5176\u7ed3\u679c\u53ea\u80fd\u662f\u63a5\u8fd1&#xff0c;\u4f46\u4e0d\u7b49\u4e8e&#xff1b;\u4e8c\u8fdb\u5236\u6d6e\u70b9\u6570\u4e0d\u80fd\u7cbe\u786e\u7684\u8868\u793a0.1,0.01,0.001\u8fd9\u683710\u7684\u8d1f\u6b21\u5e42\u3002\u5e76\u4e0d\u662f\u6240\u6709\u7684\u5c0f\u6570\u90fd\u80fd\u53ef\u4ee5\u7cbe\u786e\u7684\u7528\u4e8c\u8fdb\u5236\u6d6e\u70b9\u6570\u8868\u793a\u3002<\/p>\n<p>\u5927\u6570\u503c&#xff1a;Java.math\u4e0b\u9762\u7684\u4e24\u4e2a\u6709\u7528\u7684\u7c7b&#xff1a;BigInteger\u548cBigDecimal&#xff0c;\u8fd9\u4e24\u4e2a\u7c7b\u53ef\u4ee5\u5904\u7406\u4efb\u610f\u957f\u5ea6\u7684\u6570 \u503c\u3002BigInteger\u5b9e\u73b0\u4e86\u4efb\u610f\u7cbe\u5ea6\u7684\u6574\u6570\u8fd0\u7b97\u3002BigDecimal\u5b9e\u73b0\u4e86\u4efb\u610f\u7cbe\u5ea6\u7684\u6d6e\u70b9\u8fd0\u7b97\u3002<\/p>\n<p>\u6d6e\u70b9\u6570\u4f7f\u7528\u603b\u7ed3&#xff1a;<\/p>\n<li>\u9ed8\u8ba4\u662fdouble<\/li>\n<li>\u6d6e\u70b9\u6570\u5b58\u5728\u820d\u5165\u8bef\u5dee&#xff0c;\u5f88\u591a\u6570\u5b57\u4e0d\u80fd\u7cbe\u786e\u8868\u793a\u3002\u5982\u679c\u9700\u8981\u8fdb\u884c\u4e0d\u4ea7\u751f\u820d\u5165\u8bef\u5dee\u7684\u7cbe\u786e\u6570\u5b57\u8ba1\u7b97&#xff0c;\u9700 \u8981\u4f7f\u7528BigDecimal\u7c7b\u3002<\/li>\n<li>\u907f\u514d\u6bd4\u8f83\u4e2d\u4f7f\u7528\u6d6e\u70b9\u6570<\/li>\n<h4 id=\"_5\u3001\u5b57\u7b26\u578b\u62d3\u5c55\">5\u3001\u5b57\u7b26\u578b\u62d3\u5c55<\/h4>\n<p>\u5355\u5f15\u53f7\u7528\u6765\u8868\u793a\u5b57\u7b26\u5e38\u91cf\u3002\u4f8b\u5982\u2018A\u2019\u662f\u4e00\u4e2a\u5b57\u7b26&#xff0c;\u5b83\u4e0e\u201cA\u201d\u662f\u4e0d\u540c\u7684&#xff0c;\u201cA\u201d\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002<\/p>\n<p>char \u7c7b\u578b\u7528\u6765\u8868\u793a\u5728Unicode\u7f16\u7801\u8868\u4e2d\u7684\u5b57\u7b26\u3002<\/p>\n<p>Unicode\u7f16\u7801\u88ab\u8bbe\u8ba1\u7528\u6765\u5904\u7406\u5404\u79cd\u8bed\u8a00\u7684\u6240\u6709\u6587\u5b57&#xff0c;\u5b83\u53602\u4e2a\u5b57\u8282&#xff0c;\u53ef\u5141\u8bb8\u670965536\u4e2a\u5b57\u7b26&#xff1b;<\/p>\n<p>\u79d1\u666e&#xff1a;2\u5b57\u8282&#061;16\u4f4d&#xff0c;2\u768416\u6b21\u65b9&#061;65536&#xff0c;\u6211\u4eec\u7528\u7684Excel\u539f\u6765\u5c31\u53ea\u6709\u8fd9\u4e48\u591a\u884c&#xff0c;\u5e76\u4e0d\u662f\u65e0\u9650\u7684<\/p>\n<p>\u3010\u4ee3\u7801\u6f14\u793a&#xff1a;\u5b57\u7b26\u8f6cint\u770b\u7ed3\u679c\u3011<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    char c1 &#061; &#039;a&#039;;<br \/>\n    char c2 &#061; &#039;\u4e2d&#039;;<br \/>\n    System.out.println(c1);<br \/>\n    System.out.println((int) c1); \/\/97<br \/>\n    System.out.println(c2);<br \/>\n    System.out.println((int) c2); \/\/20013<br \/>\n} <\/p>\n<p>Unicode\u5177\u6709\u4ece0\u523065535\u4e4b\u95f4\u7684\u7f16\u7801&#xff0c;\u4ed6\u4eec\u901a\u5e38\u7528\u4ece\u2019u0000\u2019\u5230\u2019uFFFF\u2019\u4e4b\u95f4\u7684\u5341\u516d\u8fdb\u5236\u503c\u6765\u8868\u793a&#xff08;\u524d\u7f00\u4e3a u\u8868\u793aUnicode&#xff09;<\/p>\n<\/p>\n<p>char c3 &#061; &#039;\\\\u0061&#039;;<br \/>\nSystem.out.println(c3); \/\/a <\/p>\n<p>Java \u8bed\u8a00\u4e2d\u8fd8\u5141\u8bb8\u4f7f\u7528\u8f6c\u4e49\u5b57\u7b26 \u2018\u2019 \u6765\u5c06\u5176\u540e\u7684\u5b57\u7b26\u8f6c\u53d8\u4e3a\u5176\u5b83\u7684\u542b\u4e49&#xff0c;\u6709\u5982\u4e0b\u5e38\u7528\u8f6c\u4e49\u5b57\u7b26&#xff1a;<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"504\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114045016-69672088af848.png\" width=\"353\" \/><\/p>\n<p>\u3010\u4ee5\u540e\u6211\u4eec\u5b66\u7684String\u7c7b&#xff0c;\u5176\u5b9e\u662f\u5b57\u7b26\u5e8f\u5217(char sequence)\u3002\u5728\u8fd9\u91cc\u7ed9\u5927\u5bb6\u4e00\u4e2a\u601d\u8003\u9898\u3011<\/p>\n<\/p>\n<p>\/\/\u4ee3\u78011<br \/>\nString sa&#061;new String(&#034;Hello world&#034;);<br \/>\nString sb&#061;new String(&#034;Hello world&#034;);<br \/>\nSystem.out.println(sa&#061;&#061;sb); \/\/ false<br \/>\n\/\/\u4ee3\u78012<br \/>\nString sc&#061;&#034;Hello world&#034;;<br \/>\nString sd&#061;&#034;Hello world&#034;;<br \/>\nSystem.out.println(sc&#061;&#061;sd); \/\/ true <\/p>\n<p>\u5927\u5bb6\u53ef\u4ee5\u5148\u601d\u8003\u4e0b\u4e3a\u4ec0\u4e48&#xff0c;\u4e4b\u540e\u6211\u4eec\u5b66\u5230\u5bf9\u8c61\u7684\u65f6\u5019&#xff0c;\u4f1a\u7ed9\u5927\u5bb6\u8fdb\u884c\u5185\u5b58\u7ea7\u522b\u7684\u5206\u6790&#xff0c;\u90a3\u65f6\u5019\u4f60\u4f1a\u604d\u7136 \u5927\u609f&#xff01;<\/p>\n<h4 id=\"_6\u3001\u5e03\u5c14\u578b\u62d3\u5c55\">6\u3001\u5e03\u5c14\u578b\u62d3\u5c55<\/h4>\n<p>boolean\u7c7b\u578b&#xff08;\u4e00\u4f4d&#xff0c;\u4e0d\u662f\u4e00\u4e2a\u5b57\u8282&#xff09;&#xff0c;\u5c31\u662f0|1<\/p>\n<p>boolean\u7c7b\u578b\u6709\u4e24\u4e2a\u503c&#xff0c;true\u548cfalse,\u4e0d\u53ef\u4ee5 0 \u6216\u975e 0 \u7684\u6574\u6570\u66ff\u4ee3 true \u548c false &#xff0c;\u8fd9\u70b9\u548cC\u8bed\u8a00\u4e0d\u540c\u3002<\/p>\n<p>boolean \u7c7b\u578b\u7528\u6765\u5224\u65ad\u903b\u8f91\u6761\u4ef6&#xff0c;\u4e00\u822c\u7528\u4e8e\u7a0b\u5e8f\u6d41\u7a0b\u63a7\u5236\u3002<\/p>\n<\/p>\n<p>boolean flag &#061; false;<br \/>\nif(flag){<br \/>\n    \/\/ true\u5206\u652f<br \/>\n}else{<br \/>\n    \/\/ false\u5206\u652f<br \/>\n} <\/p>\n<p>\u3010\u7f16\u7801\u89c4\u8303&#xff1a;\u5f88\u591a\u65b0\u624b\u7a0b\u5e8f\u5458\u559c\u6b22\u8fd9\u6837\u5199\u3011<\/p>\n<\/p>\n<p>if (is &#061;&#061; true &amp;&amp; un &#061;&#061; false ) {&#8230;} <\/p>\n<p>\u53ea\u6709\u65b0\u624b\u624d\u90a3\u4e48\u5199\u3002\u5bf9\u4e8e\u4e00\u4e2a\u719f\u7ec3\u7684\u4eba\u6765\u8bf4&#xff0c;\u5e94\u8be5\u7528\u5982\u4e0b\u65b9\u5f0f\u6765\u8868\u793a&#xff1a;<\/p>\n<\/p>\n<p>if ( is &amp;&amp; !un ) {&#8230;.} <\/p>\n<p>\u524d\u9762\u52a0\u4e2a ! \u8868\u793a\u5426\u5b9a<\/p>\n<p>\u8fd9\u70b9\u90fd\u4e0d\u96be\u7406\u89e3\u5427\u3002\u6240\u4ee5\u8981\u4e60\u60ef\u53bb\u6389\u6240\u6709\u7684&#061;&#061;fasle \u548c &#061;&#061;true\u3002Less is More&#xff01;&#xff01; \u4ee3\u7801\u8981\u7cbe\u7b80\u6613\u8bfb&#xff01;<\/p>\n<h2>\u4e94\u3001\u7c7b\u578b\u8f6c\u6362 \u00a0<\/h2>\n<p>\u7531\u4e8eJava\u662f\u5f3a\u7c7b\u578b\u8bed\u8a00&#xff0c;\u6240\u4ee5\u8981\u8fdb\u884c\u6709\u4e9b\u8fd0\u7b97\u7684\u65f6\u5019\u7684&#xff0c;\u9700\u8981\u7528\u5230\u7c7b\u578b\u8f6c\u6362\u3002<\/p>\n<p>\u6574\u578b\u3001\u5b9e\u578b&#xff08;\u5e38\u91cf&#xff09;\u3001\u5b57\u7b26\u578b\u6570\u636e\u53ef\u4ee5\u6df7\u5408\u8fd0\u7b97\u3002<\/p>\n<p>\u8fd0\u7b97\u4e2d&#xff0c;\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u5148\u8f6c\u5316\u4e3a\u540c\u4e00\u7c7b\u578b&#xff0c;\u7136\u540e\u8fdb\u884c\u8fd0\u7b97\u3002<\/p>\n<p>\u8f6c\u6362\u4ece\u4f4e\u7ea7\u5230\u9ad8\u7ea7&#xff08;\u6839\u636e\u5bb9\u91cf\u6765\u770b&#xff09;\u3002<\/p>\n<p>\u4f4e &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&gt; \u9ad8<\/p>\n<p>byte,short,char\u2014&gt; int \u2014&gt; long\u2014&gt; float \u2014&gt; double<\/p>\n<p>\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u5fc5\u987b\u6ee1\u8db3\u5982\u4e0b\u89c4\u5219&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4e0d\u80fd\u5bf9boolean\u7c7b\u578b\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e0d\u80fd\u628a\u5bf9\u8c61\u7c7b\u578b\u8f6c\u6362\u6210\u4e0d\u76f8\u5173\u7c7b\u7684\u5bf9\u8c61\u3002<\/p>\n<\/li>\n<li>\n<p>\u5728\u628a\u5bb9\u91cf\u5927\u7684\u7c7b\u578b\u8f6c\u6362\u4e3a\u5bb9\u91cf\u5c0f\u7684\u7c7b\u578b\u65f6\u5fc5\u987b\u4f7f\u7528\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u3002<\/p>\n<\/li>\n<li>\n<p>\u8f6c\u6362\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u5bfc\u81f4\u6ea2\u51fa\u6216\u635f\u5931\u7cbe\u5ea6&#xff0c;\u4f8b\u5982&#xff1a;<\/p>\n<p> int i &#061; 128;<br \/>\nbyte b &#061; (byte)i; <\/p>\n<p>\u56e0\u4e3a byte \u7c7b\u578b\u662f 8 \u4f4d&#xff0c;\u6700\u5927\u503c\u4e3a127&#xff0c;\u6240\u4ee5\u5f53 int \u5f3a\u5236\u8f6c\u6362\u4e3a byte \u7c7b\u578b\u65f6&#xff0c;\u503c 128 \u65f6\u5019\u5c31\u4f1a\u5bfc\u81f4\u6ea2\u51fa\u3002<\/p>\n<p>\u63a8\u8350\u6587\u7ae0&#xff1a;\u7ec6\u8c08\u4e3a\u4ec0\u4e48\u5355\u5b57\u8282\u7684\u6574\u6570\u8303\u56f4\u662f[-128 ~ 127]<\/p>\n<\/li>\n<\/ul>\n<p>\u6d6e\u70b9\u6570\u5230\u6574\u6570\u7684\u8f6c\u6362\u662f\u901a\u8fc7\u820d\u5f03\u5c0f\u6570\u5f97\u5230&#xff0c;\u800c\u4e0d\u662f\u56db\u820d\u4e94\u5165&#xff0c;\u4f8b\u5982&#xff1a;<\/p>\n<p>(int)23.7 &#061;&#061; 23; (int)-45.89f &#061;&#061; -45<\/p>\n<h4 id=\"_1\u3001\u81ea\u52a8\u7c7b\u578b\u8f6c\u6362\">1\u3001\u81ea\u52a8\u7c7b\u578b\u8f6c\u6362<\/h4>\n<p>\u81ea\u52a8\u7c7b\u578b\u8f6c\u6362&#xff1a;\u5bb9\u91cf\u5c0f\u7684\u6570\u636e\u7c7b\u578b\u53ef\u4ee5\u81ea\u52a8\u8f6c\u6362\u4e3a\u5bb9\u91cf\u5927\u7684\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<p>\u4f8b\u5982: short\u6570\u636e\u7c7b\u578b\u7684\u4f4d\u6570\u4e3a16\u4f4d&#xff0c;\u5c31\u53ef\u4ee5\u81ea\u52a8\u8f6c\u6362\u4f4d\u6570\u4e3a32\u7684int\u7c7b\u578b&#xff0c;\u540c\u6837float\u6570\u636e\u7c7b\u578b\u7684\u4f4d\u6570\u4e3a 32&#xff0c;\u53ef\u4ee5\u81ea\u52a8\u8f6c\u6362\u4e3a64\u4f4d\u7684double\u7c7b\u578b\u3002<\/p>\n<p>public static void main(String[] args) {<br \/>\n    char c1 &#061; &#039;a&#039;;\/\/\u5b9a\u4e49\u4e00\u4e2achar\u7c7b\u578b<br \/>\n    int i1 &#061; c1;\/\/char\u81ea\u52a8\u7c7b\u578b\u8f6c\u6362\u4e3aint<br \/>\n    System.out.println(&#034;char\u81ea\u52a8\u7c7b\u578b\u8f6c\u6362\u4e3aint\u540e\u7684\u503c\u7b49\u4e8e&#034; &#043; i1);<br \/>\n    char c2 &#061; &#039;A&#039;;\/\/\u5b9a\u4e49\u4e00\u4e2achar\u7c7b\u578b<br \/>\n    int i2 &#061; c2 &#043; 1;\/\/char \u7c7b\u578b\u548c int \u7c7b\u578b\u8ba1\u7b97<br \/>\n    System.out.println(&#034;char\u7c7b\u578b\u548cint\u8ba1\u7b97\u540e\u7684\u503c\u7b49\u4e8e&#034; &#043; i2);<br \/>\n} <\/p>\n<p>\u89e3\u6790&#xff1a;c1 \u7684\u503c\u4e3a\u5b57\u7b26 a ,\u67e5 ASCII \u7801\u8868\u53ef\u77e5\u5bf9\u5e94\u7684 int \u7c7b\u578b\u503c\u4e3a 97&#xff0c;\u6240\u4ee5i1&#061;97\u3002 A \u5bf9\u5e94\u503c\u4e3a 65&#xff0c;\u6240\u4ee5 i2&#061;65&#043;1&#061;66\u3002<\/p>\n<h4 id=\"_2\u3001\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\">2\u3001\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362<\/h4>\n<p>\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362&#xff0c;\u53c8\u88ab\u79f0\u4e3a\u9020\u578b&#xff0c;\u7528\u4e8e\u663e\u5f0f\u7684\u8f6c\u6362\u4e00\u4e2a\u6570\u503c\u7684\u7c7b\u578b\u3002<\/p>\n<p>\u5728\u6709\u53ef\u80fd\u4e22\u5931\u4fe1\u606f\u7684\u60c5\u51b5\u4e0b\u8fdb\u884c\u7684\u8f6c\u6362\u662f\u901a\u8fc7\u9020\u578b\u6765\u5b8c\u6210\u7684&#xff0c;\u4f46\u53ef\u80fd\u9020\u6210\u7cbe\u5ea6\u964d\u4f4e\u6216\u6ea2\u51fa\u3002<\/p>\n<p>\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u7684\u8bed\u6cd5\u683c\u5f0f&#xff1a;\u00a0(type)var\u00a0&#xff0c;\u8fd0\u7b97\u7b26 \u201c()\u201d \u4e2d\u7684 type \u8868\u793a\u5c06\u503cvar\u60f3\u8981\u8f6c\u6362\u6210\u7684\u76ee\u6807\u6570\u636e\u7c7b\u578b\u3002 \u6761\u4ef6\u662f\u8f6c\u6362\u7684\u6570\u636e\u7c7b\u578b\u5fc5\u987b\u662f\u517c\u5bb9\u7684\u3002<\/p>\n<p>public static void main(String[] args) {<br \/>\n    double x &#061; 3.14;<br \/>\n    int nx &#061; (int) x; \/\/\u503c\u4e3a3<br \/>\n    char c &#061; &#039;a&#039;;<br \/>\n    int d &#061; c &#043; 1;<br \/>\n    System.out.println(d); \/\/98<br \/>\n    System.out.println((char) d); \/\/b<br \/>\n} <\/p>\n<p>\u5f53\u5c06\u4e00\u79cd\u7c7b\u578b\u5f3a\u5236\u8f6c\u6362\u6210\u53e6\u4e00\u79cd\u7c7b\u578b&#xff0c;\u800c\u53c8\u8d85\u51fa\u4e86\u76ee\u6807\u7c7b\u578b\u7684\u8868\u793a\u8303\u56f4&#xff0c;\u5c31\u4f1a\u88ab\u622a\u65ad\u6210\u4e3a\u4e00\u4e2a\u5b8c\u5168\u4e0d\u540c \u7684\u503c&#xff0c;\u6ea2\u51fa\u3002<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int x &#061; 300;<br \/>\n    byte bx &#061; (byte)x; \/\/\u503c\u4e3a44<br \/>\n    System.out.println(bx);<br \/>\n} <\/p>\n<h4 id=\"_3\u3001\u5e38\u89c1\u9519\u8bef\u548c\u95ee\u9898\">3\u3001\u5e38\u89c1\u9519\u8bef\u548c\u95ee\u9898<\/h4>\n<ul>\n<li>\n<p>\u64cd\u4f5c\u6bd4\u8f83\u5927\u7684\u6570\u65f6&#xff0c;\u8981\u7559\u610f\u662f\u5426\u6ea2\u51fa&#xff0c;\u5c24\u5176\u662f\u6574\u6570\u64cd\u4f5c\u65f6&#xff1b;<\/p>\n<p> public static void main(String[] args) {<br \/>\n    int money &#061; 1000000000; \/\/10\u4ebf<br \/>\n    int years &#061; 20;<br \/>\n    int total &#061; money * years; \/\/\u8fd4\u56de\u7684\u662f\u8d1f\u6570<br \/>\n    long total1 &#061; money * years; \/\/\u8fd4\u56de\u7684\u4ecd\u7136\u662f\u8d1f\u6570\u3002\u9ed8\u8ba4\u662fint&#xff0c;\u56e0\u6b64\u7ed3\u679c\u4f1a\u8f6c\u6210int\u503c&#xff0c;\u518d\u8f6c\u6210long\u3002\u4f46\u662f\u5df2\u7ecf\u53d1\u751f\u4e86\u6570\u636e\u4e22\u5931<br \/>\n    long total2 &#061; money * ((long) years); \/\/\u5148\u5c06\u4e00\u4e2a\u56e0\u5b50\u53d8\u6210long&#xff0c;\u6574\u4e2a\u8868\u8fbe\u5f0f\u53d1\u751f\u63d0\u5347\u3002\u5168\u90e8\u7528long\u6765\u8ba1\u7b97\u3002<br \/>\n    System.out.println(total); \/\/-1474836480<br \/>\n    System.out.println(total1); \/\/-1474836480<br \/>\n    System.out.println(total2); \/\/20000000000<br \/>\n} <\/p>\n<\/li>\n<li>\n<p>L\u548cl \u7684\u95ee\u9898&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4e0d\u8981\u547d\u540d\u540d\u5b57\u4e3al\u7684\u53d8\u91cf<\/p>\n<\/li>\n<li>\n<p>long\u7c7b\u578b\u4f7f\u7528\u5927\u5199L\u4e0d\u8981\u7528\u5c0f\u5199\u3002<\/p>\n<p> public static void main(String[] args) {<br \/>\n    int l &#061; 2;<br \/>\n    long a &#061; 23451l;<br \/>\n    System.out.println(l &#043; 1); \/\/3<br \/>\n    System.out.println(a); \/\/23451<br \/>\n} <\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4 id=\"_4\u3001jdk7\u6269\u5c55\">4\u3001JDK7\u6269\u5c55<\/h4>\n<p>JDK7\u65b0\u7279\u6027:\u00a0\u4e8c\u8fdb\u5236\u6574\u6570<\/p>\n<p>\u7531\u4e8e\u6211\u4eec\u5728\u5f00\u53d1\u4e2d\u4e5f\u7ecf\u5e38\u4f7f\u7528\u4e8c\u8fdb\u5236\u6574\u6570&#xff0c;\u56e0\u6b64JDK7\u4e3a\u6211\u4eec\u76f4\u63a5\u63d0\u4f9b\u4e86\u4e8c\u8fdb\u5236\u6574\u6570\u7684\u7c7b\u578b\u3002<\/p>\n<p>\u6211\u4eec\u53ea\u8981\u4ee5&#xff1a;0b\u5f00\u5934\u5373\u53ef\u3002<\/p>\n<p>int a &#061; 0b0101; <\/p>\n<p>JDK7\u65b0\u7279\u6027&#xff1a;\u4e0b\u5212\u7ebf\u5206\u9694\u7b26<\/p>\n<p>\u5728\u5b9e\u9645\u5f00\u53d1\u548c\u5b66\u4e60\u4e2d&#xff0c;\u5982\u679c\u9047\u5230\u7279\u522b\u957f\u7684\u6570\u5b57&#xff0c;\u8bfb\u61c2\u5b83\u4ee4\u4eba\u5934\u75bc&#xff01;JDK7\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u4e0b\u5212\u7ebf\u5206\u9694\u7b26&#xff0c;\u53ef \u4ee5\u6309\u7167\u81ea\u5df1\u7684\u4e60\u60ef\u8fdb\u884c\u5206\u5272\u3002<\/p>\n<p>int b &#061; 1_2234_5678; <\/p>\n<p>\u6211\u4eec\u5f88\u5bb9\u6613\u5c31\u77e5\u9053\u8fd9\u662f1\u4ebf2234\u4e075678\u5566&#xff01; \u975e\u5e38\u7b26\u5408\u56fd\u4eba\u7684\u4e60\u60ef&#xff01;<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int a &#061; 0b0101;<br \/>\n    int b &#061; 1_2345_7893;<br \/>\n    System.out.println(a); \/\/5<br \/>\n    System.out.println(b); \/\/123457893<br \/>\n} <\/p>\n<h2>\u516d\u3001\u53d8\u91cf\u548c\u5e38\u91cf \u00a0<\/h2>\n<h4 id=\"_1\u3001\u53d8\u91cf-variable\">1\u3001\u53d8\u91cf&#xff08;variable&#xff09;<\/h4>\n<p>\u53d8\u91cf\u662f\u4ec0\u4e48&#xff1a;\u5c31\u662f\u53ef\u4ee5\u53d8\u5316\u7684\u91cf&#xff01;<\/p>\n<p>\u6211\u4eec\u901a\u8fc7\u53d8\u91cf\u6765\u64cd\u7eb5\u5b58\u50a8\u7a7a\u95f4\u4e2d\u7684\u6570\u636e&#xff0c;\u53d8\u91cf\u5c31\u662f\u6307\u4ee3\u8fd9\u4e2a\u5b58\u50a8\u7a7a\u95f4&#xff01;\u7a7a\u95f4\u4f4d\u7f6e\u662f\u786e\u5b9a\u7684&#xff0c;\u4f46\u662f\u91cc\u9762\u653e \u7f6e\u4ec0\u4e48\u503c\u4e0d\u786e\u5b9a&#xff01; \u6253\u4e2a\u6bd4\u65b9&#xff1a;<\/p>\n<p>\u8fd9\u5c31\u597d\u50cf\u6211\u4eec\u5bb6\u91cc\u6709\u4e00\u4e2a\u5927\u8863\u67dc&#xff0c;\u91cc\u9762\u6709\u5341\u5206\u591a\u7684\u5c0f\u683c\u5b50&#xff0c;\u6211\u4eec\u7ed9\u683c\u5b50\u4e0a\u8d34\u4e0a\u6807\u7b7e&#xff0c;\u653e\u8863\u670d&#xff0c;\u653e\u978b\u5b50&#xff0c; \u653e\u624b\u8868\u7b49\u7b49&#xff0c;\u6b64\u65f6\u6211\u4eec\u77e5\u9053\u4e86\u54ea\u91cc\u8be5\u653e\u4ec0\u4e48&#xff0c;\u4f46\u662f&#xff0c;\u6211\u4eec\u5e76\u4e0d\u77e5\u9053\u91cc\u9762\u5230\u5e95\u653e\u7684\u662f\u4ec0\u4e48\u724c\u5b50\u7684\u978b\u5b50&#xff0c;\u662f \u8863\u670d\u8fd8\u662f\u88e4\u5b50\u3002\u90a3\u4e2a\u6807\u7b7e\u5c31\u76f8\u5f53\u4e8e\u6211\u4eec\u7684\u53d8\u91cf&#xff0c;\u6211\u4eec\u7ed9\u4ed6\u8d77\u4e86\u4e2a\u540d\u5b57&#xff0c;\u4f46\u662f\u91cc\u9762\u8981\u653e\u4ec0\u4e48\u9700\u8981\u6211\u4eec\u81ea\u5df1 \u53bb\u653e\u3002<\/p>\n<p>Java\u662f\u4e00\u79cd\u5f3a\u7c7b\u578b\u8bed\u8a00&#xff0c;\u6bcf\u4e2a\u53d8\u91cf\u90fd\u5fc5\u987b\u58f0\u660e\u5176\u7c7b\u578b\u3002<\/p>\n<p>Java\u53d8\u91cf\u662f\u7a0b\u5e8f\u4e2d\u6700\u57fa\u672c\u7684\u5b58\u50a8\u5355\u5143&#xff0c;\u5176\u8981\u7d20\u5305\u62ec\u53d8\u91cf\u540d&#xff0c;\u53d8\u91cf\u7c7b\u578b\u548c\u4f5c\u7528\u57df\u3002<\/p>\n<p>\u53d8\u91cf\u5728\u4f7f\u7528\u524d\u5fc5\u987b\u5bf9\u5176\u58f0\u660e&#xff0c;\u53ea\u6709\u5728\u53d8\u91cf\u58f0\u660e\u4ee5\u540e&#xff0c;\u624d\u80fd\u4e3a\u5176\u5206\u914d\u76f8\u5e94\u957f\u5ea6\u7684\u5b58\u50a8\u5355\u5143&#xff0c;\u58f0\u660e\u683c\u5f0f\u4e3a&#xff1a;<\/p>\n<p>\u6570\u636e\u7c7b\u578b \u53d8\u91cf\u540d &#061; \u503c&#xff1b;<\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u9017\u53f7\u9694\u5f00\u6765\u58f0\u660e\u591a\u4e2a\u540c\u7c7b\u578b\u53d8\u91cf\u3002<\/p>\n<p>\u6ce8\u610f\u4e8b\u9879&#xff1a;<\/p>\n<ul>\n<li>\u6bcf\u4e2a\u53d8\u91cf\u90fd\u6709\u7c7b\u578b&#xff0c;\u7c7b\u578b\u53ef\u4ee5\u662f\u57fa\u672c\u7c7b\u578b&#xff0c;\u4e5f\u53ef\u4ee5\u662f\u5f15\u7528\u7c7b\u578b\u3002<\/li>\n<li>\u53d8\u91cf\u540d\u5fc5\u987b\u662f\u5408\u6cd5\u7684\u6807\u8bc6\u7b26\u3002<\/li>\n<li>\u53d8\u91cf\u58f0\u660e\u662f\u4e00\u6761\u5b8c\u6574\u7684\u8bed\u53e5&#xff0c;\u56e0\u6b64\u6bcf\u4e00\u4e2a\u58f0\u660e\u90fd\u5fc5\u987b\u4ee5\u5206\u53f7\u7ed3\u675f<\/li>\n<\/ul>\n<p>\u3010\u6f14\u793a\u3011<\/p>\n<\/p>\n<p>int a, b, c; \/\/ \u58f0\u660e\u4e09\u4e2aint\u578b\u6574\u6570&#xff1a;a\u3001 b\u3001c<br \/>\nint d &#061; 3, e &#061; 4, f &#061; 5; \/\/ \u58f0\u660e\u4e09\u4e2a\u6574\u6570\u5e76\u8d4b\u4e88\u521d\u503c<br \/>\nbyte z &#061; 22; \/\/ \u58f0\u660e\u5e76\u521d\u59cb\u5316 z<br \/>\nString s &#061; &#034;runoob&#034;; \/\/ \u58f0\u660e\u5e76\u521d\u59cb\u5316\u5b57\u7b26\u4e32 s<br \/>\ndouble pi &#061; 3.14159; \/\/ \u58f0\u660e\u4e86\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u578b\u53d8\u91cf pi<br \/>\nchar x &#061; &#039;x&#039;; \/\/ \u58f0\u660e\u53d8\u91cf x \u7684\u503c\u662f\u5b57\u7b26 &#039;x&#039;\u3002 <\/p>\n<p>\u3010\u7f16\u7801\u89c4\u8303\u3011<\/p>\n<p>\u867d\u7136\u53ef\u4ee5\u5728\u4e00\u884c\u58f0\u660e\u591a\u4e2a\u53d8\u91cf&#xff0c;\u4f46\u662f\u4e0d\u63d0\u5021\u8fd9\u4e2a\u98ce\u683c&#xff0c;\u9010\u4e00\u58f0\u660e\u6bcf\u4e00\u4e2a\u53d8\u91cf\u53ef\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u53ef\u8bfb\u6027\u3002<\/p>\n<h4 id=\"_2\u3001\u53d8\u91cf\u4f5c\u7528\u57df\">2\u3001\u53d8\u91cf\u4f5c\u7528\u57df<\/h4>\n<p>\u53d8\u91cf\u6839\u636e\u4f5c\u7528\u57df\u53ef\u5212\u5206\u4e3a\u4e09\u79cd&#xff1a;<\/p>\n<ul>\n<li>\u7c7b\u53d8\u91cf&#xff08;\u9759\u6001\u53d8\u91cf&#xff1a; static variable&#xff09;&#xff1a;\u72ec\u7acb\u4e8e\u65b9\u6cd5\u4e4b\u5916\u7684\u53d8\u91cf&#xff0c;\u7528 static \u4fee\u9970\u3002<\/li>\n<li>\u5b9e\u4f8b\u53d8\u91cf&#xff08;\u6210\u5458\u53d8\u91cf&#xff1a;member variable&#xff09;&#xff1a;\u72ec\u7acb\u4e8e\u65b9\u6cd5\u4e4b\u5916\u7684\u53d8\u91cf&#xff0c;\u4e0d\u8fc7\u6ca1\u6709 static \u4fee\u9970\u3002<\/li>\n<li>\u5c40\u90e8\u53d8\u91cf&#xff08;lacal variable&#xff09;&#xff1a;\u7c7b\u7684\u65b9\u6cd5\u4e2d\u7684\u53d8\u91cf\u3002<\/li>\n<\/ul>\n<p>public class Variable{<br \/>\n    static int allClicks &#061; 0; \/\/ \u7c7b\u53d8\u91cf<br \/>\n    String str &#061; &#034;hello world&#034;; \/\/ \u5b9e\u4f8b\u53d8\u91cf<\/p>\n<p>    public void method(){<br \/>\n        int i &#061;0; \/\/ \u5c40\u90e8\u53d8\u91cf<br \/>\n    }<br \/>\n} <\/p>\n<h5 id=\"\u5c40\u90e8\u53d8\u91cf\">\u5c40\u90e8\u53d8\u91cf<\/h5>\n<p>\u65b9\u6cd5\u6216\u8bed\u53e5\u5757\u5185\u90e8\u5b9a\u4e49\u7684\u53d8\u91cf\u3002\u751f\u547d\u5468\u671f\u662f\u4ece\u58f0\u660e\u4f4d\u7f6e\u5f00\u59cb\u5230 \u201d}\u201d \u4e3a\u6b62<\/p>\n<p>\u5728\u4f7f\u7528\u524d\u5fc5\u987b\u5148\u58f0\u660e\u548c\u521d\u59cb\u5316(\u8d4b\u521d\u503c)\u3002<\/p>\n<p>\u5c40\u90e8\u53d8\u91cf\u6ca1\u6709\u9ed8\u8ba4\u503c&#xff0c;\u6240\u4ee5\u5c40\u90e8\u53d8\u91cf\u88ab\u58f0\u660e\u540e&#xff0c;\u5fc5\u987b\u7ecf\u8fc7\u521d\u59cb\u5316&#xff0c;\u624d\u53ef\u4ee5\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int i;<br \/>\n    int j &#061; i &#043; 5; \/\/ \u7f16\u8bd1\u51fa\u9519&#xff0c;\u53d8\u91cfi\u8fd8\u672a\u88ab\u521d\u59cb\u5316<br \/>\n    System.out.println(j);<br \/>\n} <\/p>\n<p>\u4fee\u6539\u4e3a&#xff1a;<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int i&#061;10;<br \/>\n    int j &#061; i&#043;5 ;<br \/>\n    System.out.println(j);<br \/>\n} <\/p>\n<h5 id=\"\u5b9e\u4f8b\u53d8\u91cf\">\u5b9e\u4f8b\u53d8\u91cf<\/h5>\n<p>\u65b9\u6cd5\u5916\u90e8\u3001\u7c7b\u7684\u5185\u90e8\u5b9a\u4e49\u7684\u53d8\u91cf\u3002<\/p>\n<p>\u4ece\u5c5e\u4e8e\u5bf9\u8c61&#xff0c;\u751f\u547d\u5468\u671f\u4f34\u968f\u5bf9\u8c61\u59cb\u7ec8\u3002<\/p>\n<p>\u5982\u679c\u4e0d\u81ea\u884c\u521d\u59cb\u5316&#xff0c;\u4ed6\u4f1a\u81ea\u52a8\u521d\u59cb\u5316\u6210\u8be5\u7c7b\u578b\u7684\u9ed8\u8ba4\u521d\u59cb\u503c<\/p>\n<p>&#xff08;\u6570\u503c\u578b\u53d8\u91cf\u521d\u59cb\u5316\u62100\u62160.0&#xff0c;\u5b57\u7b26\u578b\u53d8\u91cf\u7684\u521d\u59cb\u5316\u503c\u662f16\u4f4d\u76840&#xff0c;\u5e03\u5c14\u578b\u9ed8\u8ba4\u662ffalse&#xff09;<\/p>\n<\/p>\n<p>public class Test {<br \/>\n    \/\/ \u8fd9\u4e2a\u5b9e\u4f8b\u53d8\u91cf\u5bf9\u5b50\u7c7b\u53ef\u89c1<br \/>\n    public String name;<br \/>\n    \/\/ \u79c1\u6709\u53d8\u91cf&#xff0c;\u4ec5\u5728\u8be5\u7c7b\u53ef\u89c1<br \/>\n    private double salary;<br \/>\n} <\/p>\n<h5 id=\"\u9759\u6001\u53d8\u91cf\">\u9759\u6001\u53d8\u91cf<\/h5>\n<p>\u4f7f\u7528static\u5b9a\u4e49\u3002<\/p>\n<p>\u4ece\u5c5e\u4e8e\u7c7b&#xff0c;\u751f\u547d\u5468\u671f\u4f34\u968f\u7c7b\u59cb\u7ec8&#xff0c;\u4ece\u7c7b\u52a0\u8f7d\u5230\u5378\u8f7d\u3002<\/p>\n<p>(\u6ce8&#xff1a;\u8bb2\u5b8c\u5185\u5b58\u5206\u6790\u540e\u6211\u4eec\u518d\u6df1\u5165&#xff01;\u5148\u653e\u4e00\u653e\u8fd9\u4e2a\u6982\u5ff5&#xff01;)<\/p>\n<p>\u4e0d\u540c\u7684\u7c7b\u4e4b\u95f4\u9700\u8981\u5bf9\u540c\u4e00\u4e2a\u53d8\u91cf\u8fdb\u884c\u64cd\u4f5c&#xff0c;\u6bd4\u5982\u4e00\u4e2a\u6c34\u6c60&#xff0c;\u540c\u65f6\u6253\u5f00\u5165\u6c34\u53e3\u548c\u51fa\u6c34\u53e3&#xff0c;\u8fdb\u6c34\u548c\u51fa\u6c34\u8fd9\u4e24\u4e2a\u52a8\u4f5c\u4f1a\u540c\u65f6\u5f71\u54cd\u5230\u6c60\u4e2d\u7684\u6c34\u91cf&#xff0c;\u6b64\u65f6\u6c60\u4e2d\u7684\u6c34\u91cf\u5c31\u53ef\u4ee5\u8ba4\u4e3a\u662f\u4e00\u4e2a\u5171\u4eab\u7684\u53d8\u91cf\u3002\u8be5\u53d8\u91cf\u5c31\u662f\u9759\u6001\u53d8\u91cf<\/p>\n<p>\u9759\u6001\u7b80\u5355\u7684\u8bf4\u662f \u88ab\u7c7b\u7684\u6240\u6709\u5bf9\u8c61\u5171\u4eab&#xff0c;\u6bd4\u5982\u6709\u4e00\u4e2a\u7c7b&#xff0c;\u6709\u5b66\u6821&#xff0c;\u59d3\u540d&#xff0c;\u5e74\u9f84\u4e09\u4e2a\u53c2\u6570&#xff0c;\u8c03\u7528\u5c31\u9700\u8981\u7ed9\u8fd9\u4e09\u4e2a\u8d4b\u4e0a\u503c&#xff0c;\u5047\u5982\u8fd9\u4e9b\u4eba\u90fd\u662f\u4e00\u4e2a\u5b66\u6821\u7684&#xff0c;\u6bcf\u6b21\u8c03\u7528\u90fd\u9700\u8981\u8d4b\u503c\u5c31\u592a\u91cd\u590d&#xff0c;\u52a0\u4e0a\u9759\u6001\u7684\u8bdd&#xff0c;\u4e00\u4e2a\u8d4b\u503c\u4e86&#xff0c;\u6bcf\u6b21\u8c03\u7528\u5219\u90fd\u662f\u90a3\u4e2a\u503c<\/p>\n<p>\u5982\u679c\u4e0d\u81ea\u884c\u521d\u59cb\u5316&#xff0c;\u4ed6\u4f1a\u81ea\u52a8\u521d\u59cb\u5316\u6210\u8be5\u7c7b\u578b\u7684\u9ed8\u8ba4\u521d\u59cb\u503c<\/p>\n<p>&#xff08;\u6570\u503c\u578b\u53d8\u91cf\u521d\u59cb\u5316\u62100\u62160.0&#xff0c;\u5b57\u7b26\u578b\u53d8\u91cf\u7684\u521d\u59cb\u5316\u503c\u662f16\u4f4d\u76840&#xff0c;\u5e03\u5c14\u578b\u9ed8\u8ba4\u662ffalse&#xff09;<\/p>\n<\/p>\n<p>public class Employee {<br \/>\n    \/\/salary\u662f\u9759\u6001\u7684\u79c1\u6709\u53d8\u91cf<br \/>\n    private static double salary;<br \/>\n    \/\/ DEPARTMENT\u662f\u4e00\u4e2a\u5e38\u91cf<br \/>\n    public static final String DEPARTMENT &#061; &#034;\u5f00\u53d1\u4eba\u5458&#034;;<br \/>\n    public static void main(String[] args){<br \/>\n        salary &#061; 10000;<br \/>\n        System.out.println(DEPARTMENT&#043;&#034;\u5e73\u5747\u5de5\u8d44:&#034;&#043;salary);<br \/>\n    }<br \/>\n} <\/p>\n<h4 id=\"_3\u3001\u5e38\u91cf\">3\u3001\u5e38\u91cf<\/h4>\n<p>\u5e38\u91cf(Constant)&#xff1a;\u521d\u59cb\u5316(initialize)\u540e\u4e0d\u80fd\u518d\u6539\u53d8\u503c&#xff01;\u4e0d\u4f1a\u53d8\u52a8\u7684\u503c\u3002<\/p>\n<p>\u6240\u8c13\u5e38\u91cf\u53ef\u4ee5\u7406\u89e3\u6210\u4e00\u79cd\u7279\u6b8a\u7684\u53d8\u91cf&#xff0c;\u5b83\u7684\u503c\u88ab\u8bbe\u5b9a\u540e&#xff0c;\u5728\u7a0b\u5e8f\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u4e0d\u5141\u8bb8\u88ab\u6539\u53d8\u3002<\/p>\n<\/p>\n<p>final \u5e38\u91cf\u540d&#061;\u503c;<br \/>\nfinal double PI&#061;3.14;<br \/>\nfinal String LOVE&#061;&#034;hello&#034;; <\/p>\n<p>\u5e38\u91cf\u540d\u4e00\u822c\u4f7f\u7528\u5927\u5199\u5b57\u7b26\u3002<\/p>\n<p>\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u5e38\u91cf\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u7ef4\u62a4\u6027\u3002\u4f8b\u5982&#xff0c;\u5728\u9879\u76ee\u5f00\u53d1\u65f6&#xff0c;\u6211\u4eec\u9700\u8981\u6307\u5b9a\u7528\u6237\u7684\u6027\u522b&#xff0c;\u6b64\u65f6\u53ef\u4ee5 \u5b9a\u4e49\u4e00\u4e2a\u5e38\u91cf SEX&#xff0c;\u8d4b\u503c\u4e3a &#034;\u7537&#034;&#xff0c;\u5728\u9700\u8981\u6307\u5b9a\u7528\u6237\u6027\u522b\u7684\u5730\u65b9\u76f4\u63a5\u8c03\u7528\u6b64\u5e38\u91cf\u5373\u53ef&#xff0c;\u907f\u514d\u4e86\u7531\u4e8e\u7528\u6237\u7684 \u4e0d\u89c4\u8303\u8d4b\u503c\u5bfc\u81f4\u7a0b\u5e8f\u51fa\u9519\u7684\u60c5\u51b5\u3002<\/p>\n<h4 id=\"_4\u3001\u53d8\u91cf\u7684\u547d\u540d\u89c4\u8303\">4\u3001\u53d8\u91cf\u7684\u547d\u540d\u89c4\u8303<\/h4>\n<li>\u6240\u6709\u53d8\u91cf\u3001\u65b9\u6cd5\u3001\u7c7b\u540d&#xff1a;\u89c1\u540d\u77e5\u610f<\/li>\n<li>\u7c7b\u6210\u5458\u53d8\u91cf&#xff1a;\u9996\u5b57\u6bcd\u5c0f\u5199\u548c\u9a7c\u5cf0\u539f\u5219 : monthSalary<\/li>\n<li>\u5c40\u90e8\u53d8\u91cf&#xff1a;\u9996\u5b57\u6bcd\u5c0f\u5199\u548c\u9a7c\u5cf0\u539f\u5219<\/li>\n<li>\u5e38\u91cf&#xff1a;\u5927\u5199\u5b57\u6bcd\u548c\u4e0b\u5212\u7ebf&#xff1a;MAX_VALUE<\/li>\n<li>\u7c7b\u540d&#xff1a;\u9996\u5b57\u6bcd\u5927\u5199\u548c\u9a7c\u5cf0\u539f\u5219: Man&#xff0c;GoodMan<\/li>\n<li>\u65b9\u6cd5\u540d&#xff1a;\u9996\u5b57\u6bcd\u5c0f\u5199\u548c\u9a7c\u5cf0\u539f\u5219: run()&#xff0c;runRun()<\/li>\n<h2>\u4e03\u3001\u8fd0\u7b97\u7b26 \u00a0<\/h2>\n<p>\u8fd0\u7b97\u7b26operator<\/p>\n<p>Java \u8bed\u8a00\u652f\u6301\u5982\u4e0b\u8fd0\u7b97\u7b26&#xff1a;<\/p>\n<ul>\n<li>\u7b97\u672f\u8fd0\u7b97\u7b26 &#043;&#xff0c;-&#xff0c;*&#xff0c;\/&#xff0c;%&#xff0c;&#043;&#043;&#xff0c;&#8211;<\/li>\n<li>\u8d4b\u503c\u8fd0\u7b97\u7b26 &#061;<\/li>\n<li>\u5173\u7cfb\u8fd0\u7b97\u7b26 &gt;&#xff0c;&lt;&#xff0c;&gt;&#061;&#xff0c;&lt;&#061;&#xff0c;&#061;&#061;&#xff0c;!&#061; instanceof<\/li>\n<li>\u903b\u8f91\u8fd0\u7b97\u7b26 &amp;&amp;&#xff0c;||&#xff0c;!<\/li>\n<li>\u4f4d\u8fd0\u7b97\u7b26 &amp;&#xff0c;|&#xff0c;^&#xff0c;~ &#xff0c; &gt;&gt;&#xff0c;&lt;&lt;&#xff0c;&gt;&gt;&gt; (\u4e86\u89e3&#xff01;&#xff01;&#xff01;)<\/li>\n<li>\u6761\u4ef6\u8fd0\u7b97\u7b26 &#xff1f;&#xff1a;<\/li>\n<li>\u6269\u5c55\u8d4b\u503c\u8fd0\u7b97\u7b26 &#043;&#061;&#xff0c;-&#061;&#xff0c;*&#061;&#xff0c;\/&#061;<\/li>\n<\/ul>\n<h4 id=\"_1\u3001\u4e8c\u5143\u8fd0\u7b97\u7b26\">1\u3001\u4e8c\u5143\u8fd0\u7b97\u7b26<\/h4>\n<p>\u4e24\u4e2a\u64cd\u4f5c\u6570&#xff0c;\u6765\u770b\u770b\u6211\u4eec\u5c0f\u65f6\u5019\u7684\u6570\u5b66\u8fd0\u7b97&#xff1b;<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int a &#061; 10;<br \/>\n    int b &#061; 20;<br \/>\n    int c &#061; 25;<br \/>\n    int d &#061; 25;<br \/>\n    System.out.println(&#034;a &#043; b &#061; &#034; &#043; (a &#043; b) );<br \/>\n    System.out.println(&#034;a &#8211; b &#061; &#034; &#043; (a &#8211; b) );<br \/>\n    System.out.println(&#034;a * b &#061; &#034; &#043; (a * b) );<br \/>\n    System.out.println(&#034;b \/ a &#061; &#034; &#043; (b \/ a) );<br \/>\n} <\/p>\n<p>\u6574\u6570\u8fd0\u7b97<\/p>\n<p>\u5982\u679c\u4e24\u4e2a\u64cd\u4f5c\u6570\u6709\u4e00\u4e2a\u4e3aLong&#xff0c;\u5219\u7ed3\u679c\u4e5f\u4e3along<\/p>\n<p>\u6ca1\u6709long\u65f6&#xff0c;\u7ed3\u679c\u4e3aint\u3002\u5373\u4f7f\u64cd\u4f5c\u6570\u5168\u4e3ashot,byte&#xff0c;\u7ed3\u679c\u4e5f\u662fint.<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    long a &#061; 1231321311231231L;<br \/>\n    int b &#061; 1213;<br \/>\n    short c &#061; 10;<br \/>\n    byte d &#061; 8;<\/p>\n<p>    System.out.println(a &#043; b &#043; c &#043; d); \/\/Long\u7c7b\u578b<br \/>\n    System.out.println(b &#043; c &#043; d);\/\/Int\u7c7b\u578b<br \/>\n    System.out.println(c &#043; d);\/\/Int\u7c7b\u578b<br \/>\n} <\/p>\n<p>\u6d6e\u70b9\u8fd0\u7b97<\/p>\n<p>\u5982\u679c\u4e24\u4e2a\u64cd\u4f5c\u6570\u6709\u4e00\u4e2a\u4e3adouble&#xff0c;\u5219\u7ed3\u679c\u4e3adouble<\/p>\n<p>\u53ea\u6709\u4e24\u4e2a\u64cd\u4f5c\u6570\u90fd\u662ffloat&#xff0c;\u5219\u7ed3\u679c\u624d\u4e3afloat<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    float a &#061; 3.14565F;<br \/>\n    double b &#061; 3.194546464;<br \/>\n    float c &#061; 1.3123123F;<br \/>\n    System.out.println(a&#043;b); \/\/double\u7c7b\u578b<br \/>\n    System.out.println(b&#043;c); \/\/double\u7c7b\u578b<br \/>\n    System.out.println(a&#043;c); \/\/float\u7c7b\u578b<br \/>\n} <\/p>\n<p>\u5173\u7cfb\u8fd0\u7b97\u7b26<\/p>\n<p>\u8fd4\u56de\u5e03\u5c14\u503c&#xff01;<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"333\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114045016-69672088bdc5d.png\" width=\"1059\" \/><\/p>\n<p>\u53ef\u53c2\u8003\u00a0\u83dc\u9e1f\u6559\u7a0b<\/p>\n<h4 id=\"_2\u3001\u53d6\u6a21\u8fd0\u7b97\">2\u3001\u53d6\u6a21\u8fd0\u7b97<\/h4>\n<p>\u5c31\u662f\u6211\u4eec\u5c0f\u5b66\u7684\u53d6\u4f59&#xff1b;<\/p>\n<p>5%3 \u4f59 2<\/p>\n<p>\u5176\u64cd\u4f5c\u6570\u53ef\u4ee5\u4e3a\u6d6e\u70b9\u6570,\u4e00\u822c\u4f7f\u7528\u6574\u6570\u3002\u5982&#xff1a;5.9%3.9&#061;2.000000004<\/p>\n<p>\u8981\u70b9&#xff1a;<\/p>\n<p>\u8d1f\u6570%\u8d1f\u6570&#xff1d;\u8d1f\u6570&#xff1b;<\/p>\n<p>\u8d1f\u6570%\u6b63\u6570&#xff1d;\u8d1f\u6570&#xff1b;<\/p>\n<p>\u6b63\u6570%\u8d1f\u6570&#xff1d;\u6b63\u6570&#xff1b;<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    System.out.println(9 % 4); \/\/1<br \/>\n    System.out.println(-9 % -4); \/\/-1<br \/>\n    System.out.println(-10 % 4); \/\/-2<br \/>\n    System.out.println(9 % -4); \/\/1<br \/>\n} <\/p>\n<p>\u3010\u6ce8&#xff1a;\u4e00\u822c\u90fd\u662f\u6b63\u6574\u6570\u8fd0\u7b97&#xff0c;\u8fdb\u884c\u7ed3\u679c\u7684\u5224\u65ad&#xff01;\u3011<\/p>\n<h4 id=\"_3\u3001\u4e00\u5143\u8fd0\u7b97\u7b26\">3\u3001\u4e00\u5143\u8fd0\u7b97\u7b26<\/h4>\n<p>\u81ea\u589e&#xff08;&#043;&#043;&#xff09;\u81ea\u51cf&#xff08;&#8211;&#xff09;\u8fd0\u7b97\u7b26\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u7b97\u672f\u8fd0\u7b97\u7b26&#xff0c;\u5728\u7b97\u672f\u8fd0\u7b97\u7b26\u4e2d\u9700\u8981\u4e24\u4e2a\u64cd\u4f5c\u6570\u6765\u8fdb\u884c\u8fd0\u7b97&#xff0c; \u800c\u81ea\u589e\u81ea\u51cf\u8fd0\u7b97\u7b26\u662f\u4e00\u4e2a\u64cd\u4f5c\u6570&#xff0c;\u5206\u4e3a\u524d\u7f00\u548c\u540e\u7f00\u4e24\u79cd\u3002<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int a &#061; 3;<br \/>\n    int b &#061; a&#043;&#043;; \/\/\u6267\u884c\u5b8c\u540e,b&#061;3\u3002\u5148\u7ed9b\u8d4b\u503c&#xff0c;\u518d\u81ea\u589e\u3002<br \/>\n    int c &#061; &#043;&#043;a; \/\/\u6267\u884c\u5b8c\u540e,c&#061;5\u3002\u5148\u81ea\u589e,\u518d\u7ed9b\u8d4b\u503c<br \/>\n} <\/p>\n<p>\u6ce8\u610f&#xff1a;java\u4e2d\u7684\u4e58\u5e42\u5904\u7406<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int a &#061; 3^2; \/\/java\u4e2d\u4e0d\u80fd\u8fd9\u4e48\u5904\u7406&#xff0c; ^\u662f\u5f02\u6216\u7b26\u53f7\u3002<br \/>\n    double b &#061; Math.pow(3, 2);<br \/>\n} <\/p>\n<p>Math\u7c7b\u63d0\u4f9b\u4e86\u5f88\u591a\u79d1\u5b66\u548c\u5de5\u7a0b\u8ba1\u7b97\u9700\u8981\u7684\u65b9\u6cd5\u548c\u5e38\u6570\u3002\u7279\u6b8a\u7684\u8fd0\u7b97\u90fd\u9700\u8981\u8fd0\u7528\u5230\u65b9\u6cd5!<\/p>\n<h4 id=\"_4\u3001\u903b\u8f91\u8fd0\u7b97\u7b26\">4\u3001\u903b\u8f91\u8fd0\u7b97\u7b26<\/h4>\n<p>\u903b\u8f91\u4e0e&#xff1a;&amp;&amp;\u548c&amp; \u903b\u8f91\u6216&#xff1a;||\u548c| \u903b\u8f91\u975e&#xff1a;&#xff01;<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"223\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114045016-69672088e7cbc.png\" width=\"1068\" \/><\/p>\n<p>\u3010\u6f14\u793a\u3011<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    boolean a &#061; true;<br \/>\n    boolean b &#061; false;<br \/>\n    System.out.println(&#034;a &amp;&amp; b &#061; &#034; &#043; (a&amp;&amp;b));<br \/>\n    System.out.println(&#034;a || b &#061; &#034; &#043; (a||b) );<br \/>\n    System.out.println(&#034;!(a &amp;&amp; b) &#061; &#034; &#043; !(a &amp;&amp; b));<br \/>\n} <\/p>\n<p>\u903b\u8f91\u4e0e\u00a0\u548c\u00a0\u903b\u8f91\u6216\u00a0\u91c7\u7528\u77ed\u8def\u7684\u65b9\u5f0f\u3002\u4ece\u5de6\u5230\u53f3\u8ba1\u7b97&#xff0c;\u5982\u679c\u786e\u5b9a\u503c\u5219\u4e0d\u4f1a\u518d\u8ba1\u7b97\u4e0b\u53bb\u3002\u5728\u4e24\u4e2a\u64cd\u4f5c\u6570\u90fd\u4e3a true\u65f6&#xff0c;\u7ed3\u679c\u624d\u4e3atrue&#xff0c;\u4f46\u662f\u5f53\u5f97\u5230\u7b2c\u4e00\u4e2a\u64cd\u4f5c\u4e3afalse\u65f6&#xff0c;\u5176\u7ed3\u679c\u5c31\u5fc5\u5b9a\u662ffalse&#xff0c;\u8fd9\u65f6\u5019\u5c31\u4e0d\u4f1a\u518d\u5224\u65ad \u7b2c\u4e8c\u4e2a\u64cd\u4f5c\u4e86\u3002<\/p>\n<p>\u903b\u8f91\u4e0e\u53ea\u8981\u6709\u4e00\u4e2a\u4e3afalse&#xff0c;\u5219\u76f4\u63a5\u8fd4\u56defalse.<\/p>\n<p>\u903b\u8f91\u6216\u53ea\u8981\u6709\u4e00\u4e2a\u4e3atrue&#xff0c;\u5219\u76f4\u63a5\u8fd4\u56detrue;<\/p>\n<\/p>\n<p>public static void main(String[] args){<br \/>\n    int a &#061; 5;\/\/\u5b9a\u4e49\u4e00\u4e2a\u53d8\u91cf&#xff1b;<br \/>\n    boolean b &#061; (a&lt;4)&amp;&amp;(a&#043;&#043;&lt;10);<br \/>\n    System.out.println(&#034;\u4f7f\u7528\u77ed\u8def\u903b\u8f91\u8fd0\u7b97\u7b26\u7684\u7ed3\u679c\u4e3a&#034;&#043;b);<br \/>\n    System.out.println(&#034;a\u7684\u7ed3\u679c\u4e3a&#034;&#043;a);<br \/>\n} <\/p>\n<p>\u89e3\u6790&#xff1a; \u8be5\u7a0b\u5e8f\u4f7f\u7528\u5230\u4e86\u77ed\u8def\u903b\u8f91\u8fd0\u7b97\u7b26(&amp;&amp;)&#xff0c;\u9996\u5148\u5224\u65ad a&lt;4 \u7684\u7ed3\u679c\u4e3a false&#xff0c;\u5219 b \u7684\u7ed3\u679c\u5fc5\u5b9a\u662f false&#xff0c; \u6240\u4ee5\u4e0d\u518d\u6267\u884c\u7b2c\u4e8c\u4e2a\u64cd\u4f5c a&#043;&#043;&lt;10 \u7684\u5224\u65ad&#xff0c;\u6240\u4ee5 a \u7684\u503c\u4e3a 5\u3002<\/p>\n<h4 id=\"_5\u3001\u4f4d\u8fd0\u7b97\u7b26\">5\u3001\u4f4d\u8fd0\u7b97\u7b26<\/h4>\n<p>Java\u5b9a\u4e49\u4e86\u4f4d\u8fd0\u7b97\u7b26&#xff0c;\u5e94\u7528\u4e8e\u6574\u6570\u7c7b\u578b(int)&#xff0c;\u957f\u6574\u578b(long)&#xff0c;\u77ed\u6574\u578b(short)&#xff0c;\u5b57\u7b26\u578b(char)&#xff0c;\u548c\u5b57\u8282\u578b (byte)\u7b49\u7c7b\u578b\u3002\u4f4d\u8fd0\u7b97\u7b26\u4f5c\u7528\u5728\u6240\u6709\u7684\u4f4d\u4e0a&#xff0c;\u5e76\u4e14\u6309\u4f4d\u8fd0\u7b97\u3002<\/p>\n<p>\u5047\u8bbea &#061; 60&#xff0c;b &#061; 13;\u5b83\u4eec\u7684\u4e8c\u8fdb\u5236\u683c\u5f0f\u8868\u793a\u5c06\u5982\u4e0b&#xff1a;<\/p>\n<\/p>\n<p>A &#061; 0011 1100<br \/>\nB &#061; 0000 1101<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nA&amp;B &#061; 0000 1100<br \/>\nA | B &#061; 0011 1101<br \/>\nA ^ B &#061; 0011 0001<br \/>\n~A&#061; 1100 0011 <\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"444\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114045017-696720891271d.png\" width=\"1059\" \/><\/p>\n<p>\u53f3\u79fb\u4e00\u4f4d\u76f8\u5f53\u4e8e\u96642\u53d6\u5546\u3002<\/p>\n<p>\u5de6\u79fb\u4e00\u4f4d\u76f8\u5f53\u4e8e\u4e582\u3002<\/p>\n<p>\u3010\u5e38\u89c1\u9762\u8bd5\u9898&#xff1a;int a&#061;2*8\u600e\u6837\u8fd0\u7b97\u6548\u7387\u6700\u5feb&#xff1f;\u3011<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    System.out.println(2 &lt;&lt; 3);<br \/>\n} <\/p>\n<p>\u7528\u79fb\u4f4d\u8fd0\u7b97 int a&#061;2&lt;&lt;3; a\u5c31\u662f2\u4e58\u4ee58 \u6700\u540e\u7ed3\u679c\u662f16 \u8fd9\u662f\u6700\u7701\u5185\u5b58 \u6700\u6709\u6548\u7387\u7684\u65b9\u6cd5<\/p>\n<p>\u8fd9\u4e2a\u65b9\u6cd5\u786e\u5b9e\u9ad8\u6548\u7387\u7684\u3002\u6211\u6765\u89e3\u91ca\u4e00\u4e0b&#xff1a; 2\u7684\u4e8c\u8fdb\u5236\u662f10 \u572832\u4f4d\u5b58\u50a8\u5668\u91cc\u9762\u662f0000 0000 0000 0010 \u5de6\u79fb\u4e09\u4f4d\u540e\u53d8\u6210 0000 0000 0001 0000 \u4e5f\u5c31\u662f16<\/p>\n<p>\u89e3\u91ca\u4e00\u4e0b&#xff0c;\u5728\u7cfb\u7edf\u4e2d\u8fd0\u7b97\u662f\u4ee5\u4e8c\u8fdb\u5236\u7684\u5f62\u5f0f\u8fdb\u884c\u7684\u3002\u76f8\u6bd4\u6765\u8bf4\u4fe9\u4e2a\u4e8c\u8fdb\u5236\u6570\u76f8\u4e58\u8fd0\u7b97\u6bd4\u79fb\u4f4d\u8fd0\u7b97\u6162\u4e00 \u4e9b\u3002<\/p>\n<p>\u4f4d\u64cd\u4f5c\u662f\u7a0b\u5e8f\u8bbe\u8ba1\u4e2d\u5bf9\u4f4d\u6a21\u5f0f\u6309\u4f4d\u6216\u4e8c\u8fdb\u5236\u6570\u7684\u4e00\u5143\u548c\u4e8c\u5143\u64cd\u4f5c\u3002 \u5728\u8bb8\u591a\u53e4\u8001\u7684\u5fae\u5904\u7406\u5668\u4e0a&#xff0c; \u4f4d\u8fd0\u7b97\u6bd4\u52a0\u51cf\u8fd0\u7b97\u7565\u5feb&#xff0c; \u901a\u5e38\u4f4d\u8fd0\u7b97\u6bd4\u4e58\u9664\u6cd5\u8fd0\u7b97\u8981\u5feb\u5f88\u591a\u3002 \u5728\u73b0\u4ee3\u67b6\u6784\u4e2d&#xff0c; \u60c5\u51b5\u5e76\u975e\u5982\u6b64&#xff1a;\u4f4d\u8fd0\u7b97\u7684\u8fd0\u7b97\u901f\u5ea6 \u901a\u5e38\u4e0e\u52a0\u6cd5\u8fd0\u7b97\u76f8\u540c(\u4ecd\u7136\u5feb\u4e8e\u4e58\u6cd5\u8fd0\u7b97). \u8be6\u7ec6\u7684\u9700\u8981\u4e86\u89e3\u8ba1\u7b97\u673a\u7684\u7ec4\u6210\u539f\u7406&#xff01;<\/p>\n<h4 id=\"_6\u3001\u6269\u5c55\u8fd0\u7b97\u7b26\">6\u3001\u6269\u5c55\u8fd0\u7b97\u7b26<\/h4>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"402\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114045017-6967208943ef9.png\" width=\"619\" \/><\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int a&#061;10;<br \/>\n    int b&#061;20;<\/p>\n<p>    a&#043;&#061;b; \/\/ a &#061; a &#043; b<\/p>\n<p>    System.out.println(a&#043;&#034;:&#034;&#043;b);<br \/>\n} <\/p>\n<h4 id=\"_7\u3001\u5b57\u7b26\u4e32\u8fde\u63a5\u7b26\">7\u3001\u5b57\u7b26\u4e32\u8fde\u63a5\u7b26<\/h4>\n<p>\u201c&#043;\u201d \u8fd0\u7b97\u7b26\u4e24\u4fa7\u7684\u64cd\u4f5c\u6570\u4e2d\u53ea\u8981\u6709\u4e00\u4e2a\u662f\u5b57\u7b26\u4e32(String)\u7c7b\u578b&#xff0c;\u7cfb\u7edf\u4f1a\u81ea\u52a8\u5c06\u53e6\u4e00\u4e2a\u64cd\u4f5c\u6570\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32 \u7136\u540e\u518d\u8fdb\u884c\u8fde\u63a5\u3002<\/p>\n<\/p>\n<p>\/\/\u5b57\u7b26\u4e32<br \/>\nString s1&#061;&#034;Hello \u4e2d\u6587!&#034;;<br \/>\nString s2&#061;1&#043;&#034;&#034;; \/\/\u8f6c\u6362\u6210String<br \/>\n\/\/int<br \/>\nint c &#061; 12;<br \/>\nSystem.out.println(&#034;c&#061;&#034; &#043; c); <\/p>\n<h4 id=\"_8\u3001\u4e09\u76ee\u6761\u4ef6\u8fd0\u7b97\u7b26\">8\u3001\u4e09\u76ee\u6761\u4ef6\u8fd0\u7b97\u7b26<\/h4>\n<p>\u4e09\u76ee\u6761\u4ef6\u8fd0\u7b97\u7b26&#xff0c;\u8bed\u6cd5\u683c\u5f0f&#xff1a;<\/p>\n<p>x ? y : z<\/p>\n<p>\u5176\u4e2dx\u4e3aboolean\u7c7b\u578b\u8868\u8fbe\u5f0f&#xff0c;\u5148\u8ba1\u7b97x\u7684\u503c&#xff0c;\u82e5\u4e3atrue&#xff0c;\u5219\u6574\u4e2a\u4e09\u76ee\u8fd0\u7b97\u7684\u7ed3\u679c\u4e3a\u8868\u8fbe\u5f0fy\u7684\u503c&#xff0c;\u5426\u5219\u6574\u4e2a\u8fd0\u7b97\u7ed3\u679c\u4e3a\u8868\u8fbe\u5f0fz\u7684\u503c\u3002<\/p>\n<p>\u3010\u6f14\u793a\u3011<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int score &#061; 80;<br \/>\n    String type &#061; score &lt; 60 ? &#034;\u4e0d\u53ca\u683c&#034; : &#034;\u53ca\u683c&#034;;<br \/>\n    System.out.println(&#034;type&#061; &#034; &#043; type);<br \/>\n} <\/p>\n<p>\u4e09\u5143\u8fd0\u7b97\u7b26\u5728\u771f\u5b9e\u5f00\u53d1\u4e2d\u5341\u5206\u7684\u5e38\u89c1&#xff0c;\u5927\u5bb6\u53ef\u4ee5\u591a\u7ec3\u4e60\u4f7f\u7528&#xff0c;\u4e4b\u540e\u6211\u4eec\u4f1a\u8bb2\u89e3\u5206\u652f\u8bed\u53e5&#xff0c;\u53ef\u4ee5\u5229\u7528\u4e09\u5143\u8fd0\u7b97\u7b26\u505a\u5230\u66f4\u52a0\u7cbe\u7b80\u4ee3\u7801&#xff01;\u4fbf\u4e8e\u7406\u89e3&#xff01;<\/p>\n<h4 id=\"_9\u3001\u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7\">9\u3001\u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7<\/h4>\n<p>\u6211\u4eec\u5c0f\u5b66\u90fd\u5b66\u8fc7&#xff1a;\u5148\u52a0\u51cf&#xff0c;\u540e\u4e58\u9664&#xff0c;\u6240\u4ee5\u4f18\u5148\u7ea7\u6211\u4eec\u5e76\u4e0d\u964c\u751f\u3002<\/p>\n<p>\u5f53\u591a\u4e2a\u8fd0\u7b97\u7b26\u51fa\u73b0\u5728\u4e00\u4e2a\u8868\u8fbe\u5f0f\u4e2d&#xff0c;\u8c01\u5148\u8c01\u540e\u5462&#xff1f;\u8fd9\u5c31\u6d89\u53ca\u5230\u8fd0\u7b97\u7b26\u7684\u4f18\u5148\u7ea7\u522b\u7684\u95ee\u9898\u3002\u5728\u4e00\u4e2a\u591a\u8fd0\u7b97\u7b26\u7684\u8868\u8fbe\u5f0f\u4e2d&#xff0c;\u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7\u4e0d\u540c\u4f1a\u5bfc\u81f4\u6700\u540e\u5f97\u51fa\u7684\u7ed3\u679c\u5dee\u522b\u751a\u5927\u3002<\/p>\n<p>\u4e0b\u8868\u4e2d\u5177\u6709\u6700\u9ad8\u4f18\u5148\u7ea7\u7684\u8fd0\u7b97\u7b26\u5728\u7684\u8868\u7684\u6700\u4e0a\u9762&#xff0c;\u6700\u4f4e\u4f18\u5148\u7ea7\u7684\u5728\u8868\u7684\u5e95\u90e8\u3002<\/p>\n<table>\n<tr>\u7c7b\u522b\u64cd\u4f5c\u7b26\u5173\u8054\u6027<\/tr>\n<tbody>\n<tr>\n<td>\u540e\u7f00<\/td>\n<td>() [] . (\u70b9\u64cd\u4f5c\u7b26)<\/td>\n<td>\u5de6\u5230\u53f3<\/td>\n<\/tr>\n<tr>\n<td>\u4e00\u5143<\/td>\n<td>expr&#043;&#043; expr&#8211;<\/td>\n<td>\u4ece\u5de6\u5230\u53f3<\/td>\n<\/tr>\n<tr>\n<td>\u4e00\u5143<\/td>\n<td>&#043;&#043;expr &#8211;expr &#043; &#8211; &#xff5e; &#xff01;<\/td>\n<td>\u4ece\u53f3\u5230\u5de6<\/td>\n<\/tr>\n<tr>\n<td>\u4e58\u6027<\/td>\n<td>* \/&#xff05;<\/td>\n<td>\u5de6\u5230\u53f3<\/td>\n<\/tr>\n<tr>\n<td>\u52a0\u6027<\/td>\n<td>&#043; &#8211;<\/td>\n<td>\u5de6\u5230\u53f3<\/td>\n<\/tr>\n<tr>\n<td>\u79fb\u4f4d<\/td>\n<td>&gt;&gt; &gt;&gt;&gt; &lt;&lt;<\/td>\n<td>\u5de6\u5230\u53f3<\/td>\n<\/tr>\n<tr>\n<td>\u5173\u7cfb<\/td>\n<td>&gt; &gt;&#061; &lt; &lt;&#061;<\/td>\n<td>\u5de6\u5230\u53f3<\/td>\n<\/tr>\n<tr>\n<td>\u76f8\u7b49<\/td>\n<td>&#061;&#061; !&#061;<\/td>\n<td>\u5de6\u5230\u53f3<\/td>\n<\/tr>\n<tr>\n<td>\u6309\u4f4d\u4e0e<\/td>\n<td>&#xff06;<\/td>\n<td>\u5de6\u5230\u53f3<\/td>\n<\/tr>\n<tr>\n<td>\u6309\u4f4d\u5f02\u6216<\/td>\n<td>^<\/td>\n<td>\u5de6\u5230\u53f3<\/td>\n<\/tr>\n<tr>\n<td>\u6309\u4f4d\u6216<\/td>\n<td>|<\/td>\n<td>\u5de6\u5230\u53f3<\/td>\n<\/tr>\n<tr>\n<td>\u903b\u8f91\u4e0e<\/td>\n<td>&amp;&amp;<\/td>\n<td>\u5de6\u5230\u53f3<\/td>\n<\/tr>\n<tr>\n<td>\u903b\u8f91\u6216<\/td>\n<td>| |<\/td>\n<td>\u5de6\u5230\u53f3<\/td>\n<\/tr>\n<tr>\n<td>\u6761\u4ef6<\/td>\n<td>&#xff1f;&#xff1a;<\/td>\n<td>\u4ece\u53f3\u5230\u5de6<\/td>\n<\/tr>\n<tr>\n<td>\u8d4b\u503c<\/td>\n<td>&#061; &#043; &#061; &#8211; &#061; * &#061; \/ &#061;&#xff05;&#061; &gt;&gt; &#061; &lt;&lt; &#061;&#xff06;&#061; ^ &#061; | &#061;<\/td>\n<td>\u4ece\u53f3\u5230\u5de6<\/td>\n<\/tr>\n<tr>\n<td>\u9017\u53f7<\/td>\n<td>&#xff0c;<\/td>\n<td>\u5de6\u5230\u53f3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5927\u5bb6\u4e0d\u9700\u8981\u53bb\u523b\u610f\u7684\u8bb0\u4f4f&#xff0c;\u8868\u8fbe\u5f0f\u91cc\u9762\u4f18\u5148\u4f7f\u7528\u5c0f\u62ec\u53f7\u6765\u7ec4\u7ec7&#xff01;&#xff01;\u65b9\u4fbf\u7406\u89e3\u548c\u4f7f\u7528&#xff0c;\u4e0d\u5efa\u8bae\u5199\u975e\u5e38\u5197\u4f59 \u7684\u4ee3\u7801\u8fd0\u7b97&#xff01;<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    boolean flag &#061; 1&lt;4*5&amp;&amp;122&gt;3||&#039;q&#039;&#043;3&lt;5;<br \/>\n    System.out.println(flag);<br \/>\n} <\/p>\n<h2>\u516b\u3001\u5305\u673a\u5236 \u00a0<\/h2>\n<h3 id=\"_1\u3001\u95ee\u9898\u53d1\u73b0\">1\u3001\u95ee\u9898\u53d1\u73b0<\/h3>\n<p>\u5b58\u5728\u8fd9\u6837\u4e00\u4e2a\u95ee\u9898&#xff1a;\u5f53\u5b9a\u4e49\u4e86\u591a\u4e2a\u7c7b\u7684\u65f6\u5019&#xff0c;\u53ef\u80fd\u4f1a\u53d1\u751f\u7c7b\u540d\u7684\u91cd\u590d\u95ee\u9898\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u5f0f&#xff1a;\u5728java\u4e2d\u91c7\u7528\u5305\u673a\u5236\u5904\u7406\u5f00\u53d1\u8005\u5b9a\u4e49\u7684\u7c7b\u540d\u51b2\u7a81\u95ee\u9898\u3002<\/p>\n<p>\u5c31\u597d\u6bd4\u6211\u4eec\u5e73\u65f6\u7684\u7528\u7535\u8111&#xff0c;\u4e00\u4e2a\u6587\u4ef6\u5939\u4e0b\u4e0d\u80fd\u5b58\u5728\u540c\u540d\u7684\u6587\u4ef6&#xff0c;\u6211\u4eec\u8981\u662f\u6709\u8fd9\u6837\u7684\u9700\u6c42&#xff0c;\u4f46\u662f\u53c8\u4e0d\u60f3\u6362 \u540d\u5b57&#xff0c;\u6211\u4eec\u5c31\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u65b0\u5efa\u4e00\u4e2a\u6587\u4ef6\u5939\u6765\u5b58\u653e&#xff01;\u5728\u6211\u4eec\u7684Java\u4e2d\u4e5f\u662f\u8fd9\u6837\u7684\u3002<\/p>\n<p>\u6211\u4eec\u5728idea\u4e2d\u521b\u5efa\u5305&#xff0c;\u8f93\u5165\u4ee3\u7801\u540e&#xff0c;\u7b2c\u4e00\u884cidea\u9ed8\u8ba4\u4f1a\u6709&#xff1a;package \u5305\u540d\u8def\u5f84&#xff0c;\u4f8b\u5982<\/p>\n<p>\u5c31\u8981\u6c42\u6b64\u4efdjava\u6587\u4ef6\u5fc5\u987b\u4fdd\u5b58\u5728\u8fd9\u6837\u4e00\u4e2a\u76ee\u5f55\u4e0b&#xff0c;\u8fd9\u6837Java\u89e3\u91ca\u5668\u624d\u80fd\u627e\u5230\u5b83\u3002 \u5728IDEA\u4e2d\u80fd\u6b63\u786e\u8fd0\u884c&#xff0c; \u4f60\u53ef\u4ee5\u53bbWindows\u4e0b\u7684\u5de5\u7a0b\u4e2d\u67e5\u770b&#xff0c;HelloWorld\u8fd9\u4e2a\u6587\u4ef6\u5fc5\u662f\u5728\u8fd9\u6837\u7684\u76ee\u5f55\u7ed3\u6784\u4e0b\u7684\u3002<\/p>\n<p>3-6\u884c\u662f\u6587\u6863\u6ce8\u91ca&#xff0c;\u4fbf\u4e8e\u628ajava\u6587\u4ef6\u6253\u5305\u6210\u6587\u6863\u81ea\u52a8\u751f\u6210\u6587\u4ef6\u4fe1\u606f&#xff0c;\u4ee5\u540e\u4f1a\u9047\u5230&#xff0c;\u5728\u963f\u91cc\u5df4\u5df4\u5f00\u53d1\u624b\u518c\u4e2d&#xff0c;\u8981\u6c42\u6dfb\u52a0&#064;author\u7684\u6ce8\u91ca\u4fe1\u606f &#xff0c;\u53ef\u4ee5\u4e0b\u8f7d\u4e2a\u963f\u91cc\u5df4\u5df4\u5f00\u53d1\u624b\u518c\u63d2\u4ef6\u914d\u7f6e\u5728ide\u91cc<\/p>\n<h3 id=\"_2\u3001\u5305\u7684\u4f5c\u7528\">2\u3001\u5305\u7684\u4f5c\u7528<\/h3>\n<p>\u4e3a\u4e86\u66f4\u597d\u5730\u7ec4\u7ec7\u7c7b&#xff0c;Java \u63d0\u4f9b\u4e86\u5305\u673a\u5236&#xff0c;\u7528\u4e8e\u533a\u522b\u7c7b\u540d\u7684\u547d\u540d\u7a7a\u95f4\u3002<\/p>\n<p>\u5305\u7684\u4f5c\u7528&#xff1a;<\/p>\n<p>1\u3001\u628a\u529f\u80fd\u76f8\u4f3c\u6216\u76f8\u5173\u7684\u7c7b\u6216\u63a5\u53e3\u7ec4\u7ec7\u5728\u540c\u4e00\u4e2a\u5305\u4e2d&#xff0c;\u65b9\u4fbf\u7c7b\u7684\u67e5\u627e\u548c\u4f7f\u7528\u3002<\/p>\n<p>2\u3001\u5982\u540c\u6587\u4ef6\u5939\u4e00\u6837&#xff0c;\u5305\u4e5f\u91c7\u7528\u4e86\u6811\u5f62\u76ee\u5f55\u7684\u5b58\u50a8\u65b9\u5f0f\u3002\u540c\u4e00\u4e2a\u5305\u4e2d\u7684\u7c7b\u540d\u5b57\u662f\u4e0d\u540c\u7684&#xff0c;\u4e0d\u540c\u7684\u5305\u4e2d\u7684\u7c7b\u7684\u540d\u5b57\u662f\u53ef\u4ee5\u76f8\u540c\u7684&#xff0c;\u5f53\u540c\u65f6\u8c03\u7528\u4e24\u4e2a\u4e0d\u540c\u5305\u4e2d\u76f8\u540c\u7c7b\u540d\u7684\u7c7b\u65f6&#xff0c;\u5e94\u8be5\u52a0\u4e0a\u5305\u540d\u52a0\u4ee5\u533a\u522b\u3002\u56e0\u6b64&#xff0c;\u5305\u53ef\u4ee5\u907f\u514d\u540d\u5b57\u51b2\u7a81\u3002<\/p>\n<p>3\u3001\u5305\u4e5f\u9650\u5b9a\u4e86\u8bbf\u95ee\u6743\u9650&#xff0c;\u62e5\u6709\u5305\u8bbf\u95ee\u6743\u9650\u7684\u7c7b\u624d\u80fd\u8bbf\u95ee\u67d0\u4e2a\u5305\u4e2d\u7684\u7c7b\u3002<\/p>\n<p>Java \u4f7f\u7528\u5305&#xff08;package&#xff09;\u8fd9\u79cd\u673a\u5236\u662f\u4e3a\u4e86\u9632\u6b62\u547d\u540d\u51b2\u7a81&#xff0c;\u8bbf\u95ee\u63a7\u5236&#xff0c;\u63d0\u4f9b\u641c\u7d22\u548c\u5b9a\u4f4d\u7c7b&#xff08;class&#xff09;\u3001\u63a5\u53e3\u3001\u679a\u4e3e&#xff08;enumerations&#xff09;\u548c\u6ce8\u91ca&#xff08;annotation&#xff09;\u7b49\u3002<\/p>\n<p>\u5305\u8bed\u53e5\u7684\u8bed\u6cd5\u683c\u5f0f\u4e3a&#xff1a;<\/p>\n<\/p>\n<p>package pkg1[&#xff0e;pkg2[&#xff0e;pkg3\u2026]]; <\/p>\n<p>\u4f8b\u5982,\u4e00\u4e2aSomething.java \u6587\u4ef6\u5b83\u7684\u5185\u5bb9:<\/p>\n<\/p>\n<p>package net.java.util;<br \/>\npublic class Something{<br \/>\n&#8230;<br \/>\n} <\/p>\n<p>\u90a3\u4e48\u5b83\u7684\u8def\u5f84\u5e94\u8be5\u662f net\/java\/util\/Something.java \u8fd9\u6837\u4fdd\u5b58\u7684\u3002<\/p>\n<p>package(\u5305) \u7684\u4f5c\u7528\u662f\u628a\u4e0d\u540c\u7684 java \u7a0b\u5e8f\u5206\u7c7b\u4fdd\u5b58&#xff0c;\u66f4\u65b9\u4fbf\u7684\u88ab\u5176\u4ed6 java \u7a0b\u5e8f\u8c03\u7528\u3002<\/p>\n<p>\u4e00\u4e2a\u5305&#xff08;package&#xff09;\u53ef\u4ee5\u5b9a\u4e49\u4e3a\u4e00\u7ec4\u76f8\u4e92\u8054\u7cfb\u7684\u7c7b\u578b&#xff08;\u7c7b\u3001\u63a5\u53e3\u3001\u679a\u4e3e\u548c\u6ce8\u91ca&#xff09;&#xff0c;\u4e3a\u8fd9\u4e9b\u7c7b\u578b\u63d0\u4f9b\u8bbf\u95ee \u4fdd\u62a4\u548c\u547d\u540d\u7a7a\u95f4\u7ba1\u7406\u7684\u529f\u80fd\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b Java \u4e2d\u7684\u5305&#xff1a;<\/p>\n<ul>\n<li>java.lang-\u6253\u5305\u57fa\u7840\u7684\u7c7b<\/li>\n<li>java.io-\u5305\u542b\u8f93\u5165\u8f93\u51fa\u529f\u80fd\u7684\u51fd\u6570<\/li>\n<\/ul>\n<p>\u5f00\u53d1\u8005\u53ef\u4ee5\u81ea\u5df1\u628a\u4e00\u7ec4\u7c7b\u548c\u63a5\u53e3\u7b49\u6253\u5305&#xff0c;\u5e76\u5b9a\u4e49\u81ea\u5df1\u7684\u5305\u3002\u800c\u4e14\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u8fd9\u6837\u505a\u662f\u503c\u5f97\u63d0\u5021\u7684&#xff0c;\u5f53\u4f60\u81ea\u5df1\u5b8c\u6210\u7c7b\u7684\u5b9e\u73b0\u4e4b\u540e&#xff0c;\u5c06\u76f8\u5173\u7684\u7c7b\u5206\u7ec4&#xff0c;\u53ef\u4ee5\u8ba9\u5176\u4ed6\u7684\u7f16\u7a0b\u8005\u66f4\u5bb9\u6613\u5730\u786e\u5b9a\u54ea\u4e9b\u7c7b\u3001\u63a5\u53e3\u3001\u679a\u4e3e\u548c \u6ce8\u91ca\u7b49\u662f\u76f8\u5173\u7684\u3002<\/p>\n<p>\u7531\u4e8e\u5305\u521b\u5efa\u4e86\u65b0\u7684\u547d\u540d\u7a7a\u95f4&#xff08;namespace&#xff09;&#xff0c;\u6240\u4ee5\u4e0d\u4f1a\u8ddf\u5176\u4ed6\u5305\u4e2d\u7684\u4efb\u4f55\u540d\u5b57\u4ea7\u751f\u547d\u540d\u51b2\u7a81\u3002\u4f7f\u7528\u5305\u8fd9 \u79cd\u673a\u5236&#xff0c;\u66f4\u5bb9\u6613\u5b9e\u73b0\u8bbf\u95ee\u63a7\u5236&#xff0c;\u5e76\u4e14\u8ba9\u5b9a\u4f4d\u76f8\u5173\u7c7b\u66f4\u52a0\u7b80\u5355\u3002<\/p>\n<h3 id=\"_3\u3001\u521b\u5efa\u5305\">3\u3001\u521b\u5efa\u5305<\/h3>\n<p>\u521b\u5efa\u5305\u7684\u65f6\u5019&#xff0c;\u4f60\u9700\u8981\u4e3a\u8fd9\u4e2a\u5305\u53d6\u4e00\u4e2a\u5408\u9002\u7684\u540d\u5b57\u3002\u4e4b\u540e&#xff0c;\u5982\u679c\u5176\u4ed6\u7684\u4e00\u4e2a\u6e90\u6587\u4ef6\u5305\u542b\u4e86\u8fd9\u4e2a\u5305\u63d0\u4f9b\u7684\u7c7b\u3001\u63a5\u53e3\u3001\u679a\u4e3e\u6216\u8005\u6ce8\u91ca\u7c7b\u578b\u7684\u65f6\u5019&#xff0c;\u90fd\u5fc5\u987b\u5c06\u8fd9\u4e2a\u5305\u7684\u58f0\u660e\u653e\u5728\u8fd9\u4e2a\u6e90\u6587\u4ef6\u7684\u5f00\u5934\u3002<\/p>\n<p>\u5305\u58f0\u660e\u5e94\u8be5\u5728\u6e90\u6587\u4ef6\u7684\u7b2c\u4e00\u884c&#xff0c;\u6bcf\u4e2a\u6e90\u6587\u4ef6\u53ea\u80fd\u6709\u4e00\u4e2a\u5305\u58f0\u660e&#xff0c;\u8fd9\u4e2a\u6587\u4ef6\u4e2d\u7684\u6bcf\u4e2a\u7c7b\u578b\u90fd\u5e94\u7528\u4e8e\u5b83\u3002<\/p>\n<p>\u5982\u679c\u4e00\u4e2a\u6e90\u6587\u4ef6\u4e2d\u6ca1\u6709\u4f7f\u7528\u5305\u58f0\u660e&#xff0c;\u90a3\u4e48\u5176\u4e2d\u7684\u7c7b&#xff0c;\u51fd\u6570&#xff0c;\u679a\u4e3e&#xff0c;\u6ce8\u91ca\u7b49\u5c06\u88ab\u653e\u5728\u4e00\u4e2a\u65e0\u540d\u7684\u5305 &#xff08;unnamed package&#xff09;\u4e2d\u3002<\/p>\n<p>\u4e00\u822c\u5229\u7528\u516c\u53f8\u57df\u540d\u5012\u7f6e\u4f5c\u4e3a\u62a5\u540d&#xff1b;<\/p>\n<p>\u4f8b\u5b50&#xff1a;<\/p>\n<p>www.baidu.com \u5305\u540d&#xff1a;com.baidu.www<\/p>\n<p>bbs.baidu.com \u5305\u540d&#xff1a;com.baidu.bbs<\/p>\n<p>\u6211\u4eec\u5e73\u65f6\u4e5f\u53ef\u4ee5\u6309\u7167\u81ea\u5df1\u7684\u516c\u53f8\u57df\u540d\u53bb\u5199&#xff0c;\u6bd4\u5982&#xff1a;com.kuangstudy.utils<\/p>\n<h3 id=\"_4\u3001import-\u5173\u952e\u5b57\">4\u3001import \u5173\u952e\u5b57<\/h3>\n<p>\u4e3a\u4e86\u80fd\u591f\u4f7f\u7528\u67d0\u4e00\u4e2a\u5305\u7684\u6210\u5458&#xff0c;\u6211\u4eec\u9700\u8981\u5728 Java \u7a0b\u5e8f\u4e2d\u660e\u786e\u5bfc\u5165\u8be5\u5305\u3002\u4f7f\u7528 &#034;import&#034; \u8bed\u53e5\u53ef\u5b8c\u6210\u6b64\u529f\u80fd\u3002<\/p>\n<p>\u5728 java \u6e90\u6587\u4ef6\u4e2d import \u8bed\u53e5\u5e94\u4f4d\u4e8e package \u8bed\u53e5\u4e4b\u540e&#xff0c;\u6240\u6709\u7c7b\u7684\u5b9a\u4e49\u4e4b\u524d&#xff0c;\u53ef\u4ee5\u6ca1\u6709&#xff0c;\u4e5f\u53ef\u4ee5\u6709\u591a\u6761&#xff0c;\u5176\u8bed\u6cd5\u683c\u5f0f\u4e3a&#xff1a;<\/p>\n<\/p>\n<p>import package1[.package2\u2026].(classname|*); <\/p>\n<p>\u5982\u679c\u5728\u4e00\u4e2a\u5305\u4e2d&#xff0c;\u4e00\u4e2a\u7c7b\u60f3\u8981\u4f7f\u7528\u672c\u5305\u4e2d\u7684\u53e6\u4e00\u4e2a\u7c7b&#xff0c;\u90a3\u4e48\u8be5\u5305\u540d\u53ef\u4ee5\u7701\u7565\u3002<\/p>\n<p>\u8981\u662f\u8981\u7528\u5230\u5176\u4ed6\u5305\u4e0b\u7684\u7c7b&#xff0c;\u5c31\u5fc5\u987b\u8981\u5148\u5bfc\u5305&#xff01;<\/p>\n<p>\u5982\u679c\u4e24\u4e2a\u7c7b\u91cd\u540d&#xff0c;\u9700\u8981\u5bfc\u5165\u5bf9\u5e94\u7684\u5305&#xff0c;\u5426\u5219\u5c31\u9700\u8981\u5199\u51fa\u5b8c\u6574\u5730\u5740&#xff1a;<\/p>\n<\/p>\n<p>com.kuang.dao.Hello hello &#061; new com.kuang.dao.Hello() <\/p>\n<p>\u7528\u00a0import\u00a0\u5173\u952e\u5b57\u5f15\u5165&#xff0c;\u4f7f\u7528\u901a\u914d\u7b26 &#034;*&#034;&#xff0c;\u5bfc\u5165io\u5305\u4e0b\u7684\u6240\u6709\u7c7b&#xff01;<\/p>\n<\/p>\n<p>import java.io.*; <\/p>\n<p>\u3010\u4e0d\u5efa\u8bae\u8fd9\u6837\u4f7f\u7528&#xff0c;\u56e0\u4e3a\u4f1a\u5168\u5c40\u626b\u63cf&#xff0c;\u5f71\u54cd\u901f\u5ea6&#xff01;\u3011<\/p>\n<p>\u4f7f\u7528\u00a0import\u00a0\u5173\u952e\u5b57\u5f15\u5165\u6307\u5b9a\u7c7b:<\/p>\n<\/p>\n<p>import com.kuang.Hello; <\/p>\n<p>\u3010\u6ce8\u610f\u3011\u7c7b\u6587\u4ef6\u4e2d\u53ef\u4ee5\u5305\u542b\u4efb\u610f\u6570\u91cf\u7684 import \u58f0\u660e\u3002import \u58f0\u660e\u5fc5\u987b\u5728\u5305\u58f0\u660e\u4e4b\u540e&#xff0c;\u7c7b\u58f0\u660e\u4e4b\u524d\u3002<\/p>\n<h2>\u4e5d\u3001JavaDoc \u00a0<\/h2>\n<h4 id=\"_1\u3001\u7b80\u4ecb\">1\u3001\u7b80\u4ecb<\/h4>\n<p>JavaDoc\u662f\u4e00\u79cd\u5c06\u6ce8\u91ca\u751f\u6210HTML\u6587\u6863\u7684\u6280\u672f&#xff0c;\u751f\u6210\u7684HTML\u6587\u6863\u7c7b\u4f3c\u4e8eJava\u7684API&#xff0c;\u6613\u8bfb\u4e14\u6e05\u6670\u660e\u4e86\u3002 \u5728\u7b80\u7565\u4ecb\u7ecdJavaDoc\u5199\u6cd5\u4e4b\u540e&#xff0c;\u518d\u770b\u4e00\u4e0b\u5728Intellij Idea \u4e2d\u5982\u4f55\u5c06\u4ee3\u7801\u4e2d\u7684\u6ce8\u91ca\u751f\u6210HTML\u6587\u6863\u3002<\/p>\n<p>javadoc\u662fSun\u516c\u53f8\u63d0\u4f9b\u7684\u4e00\u4e2a\u6280\u672f&#xff0c;\u5b83\u4ece\u7a0b\u5e8f\u6e90\u4ee3\u7801\u4e2d\u62bd\u53d6\u7c7b\u3001\u65b9\u6cd5\u3001\u6210\u5458\u7b49\u6ce8\u91ca\u5f62\u6210\u4e00\u4e2a\u548c\u6e90\u4ee3\u7801\u914d \u5957\u7684API\u5e2e\u52a9\u6587\u6863\u3002\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u53ea\u8981\u5728\u7f16\u5199\u7a0b\u5e8f\u65f6\u4ee5\u4e00\u5957\u7279\u5b9a\u7684\u6807\u7b7e\u4f5c\u6ce8\u91ca&#xff0c;\u5728\u7a0b\u5e8f\u7f16\u5199\u5b8c\u6210\u540e&#xff0c;\u901a\u8fc7 Javadoc\u5c31\u53ef\u4ee5\u540c\u65f6\u5f62\u6210\u7a0b\u5e8f\u7684\u5f00\u53d1\u6587\u6863\u4e86\u3002javadoc\u547d\u4ee4\u662f\u7528\u6765\u751f\u6210\u81ea\u5df1API\u6587\u6863\u7684&#xff0c;\u4f7f\u7528\u65b9\u5f0f&#xff1a;\u4f7f\u7528 \u547d\u4ee4\u884c\u5728\u76ee\u6807\u6587\u4ef6\u6240\u5728\u76ee\u5f55\u8f93\u5165javadoc &#043;\u6587\u4ef6\u540d.java\u3002<\/p>\n<p>\u5148\u770b\u4e00\u6bb5\u6837\u4f8b\u4ee3\u7801&#xff1a;<\/p>\n<\/p>\n<p>\/**<br \/>\n * \u8fd9\u662f\u4e00\u4e2aJavadoc\u6d4b\u8bd5\u7a0b\u5e8f<br \/>\n *<br \/>\n * &#064;author Kuangshen<br \/>\n * &#064;version 1.0<br \/>\n * &#064;since 1.5<br \/>\n *\/<br \/>\npublic class HelloWorld {<br \/>\n    public String name;<\/p>\n<p>    \/**<br \/>\n     * &#064;param name \u59d3\u540d<br \/>\n     * &#064;return \u8fd4\u56dename\u59d3\u540d<br \/>\n     * &#064;throws Exception \u65e0\u5f02\u5e38\u629b\u51fa<br \/>\n     *\/<br \/>\n    public String function(String name) throws Exception {<br \/>\n        return name;<br \/>\n    }<\/p>\n<p>} <\/p>\n<p>\u89e3\u91ca\u4e00\u4e0b&#xff1a; \u4ee5 \/* \u5f00\u59cb&#xff0c;\u4ee5 \/ \u7ed3\u675f\u3002 &#064;author \u4f5c\u8005\u540d &#064;version \u7248\u672c\u53f7 &#064;since \u6307\u660e\u9700\u8981\u6700\u65e9\u4f7f\u7528\u7684jdk\u7248\u672c &#064;param \u53c2\u6570\u540d &#064;return \u8fd4\u56de\u503c\u60c5\u51b5 &#064;throws \u5f02\u5e38\u629b\u51fa\u60c5\u51b5<\/p>\n<h4 id=\"_2\u3001\u547d\u4ee4\u884c\u751f\u6210doc\">2\u3001\u547d\u4ee4\u884c\u751f\u6210Doc<\/h4>\n<p>\u6253\u5f00cmd<\/p>\n<p>\u5207\u6362\u5230\u6587\u4ef6\u5f53\u524d\u76ee\u5f55\u00a0cd \/d E:\\\\java\\\\study\\\\package\\\\test<\/p>\n<p>\u8f93\u5165\u6307\u4ee4&#xff1a; javadoc HelloWorld.java<\/p>\n<p>\u4e00\u822c\u4f1a\u52a0\u4e0a-encoding UTF-8 -charset UTF-8\u00a0\u89e3\u51b3GBK\u4e71\u7801\u95ee\u9898&#xff0c;\u5728\u4e2d\u95f4\u6dfb\u52a0\u7f16\u7801\u8bbe\u7f6e<\/p>\n<\/p>\n<p>javadoc -encoding UTF-8 -charset UTF-8 HelloWorld.java <\/p>\n<h2>\u5341\u3001\u65b9\u6cd5<\/h2>\n<h3 id=\"_1\u3001\u4f55\u8c13\u65b9\u6cd5\">1\u3001\u4f55\u8c13\u65b9\u6cd5&#xff1f;<\/h3>\n<p>\u5728\u524d\u9762\u51e0\u4e2a\u7ae0\u8282\u4e2d\u6211\u4eec\u7ecf\u5e38\u4f7f\u7528\u5230 System.out.println()&#xff0c;\u90a3\u4e48\u5b83\u662f\u4ec0\u4e48\u5462&#xff1f;<\/p>\n<ul>\n<li>println() \u662f\u4e00\u4e2a\u65b9\u6cd5\u3002<\/li>\n<li>System \u662f\u7cfb\u7edf\u7c7b\u3002<\/li>\n<li>out \u662f\u6807\u51c6\u8f93\u51fa\u5bf9\u8c61\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u53e5\u8bdd\u7684\u7528\u6cd5\u662f\u8c03\u7528\u7cfb\u7edf\u7c7b System \u4e2d\u7684\u6807\u51c6\u8f93\u51fa\u5bf9\u8c61 out \u4e2d\u7684\u65b9\u6cd5 println()\u3002<\/p>\n<p>\u90a3\u4e48\u4ec0\u4e48\u662f\u65b9\u6cd5\u5462&#xff1f;<\/p>\n<p>Java\u65b9\u6cd5\u662f\u8bed\u53e5\u7684\u96c6\u5408&#xff0c;\u5b83\u4eec\u5728\u4e00\u8d77\u6267\u884c\u4e00\u4e2a\u529f\u80fd\u3002<\/p>\n<ul>\n<li>\u65b9\u6cd5\u662f\u89e3\u51b3\u4e00\u7c7b\u95ee\u9898\u7684\u6b65\u9aa4\u7684\u6709\u5e8f\u7ec4\u5408<\/li>\n<li>\u65b9\u6cd5\u5305\u542b\u4e8e\u7c7b\u6216\u5bf9\u8c61\u4e2d<\/li>\n<li>\u65b9\u6cd5\u5728\u7a0b\u5e8f\u4e2d\u88ab\u521b\u5efa&#xff0c;\u5728\u5176\u4ed6\u5730\u65b9\u88ab\u5f15\u7528<\/li>\n<\/ul>\n<p>\u8bbe\u8ba1\u65b9\u6cd5\u7684\u539f\u5219&#xff1a;\u65b9\u6cd5\u7684\u672c\u610f\u662f\u529f\u80fd\u5757&#xff0c;\u5c31\u662f\u5b9e\u73b0\u67d0\u4e2a\u529f\u80fd\u7684\u8bed\u53e5\u5757\u7684\u96c6\u5408\u3002\u6211\u4eec\u8bbe\u8ba1\u65b9\u6cd5\u7684\u65f6\u5019&#xff0c;\u6700 \u597d\u4fdd\u6301\u65b9\u6cd5\u7684\u539f\u5b50\u6027&#xff0c;\u5c31\u662f\u4e00\u4e2a\u65b9\u6cd5\u53ea\u5b8c\u62101\u4e2a\u529f\u80fd&#xff0c;\u8fd9\u6837\u5229\u4e8e\u6211\u4eec\u540e\u671f\u7684\u6269\u5c55\u3002<\/p>\n<p>\u65b9\u6cd5\u7684\u4f18\u70b9<\/p>\n<ul>\n<li>\u4f7f\u7a0b\u5e8f\u53d8\u5f97\u66f4\u7b80\u77ed\u800c\u6e05\u6670\u3002<\/li>\n<li>\u6709\u5229\u4e8e\u7a0b\u5e8f\u7ef4\u62a4\u3002<\/li>\n<li>\u53ef\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u5f00\u53d1\u7684\u6548\u7387\u3002<\/li>\n<li>\u63d0\u9ad8\u4e86\u4ee3\u7801\u7684\u91cd\u7528\u6027\u3002<\/li>\n<\/ul>\n<p>\u56de\u987e&#xff1a;\u65b9\u6cd5\u7684\u547d\u540d\u89c4\u5219&#xff1f;<\/p>\n<h3 id=\"_2\u3001\u65b9\u6cd5\u7684\u5b9a\u4e49\">2\u3001\u65b9\u6cd5\u7684\u5b9a\u4e49<\/h3>\n<p>Java\u7684\u65b9\u6cd5\u7c7b\u4f3c\u4e8e\u5176\u5b83\u8bed\u8a00\u7684\u51fd\u6570&#xff0c;\u662f\u4e00\u6bb5\u7528\u6765\u5b8c\u6210\u7279\u5b9a\u529f\u80fd\u7684\u4ee3\u7801\u7247\u6bb5&#xff0c;\u4e00\u822c\u60c5\u51b5\u4e0b&#xff0c;\u5b9a\u4e49\u4e00\u4e2a\u65b9\u6cd5 \u5305\u542b\u4ee5\u4e0b\u8bed\u6cd5&#xff1a;<\/p>\n<\/p>\n<p>\u4fee\u9970\u7b26 \u8fd4\u56de\u503c\u7c7b\u578b \u65b9\u6cd5\u540d(\u53c2\u6570\u7c7b\u578b \u53c2\u6570\u540d){<br \/>\n    &#8230;<br \/>\n    \u65b9\u6cd5\u4f53<br \/>\n    &#8230;<br \/>\n    return \u8fd4\u56de\u503c;<br \/>\n} <\/p>\n<p>\u65b9\u6cd5\u5305\u542b\u4e00\u4e2a\u65b9\u6cd5\u5934\u548c\u4e00\u4e2a\u65b9\u6cd5\u4f53\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u65b9\u6cd5\u7684\u6240\u6709\u90e8\u5206&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4fee\u9970\u7b26<\/p>\n<p>\u4fee\u9970\u7b26&#xff0c;\u8fd9\u662f\u53ef\u9009\u7684&#xff0c;\u544a\u8bc9\u7f16\u8bd1\u5668\u5982\u4f55\u8c03\u7528\u8be5\u65b9\u6cd5\u3002\u5b9a\u4e49\u4e86\u8be5\u65b9\u6cd5\u7684\u8bbf\u95ee\u7c7b\u578b\u3002<\/p>\n<\/li>\n<li>\n<p>\u8fd4\u56de\u503c\u7c7b\u578b<\/p>\n<p>\u65b9\u6cd5\u53ef\u80fd\u4f1a\u8fd4\u56de\u503c\u3002returnValueType \u662f\u65b9\u6cd5\u8fd4\u56de\u503c\u7684\u6570\u636e\u7c7b\u578b\u3002\u6709\u4e9b\u65b9\u6cd5\u6267\u884c\u6240\u9700 \u7684\u64cd\u4f5c&#xff0c;\u4f46\u6ca1\u6709\u8fd4\u56de\u503c\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b&#xff0c;returnValueType \u662f\u5173\u952e\u5b57void\u3002<\/p>\n<\/li>\n<li>\n<p>\u65b9\u6cd5\u540d<\/p>\n<p>\u662f\u65b9\u6cd5\u7684\u5b9e\u9645\u540d\u79f0\u3002\u65b9\u6cd5\u540d\u548c\u53c2\u6570\u8868\u5171\u540c\u6784\u6210\u65b9\u6cd5\u7b7e\u540d\u3002<\/p>\n<\/li>\n<li>\n<p>\u53c2\u6570\u7c7b\u578b<\/p>\n<p>\u53c2\u6570\u50cf\u662f\u4e00\u4e2a\u5360\u4f4d\u7b26\u3002\u5f53\u65b9\u6cd5\u88ab\u8c03\u7528\u65f6&#xff0c;\u4f20\u9012\u503c\u7ed9\u53c2\u6570\u3002\u8fd9\u4e2a\u503c\u88ab\u79f0\u4e3a\u5b9e\u53c2\u6216\u53d8\u91cf\u3002\u53c2\u6570\u5217\u8868\u662f\u6307\u65b9\u6cd5\u7684\u53c2\u6570\u7c7b\u578b\u3001\u987a\u5e8f\u548c\u53c2\u6570\u7684\u4e2a\u6570\u3002\u53c2\u6570\u662f\u53ef\u9009\u7684&#xff0c;\u65b9\u6cd5\u53ef\u4ee5\u4e0d\u5305\u542b\u4efb\u4f55\u53c2\u6570\u3002<\/p>\n<ul>\n<li>\u5f62\u5f0f\u53c2\u6570&#xff1a;\u5728\u65b9\u6cd5\u88ab\u8c03\u7528\u65f6\u7528\u4e8e\u63a5\u6536\u5916\u754c\u8f93\u5165\u7684\u6570\u636e\u3002<\/li>\n<li>\u5b9e\u53c2&#xff1a;\u8c03\u7528\u65b9\u6cd5\u65f6\u5b9e\u9645\u4f20\u7ed9\u65b9\u6cd5\u7684\u6570\u636e\u3002<\/li>\n<\/ul>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"717\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114045017-69672089589b8.png\" width=\"588\" \/><\/p>\n<\/li>\n<li>\n<p>\u65b9\u6cd5\u4f53<\/p>\n<p>\u65b9\u6cd5\u4f53\u5305\u542b\u5177\u4f53\u7684\u8bed\u53e5&#xff0c;\u5b9a\u4e49\u8be5\u65b9\u6cd5\u7684\u529f\u80fd\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u6bd4\u5982\u6211\u4eec\u5199\u4e00\u4e2a\u6bd4\u5927\u5c0f\u7684\u65b9\u6cd5&#xff1a;<\/p>\n<p>\u3010\u6f14\u793a\u3011\u4e0b\u9762\u7684\u65b9\u6cd5\u5305\u542b 2 \u4e2a\u53c2\u6570 num1 \u548c num2&#xff0c;\u5b83\u8fd4\u56de\u8fd9\u4e24\u4e2a\u53c2\u6570\u7684\u6700\u5927\u503c\u3002<\/p>\n<\/p>\n<p>\/** \u8fd4\u56de\u4e24\u4e2a\u6574\u578b\u53d8\u91cf\u6570\u636e\u7684\u8f83\u5927\u503c *\/<br \/>\npublic static int max(int num1, int num2) {<br \/>\n    int result;<br \/>\n    if (num1 &gt; num2){<br \/>\n        result &#061; num1;<br \/>\n    }<br \/>\n    else{<br \/>\n        result &#061; num2;<br \/>\n    }<\/p>\n<p>    return result;<br \/>\n} <\/p>\n<p>\u3010\u6f14\u793a&#xff1a;\u52a0\u6cd5\u3011<\/p>\n<\/p>\n<p>public int add(int num1, int num2) {<br \/>\n    return num1&#043;num2;<br \/>\n} <\/p>\n<h3 id=\"_3\u3001\u65b9\u6cd5\u8c03\u7528\">3\u3001\u65b9\u6cd5\u8c03\u7528<\/h3>\n<p>Java \u652f\u6301\u4e24\u79cd\u8c03\u7528\u65b9\u6cd5\u7684\u65b9\u5f0f&#xff0c;\u6839\u636e\u65b9\u6cd5\u662f\u5426\u8fd4\u56de\u503c\u6765\u9009\u62e9\u3002<\/p>\n<p>\u5f53\u7a0b\u5e8f\u8c03\u7528\u4e00\u4e2a\u65b9\u6cd5\u65f6&#xff0c;\u7a0b\u5e8f\u7684\u63a7\u5236\u6743\u4ea4\u7ed9\u4e86\u88ab\u8c03\u7528\u7684\u65b9\u6cd5\u3002\u5f53\u88ab\u8c03\u7528\u65b9\u6cd5\u7684\u8fd4\u56de\u8bed\u53e5\u6267\u884c\u6216\u8005\u5230\u8fbe\u65b9\u6cd5\u4f53\u95ed\u62ec\u53f7\u65f6\u5019\u4ea4\u8fd8\u63a7\u5236\u6743\u7ed9\u7a0b\u5e8f\u3002<\/p>\n<p>\u5f53\u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u503c\u7684\u65f6\u5019&#xff0c;\u65b9\u6cd5\u8c03\u7528\u901a\u5e38\u88ab\u5f53\u505a\u4e00\u4e2a\u503c\u3002\u4f8b\u5982&#xff1a;<\/p>\n<\/p>\n<p>int larger &#061; max(30, 40); <\/p>\n<p>Java\u8bed\u8a00\u4e2d\u4f7f\u7528\u4e0b\u8ff0\u5f62\u5f0f\u8c03\u7528\u65b9\u6cd5&#xff1a;\u5bf9\u8c61\u540d.\u65b9\u6cd5\u540d(\u5b9e\u53c2\u5217\u8868)<\/p>\n<p>\u5982\u679c\u65b9\u6cd5\u8fd4\u56de\u503c\u662fvoid&#xff0c;\u65b9\u6cd5\u8c03\u7528\u4e00\u5b9a\u662f\u4e00\u6761\u8bed\u53e5\u3002\u4f8b\u5982&#xff0c;\u65b9\u6cd5println\u8fd4\u56devoid\u3002\u4e0b\u9762\u7684\u8c03\u7528\u662f\u4e2a\u8bed\u53e5&#xff1a;<\/p>\n<\/p>\n<p>System.out.println(&#034;Hello,kuangshen!&#034;); <\/p>\n<p>\u3010\u6f14\u793a&#xff1a;\u5b9a\u4e49\u65b9\u6cd5\u5e76\u4e14\u8c03\u7528\u5b83\u3011<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int i &#061; 5;<br \/>\n    int j &#061; 2;<br \/>\n    int k &#061; max(i, j);<br \/>\n    System.out.println( i &#043; &#034; \u548c &#034; &#043; j &#043; &#034; \u6bd4\u8f83&#xff0c;\u6700\u5927\u503c\u662f&#xff1a;&#034; &#043; k);<br \/>\n}<\/p>\n<p>\/** \u8fd4\u56de\u4e24\u4e2a\u6574\u6570\u53d8\u91cf\u8f83\u5927\u7684\u503c *\/<br \/>\npublic static int max(int num1, int num2) {<br \/>\n    int result;<br \/>\n    if (num1 &gt; num2){<br \/>\n        result &#061; num1;<br \/>\n    }<br \/>\n    else{<br \/>\n        result &#061; num2;<br \/>\n    }<br \/>\n    return result;<br \/>\n} <\/p>\n<p>\u8fd9\u4e2a\u7a0b\u5e8f\u5305\u542b main \u65b9\u6cd5\u548c max \u65b9\u6cd5\u3002main \u65b9\u6cd5\u662f\u88ab JVM \u8c03\u7528\u7684&#xff0c;\u9664\u6b64\u4e4b\u5916&#xff0c;main \u65b9\u6cd5\u548c\u5176\u5b83\u65b9\u6cd5 \u6ca1\u4ec0\u4e48\u533a\u522b\u3002JAVA\u4e2d\u53ea\u6709\u503c\u4f20\u9012&#xff01;<\/p>\n<p>main \u65b9\u6cd5\u7684\u5934\u90e8\u662f\u4e0d\u53d8\u7684&#xff0c;\u5982\u4f8b\u5b50\u6240\u793a&#xff0c;\u5e26\u4fee\u9970\u7b26 public \u548c static,\u8fd4\u56de void \u7c7b\u578b\u503c&#xff0c;\u65b9\u6cd5\u540d\u5b57\u662f main,\u6b64\u5916\u5e26\u4e2a\u4e00\u4e2a String[] \u7c7b\u578b\u53c2\u6570\u3002String[] \u8868\u660e\u53c2\u6570\u662f\u5b57\u7b26\u4e32\u6570\u7ec4\u3002<\/p>\n<h3 id=\"_4\u3001\u65b9\u6cd5\u7684\u91cd\u8f7d\">4\u3001\u65b9\u6cd5\u7684\u91cd\u8f7d<\/h3>\n<p>\u4e0a\u9762\u4f7f\u7528\u7684max\u65b9\u6cd5\u4ec5\u4ec5\u9002\u7528\u4e8eint\u578b\u6570\u636e\u3002\u4f46\u5982\u679c\u4f60\u60f3\u5f97\u5230\u4e24\u4e2a\u6d6e\u70b9\u7c7b\u578b\u6570\u636e\u7684\u6700\u5927\u503c\u5462&#xff1f;<\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5\u662f\u521b\u5efa\u53e6\u4e00\u4e2a\u6709\u76f8\u540c\u540d\u5b57\u4f46\u53c2\u6570\u4e0d\u540c\u7684\u65b9\u6cd5&#xff0c;\u5982\u4e0b\u9762\u4ee3\u7801\u6240\u793a&#xff1a;<\/p>\n<\/p>\n<p>public static double max(double num1, double num2) {<br \/>\n    if (num1 &gt; num2)<br \/>\n    return num1;<br \/>\n    else<br \/>\n    return num2;<br \/>\n}<\/p>\n<p>public static int max(int num1, int num2) {<br \/>\n    int result;<br \/>\n    if (num1 &gt; num2)<br \/>\n    result &#061; num1;<br \/>\n    else<br \/>\n    result &#061; num2;<br \/>\n    return result;<br \/>\n} <\/p>\n<p>\u5982\u679c\u4f60\u8c03\u7528max\u65b9\u6cd5\u65f6\u4f20\u9012\u7684\u662fint\u578b\u53c2\u6570&#xff0c;\u5219 int\u578b\u53c2\u6570\u7684max\u65b9\u6cd5\u5c31\u4f1a\u88ab\u8c03\u7528&#xff1b;<\/p>\n<p>\u5982\u679c\u4f20\u9012\u7684\u662fdouble\u578b\u53c2\u6570&#xff0c;\u5219double\u7c7b\u578b\u7684max\u65b9\u6cd5\u4f53\u4f1a\u88ab\u8c03\u7528&#xff0c;\u8fd9\u53eb\u505a\u65b9\u6cd5\u91cd\u8f7d&#xff1b;<\/p>\n<p>\u5c31\u662f\u8bf4\u4e00\u4e2a\u7c7b\u7684\u4e24\u4e2a\u65b9\u6cd5\u62e5\u6709\u76f8\u540c\u7684\u540d\u5b57&#xff0c;\u4f46\u662f\u6709\u4e0d\u540c\u7684\u53c2\u6570\u5217\u8868\u3002<\/p>\n<p>Java\u7f16\u8bd1\u5668\u6839\u636e\u65b9\u6cd5\u7b7e\u540d\u5224\u65ad\u54ea\u4e2a\u65b9\u6cd5\u5e94\u8be5\u88ab\u8c03\u7528\u3002<\/p>\n<p>\u65b9\u6cd5\u91cd\u8f7d\u53ef\u4ee5\u8ba9\u7a0b\u5e8f\u66f4\u6e05\u6670\u6613\u8bfb\u3002\u6267\u884c\u5bc6\u5207\u76f8\u5173\u4efb\u52a1\u7684\u65b9\u6cd5\u5e94\u8be5\u4f7f\u7528\u76f8\u540c\u7684\u540d\u5b57\u3002<\/p>\n<p>\u91cd\u8f7d\u7684\u65b9\u6cd5\u5fc5\u987b\u62e5\u6709\u4e0d\u540c\u7684\u53c2\u6570\u5217\u8868\u3002\u4f60\u4e0d\u80fd\u4ec5\u4ec5\u4f9d\u636e\u4fee\u9970\u7b26\u6216\u8005\u8fd4\u56de\u7c7b\u578b\u7684\u4e0d\u540c\u6765\u91cd\u8f7d\u65b9\u6cd5\u3002<\/p>\n<h3 id=\"_5\u3001\u62d3\u5c55\u547d\u4ee4\u884c\u4f20\u53c2\">5\u3001\u62d3\u5c55\u547d\u4ee4\u884c\u4f20\u53c2<\/h3>\n<p>\u6709\u65f6\u5019\u4f60\u5e0c\u671b\u8fd0\u884c\u4e00\u4e2a\u7a0b\u5e8f\u65f6\u5019\u518d\u4f20\u9012\u7ed9\u5b83\u6d88\u606f\u3002\u8fd9\u8981\u9760\u4f20\u9012\u547d\u4ee4\u884c\u53c2\u6570\u7ed9main()\u51fd\u6570\u5b9e\u73b0\u3002<\/p>\n<p>\u547d\u4ee4\u884c\u53c2\u6570\u662f\u5728\u6267\u884c\u7a0b\u5e8f\u65f6\u5019\u7d27\u8ddf\u5728\u7a0b\u5e8f\u540d\u5b57\u540e\u9762\u7684\u4fe1\u606f\u3002<\/p>\n<p>\u3010\u4e0b\u9762\u7684\u7a0b\u5e8f\u6253\u5370\u6240\u6709\u7684\u547d\u4ee4\u884c\u53c2\u6570\u3011<\/p>\n<\/p>\n<p>public class CommandLine {<br \/>\npublic static void main(String args[]){<br \/>\nfor(int i&#061;0; i&lt;args.length; i&#043;&#043;){<br \/>\nSystem.out.println(&#034;args[&#034; &#043; i &#043; &#034;]: &#034; &#043; args[i]);<br \/>\n}<br \/>\n}<br \/>\n} <\/p>\n<p>\u3010\u547d\u4ee4\u884c\u3011<\/p>\n<\/p>\n<p>javac CommandLine.java<br \/>\njava CommandLine this is a command line 200 -100 <\/p>\n<p>args[0]: this args[1]: is args[2]: a args[3]: command args[4]: line args[5]: 200 args[6]: -100<\/p>\n<h3 id=\"_6\u3001\u53ef\u53d8\u53c2\u6570\">6\u3001\u53ef\u53d8\u53c2\u6570<\/h3>\n<p>JDK 1.5 \u5f00\u59cb&#xff0c;Java\u652f\u6301\u4f20\u9012\u540c\u7c7b\u578b\u7684\u53ef\u53d8\u53c2\u6570\u7ed9\u4e00\u4e2a\u65b9\u6cd5\u3002<\/p>\n<p>\u65b9\u6cd5\u7684\u53ef\u53d8\u53c2\u6570\u7684\u58f0\u660e\u5982\u4e0b\u6240\u793a&#xff1a;<\/p>\n<p>typeName&#8230; parameterName<\/p>\n<p>\u5728\u65b9\u6cd5\u58f0\u660e\u4e2d&#xff0c;\u5728\u6307\u5b9a\u53c2\u6570\u7c7b\u578b\u540e\u52a0\u4e00\u4e2a\u7701\u7565\u53f7(&#8230;)<\/p>\n<p>\u4e00\u4e2a\u65b9\u6cd5\u4e2d\u53ea\u80fd\u6307\u5b9a\u4e00\u4e2a\u53ef\u53d8\u53c2\u6570&#xff0c;\u5b83\u5fc5\u987b\u662f\u65b9\u6cd5\u7684\u6700\u540e\u4e00\u4e2a\u53c2\u6570\u3002\u4efb\u4f55\u666e\u901a\u7684\u53c2\u6570\u5fc5\u987b\u5728\u5b83\u4e4b\u524d\u58f0\u660e\u3002<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    \/\/ \u8c03\u7528\u53ef\u53d8\u53c2\u6570\u7684\u65b9\u6cd5<br \/>\n    printMax(34, 3, 3, 2, 56.5);<br \/>\n    printMax(new double[]{1, 2, 3});<br \/>\n}<\/p>\n<p>public static void printMax(double&#8230; numbers) {<br \/>\n    if (numbers.length &#061;&#061; 0) {<br \/>\n        System.out.println(&#034;No argument passed&#034;);<br \/>\n        return;<br \/>\n    }<br \/>\n    double result &#061; numbers[0];<br \/>\n    \/\/\u6392\u5e8f&#xff01;<br \/>\n    for (int i &#061; 1; i &lt; numbers.length; i&#043;&#043;) {<br \/>\n        if (numbers[i] &gt; result) {<br \/>\n            result &#061; numbers[i];<br \/>\n        }<br \/>\n    }<br \/>\n    System.out.println(&#034;The max value is &#034; &#043; result);<br \/>\n} <\/p>\n<h3 id=\"_7\u3001\u9012\u5f52\">7\u3001\u9012\u5f52<\/h3>\n<p>A\u65b9\u6cd5\u8c03\u7528B\u65b9\u6cd5&#xff0c;\u6211\u4eec\u5f88\u5bb9\u6613\u7406\u89e3&#xff01;<\/p>\n<p>\u9012\u5f52\u5c31\u662f&#xff1a;A\u65b9\u6cd5\u8c03\u7528A\u65b9\u6cd5&#xff01;\u5c31\u662f\u81ea\u5df1\u8c03\u7528\u81ea\u5df1&#xff0c;\u56e0\u6b64\u6211\u4eec\u5728\u8bbe\u8ba1\u9012\u5f52\u7b97\u6cd5\u65f6&#xff0c;\u4e00\u5b9a\u8981\u6307\u660e\u4ec0\u4e48\u65f6\u5019\u81ea\u5df1\u4e0d\u8c03\u7528\u81ea\u5df1\u3002\u5426\u5219&#xff0c;\u5c31\u662f\u4e2a\u6b7b\u5faa\u73af&#xff01;<\/p>\n<p>\u9012\u5f52\u7b97\u6cd5\u91cd\u70b9&#xff1a;<\/p>\n<p>\u9012\u5f52\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u89e3\u51b3\u95ee\u9898\u7684\u65b9\u6cd5&#xff0c;\u5373\u628a\u95ee\u9898\u9010\u6e10\u7b80\u5355\u5316\u3002\u9012\u5f52\u7684\u57fa\u672c\u601d\u60f3\u5c31\u662f\u201c\u81ea\u5df1\u8c03\u7528\u81ea\u5df1\u201d&#xff0c;\u4e00\u4e2a\u4f7f\u7528\u9012\u5f52\u6280\u672f\u7684\u65b9\u6cd5\u5c06\u4f1a\u76f4\u63a5\u6216\u8005\u95f4\u63a5\u7684\u8c03\u7528\u81ea\u5df1\u3002<\/p>\n<p>\u5229\u7528\u9012\u5f52\u53ef\u4ee5\u7528\u7b80\u5355\u7684\u7a0b\u5e8f\u6765\u89e3\u51b3\u4e00\u4e9b\u590d\u6742\u7684\u95ee\u9898\u3002\u5b83\u901a\u5e38\u628a\u4e00\u4e2a\u5927\u578b\u590d\u6742\u7684\u95ee\u9898\u5c42\u5c42\u8f6c\u5316\u4e3a\u4e00\u4e2a\u4e0e\u539f \u95ee\u9898\u76f8\u4f3c\u7684\u89c4\u6a21\u8f83\u5c0f\u7684\u95ee\u9898\u6765\u6c42\u89e3&#xff0c;\u9012\u5f52\u7b56\u7565\u53ea\u9700\u5c11\u91cf\u7684\u7a0b\u5e8f\u5c31\u53ef\u63cf\u8ff0\u51fa\u89e3\u9898\u8fc7\u7a0b\u6240\u9700\u8981\u7684\u591a\u6b21\u91cd\u590d\u8ba1 \u7b97&#xff0c;\u5927\u5927\u5730\u51cf\u5c11\u4e86\u7a0b\u5e8f\u7684\u4ee3\u7801\u91cf\u3002\u9012\u5f52\u7684\u80fd\u529b\u5728\u4e8e\u7528\u6709\u9650\u7684\u8bed\u53e5\u6765\u5b9a\u4e49\u5bf9\u8c61\u7684\u65e0\u9650\u96c6\u5408\u3002<\/p>\n<p>\u9012\u5f52\u7ed3\u6784\u5305\u62ec\u4e24\u4e2a\u90e8\u5206&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u9012\u5f52\u5934<\/p>\n<p>\u4ec0\u4e48\u65f6\u5019\u4e0d\u8c03\u7528\u81ea\u8eab\u65b9\u6cd5\u3002\u5982\u679c\u6ca1\u6709\u5934&#xff0c;\u5c06\u9677\u5165\u6b7b\u5faa\u73af\u3002<\/p>\n<\/li>\n<li>\n<p>\u9012\u5f52\u4f53<\/p>\n<\/li>\n<\/ul>\n<p>\u4ec0\u4e48\u65f6\u5019\u9700\u8981\u8c03\u7528\u81ea\u8eab\u65b9\u6cd5\u3002<\/p>\n<p>\u3010\u6f14\u793a&#xff1a;\u5229\u7528\u4ee3\u7801\u8ba1\u7b975\u7684\u4e58\u9636&#xff01;\u3011<\/p>\n<\/p>\n<p>\/\/5*4*3*2*1<br \/>\npublic static void main(String[] args) {<br \/>\n    System.out.println(f(5));<br \/>\n}<br \/>\npublic static int f(int n) {<br \/>\n    if (1 &#061;&#061; n)<br \/>\n    return 1;<br \/>\n    else<br \/>\n    return n*f(n-1);<br \/>\n} <\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"312\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114045017-6967208973577.png\" width=\"825\" \/><\/p>\n<p>\u6b64\u9898\u4e2d&#xff0c;\u6309\u7167\u9012\u5f52\u7684\u4e09\u4e2a\u6761\u4ef6\u6765\u5206\u6790&#xff1a;<\/p>\n<p>(1)\u8fb9\u754c\u6761\u4ef6&#xff1a;\u9636\u4e58&#xff0c;\u4e58\u5230\u6700\u540e\u4e00\u4e2a\u6570&#xff0c;\u53731\u7684\u65f6\u5019&#xff0c;\u8fd4\u56de1&#xff0c;\u7a0b\u5e8f\u6267\u884c\u5230\u5e95&#xff1b; (2)\u9012\u5f52\u524d\u8fdb\u6bb5&#xff1a;\u5f53\u524d\u7684\u53c2\u6570\u4e0d\u7b49\u4e8e1\u7684\u65f6\u5019&#xff0c;\u7ee7\u7eed\u8c03\u7528\u81ea\u8eab&#xff1b; (3)\u9012\u5f52\u8fd4\u56de\u6bb5&#xff1a;\u4ece\u6700\u5927\u7684\u6570\u5f00\u59cb\u4e58&#xff0c;\u5982\u679c\u5f53\u524d\u53c2\u6570\u662f5&#xff0c;\u90a3\u4e48\u5c31\u662f5* 4&#xff0c;\u53735 (5-1)&#xff0c;\u5373n * (n-1)<\/p>\n<p>\u9012\u5f52\u5176\u5b9e\u662f\u65b9\u4fbf\u4e86\u7a0b\u5e8f\u5458\u96be\u4e3a\u4e86\u673a\u5668&#xff0c;\u9012\u5f52\u53ef\u4ee5\u901a\u8fc7\u6570\u5b66\u516c\u5f0f\u5f88\u65b9\u4fbf\u7684\u8f6c\u6362\u4e3a\u7a0b\u5e8f\u3002\u5176\u4f18\u70b9\u5c31\u662f\u6613\u7406 \u89e3&#xff0c;\u5bb9\u6613\u7f16\u7a0b\u3002\u4f46\u9012\u5f52\u662f\u7528\u6808\u673a\u5236\u5b9e\u73b0\u7684&#xff0c;\u6bcf\u6df1\u5165\u4e00\u5c42&#xff0c;\u90fd\u8981\u5360\u53bb\u4e00\u5757\u6808\u6570\u636e\u533a\u57df&#xff0c;\u5bf9\u5d4c\u5957\u5c42\u6570\u6df1\u7684\u4e00 \u4e9b\u7b97\u6cd5&#xff0c;\u9012\u5f52\u4f1a\u529b\u4e0d\u4ece\u5fc3&#xff0c;\u7a7a\u95f4\u4e0a\u4f1a\u4ee5\u5185\u5b58\u5d29\u6e83\u800c\u544a\u7ec8&#xff0c;\u800c\u4e14\u9012\u5f52\u4e5f\u5e26\u6765\u4e86\u5927\u91cf\u7684\u51fd\u6570\u8c03\u7528&#xff0c;\u8fd9\u4e5f\u6709\u8bb8 \u591a\u989d\u5916\u7684\u65f6\u95f4\u5f00\u9500\u3002\u6240\u4ee5\u5728\u6df1\u5ea6\u5927\u65f6&#xff0c;\u5b83\u7684\u65f6\u7a7a\u6027\u5c31\u4e0d\u597d\u4e86\u3002&#xff08;\u4f1a\u5360\u7528\u5927\u91cf\u7684\u5185\u5b58\u7a7a\u95f4&#xff09;<\/p>\n<p>\u800c\u8fed\u4ee3\u867d\u7136\u6548\u7387\u9ad8&#xff0c;\u8fd0\u884c\u65f6\u95f4\u53ea\u56e0\u5faa\u73af\u6b21\u6570\u589e\u52a0\u800c\u589e\u52a0&#xff0c;\u6ca1\u4ec0\u4e48\u989d\u5916\u5f00\u9500&#xff0c;\u7a7a\u95f4\u4e0a\u4e5f\u6ca1\u6709\u4ec0\u4e48\u589e\u52a0&#xff0c;\u4f46 \u7f3a\u70b9\u5c31\u662f\u4e0d\u5bb9\u6613\u7406\u89e3&#xff0c;\u7f16\u5199\u590d\u6742\u95ee\u9898\u65f6\u56f0\u96be\u3002<\/p>\n<p>\u80fd\u4e0d\u7528\u9012\u5f52\u5c31\u4e0d\u7528\u9012\u5f52&#xff0c;\u9012\u5f52\u90fd\u53ef\u4ee5\u7528\u8fed\u4ee3\u6765\u4ee3\u66ff<\/p>\n<h2>\u5341\u4e00\u3001\u7528\u6237\u4ea4\u4e92Scanner<\/h2>\n<h4 id=\"_1\u3001scanner\u5bf9\u8c61\">1\u3001Scanner\u5bf9\u8c61<\/h4>\n<p>\u4e4b\u524d\u6211\u4eec\u5b66\u7684\u57fa\u672c\u8bed\u6cd5\u4e2d\u6211\u4eec\u5e76\u6ca1\u6709\u5b9e\u73b0\u7a0b\u5e8f\u548c\u4eba\u7684\u4ea4\u4e92&#xff0c;\u4f46\u662fJava\u7ed9\u6211\u4eec\u63d0\u4f9b\u4e86\u8fd9\u6837\u4e00\u4e2a\u5de5\u5177\u7c7b&#xff0c;\u6211 \u4eec\u53ef\u4ee5\u83b7\u53d6\u7528\u6237\u7684\u8f93\u5165\u3002java.util.Scanner \u662f Java5 \u7684\u65b0\u7279\u5f81&#xff0c;\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7 Scanner \u7c7b\u6765\u83b7\u53d6\u7528\u6237\u7684\u8f93\u5165\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u521b\u5efa Scanner \u5bf9\u8c61\u7684\u57fa\u672c\u8bed\u6cd5&#xff1a;<\/p>\n<\/p>\n<p>Scanner s &#061; new Scanner(System.in); <\/p>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u6f14\u793a\u4e00\u4e2a\u6700\u7b80\u5355\u7684\u6570\u636e\u8f93\u5165&#xff0c;\u5e76\u901a\u8fc7 Scanner \u7c7b\u7684 next() \u4e0e nextLine() \u65b9\u6cd5\u83b7\u53d6\u8f93\u5165\u7684\u5b57\u7b26\u4e32&#xff0c;\u5728\u8bfb\u53d6\u524d\u6211\u4eec\u4e00\u822c\u9700\u8981 \u4f7f\u7528 hasNext() \u4e0e hasNextLine() \u5224\u65ad\u662f\u5426\u8fd8\u6709\u8f93\u5165\u7684\u6570\u636e\u3002<\/p>\n<h4 id=\"_2\u3001next-nextline\">2\u3001next &amp; nextLine<\/h4>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    \/\/\u521b\u5efa\u4e00\u4e2a\u626b\u63cf\u5668\u5bf9\u8c61&#xff0c;\u7528\u4e8e\u63a5\u6536\u952e\u76d8\u6570\u636e<br \/>\n    Scanner scanner &#061; new Scanner(System.in);<br \/>\n    \/\/next\u65b9\u5f0f\u63a5\u6536\u5b57\u7b26\u4e32<br \/>\n    System.out.println(&#034;Next\u65b9\u5f0f\u63a5\u6536:&#034;);<br \/>\n    \/\/\u5224\u65ad\u7528\u6237\u8fd8\u6709\u6ca1\u6709\u8f93\u5165\u5b57\u7b26<br \/>\n    if (scanner.hasNext()) {<br \/>\n        String str &#061; scanner.next();<br \/>\n        System.out.println(&#034;\u8f93\u5165\u5185\u5bb9&#xff1a;&#034; &#043; str);<br \/>\n    }<br \/>\n    \/\/\u51e1\u662f\u5c5e\u4e8eIO\u6d41\u7684\u7c7b\u5982\u679c\u4e0d\u5173\u95ed\u4f1a\u4e00\u76f4\u5360\u7528\u8d44\u6e90.\u8981\u517b\u6210\u597d\u4e60\u60ef\u7528\u5b8c\u5c31\u5173\u6389.\u5c31\u597d\u50cf\u4f60\u63a5\u6c34\u5b8c\u4e86\u8981\u5173\u6c34\u9f99\u5934\u4e00\u6837.\u5f88\u591a\u4e0b\u8f7d\u8f6f\u4ef6\u6216\u8005\u89c6\u9891\u8f6f\u4ef6\u5982\u679c\u4f60\u4e0d\u5f7b\u5e95\u5173, \u90fd\u4f1a\u81ea\u5df1\u4e0a\u4f20\u4e0b\u8f7d\u4ece\u800c\u5360\u7528\u8d44\u6e90, \u4f60\u5c31\u4f1a\u89c9\u5f97\u5361, \u8fd9\u4e00\u4e2a\u9053\u7406.<br \/>\n    scanner.close();<br \/>\n} <\/p>\n<p>\u6d4b\u8bd5\u6570\u636e&#xff1a;Hello World&#xff01;<\/p>\n<p>\u7ed3\u679c&#xff1a;\u53ea\u8f93\u51fa\u4e86Hello\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u4f7f\u7528\u53e6\u4e00\u4e2a\u65b9\u6cd5\u6765\u63a5\u6536\u6570\u636e&#xff1a;nextLine()<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    Scanner scan &#061; new Scanner(System.in);<br \/>\n    \/\/ \u4ece\u952e\u76d8\u63a5\u6536\u6570\u636e<br \/>\n    \/\/ nextLine\u65b9\u5f0f\u63a5\u6536\u5b57\u7b26\u4e32<br \/>\n    System.out.println(&#034;nextLine\u65b9\u5f0f\u63a5\u6536&#xff1a;&#034;);<br \/>\n    \/\/ \u5224\u65ad\u662f\u5426\u8fd8\u6709\u8f93\u5165<br \/>\n    if (scan.hasNextLine()) {<br \/>\n        String str2 &#061; scan.nextLine();<br \/>\n        System.out.println(&#034;\u8f93\u5165\u5185\u5bb9&#xff1a;&#034; &#043; str2);<br \/>\n    }<br \/>\n    scan.close();<br \/>\n} <\/p>\n<p>\u6d4b\u8bd5\u6570\u636e&#xff1a;Hello World&#xff01;<\/p>\n<p>\u7ed3\u679c&#xff1a;\u8f93\u51fa\u4e86Hello World&#xff01;<\/p>\n<p>\u4e24\u8005\u533a\u522b&#xff1a;<\/p>\n<p>next():<\/p>\n<ul>\n<li>\u4e00\u5b9a\u8981\u8bfb\u53d6\u5230\u6709\u6548\u5b57\u7b26\u540e\u624d\u53ef\u4ee5\u7ed3\u675f\u8f93\u5165\u3002<\/li>\n<li>\u5bf9\u8f93\u5165\u6709\u6548\u5b57\u7b26\u4e4b\u524d\u9047\u5230\u7684\u7a7a\u767d&#xff0c;next() \u65b9\u6cd5\u4f1a\u81ea\u52a8\u5c06\u5176\u53bb\u6389\u3002<\/li>\n<li>\u53ea\u6709\u8f93\u5165\u6709\u6548\u5b57\u7b26\u540e\u624d\u5c06\u5176\u540e\u9762\u8f93\u5165\u7684\u7a7a\u767d\u4f5c\u4e3a\u5206\u9694\u7b26\u6216\u8005\u7ed3\u675f\u7b26\u3002<\/li>\n<li>next() \u4e0d\u80fd\u5f97\u5230\u5e26\u6709\u7a7a\u683c\u7684\u5b57\u7b26\u4e32\u3002<\/li>\n<\/ul>\n<p>nextLine()&#xff1a;<\/p>\n<ul>\n<li>\u4ee5Enter\u4e3a\u7ed3\u675f\u7b26,\u4e5f\u5c31\u662f\u8bf4 nextLine()\u65b9\u6cd5\u8fd4\u56de\u7684\u662f\u8f93\u5165\u56de\u8f66\u4e4b\u524d\u7684\u6240\u6709\u5b57\u7b26\u3002<\/li>\n<li>\u53ef\u4ee5\u83b7\u5f97\u7a7a\u767d\u3002<\/li>\n<\/ul>\n<h4 id=\"_3\u3001\u5176\u4ed6\u65b9\u6cd5\">3\u3001\u5176\u4ed6\u65b9\u6cd5<\/h4>\n<p>\u5982\u679c\u8981\u8f93\u5165 int \u6216 float \u7c7b\u578b\u7684\u6570\u636e&#xff0c;\u5728 Scanner \u7c7b\u4e2d\u4e5f\u6709\u652f\u6301&#xff0c;\u4f46\u662f\u5728\u8f93\u5165\u4e4b\u524d\u6700\u597d\u5148\u4f7f\u7528 hasNextXxx() \u65b9\u6cd5\u8fdb\u884c\u9a8c\u8bc1&#xff0c;\u518d\u4f7f\u7528 nextXxx() \u6765\u8bfb\u53d6&#xff1a;<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    Scanner scan &#061; new Scanner(System.in);<br \/>\n    \/\/ \u4ece\u952e\u76d8\u63a5\u6536\u6570\u636e<br \/>\n    int i &#061; 0;<br \/>\n    float f &#061; 0.0f;<br \/>\n    System.out.print(&#034;\u8f93\u5165\u6574\u6570&#xff1a;&#034;);<br \/>\n    if (scan.hasNextInt()) {<br \/>\n        \/\/ \u5224\u65ad\u8f93\u5165\u7684\u662f\u5426\u662f\u6574\u6570<br \/>\n        i &#061; scan.nextInt();<br \/>\n        \/\/ \u63a5\u6536\u6574\u6570<br \/>\n        System.out.println(&#034;\u6574\u6570\u6570\u636e&#xff1a;&#034; &#043; i);<br \/>\n    } else {<br \/>\n        \/\/ \u8f93\u5165\u9519\u8bef\u7684\u4fe1\u606f<br \/>\n        System.out.println(&#034;\u8f93\u5165\u7684\u4e0d\u662f\u6574\u6570&#xff01;&#034;);<br \/>\n    }<br \/>\n    System.out.print(&#034;\u8f93\u5165\u5c0f\u6570&#xff1a;&#034;);<br \/>\n    if (scan.hasNextFloat()) {<br \/>\n        \/\/ \u5224\u65ad\u8f93\u5165\u7684\u662f\u5426\u662f\u5c0f\u6570<br \/>\n        f &#061; scan.nextFloat();<br \/>\n        \/\/ \u63a5\u6536\u5c0f\u6570<br \/>\n        System.out.println(&#034;\u5c0f\u6570\u6570\u636e&#xff1a;&#034; &#043; f);<br \/>\n    } else {<br \/>\n        \/\/ \u8f93\u5165\u9519\u8bef\u7684\u4fe1\u606f<br \/>\n        System.out.println(&#034;\u8f93\u5165\u7684\u4e0d\u662f\u5c0f\u6570&#xff01;&#034;);<br \/>\n    }<br \/>\n    scan.close();<br \/>\n} <\/p>\n<p>\u5177\u4f53Scanner\u7c7b\u90fd\u6709\u4ec0\u4e48\u65b9\u6cd5&#xff0c;\u53ef\u67e5\u770b\u5176\u4e2d\u7684\u6e90\u7801&#xff0c;ctrl&#043;\u9f20\u6807\u5de6\u952e\u00a0\u70b9\u4e2didea\u4e2d\u7684Scanner<\/p>\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u6211\u4eec\u53ef\u4ee5\u8f93\u5165\u591a\u4e2a\u6570\u5b57&#xff0c;\u5e76\u6c42\u5176\u603b\u548c\u4e0e\u5e73\u5747\u6570&#xff0c;\u6bcf\u8f93\u5165\u4e00\u4e2a\u6570\u5b57\u7528\u56de\u8f66\u786e\u8ba4&#xff0c;\u901a\u8fc7\u8f93\u5165\u975e\u6570\u5b57\u6765\u7ed3\u675f\u8f93\u5165&#xff0c;\u5e76\u8f93\u51fa\u6267\u884c\u7ed3\u679c&#xff1a;<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    \/\/\u626b\u63cf\u5668\u63a5\u6536\u952e\u76d8\u6570\u636e<br \/>\n    Scanner scan &#061; new Scanner(System.in);<br \/>\n    double sum &#061; 0; \/\/\u548c<br \/>\n    int m &#061; 0; \/\/\u8f93\u5165\u4e86\u591a\u5c11\u4e2a\u6570\u5b57<br \/>\n    \/\/\u901a\u8fc7\u5faa\u73af\u5224\u65ad\u662f\u5426\u8fd8\u6709\u8f93\u5165&#xff0c;\u5e76\u5728\u91cc\u9762\u5bf9\u6bcf\u4e00\u6b21\u8fdb\u884c\u6c42\u548c\u548c\u7edf\u8ba1<br \/>\n    while (scan.hasNextDouble()) {<br \/>\n        double x &#061; scan.nextDouble();<br \/>\n        m &#061; m &#043; 1;<br \/>\n        sum &#061; sum &#043; x;<br \/>\n    }<br \/>\n    System.out.println(m &#043; &#034;\u4e2a\u6570\u7684\u548c\u4e3a&#034; &#043; sum);<br \/>\n    System.out.println(m &#043; &#034;\u4e2a\u6570\u7684\u5e73\u5747\u503c\u662f&#034; &#043; (sum \/ m));<br \/>\n    scan.close();<br \/>\n} <\/p>\n<p>\u53ef\u80fd\u5f88\u591a\u5c0f\u4f19\u4f34\u5230\u8fd9\u91cc\u5c31\u770b\u4e0d\u61c2\u5199\u7684\u4ec0\u4e48\u4e1c\u897f\u4e86&#xff01;\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528\u4e86\u6211\u4eec\u4e00\u4f1a\u8981\u5b66\u7684\u6d41\u7a0b\u63a7\u5236\u8bed\u53e5&#xff0c;\u6211\u4eec \u63a5\u4e0b\u6765\u5c31\u53bb\u5b66\u4e60\u8fd9\u4e9b\u8bed\u53e5\u7684\u5177\u4f53\u4f5c\u7528&#xff01;<\/p>\n<p>Java\u4e2d\u7684\u6d41\u7a0b\u63a7\u5236\u8bed\u53e5\u53ef\u4ee5\u8fd9\u6837\u5206\u7c7b&#xff1a;\u987a\u5e8f\u7ed3\u6784&#xff0c;\u9009\u62e9\u7ed3\u6784&#xff0c;\u5faa\u73af\u7ed3\u6784&#xff01;\u8fd9\u4e09\u79cd\u7ed3\u6784\u5c31\u8db3\u591f\u89e3\u51b3\u6240\u6709\u7684 \u95ee\u9898\u4e86&#xff01;<\/p>\n<h2>\u5341\u4e8c\u3001\u987a\u5e8f\u7ed3\u6784<\/h2>\n<p>JAVA\u7684\u57fa\u672c\u7ed3\u6784\u5c31\u662f\u987a\u5e8f\u7ed3\u6784&#xff0c;\u9664\u975e\u7279\u522b\u6307\u660e&#xff0c;\u5426\u5219\u5c31\u6309\u7167\u987a\u5e8f\u4e00\u53e5\u4e00\u53e5\u6267\u884c\u3002<\/p>\n<p>\u987a\u5e8f\u7ed3\u6784\u662f\u6700\u7b80\u5355\u7684\u7b97\u6cd5\u7ed3\u6784\u3002<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"250\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114045017-696720898e329.png\" width=\"238\" \/><\/p>\n<p>\u8bed\u53e5\u4e0e\u8bed\u53e5\u4e4b\u95f4&#xff0c;\u6846\u4e0e\u6846\u4e4b\u95f4\u662f\u6309\u4ece\u4e0a\u5230\u4e0b\u7684\u987a\u5e8f\u8fdb\u884c\u7684&#xff0c;\u5b83\u662f\u7531\u82e5\u5e72\u4e2a\u4f9d\u6b21\u6267\u884c\u7684\u5904\u7406\u6b65\u9aa4\u7ec4\u6210\u7684&#xff0c; \u5b83\u662f\u4efb\u4f55\u4e00\u4e2a\u7b97\u6cd5\u90fd\u79bb\u4e0d\u5f00\u7684\u4e00\u79cd\u57fa\u672c\u7b97\u6cd5\u7ed3\u6784\u3002<\/p>\n<p>\u987a\u5e8f\u7ed3\u6784\u5728\u7a0b\u5e8f\u6d41\u7a0b\u56fe\u4e2d\u7684\u4f53\u73b0\u5c31\u662f\u7528\u6d41\u7a0b\u7ebf\u5c06\u7a0b\u5e8f\u6846\u81ea\u4e0a\u800c\u5730\u8fde\u63a5\u8d77\u6765&#xff0c;\u6309\u987a\u5e8f\u6267\u884c\u7b97\u6cd5\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    System.out.println(&#034;Hello1&#034;);<br \/>\n    System.out.println(&#034;Hello2&#034;);<br \/>\n    System.out.println(&#034;Hello3&#034;);<br \/>\n    System.out.println(&#034;Hello4&#034;);<br \/>\n    System.out.println(&#034;Hello5&#034;);<br \/>\n}<br \/>\n\/\/\u6309\u7167\u81ea\u4e0a\u800c\u4e0b\u7684\u987a\u5e8f\u6267\u884c&#xff01;\u4f9d\u6b21\u8f93\u51fa\u3002 <\/p>\n<h2>\u5341\u4e09\u3001\u9009\u62e9\u7ed3\u6784<\/h2>\n<h4 id=\"_1\u3001if\u5355\u9009\u62e9\u7ed3\u6784\">1\u3001if\u5355\u9009\u62e9\u7ed3\u6784<\/h4>\n<p>\u6211\u4eec\u5f88\u591a\u65f6\u5019\u9700\u8981\u53bb\u5224\u65ad\u4e00\u4e2a\u4e1c\u897f\u662f\u5426\u53ef\u884c&#xff0c;\u7136\u540e\u6211\u4eec\u624d\u53bb\u6267\u884c&#xff0c;\u8fd9\u6837\u4e00\u4e2a\u8fc7\u7a0b\u5728\u7a0b\u5e8f\u4e2d\u7528if\u8bed\u53e5\u6765\u8868 \u793a&#xff1a;<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"229\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114045017-6967208996f00.png\" width=\"278\" \/><\/p>\n<\/p>\n<p>if(\u5e03\u5c14\u8868\u8fbe\u5f0f){<br \/>\n    \/\/\u5982\u679c\u5e03\u5c14\u8868\u8fbe\u5f0f\u4e3atrue\u5c06\u6267\u884c\u7684\u8bed\u53e5<br \/>\n} <\/p>\n<p>\u610f\u4e49&#xff1a;if\u8bed\u53e5\u5bf9\u6761\u4ef6\u8868\u8fbe\u5f0f\u8fdb\u884c\u4e00\u6b21\u6d4b\u8bd5&#xff0c;\u82e5\u6d4b\u8bd5\u4e3a\u771f&#xff0c;\u5219\u6267\u884c\u4e0b\u9762\u7684\u8bed\u53e5&#xff0c;\u5426\u5219\u8df3\u8fc7\u8be5\u8bed\u53e5\u3002<\/p>\n<p>\u3010\u6f14\u793a\u3011\u6bd4\u5982\u6211\u4eec\u6765\u63a5\u6536\u4e00\u4e2a\u7528\u6237\u8f93\u5165&#xff0c;\u5224\u65ad\u8f93\u5165\u7684\u662f\u5426\u4e3aHello\u5b57\u7b26\u4e32&#xff1a;<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    Scanner scanner &#061; new Scanner(System.in);<br \/>\n    \/\/\u63a5\u6536\u7528\u6237\u8f93\u5165<br \/>\n    System.out.print(&#034;\u8bf7\u8f93\u5165\u5185\u5bb9&#xff1a;&#034;);<br \/>\n    String s &#061; scanner.nextLine();<\/p>\n<p>    if (s.equals(&#034;Hello&#034;)){<br \/>\n        System.out.println(&#034;\u8f93\u5165\u7684\u662f&#xff1a;&#034;&#043;s);<br \/>\n    }<\/p>\n<p>    System.out.println(&#034;End&#034;);<br \/>\n    scanner.close();<br \/>\n} <\/p>\n<p>equals\u65b9\u6cd5\u662f\u7528\u6765\u8fdb\u884c\u5b57\u7b26\u4e32\u7684\u6bd4\u8f83\u7684&#xff0c;\u4e4b\u540e\u4f1a\u8be6\u89e3&#xff0c;\u8fd9\u91cc\u5927\u5bb6\u53ea\u9700\u8981\u77e5\u9053\u4ed6\u662f\u7528\u6765\u6bd4\u8f83\u5b57\u7b26\u4e32\u662f\u5426 \u4e00\u81f4\u7684\u5373\u53ef&#xff01;\u548c&#061;&#061;\u662f\u6709\u533a\u522b\u7684\u3002<\/p>\n<h4 id=\"_2\u3001if\u53cc\u9009\u62e9\u7ed3\u6784\">2\u3001if\u53cc\u9009\u62e9\u7ed3\u6784<\/h4>\n<p>\u90a3\u73b0\u5728\u6709\u4e2a\u9700\u6c42&#xff0c;\u516c\u53f8\u8981\u6536\u8d2d\u4e00\u4e2a\u8f6f\u4ef6&#xff0c;\u6210\u529f\u4e86&#xff0c;\u7ed9\u4eba\u652f\u4ed8100\u4e07\u5143&#xff0c;\u5931\u8d25\u4e86&#xff0c;\u81ea\u5df1\u627e\u4eba\u5f00\u53d1\u3002\u8fd9\u6837\u7684 \u9700\u6c42\u7528\u4e00\u4e2aif\u5c31\u641e\u4e0d\u5b9a\u4e86&#xff0c;\u6211\u4eec\u9700\u8981\u6709\u4e24\u4e2a\u5224\u65ad&#xff0c;\u9700\u8981\u4e00\u4e2a\u53cc\u9009\u62e9\u7ed3\u6784&#xff0c;\u6240\u4ee5\u5c31\u6709\u4e86if-else\u7ed3\u6784\u3002<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"268\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114045017-69672089a01cc.png\" width=\"298\" \/><\/p>\n<\/p>\n<p>if(\u5e03\u5c14\u8868\u8fbe\u5f0f){<br \/>\n    \/\/\u5982\u679c\u5e03\u5c14\u8868\u8fbe\u5f0f\u7684\u503c\u4e3atrue<br \/>\n    }else{<br \/>\n    \/\/\u5982\u679c\u5e03\u5c14\u8868\u8fbe\u5f0f\u7684\u503c\u4e3afalse<br \/>\n} <\/p>\n<p>\u610f\u4e49&#xff1a;\u5f53\u6761\u4ef6\u8868\u8fbe\u5f0f\u4e3a\u771f\u65f6&#xff0c;\u6267\u884c\u8bed\u53e5\u57571&#xff0c;\u5426\u5219&#xff0c;\u6267\u884c\u8bed\u53e5\u57572\u3002\u4e5f\u5c31\u662felse\u90e8\u5206\u3002<\/p>\n<p>\u3010\u6f14\u793a\u3011\u6211\u4eec\u6765\u5199\u4e00\u4e2a\u793a\u4f8b&#xff1a;\u8003\u8bd5\u5206\u6570\u5927\u4e8e60\u5c31\u662f\u53ca\u683c&#xff0c;\u5c0f\u4e8e60\u5206\u5c31\u4e0d\u53ca\u683c\u3002<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    Scanner scanner &#061; new Scanner(System.in);<\/p>\n<p>    System.out.print(&#034;\u8bf7\u8f93\u5165\u6210\u7ee9&#xff1a;&#034;);<br \/>\n    int score &#061; scanner.nextInt();<\/p>\n<p>    if (score&gt;60){<br \/>\n        System.out.println(&#034;\u53ca\u683c&#034;);<br \/>\n    }else {<br \/>\n        System.out.println(&#034;\u4e0d\u53ca\u683c&#034;);<br \/>\n    }<\/p>\n<p>    scanner.close();<br \/>\n} <\/p>\n<h4 id=\"_3\u3001if\u591a\u9009\u62e9\u7ed3\u6784\">3\u3001if\u591a\u9009\u62e9\u7ed3\u6784<\/h4>\n<p>\u6211\u4eec\u53d1\u73b0\u4e0a\u9762\u7684\u793a\u4f8b\u4e0d\u7b26\u5408\u5b9e\u9645\u60c5\u51b5&#xff0c;\u771f\u5b9e\u7684\u60c5\u51b5\u8fd8\u53ef\u80fd\u5b58\u5728ABCD&#xff0c;\u5b58\u5728\u533a\u95f4\u591a\u7ea7\u5224\u65ad\u3002\u6bd4\u598290-100 \u5c31\u662fA&#xff0c;80-90 \u5c31\u662fB&#8230;..&#xff0c;\u5728\u751f\u6d3b\u4e2d\u6211\u4eec\u5f88\u591a\u65f6\u5019\u7684\u9009\u62e9\u4e5f\u4e0d\u4ec5\u4ec5\u53ea\u6709\u4e24\u4e2a&#xff0c;\u6240\u4ee5\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u591a\u9009 \u62e9\u7ed3\u6784\u6765\u5904\u7406\u8fd9\u7c7b\u95ee\u9898&#xff01;<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"462\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114045017-69672089a9b79.png\" width=\"586\" \/><\/p>\n<\/p>\n<p>if(\u5e03\u5c14\u8868\u8fbe\u5f0f 1){<br \/>\n    \/\/\u5982\u679c\u5e03\u5c14\u8868\u8fbe\u5f0f 1\u7684\u503c\u4e3atrue\u6267\u884c\u4ee3\u7801<br \/>\n}else if(\u5e03\u5c14\u8868\u8fbe\u5f0f 2){<br \/>\n    \/\/\u5982\u679c\u5e03\u5c14\u8868\u8fbe\u5f0f 2\u7684\u503c\u4e3atrue\u6267\u884c\u4ee3\u7801<br \/>\n}else if(\u5e03\u5c14\u8868\u8fbe\u5f0f 3){<br \/>\n    \/\/\u5982\u679c\u5e03\u5c14\u8868\u8fbe\u5f0f 3\u7684\u503c\u4e3atrue\u6267\u884c\u4ee3\u7801<br \/>\n}else {<br \/>\n    \/\/\u5982\u679c\u4ee5\u4e0a\u5e03\u5c14\u8868\u8fbe\u5f0f\u90fd\u4e0d\u4e3atrue\u6267\u884c\u4ee3\u7801<br \/>\n} <\/p>\n<p>if \u8bed\u53e5\u540e\u9762\u53ef\u4ee5\u8ddf else if\u2026else \u8bed\u53e5&#xff0c;\u8fd9\u79cd\u8bed\u53e5\u53ef\u4ee5\u68c0\u6d4b\u5230\u591a\u79cd\u53ef\u80fd\u7684\u60c5\u51b5\u3002<\/p>\n<p>\u4f7f\u7528 if&#xff0c;else if&#xff0c;else \u8bed\u53e5\u7684\u65f6\u5019&#xff0c;\u9700\u8981\u6ce8\u610f\u4e0b\u9762\u51e0\u70b9&#xff1a;<\/p>\n<ul>\n<li>if \u8bed\u53e5\u81f3\u591a\u6709 1 \u4e2a else \u8bed\u53e5&#xff0c;else \u8bed\u53e5\u5728\u6240\u6709\u7684 else if \u8bed\u53e5\u4e4b\u540e\u3002<\/li>\n<li>if \u8bed\u53e5\u53ef\u4ee5\u6709\u82e5\u5e72\u4e2a else if \u8bed\u53e5&#xff0c;\u5b83\u4eec\u5fc5\u987b\u5728 else \u8bed\u53e5\u4e4b\u524d\u3002<\/li>\n<li>\u4e00\u65e6\u5176\u4e2d\u4e00\u4e2a else if \u8bed\u53e5\u68c0\u6d4b\u4e3a true&#xff0c;\u5176\u4ed6\u7684 else if \u4ee5\u53ca else \u8bed\u53e5\u90fd\u5c06\u8df3\u8fc7\u6267\u884c\u3002<\/li>\n<\/ul>\n<p>\u3010\u6f14\u793a\u3011\u6211\u4eec\u6765\u6539\u9020\u4e00\u4e0b\u4e0a\u9762\u7684\u6210\u7ee9\u6848\u4f8b&#xff0c;\u5b66\u6821\u6839\u636e\u5206\u6570\u533a\u95f4\u5206\u4e3aABCD\u56db\u4e2a\u7b49\u7ea7&#xff01;<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    Scanner scanner &#061; new Scanner(System.in);<\/p>\n<p>    System.out.print(&#034;\u8bf7\u8f93\u5165\u6210\u7ee9&#xff1a;&#034;);<br \/>\n    int score &#061; scanner.nextInt();<\/p>\n<p>    if (score&#061;&#061;100){<br \/>\n        System.out.println(&#034;\u606d\u559c\u6ee1\u5206&#034;);<br \/>\n    }else if (score&lt;100 &amp;&amp; score &gt;&#061;90){<br \/>\n        System.out.println(&#034;A\u7ea7&#034;);<br \/>\n    }else if (score&lt;90 &amp;&amp; score &gt;&#061;80){<br \/>\n        System.out.println(&#034;B\u7ea7&#034;);<br \/>\n    }else if (score&lt;80 &amp;&amp; score &gt;&#061;70){<br \/>\n        System.out.println(&#034;C\u7ea7&#034;);<br \/>\n    }else if (score&lt;70 &amp;&amp; score &gt;&#061;60){<br \/>\n        System.out.println(&#034;D\u7ea7&#034;);<br \/>\n    }else if (score&lt;60 &amp;&amp; score &gt;&#061;0){<br \/>\n        System.out.println(&#034;\u4e0d\u53ca\u683c&#xff01;&#034;);<br \/>\n    }else {<br \/>\n        System.out.println(&#034;\u6210\u7ee9\u8f93\u5165\u4e0d\u5408\u6cd5&#xff01;&#034;);<br \/>\n    }<br \/>\n    scanner.close();<br \/>\n} <\/p>\n<p>\u6211\u4eec\u5e73\u65f6\u5199\u7a0b\u5e8f\u4e00\u5b9a\u8981\u4e25\u8c28&#xff0c;\u4e0d\u7136\u4e4b\u540e\u4fee\u8865Bug\u662f\u4e00\u4ef6\u5341\u5206\u5934\u75bc\u7684\u4e8b\u60c5&#xff0c;\u8981\u5728\u7f16\u5199\u4ee3\u7801\u7684\u65f6\u5019\u5c31\u628a\u6240\u6709\u7684\u95ee\u9898\u90fd\u601d\u8003\u6e05\u9664&#xff0c;\u518d\u53bb\u4e00\u4e2a\u4e2a\u89e3\u51b3&#xff0c;\u8fd9\u624d\u662f\u4e00\u4e2a\u4f18\u79c0\u7684\u7a0b\u5e8f\u5458\u5e94\u8be5\u505a\u7684\u4e8b\u60c5&#xff0c;\u591a\u601d\u8003&#xff0c;\u5c11\u72af\u9519&#xff01;<\/p>\n<h4 id=\"_4\u3001\u5d4c\u5957\u7684if\u7ed3\u6784\">4\u3001\u5d4c\u5957\u7684if\u7ed3\u6784<\/h4>\n<p>\u4f7f\u7528\u5d4c\u5957\u7684 if\u2026else \u8bed\u53e5\u662f\u5408\u6cd5\u7684\u3002\u4e5f\u5c31\u662f\u8bf4\u4f60\u53ef\u4ee5\u5728\u53e6\u4e00\u4e2a if \u6216\u8005 else if \u8bed\u53e5\u4e2d\u4f7f\u7528 if \u6216\u8005 else if \u8bed \u53e5\u3002\u4f60\u53ef\u4ee5\u50cf if \u8bed\u53e5\u4e00\u6837\u5d4c\u5957 else if&#8230;else\u3002<\/p>\n<\/p>\n<p>if(\u5e03\u5c14\u8868\u8fbe\u5f0f 1){<br \/>\n    \/\/\/\/\u5982\u679c\u5e03\u5c14\u8868\u8fbe\u5f0f 1\u7684\u503c\u4e3atrue\u6267\u884c\u4ee3\u7801<br \/>\n    if(\u5e03\u5c14\u8868\u8fbe\u5f0f 2){<br \/>\n        \/\/\/\/\u5982\u679c\u5e03\u5c14\u8868\u8fbe\u5f0f 2\u7684\u503c\u4e3atrue\u6267\u884c\u4ee3\u7801<br \/>\n    }<br \/>\n} <\/p>\n<p>\u6709\u65f6\u5019\u6211\u4eec\u5728\u89e3\u51b3\u67d0\u4e9b\u95ee\u9898\u7684\u65f6\u5019&#xff0c;\u9700\u8981\u7f29\u5c0f\u67e5\u627e\u8303\u56f4&#xff0c;\u9700\u8981\u6709\u5c42\u7ea7\u6761\u4ef6\u5224\u65ad&#xff0c;\u63d0\u9ad8\u6548\u7387\u3002\u6bd4\u5982&#xff1a;\u6211\u4eec\u9700\u8981\u5bfb\u627e\u4e00\u4e2a\u6570&#xff0c;\u57281-100\u4e4b\u95f4&#xff0c;\u6211\u4eec\u4e0d\u77e5\u9053\u8fd9\u4e2a\u6570\u662f\u591a\u5c11\u7684\u60c5\u51b5\u4e0b&#xff0c;\u6211\u4eec\u6700\u7b28\u7684\u65b9\u5f0f\u5c31\u662f\u4e00\u4e2a\u4e2a\u53bb\u5bf9\u6bd4&#xff0c;\u770b\u4ed6\u5230\u5e95\u662f\u591a\u5c11&#xff0c;\u8fd9\u4f1a\u82b1\u6389\u4f60\u5927\u91cf\u7684\u65f6\u95f4&#xff0c;\u5982\u679c\u53ef\u4ee5\u5229\u7528if\u5d4c\u5957\u6bd4\u8f83&#xff0c;\u6211\u4eec\u53ef\u4ee5\u8282\u7701\u5927\u91cf\u7684\u6210\u672c&#xff0c;\u5982\u679c\u4f60\u6709\u8fd9\u4e2a\u601d\u60f3&#xff0c;\u4f60\u5df2\u7ecf\u5f88\u4f18\u79c0\u4e86&#xff0c;\u56e0\u4e3a\u5f88\u591a\u5927\u91cf\u7684\u5de5\u7a0b\u5e08\u5c31\u5728\u5bfb\u627e\u80fd\u591f\u5feb\u901f\u63d0\u9ad8&#xff0c;\u67e5\u627e\u548c\u641c\u7d22\u6548\u7387\u7684\u65b9\u5f0f\u3002\u4e3a\u6b64\u63d0\u51fa\u4e86\u4e00\u7cfb\u5217\u7684\u6982\u5ff5&#xff0c;\u6211\u4eec\u751f\u6d3b\u5728\u5927\u6570\u636e\u65f6\u4ee3&#xff0c;\u6211\u4eec\u9700\u8981\u4e0d\u65ad\u7684\u53bb\u601d\u8003\u5982\u4f55\u63d0\u9ad8\u6548\u7387&#xff0c;\u6216\u8bb8\u54ea\u4e00\u5929&#xff0c;\u4f60\u4eec\u60f3\u51fa\u4e00\u4e2a\u7b97\u6cd5&#xff0c;\u80fd\u591f\u5c06\u5206\u6790\u6570\u636e\u6548\u7387\u63d0\u9ad8&#xff0c;\u6216\u8bb8\u4f60\u5c31\u53ef\u4ee5\u5728\u5386\u53f2\u7684\u957f\u6cb3\u4e2d\u7559\u4e0b\u4e00\u4e9b\u75d5\u8ff9\u4e86&#xff0c;\u5f53\u7136\u8fd9\u662f\u540e\u8bdd\u3002<\/p>\n<h4 id=\"_5\u3001switch\u591a\u9009\u62e9\u7ed3\u6784\">5\u3001switch\u591a\u9009\u62e9\u7ed3\u6784<\/h4>\n<p>\u591a\u9009\u62e9\u7ed3\u6784\u8fd8\u6709\u4e00\u4e2a\u5b9e\u73b0\u65b9\u5f0f\u5c31\u662fswitch case \u8bed\u53e5\u3002<\/p>\n<p>switch case \u8bed\u53e5\u5224\u65ad\u4e00\u4e2a\u53d8\u91cf\u4e0e\u4e00\u7cfb\u5217\u503c\u4e2d\u67d0\u4e2a\u503c\u662f\u5426\u76f8\u7b49&#xff0c;\u6bcf\u4e2a\u503c\u79f0\u4e3a\u4e00\u4e2a\u5206\u652f\u3002<\/p>\n<\/p>\n<p>switch(expression){<br \/>\n    case value :<br \/>\n        \/\/\u8bed\u53e5<br \/>\n        break; \/\/\u53ef\u9009<br \/>\n    case value :<br \/>\n        \/\/\u8bed\u53e5<br \/>\n        break; \/\/\u53ef\u9009<br \/>\n    \/\/\u4f60\u53ef\u4ee5\u6709\u4efb\u610f\u6570\u91cf\u7684case\u8bed\u53e5<br \/>\n    default : \/\/\u53ef\u9009<br \/>\n        \/\/\u8bed\u53e5<br \/>\n} <\/p>\n<p>switch case \u8bed\u53e5\u6709\u5982\u4e0b\u89c4\u5219&#xff1a;<\/p>\n<ul>\n<li>switch \u8bed\u53e5\u4e2d\u7684\u53d8\u91cf\u7c7b\u578b\u53ef\u4ee5\u662f&#xff1a; byte\u3001short\u3001int \u6216\u8005 char\u3002\u4ece Java SE 7 \u5f00\u59cb&#xff0c;switch \u652f\u6301\u5b57\u7b26\u4e32 String \u7c7b\u578b\u4e86&#xff0c;\u540c\u65f6 case \u6807\u7b7e\u5fc5\u987b\u4e3a\u5b57\u7b26\u4e32\u5e38\u91cf\u6216\u5b57\u9762\u91cf\u3002<\/li>\n<li>switch \u8bed\u53e5\u53ef\u4ee5\u62e5\u6709\u591a\u4e2a case \u8bed\u53e5\u3002\u6bcf\u4e2a case \u540e\u9762\u8ddf\u4e00\u4e2a\u8981\u6bd4\u8f83\u7684\u503c\u548c\u5192\u53f7\u3002<\/li>\n<li>case \u8bed\u53e5\u4e2d\u7684\u503c\u7684\u6570\u636e\u7c7b\u578b\u5fc5\u987b\u4e0e\u53d8\u91cf\u7684\u6570\u636e\u7c7b\u578b\u76f8\u540c&#xff0c;\u800c\u4e14\u53ea\u80fd\u662f\u5e38\u91cf\u6216\u8005\u5b57\u9762\u5e38\u91cf\u3002<\/li>\n<li>\u5f53\u53d8\u91cf\u7684\u503c\u4e0e case \u8bed\u53e5\u7684\u503c\u76f8\u7b49\u65f6&#xff0c;\u90a3\u4e48 case \u8bed\u53e5\u4e4b\u540e\u7684\u8bed\u53e5\u5f00\u59cb\u6267\u884c&#xff0c;\u76f4\u5230 break \u8bed\u53e5\u51fa\u73b0\u624d\u4f1a\u8df3\u51fa switch \u8bed\u53e5\u3002<\/li>\n<li>\u5f53\u9047\u5230 break \u8bed\u53e5\u65f6&#xff0c;switch \u8bed\u53e5\u7ec8\u6b62\u3002\u7a0b\u5e8f\u8df3\u8f6c\u5230 switch \u8bed\u53e5\u540e\u9762\u7684\u8bed\u53e5\u6267\u884c\u3002case \u8bed\u53e5\u4e0d\u5fc5\u987b\u8981\u5305\u542b break \u8bed\u53e5\u3002\u5982\u679c\u6ca1\u6709 break \u8bed\u53e5\u51fa\u73b0&#xff0c;\u7a0b\u5e8f\u4f1a\u7ee7\u7eed\u6267\u884c\u4e0b\u4e00\u6761 case \u8bed\u53e5&#xff0c;\u76f4\u5230\u51fa\u73b0 break \u8bed\u53e5\u3002<\/li>\n<li>switch \u8bed\u53e5\u53ef\u4ee5\u5305\u542b\u4e00\u4e2a default \u5206\u652f&#xff0c;\u8be5\u5206\u652f\u4e00\u822c\u662f switch \u8bed\u53e5\u7684\u6700\u540e\u4e00\u4e2a\u5206\u652f&#xff08;\u53ef\u4ee5\u5728\u4efb\u4f55\u4f4d\u7f6e&#xff0c;\u4f46\u5efa\u8bae\u5728\u6700\u540e\u4e00\u4e2a&#xff09;\u3002default \u5728\u6ca1\u6709 case \u8bed\u53e5\u7684\u503c\u548c\u53d8\u91cf\u503c\u76f8\u7b49\u7684\u65f6\u5019\u6267\u884c\u3002default \u5206\u652f\u4e0d\u9700\u8981 break \u8bed\u53e5\u3002<\/li>\n<\/ul>\n<p>switch case \u6267\u884c\u65f6&#xff0c;\u4e00\u5b9a\u4f1a\u5148\u8fdb\u884c\u5339\u914d&#xff0c;\u5339\u914d\u6210\u529f\u8fd4\u56de\u5f53\u524d case \u7684\u503c&#xff0c;\u518d\u6839\u636e\u662f\u5426\u6709 break&#xff0c;\u5224\u65ad\u662f\u5426\u7ee7\u7eed\u8f93\u51fa&#xff0c;\u6216\u662f\u8df3\u51fa\u5224\u65ad\u3002<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    char grade &#061; &#039;C&#039;;<br \/>\n    switch (grade) {<br \/>\n        case &#039;A&#039;:<br \/>\n            System.out.println(&#034;\u4f18\u79c0&#034;);<br \/>\n            break;<br \/>\n        case &#039;B&#039;:<br \/>\n            System.out.println(&#034;\u79c0&#034;);<br \/>\n            break;<br \/>\n        case &#039;C&#039;:<br \/>\n            System.out.println(&#034;\u826f\u597d&#034;);<br \/>\n            break;<br \/>\n        case &#039;D&#039;:<br \/>\n            System.out.println(&#034;\u53ca\u683c&#034;);<br \/>\n            break;<br \/>\n        case &#039;F&#039;:<br \/>\n            System.out.println(&#034;\u4f60\u9700\u8981\u518d\u52aa\u529b\u52aa\u529b&#034;);<br \/>\n            break;<br \/>\n        default:<br \/>\n            System.out.println(&#034;\u672a\u77e5\u7b49\u7ea7&#034;);<br \/>\n    }<br \/>\n    System.out.println(&#034;\u4f60\u7684\u7b49\u7ea7\u662f &#034; &#043; grade);<br \/>\n} <\/p>\n<p>\u5982\u679c case \u8bed\u53e5\u5757\u4e2d\u6ca1\u6709 break \u8bed\u53e5\u65f6&#xff0c;\u5339\u914d\u6210\u529f\u540e&#xff0c;\u4ece\u5f53\u524d case \u5f00\u59cb&#xff0c;\u540e\u7eed\u6240\u6709 case \u7684\u503c\u90fd\u4f1a\u8f93 \u51fa\u3002\u5982\u679c\u540e\u7eed\u7684 case \u8bed\u53e5\u5757\u6709 break \u8bed\u53e5\u5219\u4f1a\u8df3\u51fa\u5224\u65ad\u3002<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int i &#061; 1;<br \/>\n    switch (i) {<br \/>\n        case 0:<br \/>\n            System.out.println(&#034;0&#034;);<br \/>\n        case 1:<br \/>\n            System.out.println(&#034;1&#034;);<br \/>\n        case 2:<br \/>\n            System.out.println(&#034;2&#034;);<br \/>\n        case 3:<br \/>\n            System.out.println(&#034;3&#034;);<br \/>\n            break;<br \/>\n        default:<br \/>\n            System.out.println(&#034;default&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u8f93\u51fa&#xff1a;1&#xff0c;2&#xff0c;3\u3002<\/p>\n<p>\u3010JDK7\u589e\u52a0\u4e86\u5b57\u7b26\u4e32\u8868\u8fbe\u5f0f\u3011<\/p>\n<p>case \u540e\u8fb9\u7684\u53ef\u4ee5\u662f\u5b57\u7b26\u4e32\u7684\u8868\u8fbe\u5f62\u5f0f<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    String name &#061; &#034;\u4f60\u597d&#034;;<\/p>\n<p>    switch (name) {<br \/>\n        \/\/JDK7\u7684\u65b0\u7279\u6027&#xff0c;\u8868\u8fbe\u5f0f\u7ed3\u679c\u53ef\u4ee5\u662f\u5b57\u7b26\u4e32&#xff01;&#xff01;&#xff01;<br \/>\n        case &#034;\u4f60\u597d&#034;:<br \/>\n            System.out.println(&#034;\u4f60\u597d&#034;);<br \/>\n            break;<br \/>\n        case &#034;\u6211\u597d&#034;:<br \/>\n            System.out.println(&#034;\u6211\u597d&#034;);<br \/>\n            break;<br \/>\n        default:<br \/>\n            System.out.println(&#034;\u5565\u90fd\u4e0d\u597d&#034;);<br \/>\n            break;<br \/>\n    }<br \/>\n} <\/p>\n<h2>\u5341\u56db\u3001\u5faa\u73af\u7ed3\u6784<\/h2>\n<p>\u4e0a\u9762\u9009\u62e9\u7ed3\u6784\u4e2d&#xff0c;\u6211\u4eec\u59cb\u7ec8\u65e0\u6cd5\u8ba9\u7a0b\u5e8f\u4e00\u76f4\u8dd1\u7740&#xff0c;\u6211\u4eec\u6bcf\u6b21\u8fd0\u884c\u5c31\u505c\u6b62\u4e86\u3002\u6211\u4eec\u9700\u8981\u89c4\u5b9a\u4e00\u4e2a\u7a0b\u5e8f\u8fd0\u884c\u591a\u5c11\u6b21&#xff0c;\u8fd0\u884c\u591a\u4e45&#xff0c;\u7b49\u7b49\u3002\u6240\u4ee5\u6309\u7167\u6211\u4eec\u7f16\u7a0b\u662f\u4e3a\u4e86\u89e3\u51b3\u4eba\u7684\u95ee\u9898\u7684\u601d\u60f3&#xff0c;\u6211\u4eec\u662f\u4e0d\u662f\u5f97\u9700\u8981\u6709\u4e00\u4e2a\u7ed3\u6784\u6765\u641e\u5b9a\u8fd9\u4e2a\u4e8b\u60c5&#xff01;\u4e8e\u662f\u5faa\u73af\u7ed3\u6784\u81ea\u7136\u7684\u8bde\u751f\u4e86&#xff01;<\/p>\n<p>\u987a\u5e8f\u7ed3\u6784\u7684\u7a0b\u5e8f\u8bed\u53e5\u53ea\u80fd\u88ab\u6267\u884c\u4e00\u6b21\u3002\u5982\u679c\u60a8\u60f3\u8981\u540c\u6837\u7684\u64cd\u4f5c\u6267\u884c\u591a\u6b21,&#xff0c;\u5c31\u9700\u8981\u4f7f\u7528\u5faa\u73af\u7ed3\u6784\u3002<\/p>\n<p>Java\u4e2d\u6709\u4e09\u79cd\u4e3b\u8981\u7684\u5faa\u73af\u7ed3\u6784&#xff1a;<\/p>\n<ul>\n<li>while \u5faa\u73af<\/li>\n<li>do\u2026while \u5faa\u73af<\/li>\n<li>for \u5faa\u73af<\/li>\n<\/ul>\n<p>\u5728Java5\u4e2d\u5f15\u5165\u4e86\u4e00\u79cd\u4e3b\u8981\u7528\u4e8e\u6570\u7ec4\u7684\u589e\u5f3a\u578bfor\u5faa\u73af\u3002<\/p>\n<h4 id=\"_1\u3001while-\u5faa\u73af\">1\u3001while \u5faa\u73af<\/h4>\n<p>while\u662f\u6700\u57fa\u672c\u7684\u5faa\u73af&#xff0c;\u5b83\u7684\u7ed3\u6784\u4e3a&#xff1a;<\/p>\n<\/p>\n<p>while( \u5e03\u5c14\u8868\u8fbe\u5f0f ) {<br \/>\n    \/\/\u5faa\u73af\u5185\u5bb9<br \/>\n} <\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"279\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114045017-69672089bd11b.png\" width=\"335\" \/><\/p>\n<p>\u3010\u56fe\u89e3\u3011\u5728\u5faa\u73af\u521a\u5f00\u59cb\u65f6&#xff0c;\u4f1a\u8ba1\u7b97\u4e00\u6b21\u201c\u5e03\u5c14\u8868\u8fbe\u5f0f\u201d\u7684\u503c&#xff0c;\u82e5\u6761\u4ef6\u4e3a\u771f&#xff0c;\u6267\u884c\u5faa\u73af\u4f53\u3002\u800c\u5bf9\u4e8e\u540e\u6765\u6bcf\u4e00 \u6b21\u989d\u5916\u7684\u5faa\u73af&#xff0c;\u90fd\u4f1a\u5728\u5f00\u59cb\u524d\u91cd\u65b0\u8ba1\u7b97\u4e00\u6b21\u5224\u65ad\u662f\u5426\u4e3a\u771f\u3002\u76f4\u5230\u6761\u4ef6\u4e0d\u6210\u7acb&#xff0c;\u5219\u5faa\u73af\u7ed3\u675f\u3002<\/p>\n<p>\u6211\u4eec\u5927\u591a\u6570\u60c5\u51b5\u662f\u4f1a\u8ba9\u5faa\u73af\u505c\u6b62\u4e0b\u6765\u7684&#xff0c;\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u8ba9\u8868\u8fbe\u5f0f\u5931\u6548\u7684\u65b9\u5f0f\u6765\u7ed3\u675f\u5faa\u73af\u3002<\/p>\n<p>\u65b9\u5f0f\u6709&#xff1a;\u5faa\u73af\u5185\u90e8\u63a7\u5236&#xff0c;\u5916\u90e8\u8bbe\u7acb\u6807\u5fd7\u4f4d&#xff01;\u7b49<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int i &#061; 0;<br \/>\n    \/\/i\u5c0f\u4e8e100\u5c31\u4f1a\u4e00\u76f4\u5faa\u73af<br \/>\n    while (i&lt;100){<br \/>\n        i&#043;&#043;;<br \/>\n        System.out.println(i);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u5c11\u90e8\u5206\u60c5\u51b5\u9700\u8981\u5faa\u73af\u4e00\u76f4\u6267\u884c&#xff0c;\u6bd4\u5982\u670d\u52a1\u5668\u7684\u8bf7\u6c42\u54cd\u5e94\u76d1\u542c\u7b49\u3002<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    while (true){<br \/>\n        \/\/\u7b49\u5f85\u5ba2\u6237\u7aef\u8fde\u63a5<br \/>\n        \/\/\u5b9a\u65f6\u68c0\u67e5<br \/>\n        \/\/&#8230;&#8230;<br \/>\n    }<br \/>\n} <\/p>\n<p>\u5faa\u73af\u6761\u4ef6\u4e00\u76f4\u4e3atrue\u5c31\u4f1a\u9020\u6210\u65e0\u9650\u5faa\u73af\u3010\u6b7b\u5faa\u73af\u3011&#xff0c;\u6211\u4eec\u6b63\u5e38\u7684\u4e1a\u52a1\u7f16\u7a0b\u4e2d\u5e94\u8be5\u5c3d\u91cf\u907f\u514d\u6b7b\u5faa\u73af\u3002\u4f1a\u5f71 \u54cd\u7a0b\u5e8f\u6027\u80fd\u6216\u8005\u9020\u6210\u7a0b\u5e8f\u5361\u6b7b\u5954\u6e83&#xff01;<\/p>\n<p>\u3010\u6848\u4f8b&#xff1a;\u8ba1\u7b971&#043;2&#043;3&#043;\u2026&#043;100&#061;?\u3011<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int i &#061; 0;<br \/>\n    int sum &#061; 0;<br \/>\n    while (i &lt;&#061; 100) {<br \/>\n        sum &#061; sum&#043;i;<br \/>\n        i&#043;&#043;;<br \/>\n    }<br \/>\n    System.out.println(&#034;Sum&#061; &#034; &#043; sum);<br \/>\n} <\/p>\n<p>\u3010\u9ad8\u65af\u7684\u6545\u4e8b\u3011<\/p>\n<p>\u5fb7\u56fd\u5927\u6570\u5b66\u5bb6\u9ad8\u65af&#xff08;Gauss&#xff09;&#xff1a;\u9ad8\u65af\u662f\u4e00\u5bf9\u666e\u901a\u592b\u5987\u7684\u513f\u5b50\u3002\u4ed6\u7684\u6bcd\u4eb2\u662f\u4e00\u4e2a\u8d2b\u7a77\u77f3\u5320\u7684\u5973\u513f&#xff0c;\u867d\u7136\u5341\u5206\u806a\u660e&#xff0c;\u4f46\u5374\u6ca1\u6709\u63a5\u53d7\u8fc7\u6559\u80b2&#xff0c;\u8fd1\u4f3c\u4e8e\u6587\u76f2\u3002\u5728\u5979\u6210\u4e3a\u9ad8\u65af\u7236\u4eb2\u7684\u7b2c\u4e8c\u4e2a\u59bb\u5b50\u4e4b\u524d&#xff0c;\u5979\u4ece\u4e8b\u5973\u4f63\u5de5\u4f5c\u3002\u4ed6\u7684\u7236\u4eb2\u66fe\u505a\u8fc7\u56ed\u4e01&#xff0c;\u5de5\u5934&#xff0c;\u5546\u4eba\u7684\u52a9\u624b\u548c\u4e00\u4e2a\u5c0f\u4fdd\u9669\u516c\u53f8\u7684\u8bc4\u4f30\u5e08\u3002\u5f53\u9ad8\u65af\u4e09\u5c81\u65f6\u4fbf\u80fd\u591f\u7ea0\u6b63\u4ed6\u7236\u4eb2\u7684\u501f\u503a\u8d26\u76ee\u7684\u4e8b\u60c5&#xff0c; \u5df2\u7ecf\u6210\u4e3a\u4e00\u4e2a\u8f76\u4e8b\u6d41\u4f20\u81f3\u4eca\u3002\u4ed6\u66fe\u8bf4&#xff0c;\u4ed6\u5728\u9ea6\u4ed9\u7fc1\u5806\u4e0a\u5b66\u4f1a\u8ba1\u7b97\u3002\u80fd\u591f\u5728\u5934\u8111\u4e2d\u8fdb\u884c\u590d\u6742\u7684\u8ba1\u7b97&#xff0c;\u662f\u4e0a\u5e1d\u8d50\u4e88\u4ed6\u4e00\u751f\u7684\u5929\u8d4b\u3002<\/p>\n<p>\u9ad8\u65af\u7528\u5f88\u77ed\u7684\u65f6\u95f4\u8ba1\u7b97\u51fa\u4e86\u5c0f\u5b66\u8001\u5e08\u5e03\u7f6e\u7684\u4efb\u52a1&#xff1a;\u5bf9\u81ea\u7136\u6570\u4ece1\u5230100\u7684\u6c42\u548c.\u4ed6\u6240\u4f7f\u7528\u7684\u65b9\u6cd5\u662f&#xff1a;\u5bf950 \u5bf9\u6784\u9020\u6210\u548c101\u7684\u6570\u5217\u6c42\u548c&#xff08;1&#xff0b;100,2&#xff0b;99,3&#xff0b;98\u2026\u2026&#xff09;,\u540c\u65f6\u5f97\u5230\u7ed3\u679c&#xff1a;5050.\u8fd9\u4e00\u5e74,\u9ad8\u65af9\u5c81.<\/p>\n<p>\u8fd9\u4e2a\u6545\u4e8b\u6211\u4eec\u5728\u9ad8\u4e2d\u6570\u5b66\u4e2d\u7684\u201c\u7b49\u5dee\u6570\u5217\u6c42\u548c\u201d\u542c\u8fc7&#xff0c;\u5f53\u65f6\u6211\u4eec\u7528\u7684\u516c\u5f0f\u6c42\u89e3\u3002<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"363\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114045017-69672089cc47a.png\" width=\"533\" \/><\/p>\n<p>\u7f16\u7a0b\u96be\u7684\u4e0d\u662f\u8bed\u8a00&#xff0c;\u662f\u7b97\u6cd5\u3002\u6570\u5b66\u80fd\u8ba9\u4f60\u5199\u7684\u7a0b\u5e8f\u8fd0\u7b97\u6b21\u6570\u66f4\u5c11&#xff0c;\u6548\u7387\u66f4\u9ad8\u3002<\/p>\n<p>\u5982\u679c\u6c421&#043;2&#043;3&#8230;..&#043;100\u4e07\u5462&#xff0c;\u867d\u7136100\u4e07\u6b21\u7684\u8fd0\u7b97\u52a0\u6cd5&#xff0c;\u5bf9\u4e8e\u8ba1\u7b97\u673a\u4e0d\u7b97\u4ec0\u4e48&#xff0c;\u4f46\u6211\u4eec\u4e3a\u4e86\u6548\u7387\u53ef\u4ee5\u7528\u6570\u5b66\u516c\u5f0f\u8fdb\u884c\u6c42\u89e3\u3002<\/p>\n<p>\u6709\u80fd\u529b\u7684\u540c\u5b66\u53ef\u4ee5\u770b\u4e0b\u7f16\u7a0b\u7a0b\u5e8f\u6bd4\u8d5b&#xff0c;\u8003\u9a8c\u7b97\u6cd5\u80fd\u529b\u7684&#xff0c;\u4f8b\u5982&#xff1a;\u201c\u4f20\u667a\u676f\u201d&#xff0c;\u201c\u84dd\u6865\u676f\u201d<\/p>\n<h4 id=\"_2\u3001do-while-\u5faa\u73af\">2\u3001do\u2026while \u5faa\u73af<\/h4>\n<p>\u5bf9\u4e8e while \u8bed\u53e5\u800c\u8a00&#xff0c;\u5982\u679c\u4e0d\u6ee1\u8db3\u6761\u4ef6&#xff0c;\u5219\u4e0d\u80fd\u8fdb\u5165\u5faa\u73af\u3002\u4f46\u6709\u65f6\u5019\u6211\u4eec\u9700\u8981\u5373\u4f7f\u4e0d\u6ee1\u8db3\u6761\u4ef6&#xff0c;\u4e5f\u81f3\u5c11 \u6267\u884c\u4e00\u6b21\u3002<\/p>\n<p>do\u2026while \u5faa\u73af\u548c while \u5faa\u73af\u76f8\u4f3c&#xff0c;\u4e0d\u540c\u7684\u662f&#xff0c;do\u2026while \u5faa\u73af\u81f3\u5c11\u4f1a\u6267\u884c\u4e00\u6b21\u3002<\/p>\n<\/p>\n<p>do {<br \/>\n    \/\/\u4ee3\u7801\u8bed\u53e5<br \/>\n}while(\u5e03\u5c14\u8868\u8fbe\u5f0f); <\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"278\" src=\"2026-01-14avt3edx4uth.png\" width=\"292\" \/><\/p>\n<p>\u6ce8\u610f&#xff1a;\u5e03\u5c14\u8868\u8fbe\u5f0f\u5728\u5faa\u73af\u4f53\u7684\u540e\u9762&#xff0c;\u6240\u4ee5\u8bed\u53e5\u5757\u5728\u68c0\u6d4b\u5e03\u5c14\u8868\u8fbe\u5f0f\u4e4b\u524d\u5df2\u7ecf\u6267\u884c\u4e86\u3002 \u5982\u679c\u5e03\u5c14\u8868\u8fbe\u5f0f\u7684\u503c\u4e3a true&#xff0c;\u5219\u8bed\u53e5\u5757\u4e00\u76f4\u6267\u884c&#xff0c;\u76f4\u5230\u5e03\u5c14\u8868\u8fbe\u5f0f\u7684\u503c\u4e3a false\u3002<\/p>\n<p>\u6211\u4eec\u7528do&#8230;while\u6539\u9020\u4e00\u4e0b\u4e0a\u9762\u7684\u6848\u4f8b&#xff01;<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int i &#061; 0;<br \/>\n    int sum &#061; 0;<br \/>\n    do {<br \/>\n        sum &#061; sum&#043;i;<br \/>\n        i&#043;&#043;;<br \/>\n    }while (i &lt;&#061; 100);<br \/>\n    System.out.println(&#034;Sum&#061; &#034; &#043; sum);<br \/>\n} <\/p>\n<p>\u6267\u884c\u7ed3\u679c\u5f53\u7136\u662f\u4e00\u6837\u7684&#xff01;<\/p>\n<p>While\u548cdo-While\u7684\u533a\u522b&#xff1a;<\/p>\n<p>while\u5148\u5224\u65ad\u540e\u6267\u884c\u3002dowhile\u662f\u5148\u6267\u884c\u540e\u5224\u65ad&#xff01;<\/p>\n<p>Do&#8230;while\u603b\u662f\u4fdd\u8bc1\u5faa\u73af\u4f53\u4f1a\u88ab\u81f3\u5c11\u6267\u884c\u4e00\u6b21&#xff01;\u8fd9\u662f\u4ed6\u4eec\u7684\u4e3b\u8981\u5dee\u522b\u3002<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int a &#061; 0;<br \/>\n    while(a&lt;0){<br \/>\n        System.out.println(a);<br \/>\n        a&#043;&#043;;<br \/>\n    }<br \/>\n    System.out.println(&#034;&#8212;&#8211;&#034;);<br \/>\n    do{<br \/>\n        System.out.println(a);<br \/>\n        a&#043;&#043;;<br \/>\n    } while (a&lt;0);<br \/>\n} <\/p>\n<h4 id=\"_3\u3001for\u5faa\u73af\">3\u3001For\u5faa\u73af<\/h4>\n<p>\u867d\u7136\u6240\u6709\u5faa\u73af\u7ed3\u6784\u90fd\u53ef\u4ee5\u7528 while \u6216\u8005 do&#8230;while\u8868\u793a&#xff0c;\u4f46 Java \u63d0\u4f9b\u4e86\u53e6\u4e00\u79cd\u8bed\u53e5 \u2014\u2014 for \u5faa\u73af&#xff0c;\u4f7f\u4e00\u4e9b\u5faa\u73af\u7ed3\u6784\u53d8\u5f97\u66f4\u52a0\u7b80\u5355\u3002<\/p>\n<p>for\u5faa\u73af\u8bed\u53e5\u662f\u652f\u6301\u8fed\u4ee3\u7684\u4e00\u79cd\u901a\u7528\u7ed3\u6784&#xff0c;\u662f\u6700\u6709\u6548\u3001\u6700\u7075\u6d3b\u7684\u5faa\u73af\u7ed3\u6784\u3002<\/p>\n<p>for\u5faa\u73af\u6267\u884c\u7684\u6b21\u6570\u662f\u5728\u6267\u884c\u524d\u5c31\u786e\u5b9a\u7684\u3002\u8bed\u6cd5\u683c\u5f0f\u5982\u4e0b&#xff1a;<\/p>\n<\/p>\n<p>for(\u521d\u59cb\u5316; \u5e03\u5c14\u8868\u8fbe\u5f0f; \u66f4\u65b0) {<br \/>\n    \/\/\u4ee3\u7801\u8bed\u53e5<br \/>\n} <\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"300\" src=\"2026-01-14nqgwfohhunt.png\" width=\"254\" \/><\/p>\n<p>\u5173\u4e8e for \u5faa\u73af\u6709\u4ee5\u4e0b\u51e0\u70b9\u8bf4\u660e&#xff1a;<\/p>\n<ul>\n<li>\u6700\u5148\u6267\u884c\u521d\u59cb\u5316\u6b65\u9aa4\u3002\u53ef\u4ee5\u58f0\u660e\u4e00\u79cd\u7c7b\u578b&#xff0c;\u4f46\u53ef\u521d\u59cb\u5316\u4e00\u4e2a\u6216\u591a\u4e2a\u5faa\u73af\u63a7\u5236\u53d8\u91cf&#xff0c;\u4e5f\u53ef\u4ee5\u662f\u7a7a\u8bed\u53e5\u3002<\/li>\n<li>\u7136\u540e&#xff0c;\u68c0\u6d4b\u5e03\u5c14\u8868\u8fbe\u5f0f\u7684\u503c\u3002\u5982\u679c\u4e3a true&#xff0c;\u5faa\u73af\u4f53\u88ab\u6267\u884c\u3002\u5982\u679c\u4e3afalse&#xff0c;\u5faa\u73af\u7ec8\u6b62&#xff0c;\u5f00\u59cb\u6267\u884c\u5faa\u73af\u4f53\u540e\u9762\u7684\u8bed\u53e5\u3002<\/li>\n<li>\u6267\u884c\u4e00\u6b21\u5faa\u73af\u540e&#xff0c;\u66f4\u65b0\u5faa\u73af\u63a7\u5236\u53d8\u91cf(\u8fed\u4ee3\u56e0\u5b50\u63a7\u5236\u5faa\u73af\u53d8\u91cf\u7684\u589e\u51cf\u3002<\/li>\n<li>\u518d\u6b21\u68c0\u6d4b\u5e03\u5c14\u8868\u8fbe\u5f0f\u3002\u5faa\u73af\u6267\u884c\u4e0a\u9762\u7684\u8fc7\u7a0b\u3002<\/li>\n<\/ul>\n<p>\u3010\u6f14\u793a&#xff1a;while\u548cfor\u8f93\u51fa\u3011<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int a &#061; 1; \/\/\u521d\u59cb\u5316<\/p>\n<p>    while(a&lt;&#061;100){ \/\/\u6761\u4ef6\u5224\u65ad<br \/>\n        System.out.println(a); \/\/\u5faa\u73af\u4f53<br \/>\n        a&#043;&#061;2; \/\/\u8fed\u4ee3<br \/>\n    }<br \/>\n    System.out.println(&#034;while\u5faa\u73af\u7ed3\u675f&#xff01;&#034;);<\/p>\n<p>    for(int i &#061; 1;i&lt;&#061;100;i&#043;&#043;){ \/\/\u521d\u59cb\u5316\/\/\u6761\u4ef6\u5224\u65ad \/\/\u8fed\u4ee3<br \/>\n        System.out.println(i); \/\/\u5faa\u73af\u4f53<br \/>\n    }<br \/>\n    System.out.println(&#034;while\u5faa\u73af\u7ed3\u675f&#xff01;&#034;);<br \/>\n} <\/p>\n<p>\u6211\u4eec\u53d1\u73b0&#xff0c;for\u5faa\u73af\u5728\u77e5\u9053\u5faa\u73af\u6b21\u6570\u7684\u60c5\u51b5\u4e0b&#xff0c;\u7b80\u5316\u4e86\u4ee3\u7801&#xff0c;\u63d0\u9ad8\u4e86\u53ef\u8bfb\u6027\u3002\u6211\u4eec\u5e73\u65f6\u7528\u5230\u7684\u6700\u591a\u7684\u4e5f\u662f \u6211\u4eec\u7684for\u5faa\u73af&#xff01;<\/p>\n<h4 id=\"_4\u3001\u7ec3\u4e60\">4\u3001\u7ec3\u4e60<\/h4>\n<p>\u3010\u7ec3\u4e601&#xff1a;\u8ba1\u7b970\u5230100\u4e4b\u95f4\u7684\u5947\u6570\u548c\u5076\u6570\u7684\u548c\u3011<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int oddSum &#061; 0; \/\/\u7528\u6765\u4fdd\u5b58\u5947\u6570\u7684\u548c<br \/>\n    int evenSum &#061; 0; \/\/\u7528\u6765\u5b58\u653e\u5076\u6570\u7684\u548c<br \/>\n    for (int i &#061; 0; i &lt;&#061; 100; i&#043;&#043;) {<br \/>\n        if (i % 2 !&#061; 0) {<br \/>\n            oddSum &#043;&#061; i;<br \/>\n        } else {<br \/>\n            evenSum &#043;&#061; i;<br \/>\n        }<br \/>\n    }<br \/>\n    System.out.println(&#034;\u5947\u6570\u7684\u548c&#xff1a;&#034; &#043; oddSum);<br \/>\n    System.out.println(&#034;\u5076\u6570\u7684\u548c&#xff1a;&#034; &#043; evenSum);<br \/>\n} <\/p>\n<p>\u3010\u7ec3\u4e602&#xff1a;\u7528while\u6216for\u5faa\u73af\u8f93\u51fa1-1000\u4e4b\u95f4\u80fd\u88ab5\u6574\u9664\u7684\u6570&#xff0c;\u5e76\u4e14\u6bcf\u884c\u8f93\u51fa3\u4e2a\u3011<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    for (int j &#061; 1; j &lt;&#061; 1000; j&#043;&#043;) {<br \/>\n        if (j % 5 &#061;&#061; 0) {<br \/>\n            System.out.print(j &#043; &#034;\\\\t&#034;);<br \/>\n        }<br \/>\n        if (j % (5 * 3) &#061;&#061; 0) {<br \/>\n            System.out.println();<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<p>\u3010\u7ec3\u4e603&#xff1a;\u6253\u5370\u4e5d\u4e5d\u4e58\u6cd5\u8868\u3011<\/p>\n<\/p>\n<p>1*1&#061;1<br \/>\n1*2&#061;2 2*2&#061;4<br \/>\n1*3&#061;3 2*3&#061;6 3*3&#061;9<br \/>\n1*4&#061;4 2*4&#061;8 3*4&#061;12 4*4&#061;16<br \/>\n1*5&#061;5 2*5&#061;10 3*5&#061;15 4*5&#061;20 5*5&#061;25<br \/>\n1*6&#061;6 2*6&#061;12 3*6&#061;18 4*6&#061;24 5*6&#061;30 6*6&#061;36<br \/>\n1*7&#061;7 2*7&#061;14 3*7&#061;21 4*7&#061;28 5*7&#061;35 6*7&#061;42 7*7&#061;49<br \/>\n1*8&#061;8 2*8&#061;16 3*8&#061;24 4*8&#061;32 5*8&#061;40 6*8&#061;48 7*8&#061;56 8*8&#061;64<br \/>\n1*9&#061;9 2*9&#061;18 3*9&#061;27 4*9&#061;36 5*9&#061;45 6*9&#061;54 7*9&#061;63 8*9&#061;72 9*9&#061;81 <\/p>\n<p>\u5f53\u7136&#xff0c;\u6210\u529f\u7684\u8def\u4e0d\u6b62\u4e00\u6761&#xff0c;\u4f46\u662f\u6211\u4eec\u8981\u8ffd\u6c42\u6700\u5b8c\u7f8e\u7684\u4e00\u6761&#xff0c;\u5982\u679c\u4f60\u505a\u4e0d\u5230&#xff0c;\u4e0d\u59a8\u8bd5\u8bd5\u7b28\u529e\u6cd5&#xff0c;\u4f9d\u65e7\u53ef\u4ee5 \u5b8c\u6210\u4efb\u52a1&#xff01;\u6bd4\u5982\u4e00\u884c\u884c\u8f93\u51fa&#xff0c;\u4e5f\u662f\u53ef\u4ee5\u641e\u5b9a\u7684\u3002\u4e00\u5b9a\u8981\u591a\u5206\u6790&#xff01;<\/p>\n<p>\u6211\u4eec\u4f7f\u7528\u5d4c\u5957for\u5faa\u73af\u5c31\u53ef\u4ee5\u5f88\u8f7b\u677e\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u4e86&#xff01;<\/p>\n<p>\u7b2c\u4e00\u6b65&#xff1a;\u6211\u4eec\u5148\u6253\u5370\u7b2c\u4e00\u5217&#xff0c;\u8fd9\u4e2a\u5927\u5bb6\u5e94\u8be5\u90fd\u4f1a<\/p>\n<\/p>\n<p>for (int i &#061; 1; i &lt;&#061; 9; i&#043;&#043;) {<br \/>\nSystem.out.println(1 &#043; &#034;*&#034; &#043; i &#043; &#034;&#061;&#034; &#043; (1 * i));<br \/>\n} <\/p>\n<p>\u7b2c\u4e8c\u6b65&#xff1a;\u6211\u4eec\u628a\u56fa\u5b9a\u76841\u518d\u7528\u4e00\u4e2a\u5faa\u73af\u5305\u8d77\u6765<\/p>\n<\/p>\n<p>for (int i &#061; 1; i &lt;&#061; 9 ; i&#043;&#043;) {<br \/>\n    for (int j &#061; 1; j &lt;&#061; 9; j&#043;&#043;) {<br \/>\n        System.out.println(i &#043; &#034;*&#034; &#043; j &#043; &#034;&#061;&#034; &#043; (i * j));<br \/>\n    }<br \/>\n} <\/p>\n<p>\u7b2c\u4e09\u6b65&#xff1a;\u53bb\u6389\u91cd\u590d\u9879&#xff0c;j&lt;&#061;i<\/p>\n<\/p>\n<p>for (int i &#061; 1; i &lt;&#061; 9 ; i&#043;&#043;) {<br \/>\n    for (int j &#061; 1; j &lt;&#061; i; j&#043;&#043;) {<br \/>\n        System.out.println(j &#043; &#034;*&#034; &#043; i &#043; &#034;&#061;&#034; &#043; (i * j));<br \/>\n    }<br \/>\n} <\/p>\n<p>\u7b2c\u56db\u6b65&#xff1a;\u8c03\u6574\u6837\u5f0f<\/p>\n<\/p>\n<p>for (int i &#061; 1; i &lt;&#061; 9 ; i&#043;&#043;) {<br \/>\n    for (int j &#061; 1; j &lt;&#061; i; j&#043;&#043;) {<br \/>\n        System.out.print(j &#043; &#034;*&#034; &#043; i &#043; &#034;&#061;&#034; &#043; (i * j)&#043; &#034;\\\\t&#034;);<br \/>\n    }<br \/>\n    System.out.println();<br \/>\n} <\/p>\n<p>\u901a\u8fc7\u672c\u7ec3\u4e60&#xff0c;\u5927\u5bb6\u8981\u4f53\u4f1a\u5982\u4f55\u5206\u6790\u95ee\u9898\u3001\u5982\u4f55\u5207\u5165\u95ee\u9898&#xff01;\u5728\u6211\u4eec\u4ee5\u540e\u5199\u4ee3\u7801\u7684\u8fc7\u7a0b\u4e2d&#xff0c;\u4e00\u5b9a\u8981\u5b66\u4f1a\u5c06\u4e00 \u4e2a\u5927\u95ee\u9898\u5206\u89e3\u6210\u82e5\u5e72\u5c0f\u95ee\u9898&#xff0c;\u7136\u540e&#xff0c;\u7531\u6613\u5230\u96be&#xff0c;\u5404\u4e2a\u51fb\u7834&#xff01;\u8fd9\u4e5f\u662f\u6211\u4eec\u4ee5\u540e\u5f00\u53d1\u9879\u76ee\u65f6\u7684\u57fa\u672c\u601d\u7ef4\u8fc7\u7a0b\u3002\u5e0c\u671b\u5927\u5bb6\u597d\u597d\u4f53\u4f1a&#xff01;<\/p>\n<h4 id=\"_5\u3001\u589e\u5f3afor\u5faa\u73af\">5\u3001\u589e\u5f3afor\u5faa\u73af<\/h4>\n<p>Java5 \u5f15\u5165\u4e86\u4e00\u79cd\u4e3b\u8981\u7528\u4e8e\u6570\u7ec4\u6216\u96c6\u5408\u7684\u589e\u5f3a\u578b for \u5faa\u73af\u3002<\/p>\n<p>Java \u589e\u5f3a for \u5faa\u73af\u8bed\u6cd5\u683c\u5f0f\u5982\u4e0b:<\/p>\n<\/p>\n<p>for(\u58f0\u660e\u8bed\u53e5 : \u8868\u8fbe\u5f0f)<br \/>\n{<br \/>\n    \/\/\u4ee3\u7801\u53e5\u5b50<br \/>\n} <\/p>\n<p>\u58f0\u660e\u8bed\u53e5&#xff1a;\u58f0\u660e\u65b0\u7684\u5c40\u90e8\u53d8\u91cf&#xff0c;\u8be5\u53d8\u91cf\u7684\u7c7b\u578b\u5fc5\u987b\u548c\u6570\u7ec4\u5143\u7d20\u7684\u7c7b\u578b\u5339\u914d\u3002\u5176\u4f5c\u7528\u57df\u9650\u5b9a\u5728\u5faa\u73af\u8bed\u53e5 \u5757&#xff0c;\u5176\u503c\u4e0e\u6b64\u65f6\u6570\u7ec4\u5143\u7d20\u7684\u503c\u76f8\u7b49\u3002<\/p>\n<p>\u8868\u8fbe\u5f0f&#xff1a;\u8868\u8fbe\u5f0f\u662f\u8981\u8bbf\u95ee\u7684\u6570\u7ec4\u540d&#xff0c;\u6216\u8005\u662f\u8fd4\u56de\u503c\u4e3a\u6570\u7ec4\u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u3010\u6f14\u793a&#xff1a;\u589e\u5f3afor\u5faa\u73af\u904d\u5386\u8f93\u51fa\u6570\u7ec4\u5143\u7d20\u3011<\/p>\n<\/p>\n<p>public static void main(String[] args) {<\/p>\n<p>    int [] numbers &#061; {10, 20, 30, 40, 50};<br \/>\n    for(int x : numbers ){<br \/>\n        System.out.print( x );<br \/>\n        System.out.print(&#034;,&#034;);<br \/>\n    }<br \/>\n    System.out.print(&#034;\\\\n&#034;);<\/p>\n<p>    String [] names &#061;{&#034;James&#034;, &#034;Larry&#034;, &#034;Tom&#034;, &#034;Lacy&#034;};<br \/>\n    for( String name : names ) {<br \/>\n        System.out.print( name );<br \/>\n        System.out.print(&#034;,&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<h2>\u5341\u4e94\u3001break\u548ccontinue \u00a0<\/h2>\n<h4 id=\"_1\u3001break-\u5173\u952e\u5b57\">1\u3001break \u5173\u952e\u5b57<\/h4>\n<p>break \u4e3b\u8981\u7528\u5728\u5faa\u73af\u8bed\u53e5\u6216\u8005 switch \u8bed\u53e5\u4e2d&#xff0c;\u7528\u6765\u8df3\u51fa\u6574\u4e2a\u8bed\u53e5\u5757\u3002<\/p>\n<p>break \u8df3\u51fa\u6700\u91cc\u5c42\u7684\u5faa\u73af&#xff0c;\u5e76\u4e14\u7ee7\u7eed\u6267\u884c\u8be5\u5faa\u73af\u4e0b\u9762\u7684\u8bed\u53e5\u3002<\/p>\n<p>\u3010\u6f14\u793a&#xff1a;\u8df3\u51fa\u5faa\u73af\u3011<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int i &#061; 0;<br \/>\n    while (i &lt; 100) {<br \/>\n        i&#043;&#043;;<br \/>\n        System.out.println(i);<br \/>\n        if (i &#061;&#061; 30) {<br \/>\n            break;<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<p>switch \u8bed\u53e5\u4e2dbreak\u5728\u4e0a\u9762\u5df2\u7ecf\u8be6\u7ec6\u8bf4\u660e\u4e86<\/p>\n<h4 id=\"_2\u3001continue-\u5173\u952e\u5b57\">2\u3001continue \u5173\u952e\u5b57<\/h4>\n<p>continue \u9002\u7528\u4e8e\u4efb\u4f55\u5faa\u73af\u63a7\u5236\u7ed3\u6784\u4e2d\u3002\u4f5c\u7528\u662f\u8ba9\u7a0b\u5e8f\u7acb\u523b\u8df3\u8f6c\u5230\u4e0b\u4e00\u6b21\u5faa\u73af\u7684\u8fed\u4ee3\u3002<\/p>\n<p>\u5728 for \u5faa\u73af\u4e2d&#xff0c;continue \u8bed\u53e5\u4f7f\u7a0b\u5e8f\u7acb\u5373\u8df3\u8f6c\u5230\u66f4\u65b0\u8bed\u53e5\u3002<\/p>\n<p>\u5728 while \u6216\u8005 do\u2026while \u5faa\u73af\u4e2d&#xff0c;\u7a0b\u5e8f\u7acb\u5373\u8df3\u8f6c\u5230\u5e03\u5c14\u8868\u8fbe\u5f0f\u7684\u5224\u65ad\u8bed\u53e5\u3002<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int i &#061; 0;<br \/>\n    while (i &lt; 100) {<br \/>\n        i&#043;&#043;;<br \/>\n        if (i % 10 &#061;&#061; 0) {<br \/>\n            System.out.println();<br \/>\n            continue;<br \/>\n        }<br \/>\n        System.out.print(i);<br \/>\n    }<br \/>\n} <\/p>\n<h4 id=\"_3\u3001\u4e24\u8005\u533a\u522b\">3\u3001\u4e24\u8005\u533a\u522b<\/h4>\n<p>break\u5728\u4efb\u4f55\u5faa\u73af\u8bed\u53e5\u7684\u4e3b\u4f53\u90e8\u5206&#xff0c;\u5747\u53ef\u7528break\u63a7\u5236\u5faa\u73af\u7684\u6d41\u7a0b\u3002break\u7528\u4e8e\u5f3a\u884c\u9000\u51fa\u5faa\u73af&#xff0c;\u4e0d\u6267\u884c\u5faa\u73af\u4e2d\u5269\u4f59\u7684\u8bed\u53e5\u3002(break\u8bed\u53e5\u4e5f\u5728switch\u8bed\u53e5\u4e2d\u4f7f\u7528)<\/p>\n<p>continue \u8bed\u53e5\u7528\u5728\u5faa\u73af\u8bed\u53e5\u4f53\u4e2d&#xff0c;\u7528\u4e8e\u7ec8\u6b62\u67d0\u6b21\u5faa\u73af\u8fc7\u7a0b&#xff0c;\u5373\u8df3\u8fc7\u5faa\u73af\u4f53\u4e2d\u5c1a\u672a\u6267\u884c\u7684\u8bed\u53e5&#xff0c;\u63a5\u7740\u8fdb\u884c\u4e0b\u4e00\u6b21\u662f\u5426\u6267\u884c\u5faa\u73af\u7684\u5224\u5b9a\u3002<\/p>\n<h4 id=\"_4\u3001\u5e26\u6807\u7b7e\u7684continue\">4\u3001\u5e26\u6807\u7b7e\u7684continue<\/h4>\n<p>\u3010\u4e86\u89e3\u5373\u53ef\u3011<\/p>\n<li>\n<p>goto\u5173\u952e\u5b57\u5f88\u65e9\u5c31\u5728\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\u4e2d\u51fa\u73b0\u3002\u5c3d\u7ba1goto\u4ecd\u662fJava\u7684\u4e00\u4e2a\u4fdd\u7559\u5b57&#xff0c;\u4f46\u5e76\u672a\u5728\u8bed\u8a00\u4e2d\u5f97\u5230\u6b63\u5f0f\u4f7f\u7528&#xff1b;Java\u6ca1\u6709goto\u3002\u7136\u800c&#xff0c;\u5728break\u548ccontinue\u8fd9\u4e24\u4e2a\u5173\u952e\u5b57\u7684\u8eab\u4e0a&#xff0c;\u6211\u4eec\u4ecd\u7136\u80fd\u770b\u51fa\u4e00\u4e9b goto\u7684\u5f71\u5b50&#8212;\u5e26\u6807\u7b7e\u7684break\u548ccontinue\u3002<\/p>\n<\/li>\n<li>\n<p>\u201c\u6807\u7b7e\u201d\u662f\u6307\u540e\u9762\u8ddf\u4e00\u4e2a\u5192\u53f7\u7684\u6807\u8bc6\u7b26&#xff0c;\u4f8b\u5982&#xff1a;label:<\/p>\n<\/li>\n<li>\n<p>\u5bf9Java\u6765\u8bf4\u552f\u4e00\u7528\u5230\u6807\u7b7e\u7684\u5730\u65b9\u662f\u5728\u5faa\u73af\u8bed\u53e5\u4e4b\u524d\u3002\u800c\u5728\u5faa\u73af\u4e4b\u524d\u8bbe\u7f6e\u6807\u7b7e\u7684\u552f\u4e00\u7406\u7531\u662f&#xff1a;\u6211\u4eec\u5e0c\u671b\u5728\u5176\u4e2d\u5d4c\u5957\u53e6\u4e00\u4e2a\u5faa\u73af&#xff0c;\u7531\u4e8ebreak\u548ccontinue\u5173\u952e\u5b57\u901a\u5e38\u53ea\u4e2d\u65ad\u5f53\u524d\u5faa\u73af&#xff0c;\u4f46\u82e5\u968f\u540c\u6807\u7b7e\u4f7f\u7528&#xff0c;\u5b83\u4eec\u5c31\u4f1a\u4e2d\u65ad\u5230\u5b58\u5728\u6807\u7b7e\u7684\u5730\u65b9\u3002<\/p>\n<\/li>\n<li>\n<p>\u5e26\u6807\u7b7e\u7684break\u548ccontinue\u7684\u4f8b\u5b50&#xff1a;<\/p>\n<p>\u3010\u6f14\u793a&#xff1a;\u6253\u5370101-150\u4e4b\u95f4\u6240\u6709\u7684\u8d28\u6570\u3011<\/p>\n<p> public static void main(String[] args) {<br \/>\n    int count &#061; 0;<br \/>\n    outer: for (int i &#061; 101; i &lt; 150; i &#043;&#043;) {<br \/>\n        for (int j &#061; 2; j &lt; i \/ 2; j&#043;&#043;) {<br \/>\n            if (i % j &#061;&#061; 0){<br \/>\n                 continue outer;<br \/>\n            }<br \/>\n        }<br \/>\n        System.out.print(i&#043; &#034; &#034;);<br \/>\n    }<br \/>\n} <\/li>\n<h2>\u5341\u516d\u3001\u6570\u7ec4<\/h2>\n<p>\u5173\u4e8e\u6570\u7ec4\u6211\u4eec\u53ef\u4ee5\u628a\u5b83\u770b\u4f5c\u662f\u4e00\u4e2a\u7c7b\u578b\u7684\u6240\u6709\u6570\u636e\u7684\u4e00\u4e2a\u96c6\u5408&#xff0c;\u5e76\u7528\u4e00\u4e2a\u6570\u7ec4\u4e0b\u6807\u6765\u533a\u5206\u6216\u6307\u5b9a\u6bcf\u4e00\u4e2a\u6570&#xff0c;\u4f8b\u5982\u4e00\u4e2a\u8db3\u7403\u961f\u901a\u5e38\u4f1a\u6709\u51e0\u5341\u4e2a\u4eba&#xff0c;\u4f46\u662f\u6211\u4eec\u6765\u8ba4\u8bc6\u4ed6\u4eec\u7684\u65f6\u5019\u9996\u5148\u4f1a\u628a\u4ed6\u4eec\u770b\u4f5c\u662f\u67d0\u67d0\u5bf9\u7684\u6210\u5458&#xff0c;\u7136\u540e\u518d\u5229\u7528\u4ed6\u4eec\u7684\u53f7\u7801\u6765\u533a\u5206\u6bcf\u4e00\u4e2a\u961f\u5458&#xff0c;\u8fd9\u65f6\u5019&#xff0c;\u7403\u961f\u5c31\u662f\u4e00\u4e2a\u6570\u7ec4&#xff0c;\u800c\u53f7\u7801\u5c31\u662f\u6570\u7ec4\u7684\u4e0b\u6807&#xff0c; \u5f53\u6211\u4eec\u6307\u660e\u662f\u51e0\u53f7\u961f\u5458\u7684\u65f6\u5019\u5c31\u627e\u5230\u4e86\u8fd9\u4e2a\u961f\u5458\u3002 \u540c\u6837\u5728\u7f16\u7a0b\u4e2d&#xff0c;\u5982\u679c\u6211\u4eec\u6709\u4e00\u7ec4\u76f8\u540c\u6570\u636e\u7c7b\u578b\u7684\u6570\u636e&#xff0c;\u4f8b\u5982\u670910\u4e2a\u6570\u5b57&#xff0c;\u8fd9\u65f6\u5019\u5982\u679c\u6211\u4eec\u8981\u7528\u53d8\u91cf\u6765\u5b58\u653e\u5b83\u4eec\u7684\u8bdd&#xff0c;\u5c31\u8981\u5206\u522b\u4f7f\u752810\u4e2a\u53d8\u91cf&#xff0c;\u800c\u4e14\u8981\u8bb0\u4f4f\u8fd910\u4e2a\u53d8\u91cf\u7684\u540d\u5b57&#xff0c;\u8fd9\u4f1a\u5341\u5206\u7684\u9ebb\u70e6&#xff0c;\u8fd9\u65f6\u5019\u6211\u4eec\u5c31\u53ef\u4ee5\u7528\u4e00\u4e2a\u6570\u7ec4\u53d8\u91cf\u6765\u5b58\u653e\u4ed6\u4eec&#xff0c;\u4f8b\u5982\u5728VB\u4e2d\u6211\u4eec \u5c31\u53ef\u4ee5\u4f7f\u7528dim a(9) as integer&#xff08;\u6ce8\u610f&#xff1a;\u6570\u7ec4\u7684\u4e0b\u6807\u662f\u4ece0\u5f00\u59cb\u7684&#xff0c;\u6240\u4ee5\u7b2c10\u4e2a\u6570\u7684\u8bdd&#xff0c;\u4e0b\u6807\u5c31\u662f 9&#xff0c;a(0)&#061;1&#xff09;\u3002 \u4f7f\u7528\u6570\u7ec4\u4f1a\u8ba9\u7a0b\u5e8f\u53d8\u7684\u7b80\u5355&#xff0c;\u800c\u4e14\u907f\u514d\u4e86\u5b9a\u4e49\u591a\u4e2a\u53d8\u91cf\u7684\u9ebb\u70e6\u3002<\/p>\n<p>\u6570\u7ec4\u7684\u5b9a\u4e49&#xff1a;<\/p>\n<ul>\n<li>\u6570\u7ec4\u662f\u76f8\u540c\u7c7b\u578b\u6570\u636e\u7684\u6709\u5e8f\u96c6\u5408<\/li>\n<li>\u6570\u7ec4\u63cf\u8ff0\u7684\u662f\u76f8\u540c\u7c7b\u578b\u7684\u82e5\u5e72\u4e2a\u6570\u636e,\u6309\u7167\u4e00\u5b9a\u7684\u5148\u540e\u6b21\u5e8f\u6392\u5217\u7ec4\u5408\u800c\u6210<\/li>\n<li>\u5176\u4e2d,\u6bcf\u4e00\u4e2a\u6570\u636e\u79f0\u4f5c\u4e00\u4e2a\u6570\u7ec4\u5143\u7d20,\u6bcf\u4e2a\u6570\u7ec4\u5143\u7d20\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e2a\u4e0b\u6807\u6765\u8bbf\u95ee\u5b83\u4eec.<\/li>\n<\/ul>\n<p>\u6570\u7ec4\u7684\u56db\u4e2a\u57fa\u672c\u7279\u70b9&#xff1a;<\/p>\n<ul>\n<li>\u5176\u957f\u5ea6\u662f\u786e\u5b9a\u7684\u3002\u6570\u7ec4\u4e00\u65e6\u88ab\u521b\u5efa&#xff0c;\u5b83\u7684\u5927\u5c0f\u5c31\u662f\u4e0d\u53ef\u4ee5\u6539\u53d8\u7684\u3002<\/li>\n<li>\u5176\u5143\u7d20\u5fc5\u987b\u662f\u76f8\u540c\u7c7b\u578b&#xff0c;\u4e0d\u5141\u8bb8\u51fa\u73b0\u6df7\u5408\u7c7b\u578b\u3002<\/li>\n<li>\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u53ef\u4ee5\u662f\u4efb\u4f55\u6570\u636e\u7c7b\u578b&#xff0c;\u5305\u62ec\u57fa\u672c\u7c7b\u578b\u548c\u5f15\u7528\u7c7b\u578b\u3002<\/li>\n<li>\u6570\u7ec4\u53d8\u91cf\u5c5e\u5f15\u7528\u7c7b\u578b&#xff0c;\u6570\u7ec4\u4e5f\u53ef\u4ee5\u770b\u6210\u662f\u5bf9\u8c61&#xff0c;\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u76f8\u5f53\u4e8e\u8be5\u5bf9\u8c61\u7684\u6210\u5458\u53d8\u91cf\u3002\u6570\u7ec4\u672c\u8eab\u5c31\u662f\u5bf9\u8c61&#xff0c;Java\u4e2d\u5bf9\u8c61\u662f\u5728\u5806\u4e2d\u7684&#xff0c;\u56e0\u6b64\u6570\u7ec4\u65e0\u8bba\u4fdd\u5b58\u539f\u59cb\u7c7b\u578b\u8fd8\u662f\u5176\u4ed6\u5bf9\u8c61\u7c7b\u578b&#xff0c;\u6570\u7ec4\u5bf9\u8c61\u672c\u8eab\u662f\u5728\u5806\u4e2d\u7684\u3002<\/li>\n<\/ul>\n<h3 id=\"\u6570\u7ec4\u58f0\u660e\u521b\u5efa\">\u6570\u7ec4\u58f0\u660e\u521b\u5efa<\/h3>\n<h4 id=\"_1\u3001\u58f0\u660e\u6570\u7ec4\">1\u3001\u58f0\u660e\u6570\u7ec4<\/h4>\n<p>\u9996\u5148\u5fc5\u987b\u58f0\u660e\u6570\u7ec4\u53d8\u91cf&#xff0c;\u624d\u80fd\u5728\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u6570\u7ec4\u3002\u4e0b\u9762\u662f\u58f0\u660e\u6570\u7ec4\u53d8\u91cf\u7684\u8bed\u6cd5&#xff1a;<\/p>\n<\/p>\n<p>dataType[] arrayRefVar; \/\/ \u9996\u9009\u7684\u65b9\u6cd5<\/p>\n<p>dataType arrayRefVar[]; \/\/ \u6548\u679c\u76f8\u540c&#xff0c;\u4f46\u4e0d\u662f\u9996\u9009\u65b9\u6cd5 <\/p>\n<p>\u5efa\u8bae\u4f7f\u7528 dataType[] arrayRefVar \u7684\u58f0\u660e\u98ce\u683c\u58f0\u660e\u6570\u7ec4\u53d8\u91cf\u3002 dataType arrayRefVar[] \u98ce\u683c\u662f\u6765\u81ea C\/C&#043;&#043; \u8bed\u8a00 &#xff0c;\u5728Java\u4e2d\u91c7\u7528\u662f\u4e3a\u4e86\u8ba9 C\/C&#043;&#043; \u7a0b\u5e8f\u5458\u80fd\u591f\u5feb\u901f\u7406\u89e3java\u8bed\u8a00\u3002<\/p>\n<\/p>\n<p>double[] myList; \/\/ \u9996\u9009\u7684\u65b9\u6cd5<br \/>\ndouble myList[]; \/\/ \u6548\u679c\u76f8\u540c&#xff0c;\u4f46\u4e0d\u662f\u9996\u9009\u65b9\u6cd5 <\/p>\n<h4 id=\"_2\u3001\u521b\u5efa\u6570\u7ec4\">2\u3001\u521b\u5efa\u6570\u7ec4<\/h4>\n<p>Java\u8bed\u8a00\u4f7f\u7528new\u64cd\u4f5c\u7b26\u6765\u521b\u5efa\u6570\u7ec4&#xff0c;\u8bed\u6cd5\u5982\u4e0b&#xff1a;<\/p>\n<\/p>\n<p>arrayRefVar &#061; new dataType[arraySize]; <\/p>\n<p>\u4e0a\u9762\u7684\u8bed\u6cd5\u8bed\u53e5\u505a\u4e86\u4e24\u4ef6\u4e8b&#xff1a;<\/p>\n<ul>\n<li>\u4f7f\u7528 dataType[arraySize] \u521b\u5efa\u4e86\u4e00\u4e2a\u6570\u7ec4\u3002<\/li>\n<li>\u628a\u65b0\u521b\u5efa\u7684\u6570\u7ec4\u7684\u5f15\u7528\u8d4b\u503c\u7ed9\u53d8\u91cf arrayRefVar\u3002<\/li>\n<\/ul>\n<p>\u6570\u7ec4\u53d8\u91cf\u7684\u58f0\u660e&#xff0c;\u548c\u521b\u5efa\u6570\u7ec4\u53ef\u4ee5\u7528\u4e00\u6761\u8bed\u53e5\u5b8c\u6210&#xff0c;\u5982\u4e0b\u6240\u793a&#xff1a;<\/p>\n<\/p>\n<p>dataType[] arrayRefVar &#061; new dataType[arraySize];<br \/>\n\/\/\u4f8b\u5982&#xff0c;\u521b\u5efa\u4e00\u4e2a\u7c7b\u578bini&#xff0c;\u5927\u5c0f\u4e3a10\u7684\u6570\u7ec4<br \/>\nint[] myList &#061;  new int[10]; <\/p>\n<p>\u83b7\u53d6\u6570\u7ec4\u957f\u5ea6&#xff1a;arrayRefVar.length<\/p>\n<p>\u6570\u7ec4\u7684\u5143\u7d20\u662f\u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee\u7684\u3002\u6570\u7ec4\u7d22\u5f15\u4ece 0 \u5f00\u59cb&#xff0c;\u6240\u4ee5\u7d22\u5f15\u503c\u4ece 0 \u5230 arrayRefVar.length-1<\/p>\n<p>\u3010\u6f14\u793a\u521b\u5efa\u4e00\u4e2a\u6570\u7ec4&#xff0c;\u5e76\u8d4b\u503c&#xff0c;\u8fdb\u884c\u8bbf\u95ee\u3011<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    \/\/1.\u58f0\u660e\u4e00\u4e2a\u6570\u7ec4<br \/>\n    int[] myList &#061; null;<br \/>\n    \/\/2.\u521b\u5efa\u4e00\u4e2a\u6570\u7ec4<br \/>\n    myList &#061; new int[10];<br \/>\n    \/\/3.\u50cf\u6570\u7ec4\u4e2d\u5b58\u503c<br \/>\n    myList[0] &#061; 1;<br \/>\n    myList[1] &#061; 2;<br \/>\n    myList[2] &#061; 3;<br \/>\n    myList[3] &#061; 4;<br \/>\n    myList[4] &#061; 5;<br \/>\n    myList[5] &#061; 6;<br \/>\n    myList[6] &#061; 7;<br \/>\n    myList[7] &#061; 8;<br \/>\n    myList[8] &#061; 9;<br \/>\n    myList[9] &#061; 10;<br \/>\n    \/\/ \u8ba1\u7b97\u6240\u6709\u5143\u7d20\u7684\u603b\u548c<br \/>\n    double total &#061; 0;<br \/>\n    for (int i &#061; 0; i &lt; myList.length; i&#043;&#043;) {<br \/>\n        total &#043;&#061; myList[i];<br \/>\n    }<br \/>\n    System.out.println(&#034;\u603b\u548c\u4e3a&#xff1a; &#034; &#043; total);<br \/>\n} <\/p>\n<h4 id=\"_3\u3001\u5185\u5b58\u5206\u6790\">3\u3001\u5185\u5b58\u5206\u6790<\/h4>\n<p>Java\u5185\u5b58\u5206\u6790 &#xff1a;<\/p>\n<li>\n<p>\u58f0\u660e\u7684\u65f6\u5019\u5e76\u6ca1\u6709\u5b9e\u4f8b\u5316\u4efb\u4f55\u5bf9\u8c61&#xff0c;\u53ea\u6709\u5728\u5b9e\u4f8b\u5316\u6570\u7ec4\u5bf9\u8c61\u65f6&#xff0c;JVM\u624d\u5206\u914d\u7a7a\u95f4&#xff0c;\u8fd9\u65f6\u624d\u4e0e\u957f\u5ea6\u6709\u5173\u3002\u56e0\u6b64&#xff0c;\u58f0\u660e\u6570\u7ec4\u65f6\u4e0d\u80fd\u6307\u5b9a\u5176\u957f\u5ea6(\u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u4e2a\u6570)<\/p>\n<p>\u4f8b\u5982&#xff1a; int a[5]; \/\/\u975e\u6cd5<\/p>\n<\/li>\n<li>\n<p>\u58f0\u660e\u4e00\u4e2a\u6570\u7ec4\u7684\u65f6\u5019\u5e76\u6ca1\u6709\u6570\u7ec4\u88ab\u771f\u6b63\u7684\u521b\u5efa\u3002<\/p>\n<\/li>\n<li>\n<p>\u6784\u9020\u4e00\u4e2a\u6570\u7ec4&#xff0c;\u5fc5\u987b\u6307\u5b9a\u957f\u5ea6<\/p>\n<\/li>\n<p>\/\/1.\u58f0\u660e\u4e00\u4e2a\u6570\u7ec4<br \/>\nint[] myList &#061; null; <\/p>\n<p>\/\/2.\u521b\u5efa\u4e00\u4e2a\u6570\u7ec4<br \/>\nmyList &#061; new int[10]; <\/p>\n<h4 id=\"_4\u3001\u4e09\u79cd\u521d\u59cb\u5316\">4\u3001\u4e09\u79cd\u521d\u59cb\u5316<\/h4>\n<p>1\u3001\u9759\u6001\u521d\u59cb\u5316<\/p>\n<p>\u9664\u4e86\u7528new\u5173\u952e\u5b57\u6765\u4ea7\u751f\u6570\u7ec4\u4ee5\u5916,\u8fd8\u53ef\u4ee5\u76f4\u63a5\u5728\u5b9a\u4e49\u6570\u7ec4\u7684\u540c\u65f6\u5c31\u4e3a\u6570\u7ec4\u5143\u7d20\u5206\u914d\u7a7a\u95f4\u5e76\u8d4b\u503c\u3002<\/p>\n<\/p>\n<p>int[] a &#061; {1,2,3};<br \/>\nMan[] mans &#061; {new Man(1,1),new Man(2,2)}; <\/p>\n<p>2\u3001\u52a8\u6001\u521d\u59cb\u5316<\/p>\n<p>\u6570\u7ec4\u5b9a\u4e49\u3001\u4e3a\u6570\u7ec4\u5143\u7d20\u5206\u914d\u7a7a\u95f4\u3001\u8d4b\u503c\u7684\u64cd\u4f5c\u3001\u5206\u5f00\u8fdb\u884c\u3002<\/p>\n<\/p>\n<p>int[] a &#061; new int[2];<br \/>\na[0]&#061;1;<br \/>\na[1]&#061;2; <\/p>\n<p>3\u3001\u6570\u7ec4\u7684\u9ed8\u8ba4\u521d\u59cb\u5316<\/p>\n<p>\u6570\u7ec4\u662f\u5f15\u7528\u7c7b\u578b&#xff0c;\u5b83\u7684\u5143\u7d20\u76f8\u5f53\u4e8e\u7c7b\u7684\u5b9e\u4f8b\u53d8\u91cf&#xff0c;\u56e0\u6b64\u6570\u7ec4\u4e00\u7ecf\u5206\u914d\u7a7a\u95f4&#xff0c;\u5176\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u4e5f\u88ab\u6309\u7167\u5b9e\u4f8b\u53d8\u91cf\u540c\u6837\u7684\u65b9\u5f0f\u88ab\u9690\u5f0f\u521d\u59cb\u5316\u3002<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int[] a&#061;new int[2];<br \/>\n    boolean[] b &#061; new boolean[2];<br \/>\n    String[] s &#061; new String[2];<br \/>\n    System.out.println(a[0]&#043;&#034;:&#034;&#043;a[1]); \/\/0,0<br \/>\n    System.out.println(b[0]&#043;&#034;:&#034;&#043;b[1]); \/\/false,false<br \/>\n    System.out.println(s[0]&#043;&#034;:&#034;&#043;s[1]); \/\/null, null<br \/>\n} <\/p>\n<h4 id=\"_5\u3001\u6570\u7ec4\u8fb9\u754c\">5\u3001\u6570\u7ec4\u8fb9\u754c<\/h4>\n<p>\u4e0b\u6807\u7684\u5408\u6cd5\u533a\u95f4&#xff1a;[0, length-1]&#xff0c;\u5982\u679c\u8d8a\u754c\u5c31\u4f1a\u62a5\u9519&#xff1b;<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int[] a&#061;new int[2];<br \/>\n    System.out.println(a[2]);<br \/>\n} <\/p>\n<p>Exception in thread &#034;main&#034; java.lang.ArrayIndexOutOfBoundsException: 2<\/p>\n<p>ArrayIndexOutOfBoundsException : \u6570\u7ec4\u4e0b\u6807\u8d8a\u754c\u5f02\u5e38&#xff01;<\/p>\n<h4 id=\"_6\u3001\u5c0f\u7ed3\">6\u3001\u5c0f\u7ed3<\/h4>\n<p>\u6570\u7ec4\u662f\u76f8\u540c\u6570\u636e\u7c7b\u578b(\u6570\u636e\u7c7b\u578b\u53ef\u4ee5\u4e3a\u4efb\u610f\u7c7b\u578b)\u7684\u6709\u5e8f\u96c6\u5408<\/p>\n<p>\u6570\u7ec4\u4e5f\u662f\u5bf9\u8c61\u3002\u6570\u7ec4\u5143\u7d20\u76f8\u5f53\u4e8e\u5bf9\u8c61\u7684\u6210\u5458\u53d8\u91cf(\u8be6\u60c5\u8bf7\u89c1\u5185\u5b58\u56fe)<\/p>\n<p>\u6570\u7ec4\u957f\u5ea6\u7684\u786e\u5b9a\u7684&#xff0c;\u4e0d\u53ef\u53d8\u7684\u3002\u5982\u679c\u8d8a\u754c&#xff0c;\u5219\u62a5&#xff1a;ArrayIndexOutofBounds<\/p>\n<h3 id=\"\u6570\u7ec4\u4f7f\u7528\">\u6570\u7ec4\u4f7f\u7528<\/h3>\n<p>\u6570\u7ec4\u7684\u5143\u7d20\u7c7b\u578b\u548c\u6570\u7ec4\u7684\u5927\u5c0f\u90fd\u662f\u786e\u5b9a\u7684&#xff0c;\u6240\u4ee5\u5f53\u5904\u7406\u6570\u7ec4\u5143\u7d20\u65f6\u5019&#xff0c;\u6211\u4eec\u901a\u5e38\u4f7f\u7528\u57fa\u672c\u5faa\u73af\u6216\u8005 ForEach \u5faa\u73af\u3002<\/p>\n<p>\u3010\u8be5\u5b9e\u4f8b\u5b8c\u6574\u5730\u5c55\u793a\u4e86\u5982\u4f55\u521b\u5efa\u3001\u521d\u59cb\u5316\u548c\u64cd\u7eb5\u6570\u7ec4\u3011<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    double[] myList &#061; {1.9, 2.9, 3.4, 3.5};<br \/>\n    \/\/ \u6253\u5370\u6240\u6709\u6570\u7ec4\u5143\u7d20<br \/>\n    for (int i &#061; 0; i &lt; myList.length; i&#043;&#043;) {<br \/>\n        System.out.println(myList[i] &#043; &#034; &#034;);<br \/>\n    }<br \/>\n    \/\/ \u8ba1\u7b97\u6240\u6709\u5143\u7d20\u7684\u603b\u548c<br \/>\n    double total &#061; 0;<br \/>\n    for (int i &#061; 0; i &lt; myList.length; i&#043;&#043;) {<br \/>\n        total &#043;&#061; myList[i];<br \/>\n    }<br \/>\n    System.out.println(&#034;Total is &#034; &#043; total);<br \/>\n    \/\/ \u67e5\u627e\u6700\u5927\u5143\u7d20<br \/>\n    double max &#061; myList[0];<br \/>\n    for (int i &#061; 1; i &lt; myList.length; i&#043;&#043;) {<br \/>\n        if (myList[i] &gt; max) {<br \/>\n            max &#061; myList[i];<br \/>\n        }<br \/>\n    }<br \/>\n    System.out.println(&#034;Max is &#034; &#043; max);<\/p>\n<p>} <\/p>\n<h4 id=\"_1\u3001for-each-\u5faa\u73af\">1\u3001For-Each \u5faa\u73af<\/h4>\n<p>JDK 1.5 \u5f15\u8fdb\u4e86\u4e00\u79cd\u65b0\u7684\u5faa\u73af\u7c7b\u578b&#xff0c;\u88ab\u79f0\u4e3a For-Each \u5faa\u73af\u6216\u8005\u52a0\u5f3a\u578b\u5faa\u73af&#xff0c;\u5b83\u80fd\u5728\u4e0d\u4f7f\u7528\u4e0b\u6807\u7684\u60c5\u51b5\u4e0b\u904d\u5386\u6570\u7ec4\u3002<\/p>\n<\/p>\n<p>for(type element: array){<br \/>\n    System.out.println(element);<br \/>\n} <\/p>\n<p>\u3010\u793a\u4f8b\u3011<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    double[] myList &#061; {1.9, 2.9, 3.4, 3.5};<\/p>\n<p>    \/\/ \u6253\u5370\u6240\u6709\u6570\u7ec4\u5143\u7d20<br \/>\n    for (double element: myList) {<br \/>\n        System.out.println(element);<br \/>\n    }<br \/>\n} <\/p>\n<h4 id=\"_2\u3001\u6570\u7ec4\u4f5c\u65b9\u6cd5\u5165\u53c2\">2\u3001\u6570\u7ec4\u4f5c\u65b9\u6cd5\u5165\u53c2<\/h4>\n<p>\u6570\u7ec4\u53ef\u4ee5\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u65b9\u6cd5\u3002<\/p>\n<p>\u4f8b\u5982&#xff0c;\u4e0b\u9762\u7684\u4f8b\u5b50\u5c31\u662f\u4e00\u4e2a\u6253\u5370 int \u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u65b9\u6cd5 :<\/p>\n<\/p>\n<p>public static void printArray(int[] array) {<br \/>\n    for (int i &#061; 0; i &lt; array.length; i&#043;&#043;) {<br \/>\n        System.out.print(array[i] &#043; &#034; &#034;);<br \/>\n    }<br \/>\n} <\/p>\n<h4 id=\"_3\u3001\u6570\u7ec4\u4f5c\u8fd4\u56de\u503c\">3\u3001\u6570\u7ec4\u4f5c\u8fd4\u56de\u503c<\/h4>\n<\/p>\n<p>public static int[] reverse(int[] list) {<br \/>\n    int[] result &#061; new int[list.length];<\/p>\n<p>    for (int i &#061; 0, j &#061; result.length &#8211; 1; i &lt; list.length; i&#043;&#043;, j&#8211;) {<br \/>\n        result[j] &#061; list[i];<br \/>\n    }<br \/>\n    return result;<br \/>\n} <\/p>\n<p>\u4ee5\u4e0a\u5b9e\u4f8b\u4e2d result \u6570\u7ec4\u4f5c\u4e3a\u51fd\u6570\u7684\u8fd4\u56de\u503c\u3002<\/p>\n<h3 id=\"\u591a\u7ef4\u6570\u7ec4\">\u591a\u7ef4\u6570\u7ec4<\/h3>\n<p>\u591a\u7ef4\u6570\u7ec4\u53ef\u4ee5\u770b\u6210\u662f\u6570\u7ec4\u7684\u6570\u7ec4&#xff0c;\u6bd4\u5982\u4e8c\u7ef4\u6570\u7ec4\u5c31\u662f\u4e00\u4e2a\u7279\u6b8a\u7684\u4e00\u7ef4\u6570\u7ec4&#xff0c;\u5176\u6bcf\u4e00\u4e2a\u5143\u7d20\u90fd\u662f\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\u3002<\/p>\n<p>1\u3001\u591a\u7ef4\u6570\u7ec4\u7684\u52a8\u6001\u521d\u59cb\u5316&#xff1a;&#xff08;\u4ee5\u4e8c\u7ef4\u6570\u7ec4\u4e3a\u4f8b&#xff09;<\/p>\n<p>\u76f4\u63a5\u4e3a\u6bcf\u4e00\u7ef4\u5206\u914d\u7a7a\u95f4&#xff0c;\u683c\u5f0f\u5982\u4e0b&#xff1a;<\/p>\n<\/p>\n<p>type[][] typeName &#061; new type[typeLength1][typeLength2]; <\/p>\n<p>type \u53ef\u4ee5\u4e3a\u57fa\u672c\u6570\u636e\u7c7b\u578b\u548c\u590d\u5408\u6570\u636e\u7c7b\u578b&#xff0c;arraylenght1 \u548c arraylenght2 \u5fc5\u987b\u4e3a\u6b63\u6574\u6570&#xff0c; arraylenght1 \u4e3a\u884c\u6570&#xff0c;arraylenght2 \u4e3a\u5217\u6570\u3002<\/p>\n<p>\u6bd4\u5982\u5b9a\u4e49\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4&#xff1a;<\/p>\n<\/p>\n<p>int a[][] &#061; new int[2][5]; <\/p>\n<p>\u89e3\u6790&#xff1a;\u4e8c\u7ef4\u6570\u7ec4 a \u53ef\u4ee5\u770b\u6210\u4e00\u4e2a\u4e24\u884c\u4e09\u5217\u7684\u6570\u7ec4\u3002<\/p>\n<p>2\u3001\u591a\u7ef4\u6570\u7ec4\u7684\u5f15\u7528&#xff08;\u4ee5\u4e8c\u7ef4\u6570\u7ec4\u4e3a\u4f8b&#xff09;<\/p>\n<p>\u5bf9\u4e8c\u7ef4\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20&#xff0c;\u5f15\u7528\u65b9\u5f0f\u4e3a arrayName[index1] [index2]&#xff0c;\u4f8b\u5982&#xff1a;<\/p>\n<p>num[1] [0];<\/p>\n<p>\u5176\u5b9e\u4e8c\u7ef4\u751a\u81f3\u591a\u7ef4\u6570\u7ec4\u5341\u5206\u597d\u7406\u89e3&#xff0c;\u6211\u4eec\u628a\u4e24\u4e2a\u6216\u8005\u591a\u4e2a\u503c\u5f53\u505a\u5b9a\u4f4d\u5c31\u597d\u3002<\/p>\n<p>\u539f\u6765\u7684\u6570\u7ec4\u5c31\u662f\u4e00\u6761\u7ebf&#xff0c;\u6211\u4eec\u77e5\u9053\u4e00\u4e2a\u4f4d\u7f6e\u5c31\u597d<\/p>\n<p>\u4e8c\u7ef4\u5c31\u662f\u4e00\u4e2a\u9762&#xff0c;\u4e24\u70b9\u786e\u5b9a\u4e00\u4e2a\u4f4d\u7f6e<\/p>\n<p>\u4e09\u7ef4\u5462&#xff0c;\u5c31\u9700\u8981\u4e09\u4e2a\u70b9\u6765\u786e\u5b9a<\/p>\n<p>3\u3001\u83b7\u53d6\u6570\u7ec4\u957f\u5ea6&#xff1a;<\/p>\n<p>a.length\u83b7\u53d6\u7684\u4e8c\u7ef4\u6570\u7ec4\u7b2c\u4e00\u7ef4\u6570\u7ec4\u7684\u957f\u5ea6&#xff0c;a[0].length\u624d\u662f\u83b7\u53d6\u7b2c\u4e8c\u7ef4\u7b2c\u4e00\u4e2a\u6570\u7ec4\u957f\u5ea6\u3002<\/p>\n<h3 id=\"arrays-\u7c7b\">Arrays \u7c7b<\/h3>\n<p>\u6570\u7ec4\u7684\u5de5\u5177\u7c7bjava.util.Arrays<\/p>\n<p>\u7531\u4e8e\u6570\u7ec4\u5bf9\u8c61\u672c\u8eab\u5e76\u6ca1\u6709\u4ec0\u4e48\u65b9\u6cd5\u53ef\u4ee5\u4f9b\u6211\u4eec\u8c03\u7528,\u4f46API\u4e2d\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5de5\u5177\u7c7bArrays\u4f9b\u6211\u4eec\u4f7f\u7528,\u4ece \u800c\u53ef\u4ee5\u5bf9\u6570\u636e\u5bf9\u8c61\u8fdb\u884c\u4e00\u4e9b\u57fa\u672c\u7684\u64cd\u4f5c\u3002<\/p>\n<p>Arrays\u7c7b\u4e2d\u7684\u65b9\u6cd5\u90fd\u662fstatic\u4fee\u9970\u7684\u9759\u6001\u65b9\u6cd5,\u5728\u4f7f\u7528\u7684\u65f6\u5019\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u7c7b\u540d\u8fdb\u884c\u8c03\u7528&#xff0c;\u800c&#034;\u4e0d\u7528&#034;\u4f7f\u7528\u5bf9\u8c61\u6765\u8c03\u7528(\u6ce8\u610f&#xff1a;\u662f&#034;\u4e0d\u7528&#034; \u800c\u4e0d\u662f &#034;\u4e0d\u80fd&#034;)<\/p>\n<p>java.util.Arrays \u7c7b\u80fd\u65b9\u4fbf\u5730\u64cd\u4f5c\u6570\u7ec4. \u4f7f\u7528\u4e4b\u524d\u9700\u8981\u5bfc\u5305&#xff01;<\/p>\n<p>\u5177\u6709\u4ee5\u4e0b\u5e38\u7528\u529f\u80fd&#xff1a;<\/p>\n<ul>\n<li>\u7ed9\u6570\u7ec4\u8d4b\u503c&#xff1a;\u901a\u8fc7 fill \u65b9\u6cd5\u3002<\/li>\n<li>\u5bf9\u6570\u7ec4\u6392\u5e8f&#xff1a;\u901a\u8fc7 sort \u65b9\u6cd5,\u6309\u5347\u5e8f\u3002<\/li>\n<li>\u6bd4\u8f83\u6570\u7ec4&#xff1a;\u901a\u8fc7 equals \u65b9\u6cd5\u6bd4\u8f83\u6570\u7ec4\u4e2d\u5143\u7d20\u503c\u662f\u5426\u76f8\u7b49\u3002<\/li>\n<li>\u67e5\u627e\u6570\u7ec4\u5143\u7d20&#xff1a;\u901a\u8fc7 binarySearch \u65b9\u6cd5\u80fd\u5bf9\u6392\u5e8f\u597d\u7684\u6570\u7ec4\u8fdb\u884c\u4e8c\u5206\u67e5\u627e\u6cd5\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<p>\u5177\u4f53\u8bf4\u660e\u8bf7\u67e5\u770b\u4e0b\u8868&#xff1a;<\/p>\n<table>\n<tr>\u5e8f\u53f7\u65b9\u6cd5\u548c\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>public static int binarySearch(Object[] a, Object key)\u00a0\u7528\u4e8c\u5206\u67e5\u627e\u7b97\u6cd5\u5728\u7ed9\u5b9a\u6570\u7ec4\u4e2d\u641c\u7d22\u7ed9\u5b9a\u503c\u7684\u5bf9\u8c61(Byte,Int,double\u7b49)\u3002\u6570\u7ec4\u5728\u8c03\u7528\u524d\u5fc5\u987b\u6392\u5e8f\u597d\u7684\u3002\u5982\u679c\u67e5\u627e\u503c\u5305\u542b\u5728\u6570\u7ec4\u4e2d&#xff0c;\u5219\u8fd4\u56de\u641c\u7d22\u952e\u7684\u7d22\u5f15&#xff1b;\u5426\u5219\u8fd4\u56de (-(\u63d2\u5165\u70b9) &#8211; 1)\u3002<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>public static boolean equals(long[] a, long[] a2)\u00a0\u5982\u679c\u4e24\u4e2a\u6307\u5b9a\u7684 long \u578b\u6570\u7ec4\u5f7c\u6b64\u76f8\u7b49&#xff0c;\u5219\u8fd4\u56de true\u3002\u5982\u679c\u4e24\u4e2a\u6570\u7ec4\u5305\u542b\u76f8\u540c\u6570\u91cf\u7684\u5143\u7d20&#xff0c;\u5e76\u4e14\u4e24\u4e2a\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u76f8\u5e94\u5143\u7d20\u5bf9\u90fd\u662f\u76f8\u7b49\u7684&#xff0c;\u5219\u8ba4\u4e3a\u8fd9\u4e24\u4e2a\u6570\u7ec4\u662f\u76f8\u7b49\u7684\u3002\u6362\u53e5\u8bdd\u8bf4&#xff0c;\u5982\u679c\u4e24\u4e2a\u6570\u7ec4\u4ee5\u76f8\u540c\u987a\u5e8f\u5305\u542b\u76f8\u540c\u7684\u5143\u7d20&#xff0c;\u5219\u4e24\u4e2a\u6570\u7ec4\u662f\u76f8\u7b49\u7684\u3002\u540c\u6837\u7684\u65b9\u6cd5\u9002\u7528\u4e8e\u6240\u6709\u7684\u5176\u4ed6\u57fa\u672c\u6570\u636e\u7c7b\u578b&#xff08;Byte&#xff0c;short&#xff0c;Int\u7b49&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>public static void fill(int[] a, int val)\u00a0\u5c06\u6307\u5b9a\u7684 int \u503c\u5206\u914d\u7ed9\u6307\u5b9a int \u578b\u6570\u7ec4\u6307\u5b9a\u8303\u56f4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u3002\u540c\u6837\u7684\u65b9\u6cd5\u9002\u7528\u4e8e\u6240\u6709\u7684\u5176\u4ed6\u57fa\u672c\u6570\u636e\u7c7b\u578b&#xff08;Byte&#xff0c;short&#xff0c;Int\u7b49&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>public static void sort(Object[] a)\u00a0\u5bf9\u6307\u5b9a\u5bf9\u8c61\u6570\u7ec4\u6839\u636e\u5176\u5143\u7d20\u7684\u81ea\u7136\u987a\u5e8f\u8fdb\u884c\u5347\u5e8f\u6392\u5217\u3002\u540c\u6837\u7684\u65b9\u6cd5\u9002\u7528\u4e8e\u6240\u6709\u7684\u5176\u4ed6\u57fa\u672c\u6570\u636e\u7c7b\u578b&#xff08;Byte&#xff0c;short&#xff0c;Int\u7b49&#xff09;\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6765\u6e90\u83dc\u9e1f\u6559\u7a0b&#xff0c;\u4e00\u4e2a\u7f16\u7a0b\u7684\u57fa\u7840\u6280\u672f\u6559\u7a0b\u7f51\u7ad9&#xff0c;\u9002\u5408\u521d\u5b66\u8005\u67e5\u770b\u8d44\u6599&#xff0c;\u6211PHP\u57fa\u7840\u5c31\u662f\u5728\u8fd9\u91cc\u5b66\u7684\u3002<\/p>\n<h4 id=\"_1\u3001\u6253\u5370\u6570\u7ec4\">1\u3001\u6253\u5370\u6570\u7ec4<\/h4>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int[] a &#061; {1,2};<br \/>\n    System.out.println(a); \/\/[I&#064;1b6d3586<br \/>\n    System.out.println(Arrays.toString(a)); \/\/[1, 2]<br \/>\n} <\/p>\n<h4 id=\"_2\u3001\u6570\u7ec4\u6392\u5e8f\">2\u3001\u6570\u7ec4\u6392\u5e8f<\/h4>\n<p>\u5bf9\u6307\u5b9a\u7684 int \u578b\u6570\u7ec4\u6309\u6570\u5b57\u5347\u5e8f\u8fdb\u884c\u6392\u5e8f<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int[] a &#061; {1,2,323,23,543,12,59};<br \/>\n    System.out.println(Arrays.toString(a));<br \/>\n    Arrays.sort(a);<br \/>\n    System.out.println(Arrays.toString(a));<br \/>\n} <\/p>\n<h4 id=\"_3\u3001\u4e8c\u5206\u6cd5\u67e5\u627e\">3\u3001\u4e8c\u5206\u6cd5\u67e5\u627e<\/h4>\n<p>\u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20\u5e76\u8fd4\u56de\u5176\u4e0b\u6807<\/p>\n<p>\u6ce8\u610f&#xff1a;\u4f7f\u7528\u4e8c\u5206\u641c\u7d22\u6cd5\u6765\u641c\u7d22\u6307\u5b9a\u7684\u6570\u7ec4&#xff0c;\u4ee5\u83b7\u5f97\u6307\u5b9a\u7684\u503c\u3002\u5fc5\u987b\u5728\u8fdb\u884c\u6b64\u8c03\u7528\u4e4b\u524d\u5bf9\u6570\u7ec4\u8fdb\u884c\u6392\u5e8f(\u901a\u8fc7sort\u65b9\u6cd5\u7b49)\u3002\u5982\u679c\u6ca1\u6709\u5bf9\u6570\u7ec4\u8fdb\u884c\u6392\u5e8f&#xff0c;\u5219\u7ed3\u679c\u662f\u4e0d\u786e\u5b9a\u7684\u3002<\/p>\n<p>\u5982\u679c\u6570\u7ec4\u5305\u542b\u591a\u4e2a\u5e26\u6709\u6307\u5b9a\u503c\u7684\u5143\u7d20&#xff0c;\u5219\u65e0\u6cd5\u4fdd\u8bc1\u627e\u5230\u7684\u662f\u54ea\u4e00\u4e2a\u3002<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int[] a &#061; {1,2,323,23,543,12,59};<br \/>\n    Arrays.sort(a); \/\/\u4f7f\u7528\u4e8c\u5206\u6cd5\u67e5\u627e&#xff0c;\u5fc5\u987b\u5148\u5bf9\u6570\u7ec4\u8fdb\u884c\u6392\u5e8f<br \/>\n    System.out.println(&#034;\u8be5\u5143\u7d20\u7684\u7d22\u5f15&#xff1a;&#034;&#043;Arrays.binarySearch(a, 12));<br \/>\n} <\/p>\n<h4 id=\"_4\u3001\u5143\u7d20\u586b\u5145\">4\u3001\u5143\u7d20\u586b\u5145<\/h4>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int[] a &#061; {1,2,323,23,543,12,59};<br \/>\n    Arrays.sort(a); \/\/\u4f7f\u7528\u4e8c\u5206\u6cd5\u67e5\u627e&#xff0c;\u5fc5\u987b\u5148\u5bf9\u6570\u7ec4\u8fdb\u884c\u6392\u5e8f<br \/>\n    Arrays.fill(a, 2, 4, 100); \/\/\u5c062\u52304\u7d22\u5f15\u7684\u5143\u7d20\u66ff\u6362\u4e3a100<br \/>\n    System.out.println(Arrays.toString(a));\/\/[1, 2, 100, 100, 59, 323, 543]<br \/>\n} <\/p>\n<h4 id=\"_5\u3001\u6570\u7ec4\u8f6c\u6362\u4e3alist\u96c6\u5408\">5\u3001\u6570\u7ec4\u8f6c\u6362\u4e3aList\u96c6\u5408<\/h4>\n<\/p>\n<p>int[] a &#061; {3,5,1,9,7};<br \/>\nList&lt;int[]&gt; list &#061; Arrays.asList(a); <\/p>\n<p>\u6211\u4eec\u5199\u4ee3\u7801\u7684\u65f6\u5019&#xff0c;\u53ef\u4ee5\u4e0d\u7528\u523b\u610f\u53bb\u8bb0\u4f4fList&lt;int[]&gt;\u00a0\u5728idea\u4e2d&#xff0c;\u8f93\u5165Arrays.asList(a);\u00a0\u6309\u4e0balt &#043; \u56de\u8f66\u952e&#xff0c;\u4f1a\u81ea\u52a8\u8865\u5168\u5168\u9762\u7684\u4fe1\u606f&#xff0c;\u975e\u5e38\u65b9\u4fbf\u3002<\/p>\n<p>\u5b66\u6821\u4e2d\u6559\u5b66\u4e00\u822c\u7528\u7684\u662feclipse&#xff0c;\u522b\u95ee\u4e3a\u5565&#xff0c;\u95ee\u5c31\u662f\u8fd9\u4e2a\u514d\u8d39&#xff0c;idea\u8981\u94b1\u3002\u60f3\u7528\u7684\u5c0f\u4f19\u4f34\u81ea\u884c\u767e\u5ea6\u89e3\u51b3&#x1f4aa;&#xff0c;\u5b66\u8ba1\u7b97\u673a\u7684\u4eba&#xff0c;pojie\u7248\u7684\u8d44\u6e90\u627e\u4e0d\u5230\u5c31\u8bf4\u4e0d\u8fc7\u53bb\u4e86\u3002&#x1f60a;<\/p>\n<h3 id=\"\u5e38\u89c1\u6392\u5e8f\u7b97\u6cd5\">\u5e38\u89c1\u6392\u5e8f\u7b97\u6cd5<\/h3>\n<h3>1. \u5192\u6ce1\u6392\u5e8f (Bubble Sort)<\/h3>\n<p>java<\/p>\n<p>public class BubbleSort {<br \/>\n    \/**<br \/>\n     * \u5192\u6ce1\u6392\u5e8f &#8211; \u57fa\u672c\u7248<br \/>\n     * \u65f6\u95f4\u590d\u6742\u5ea6&#xff1a;O(n\u00b2)<br \/>\n     * \u7a7a\u95f4\u590d\u6742\u5ea6&#xff1a;O(1)<br \/>\n     * \u7a33\u5b9a\u6392\u5e8f<br \/>\n     *\/<br \/>\n    public static void bubbleSort(int[] arr) {<br \/>\n        if (arr &#061;&#061; null || arr.length &lt;&#061; 1) return;<\/p>\n<p>        int n &#061; arr.length;<br \/>\n        \/\/ \u5916\u5c42\u5faa\u73af\u63a7\u5236\u6392\u5e8f\u8d9f\u6570<br \/>\n        for (int i &#061; 0; i &lt; n &#8211; 1; i&#043;&#043;) {<br \/>\n            \/\/ \u5185\u5c42\u5faa\u73af\u8fdb\u884c\u76f8\u90bb\u5143\u7d20\u6bd4\u8f83\u548c\u4ea4\u6362<br \/>\n            for (int j &#061; 0; j &lt; n &#8211; 1 &#8211; i; j&#043;&#043;) {<br \/>\n                \/\/ \u5982\u679c\u524d\u4e00\u4e2a\u5143\u7d20\u5927\u4e8e\u540e\u4e00\u4e2a\u5143\u7d20&#xff0c;\u5219\u4ea4\u6362<br \/>\n                if (arr[j] &gt; arr[j &#043; 1]) {<br \/>\n                    swap(arr, j, j &#043; 1);<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u5192\u6ce1\u6392\u5e8f &#8211; \u4f18\u5316\u7248&#xff08;\u63d0\u524d\u7ec8\u6b62&#xff09;<br \/>\n     *\/<br \/>\n    public static void bubbleSortOptimized(int[] arr) {<br \/>\n        if (arr &#061;&#061; null || arr.length &lt;&#061; 1) return;<\/p>\n<p>        int n &#061; arr.length;<br \/>\n        for (int i &#061; 0; i &lt; n &#8211; 1; i&#043;&#043;) {<br \/>\n            boolean swapped &#061; false; \/\/ \u6807\u8bb0\u662f\u5426\u53d1\u751f\u4ea4\u6362<\/p>\n<p>            for (int j &#061; 0; j &lt; n &#8211; 1 &#8211; i; j&#043;&#043;) {<br \/>\n                if (arr[j] &gt; arr[j &#043; 1]) {<br \/>\n                    swap(arr, j, j &#043; 1);<br \/>\n                    swapped &#061; true;<br \/>\n                }<br \/>\n            }<\/p>\n<p>            \/\/ \u5982\u679c\u8fd9\u4e00\u8f6e\u6ca1\u6709\u53d1\u751f\u4ea4\u6362&#xff0c;\u8bf4\u660e\u5df2\u7ecf\u6709\u5e8f&#xff0c;\u63d0\u524d\u7ed3\u675f<br \/>\n            if (!swapped) {<br \/>\n                break;<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u5192\u6ce1\u6392\u5e8f &#8211; \u4f18\u5316\u7248&#xff08;\u8bb0\u5f55\u6700\u540e\u4ea4\u6362\u4f4d\u7f6e&#xff09;<br \/>\n     *\/<br \/>\n    public static void bubbleSortOptimized2(int[] arr) {<br \/>\n        if (arr &#061;&#061; null || arr.length &lt;&#061; 1) return;<\/p>\n<p>        int n &#061; arr.length;<br \/>\n        int lastSwapIndex &#061; n &#8211; 1; \/\/ \u8bb0\u5f55\u6700\u540e\u4e00\u6b21\u4ea4\u6362\u7684\u4f4d\u7f6e<\/p>\n<p>        while (lastSwapIndex &gt; 0) {<br \/>\n            int k &#061; lastSwapIndex;<br \/>\n            lastSwapIndex &#061; 0;<\/p>\n<p>            for (int j &#061; 0; j &lt; k; j&#043;&#043;) {<br \/>\n                if (arr[j] &gt; arr[j &#043; 1]) {<br \/>\n                    swap(arr, j, j &#043; 1);<br \/>\n                    lastSwapIndex &#061; j; \/\/ \u66f4\u65b0\u6700\u540e\u4e00\u6b21\u4ea4\u6362\u7684\u4f4d\u7f6e<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    private static void swap(int[] arr, int i, int j) {<br \/>\n        int temp &#061; arr[i];<br \/>\n        arr[i] &#061; arr[j];<br \/>\n        arr[j] &#061; temp;<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        int[] arr &#061; {64, 34, 25, 12, 22, 11, 90};<br \/>\n        System.out.println(&#034;\u539f\u59cb\u6570\u7ec4: &#034; &#043; Arrays.toString(arr));<br \/>\n        bubbleSortOptimized(arr);<br \/>\n        System.out.println(&#034;\u5192\u6ce1\u6392\u5e8f\u540e: &#034; &#043; Arrays.toString(arr));<br \/>\n    }<br \/>\n} <\/p>\n<h3>2. \u9009\u62e9\u6392\u5e8f (Selection Sort)<\/h3>\n<p>java<\/p>\n<p>public class SelectionSort {<br \/>\n    \/**<br \/>\n     * \u9009\u62e9\u6392\u5e8f &#8211; \u6bcf\u6b21\u9009\u62e9\u6700\u5c0f\u7684\u5143\u7d20\u653e\u5230\u5df2\u6392\u5e8f\u5e8f\u5217\u7684\u672b\u5c3e<br \/>\n     * \u65f6\u95f4\u590d\u6742\u5ea6&#xff1a;O(n\u00b2)<br \/>\n     * \u7a7a\u95f4\u590d\u6742\u5ea6&#xff1a;O(1)<br \/>\n     * \u4e0d\u7a33\u5b9a\u6392\u5e8f<br \/>\n     *\/<br \/>\n    public static void selectionSort(int[] arr) {<br \/>\n        if (arr &#061;&#061; null || arr.length &lt;&#061; 1) return;<\/p>\n<p>        int n &#061; arr.length;<\/p>\n<p>        \/\/ \u5916\u5c42\u5faa\u73af\u63a7\u5236\u5df2\u6392\u5e8f\u5e8f\u5217\u7684\u672b\u5c3e\u4f4d\u7f6e<br \/>\n        for (int i &#061; 0; i &lt; n &#8211; 1; i&#043;&#043;) {<br \/>\n            \/\/ \u5047\u8bbe\u5f53\u524d\u4f4d\u7f6e\u662f\u6700\u5c0f\u503c\u7684\u4f4d\u7f6e<br \/>\n            int minIndex &#061; i;<\/p>\n<p>            \/\/ \u5728\u672a\u6392\u5e8f\u90e8\u5206\u5bfb\u627e\u6700\u5c0f\u5143\u7d20<br \/>\n            for (int j &#061; i &#043; 1; j &lt; n; j&#043;&#043;) {<br \/>\n                if (arr[j] &lt; arr[minIndex]) {<br \/>\n                    minIndex &#061; j;<br \/>\n                }<br \/>\n            }<\/p>\n<p>            \/\/ \u5c06\u627e\u5230\u7684\u6700\u5c0f\u5143\u7d20\u4e0e\u5f53\u524d\u4f4d\u7f6e\u4ea4\u6362<br \/>\n            if (minIndex !&#061; i) {<br \/>\n                swap(arr, i, minIndex);<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u9009\u62e9\u6392\u5e8f &#8211; \u53cc\u5411\u9009\u62e9&#xff08;\u540c\u65f6\u627e\u5230\u6700\u5c0f\u548c\u6700\u5927\u5143\u7d20&#xff09;<br \/>\n     *\/<br \/>\n    public static void selectionSortBidirectional(int[] arr) {<br \/>\n        if (arr &#061;&#061; null || arr.length &lt;&#061; 1) return;<\/p>\n<p>        int left &#061; 0;<br \/>\n        int right &#061; arr.length &#8211; 1;<\/p>\n<p>        while (left &lt; right) {<br \/>\n            int minIndex &#061; left;<br \/>\n            int maxIndex &#061; right;<\/p>\n<p>            \/\/ \u786e\u4fddminIndex &lt;&#061; maxIndex<br \/>\n            if (arr[minIndex] &gt; arr[maxIndex]) {<br \/>\n                swap(arr, minIndex, maxIndex);<br \/>\n            }<\/p>\n<p>            \/\/ \u5728\u5269\u4f59\u90e8\u5206\u4e2d\u5bfb\u627e\u6700\u5c0f\u548c\u6700\u5927\u5143\u7d20<br \/>\n            for (int i &#061; left &#043; 1; i &lt; right; i&#043;&#043;) {<br \/>\n                if (arr[i] &lt; arr[minIndex]) {<br \/>\n                    minIndex &#061; i;<br \/>\n                } else if (arr[i] &gt; arr[maxIndex]) {<br \/>\n                    maxIndex &#061; i;<br \/>\n                }<br \/>\n            }<\/p>\n<p>            \/\/ \u5c06\u6700\u5c0f\u5143\u7d20\u4ea4\u6362\u5230\u5de6\u8fb9<br \/>\n            swap(arr, left, minIndex);<\/p>\n<p>            \/\/ \u5982\u679c\u6700\u5927\u5143\u7d20\u7684\u4f4d\u7f6e\u88ab\u6700\u5c0f\u5143\u7d20\u4ea4\u6362\u5f71\u54cd\u4e86&#xff0c;\u9700\u8981\u66f4\u65b0maxIndex<br \/>\n            if (maxIndex &#061;&#061; left) {<br \/>\n                maxIndex &#061; minIndex;<br \/>\n            }<\/p>\n<p>            \/\/ \u5c06\u6700\u5927\u5143\u7d20\u4ea4\u6362\u5230\u53f3\u8fb9<br \/>\n            swap(arr, right, maxIndex);<\/p>\n<p>            left&#043;&#043;;<br \/>\n            right&#8211;;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    private static void swap(int[] arr, int i, int j) {<br \/>\n        int temp &#061; arr[i];<br \/>\n        arr[i] &#061; arr[j];<br \/>\n        arr[j] &#061; temp;<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        int[] arr &#061; {64, 25, 12, 22, 11, 90};<br \/>\n        System.out.println(&#034;\u539f\u59cb\u6570\u7ec4: &#034; &#043; Arrays.toString(arr));<br \/>\n        selectionSortBidirectional(arr);<br \/>\n        System.out.println(&#034;\u9009\u62e9\u6392\u5e8f\u540e: &#034; &#043; Arrays.toString(arr));<br \/>\n    }<br \/>\n} <\/p>\n<h3>3. \u76f4\u63a5\u63d2\u5165\u6392\u5e8f (Insertion Sort)<\/h3>\n<p>java<\/p>\n<p>public class InsertionSort {<br \/>\n    \/**<br \/>\n     * \u76f4\u63a5\u63d2\u5165\u6392\u5e8f &#8211; \u5c06\u5143\u7d20\u63d2\u5165\u5230\u5df2\u6392\u5e8f\u5e8f\u5217\u7684\u9002\u5f53\u4f4d\u7f6e<br \/>\n     * \u65f6\u95f4\u590d\u6742\u5ea6&#xff1a;O(n\u00b2)&#xff0c;\u6700\u597d\u60c5\u51b5O(n)&#xff08;\u5df2\u6392\u5e8f\u6570\u7ec4&#xff09;<br \/>\n     * \u7a7a\u95f4\u590d\u6742\u5ea6&#xff1a;O(1)<br \/>\n     * \u7a33\u5b9a\u6392\u5e8f<br \/>\n     *\/<br \/>\n    public static void insertionSort(int[] arr) {<br \/>\n        if (arr &#061;&#061; null || arr.length &lt;&#061; 1) return;<\/p>\n<p>        int n &#061; arr.length;<\/p>\n<p>        \/\/ \u4ece\u7b2c\u4e8c\u4e2a\u5143\u7d20\u5f00\u59cb&#xff08;\u7b2c\u4e00\u4e2a\u5143\u7d20\u9ed8\u8ba4\u5df2\u6392\u5e8f&#xff09;<br \/>\n        for (int i &#061; 1; i &lt; n; i&#043;&#043;) {<br \/>\n            int key &#061; arr[i]; \/\/ \u5f53\u524d\u8981\u63d2\u5165\u7684\u5143\u7d20<br \/>\n            int j &#061; i &#8211; 1;<\/p>\n<p>            \/\/ \u5c06\u6bd4key\u5927\u7684\u5143\u7d20\u5411\u540e\u79fb\u52a8<br \/>\n            while (j &gt;&#061; 0 &amp;&amp; arr[j] &gt; key) {<br \/>\n                arr[j &#043; 1] &#061; arr[j];<br \/>\n                j&#8211;;<br \/>\n            }<\/p>\n<p>            \/\/ \u63d2\u5165key\u5230\u6b63\u786e\u4f4d\u7f6e<br \/>\n            arr[j &#043; 1] &#061; key;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u63d2\u5165\u6392\u5e8f &#8211; \u4f7f\u7528\u4e8c\u5206\u67e5\u627e\u4f18\u5316\u63d2\u5165\u4f4d\u7f6e<br \/>\n     *\/<br \/>\n    public static void insertionSortBinary(int[] arr) {<br \/>\n        if (arr &#061;&#061; null || arr.length &lt;&#061; 1) return;<\/p>\n<p>        int n &#061; arr.length;<\/p>\n<p>        for (int i &#061; 1; i &lt; n; i&#043;&#043;) {<br \/>\n            int key &#061; arr[i];<\/p>\n<p>            \/\/ \u4f7f\u7528\u4e8c\u5206\u67e5\u627e\u627e\u5230\u63d2\u5165\u4f4d\u7f6e<br \/>\n            int pos &#061; binarySearchPosition(arr, 0, i &#8211; 1, key);<\/p>\n<p>            \/\/ \u5c06\u5143\u7d20\u5411\u540e\u79fb\u52a8<br \/>\n            for (int j &#061; i &#8211; 1; j &gt;&#061; pos; j&#8211;) {<br \/>\n                arr[j &#043; 1] &#061; arr[j];<br \/>\n            }<\/p>\n<p>            \/\/ \u63d2\u5165\u5143\u7d20<br \/>\n            arr[pos] &#061; key;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u4f4d\u7f6e<br \/>\n     *\/<br \/>\n    private static int binarySearchPosition(int[] arr, int left, int right, int key) {<br \/>\n        while (left &lt;&#061; right) {<br \/>\n            int mid &#061; left &#043; (right &#8211; left) \/ 2;<\/p>\n<p>            if (arr[mid] &#061;&#061; key) {<br \/>\n                return mid &#043; 1; \/\/ \u4fdd\u6301\u7a33\u5b9a\u6027&#xff0c;\u76f8\u7b49\u5143\u7d20\u653e\u5728\u540e\u9762<br \/>\n            } else if (arr[mid] &lt; key) {<br \/>\n                left &#061; mid &#043; 1;<br \/>\n            } else {<br \/>\n                right &#061; mid &#8211; 1;<br \/>\n            }<br \/>\n        }<\/p>\n<p>        return left;<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u63d2\u5165\u6392\u5e8f &#8211; \u964d\u5e8f\u6392\u5217<br \/>\n     *\/<br \/>\n    public static void insertionSortDesc(int[] arr) {<br \/>\n        if (arr &#061;&#061; null || arr.length &lt;&#061; 1) return;<\/p>\n<p>        int n &#061; arr.length;<\/p>\n<p>        for (int i &#061; 1; i &lt; n; i&#043;&#043;) {<br \/>\n            int key &#061; arr[i];<br \/>\n            int j &#061; i &#8211; 1;<\/p>\n<p>            \/\/ \u5c06\u6bd4key\u5c0f\u7684\u5143\u7d20\u5411\u540e\u79fb\u52a8&#xff08;\u5b9e\u73b0\u964d\u5e8f&#xff09;<br \/>\n            while (j &gt;&#061; 0 &amp;&amp; arr[j] &lt; key) {<br \/>\n                arr[j &#043; 1] &#061; arr[j];<br \/>\n                j&#8211;;<br \/>\n            }<\/p>\n<p>            arr[j &#043; 1] &#061; key;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        int[] arr &#061; {12, 11, 13, 5, 6};<br \/>\n        System.out.println(&#034;\u539f\u59cb\u6570\u7ec4: &#034; &#043; Arrays.toString(arr));<br \/>\n        insertionSort(arr);<br \/>\n        System.out.println(&#034;\u63d2\u5165\u6392\u5e8f\u540e: &#034; &#043; Arrays.toString(arr));<\/p>\n<p>        int[] arr2 &#061; {64, 34, 25, 12, 22, 11, 90};<br \/>\n        System.out.println(&#034;\\\\n\u539f\u59cb\u6570\u7ec4: &#034; &#043; Arrays.toString(arr2));<br \/>\n        insertionSortBinary(arr2);<br \/>\n        System.out.println(&#034;\u4e8c\u5206\u63d2\u5165\u6392\u5e8f\u540e: &#034; &#043; Arrays.toString(arr2));<br \/>\n    }<br \/>\n} <\/p>\n<h3>4. \u5e0c\u5c14\u6392\u5e8f (Shell Sort)<\/h3>\n<p>java<\/p>\n<p>public class ShellSort {<br \/>\n    \/**<br \/>\n     * \u5e0c\u5c14\u6392\u5e8f &#8211; \u63d2\u5165\u6392\u5e8f\u7684\u6539\u8fdb\u7248&#xff0c;\u4f7f\u7528\u4e0d\u540c\u7684\u95f4\u9694\u5e8f\u5217<br \/>\n     * \u65f6\u95f4\u590d\u6742\u5ea6&#xff1a;\u53d6\u51b3\u4e8e\u95f4\u9694\u5e8f\u5217&#xff0c;\u4e00\u822c\u4e3aO(n^1.3) ~ O(n^2)<br \/>\n     * \u7a7a\u95f4\u590d\u6742\u5ea6&#xff1a;O(1)<br \/>\n     * \u4e0d\u7a33\u5b9a\u6392\u5e8f<br \/>\n     *\/<\/p>\n<p>    \/**<br \/>\n     * \u5e0c\u5c14\u6392\u5e8f &#8211; \u4f7f\u7528\u5e0c\u5c14\u539f\u59cb\u95f4\u9694\u5e8f\u5217 (n\/2, n\/4, &#8230;, 1)<br \/>\n     *\/<br \/>\n    public static void shellSort(int[] arr) {<br \/>\n        if (arr &#061;&#061; null || arr.length &lt;&#061; 1) return;<\/p>\n<p>        int n &#061; arr.length;<\/p>\n<p>        \/\/ \u4f7f\u7528\u5e0c\u5c14\u539f\u59cb\u95f4\u9694\u5e8f\u5217<br \/>\n        for (int gap &#061; n \/ 2; gap &gt; 0; gap \/&#061; 2) {<br \/>\n            \/\/ \u5bf9\u6bcf\u4e2a\u95f4\u9694\u8fdb\u884c\u63d2\u5165\u6392\u5e8f<br \/>\n            for (int i &#061; gap; i &lt; n; i&#043;&#043;) {<br \/>\n                int temp &#061; arr[i];<br \/>\n                int j;<\/p>\n<p>                \/\/ \u5bf9\u95f4\u9694\u4e3agap\u7684\u5143\u7d20\u8fdb\u884c\u63d2\u5165\u6392\u5e8f<br \/>\n                for (j &#061; i; j &gt;&#061; gap &amp;&amp; arr[j &#8211; gap] &gt; temp; j -&#061; gap) {<br \/>\n                    arr[j] &#061; arr[j &#8211; gap];<br \/>\n                }<br \/>\n                arr[j] &#061; temp;<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u5e0c\u5c14\u6392\u5e8f &#8211; \u4f7f\u7528Knuth\u95f4\u9694\u5e8f\u5217 (1, 4, 13, 40, 121, &#8230;)<br \/>\n     *\/<br \/>\n    public static void shellSortKnuth(int[] arr) {<br \/>\n        if (arr &#061;&#061; null || arr.length &lt;&#061; 1) return;<\/p>\n<p>        int n &#061; arr.length;<\/p>\n<p>        \/\/ \u751f\u6210Knuth\u95f4\u9694\u5e8f\u5217<br \/>\n        int h &#061; 1;<br \/>\n        while (h &lt; n \/ 3) {<br \/>\n            h &#061; 3 * h &#043; 1; \/\/ 1, 4, 13, 40, 121, &#8230;<br \/>\n        }<\/p>\n<p>        \/\/ \u4f7f\u7528Knuth\u95f4\u9694\u5e8f\u5217<br \/>\n        while (h &gt;&#061; 1) {<br \/>\n            \/\/ \u5bf9\u6bcf\u4e2a\u95f4\u9694\u8fdb\u884c\u63d2\u5165\u6392\u5e8f<br \/>\n            for (int i &#061; h; i &lt; n; i&#043;&#043;) {<br \/>\n                for (int j &#061; i; j &gt;&#061; h &amp;&amp; arr[j] &lt; arr[j &#8211; h]; j -&#061; h) {<br \/>\n                    swap(arr, j, j &#8211; h);<br \/>\n                }<br \/>\n            }<br \/>\n            h &#061; h \/ 3;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u5e0c\u5c14\u6392\u5e8f &#8211; \u4f7f\u7528Sedgewick\u95f4\u9694\u5e8f\u5217<br \/>\n     *\/<br \/>\n    public static void shellSortSedgewick(int[] arr) {<br \/>\n        if (arr &#061;&#061; null || arr.length &lt;&#061; 1) return;<\/p>\n<p>        int n &#061; arr.length;<\/p>\n<p>        \/\/ Sedgewick\u95f4\u9694\u5e8f\u5217<br \/>\n        int[] sedgewickGaps &#061; {1, 5, 19, 41, 109, 209, 505, 929, 2161, 3905};<\/p>\n<p>        \/\/ \u9009\u62e9\u5408\u9002\u7684\u6700\u5927\u95f4\u9694<br \/>\n        int gapIndex &#061; 0;<br \/>\n        while (sedgewickGaps[gapIndex] &lt; n &amp;&amp; gapIndex &lt; sedgewickGaps.length &#8211; 1) {<br \/>\n            gapIndex&#043;&#043;;<br \/>\n        }<\/p>\n<p>        \/\/ \u4f7f\u7528Sedgewick\u95f4\u9694\u5e8f\u5217<br \/>\n        for (int k &#061; gapIndex; k &gt;&#061; 0; k&#8211;) {<br \/>\n            int gap &#061; sedgewickGaps[k];<\/p>\n<p>            \/\/ \u5bf9\u6bcf\u4e2a\u95f4\u9694\u8fdb\u884c\u63d2\u5165\u6392\u5e8f<br \/>\n            for (int i &#061; gap; i &lt; n; i&#043;&#043;) {<br \/>\n                int temp &#061; arr[i];<br \/>\n                int j;<\/p>\n<p>                for (j &#061; i; j &gt;&#061; gap &amp;&amp; arr[j &#8211; gap] &gt; temp; j -&#061; gap) {<br \/>\n                    arr[j] &#061; arr[j &#8211; gap];<br \/>\n                }<br \/>\n                arr[j] &#061; temp;<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    private static void swap(int[] arr, int i, int j) {<br \/>\n        int temp &#061; arr[i];<br \/>\n        arr[i] &#061; arr[j];<br \/>\n        arr[j] &#061; temp;<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        int[] arr &#061; {8, 9, 1, 7, 2, 3, 5, 4, 6, 0};<br \/>\n        System.out.println(&#034;\u539f\u59cb\u6570\u7ec4: &#034; &#043; Arrays.toString(arr));<br \/>\n        shellSortKnuth(arr);<br \/>\n        System.out.println(&#034;\u5e0c\u5c14\u6392\u5e8f\u540e: &#034; &#043; Arrays.toString(arr));<br \/>\n    }<br \/>\n} <\/p>\n<h3>5. \u5feb\u901f\u6392\u5e8f (Quick Sort)<\/h3>\n<p>java<\/p>\n<p>public class QuickSort {<br \/>\n    \/**<br \/>\n     * \u5feb\u901f\u6392\u5e8f &#8211; \u9012\u5f52\u5b9e\u73b0<br \/>\n     * \u65f6\u95f4\u590d\u6742\u5ea6&#xff1a;\u5e73\u5747O(nlogn)&#xff0c;\u6700\u574fO(n\u00b2)<br \/>\n     * \u7a7a\u95f4\u590d\u6742\u5ea6&#xff1a;O(logn) ~ O(n)&#xff08;\u9012\u5f52\u6808\u7a7a\u95f4&#xff09;<br \/>\n     * \u4e0d\u7a33\u5b9a\u6392\u5e8f<br \/>\n     *\/<\/p>\n<p>    \/**<br \/>\n     * \u5feb\u901f\u6392\u5e8f\u4e3b\u51fd\u6570<br \/>\n     *\/<br \/>\n    public static void quickSort(int[] arr) {<br \/>\n        if (arr &#061;&#061; null || arr.length &lt;&#061; 1) return;<br \/>\n        quickSort(arr, 0, arr.length &#8211; 1);<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u5feb\u901f\u6392\u5e8f\u9012\u5f52\u51fd\u6570<br \/>\n     *\/<br \/>\n    private static void quickSort(int[] arr, int left, int right) {<br \/>\n        if (left &lt; right) {<br \/>\n            \/\/ \u5206\u533a\u64cd\u4f5c&#xff0c;\u8fd4\u56de\u57fa\u51c6\u5143\u7d20\u7684\u6b63\u786e\u4f4d\u7f6e<br \/>\n            int partitionIndex &#061; partition(arr, left, right);<\/p>\n<p>            \/\/ \u9012\u5f52\u6392\u5e8f\u5de6\u534a\u90e8\u5206<br \/>\n            quickSort(arr, left, partitionIndex &#8211; 1);<br \/>\n            \/\/ \u9012\u5f52\u6392\u5e8f\u53f3\u534a\u90e8\u5206<br \/>\n            quickSort(arr, partitionIndex &#043; 1, right);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u5206\u533a\u51fd\u6570 &#8211; \u4f7f\u7528\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u4f5c\u4e3a\u57fa\u51c6<br \/>\n     *\/<br \/>\n    private static int partition(int[] arr, int left, int right) {<br \/>\n        \/\/ \u9009\u62e9\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u4f5c\u4e3a\u57fa\u51c6<br \/>\n        int pivot &#061; arr[right];<\/p>\n<p>        \/\/ \u5c0f\u4e8e\u57fa\u51c6\u7684\u5143\u7d20\u7684\u7d22\u5f15<br \/>\n        int i &#061; left &#8211; 1;<\/p>\n<p>        for (int j &#061; left; j &lt; right; j&#043;&#043;) {<br \/>\n            \/\/ \u5982\u679c\u5f53\u524d\u5143\u7d20\u5c0f\u4e8e\u7b49\u4e8e\u57fa\u51c6<br \/>\n            if (arr[j] &lt;&#061; pivot) {<br \/>\n                i&#043;&#043;;<br \/>\n                swap(arr, i, j);<br \/>\n            }<br \/>\n        }<\/p>\n<p>        \/\/ \u5c06\u57fa\u51c6\u5143\u7d20\u653e\u5230\u6b63\u786e\u4f4d\u7f6e<br \/>\n        swap(arr, i &#043; 1, right);<br \/>\n        return i &#043; 1;<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u5feb\u901f\u6392\u5e8f\u4f18\u5316\u7248 &#8211; \u4e09\u6570\u53d6\u4e2d\u6cd5\u9009\u62e9\u57fa\u51c6<br \/>\n     *\/<br \/>\n    public static void quickSortOptimized(int[] arr) {<br \/>\n        if (arr &#061;&#061; null || arr.length &lt;&#061; 1) return;<br \/>\n        quickSortOptimized(arr, 0, arr.length &#8211; 1);<br \/>\n    }<\/p>\n<p>    private static void quickSortOptimized(int[] arr, int left, int right) {<br \/>\n        if (left &lt; right) {<br \/>\n            \/\/ \u5f53\u5b50\u6570\u7ec4\u8f83\u5c0f\u65f6&#xff0c;\u4f7f\u7528\u63d2\u5165\u6392\u5e8f<br \/>\n            if (right &#8211; left &#043; 1 &lt; 10) {<br \/>\n                insertionSort(arr, left, right);<br \/>\n                return;<br \/>\n            }<\/p>\n<p>            \/\/ \u4e09\u6570\u53d6\u4e2d\u6cd5\u9009\u62e9\u57fa\u51c6<br \/>\n            int pivotIndex &#061; medianOfThree(arr, left, right);<br \/>\n            swap(arr, pivotIndex, right);<\/p>\n<p>            int partitionIndex &#061; partition(arr, left, right);<br \/>\n            quickSortOptimized(arr, left, partitionIndex &#8211; 1);<br \/>\n            quickSortOptimized(arr, partitionIndex &#043; 1, right);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u4e09\u6570\u53d6\u4e2d\u6cd5 &#8211; \u9009\u62e9\u5de6\u3001\u4e2d\u3001\u53f3\u4e09\u4e2a\u6570\u7684\u4e2d\u4f4d\u6570<br \/>\n     *\/<br \/>\n    private static int medianOfThree(int[] arr, int left, int right) {<br \/>\n        int mid &#061; left &#043; (right &#8211; left) \/ 2;<\/p>\n<p>        \/\/ \u786e\u4fddarr[left] &lt;&#061; arr[mid] &lt;&#061; arr[right]<br \/>\n        if (arr[left] &gt; arr[mid]) {<br \/>\n            swap(arr, left, mid);<br \/>\n        }<br \/>\n        if (arr[left] &gt; arr[right]) {<br \/>\n            swap(arr, left, right);<br \/>\n        }<br \/>\n        if (arr[mid] &gt; arr[right]) {<br \/>\n            swap(arr, mid, right);<br \/>\n        }<\/p>\n<p>        return mid; \/\/ \u4e2d\u4f4d\u6570\u7684\u4f4d\u7f6e<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u5feb\u901f\u6392\u5e8f &#8211; \u8fed\u4ee3\u5b9e\u73b0&#xff08;\u4f7f\u7528\u6808&#xff09;<br \/>\n     *\/<br \/>\n    public static void quickSortIterative(int[] arr) {<br \/>\n        if (arr &#061;&#061; null || arr.length &lt;&#061; 1) return;<\/p>\n<p>        \/\/ \u4f7f\u7528\u6808\u5b58\u50a8\u5b50\u6570\u7ec4\u7684\u8fb9\u754c<br \/>\n        Stack&lt;Integer&gt; stack &#061; new Stack&lt;&gt;();<br \/>\n        stack.push(0);<br \/>\n        stack.push(arr.length &#8211; 1);<\/p>\n<p>        while (!stack.isEmpty()) {<br \/>\n            int right &#061; stack.pop();<br \/>\n            int left &#061; stack.pop();<\/p>\n<p>            if (left &lt; right) {<br \/>\n                int partitionIndex &#061; partition(arr, left, right);<\/p>\n<p>                \/\/ \u5c06\u5de6\u5b50\u6570\u7ec4\u8fb9\u754c\u538b\u5165\u6808<br \/>\n                if (partitionIndex &#8211; 1 &gt; left) {<br \/>\n                    stack.push(left);<br \/>\n                    stack.push(partitionIndex &#8211; 1);<br \/>\n                }<\/p>\n<p>                \/\/ \u5c06\u53f3\u5b50\u6570\u7ec4\u8fb9\u754c\u538b\u5165\u6808<br \/>\n                if (partitionIndex &#043; 1 &lt; right) {<br \/>\n                    stack.push(partitionIndex &#043; 1);<br \/>\n                    stack.push(right);<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u8f85\u52a9\u63d2\u5165\u6392\u5e8f&#xff08;\u7528\u4e8e\u5c0f\u6570\u7ec4&#xff09;<br \/>\n     *\/<br \/>\n    private static void insertionSort(int[] arr, int left, int right) {<br \/>\n        for (int i &#061; left &#043; 1; i &lt;&#061; right; i&#043;&#043;) {<br \/>\n            int key &#061; arr[i];<br \/>\n            int j &#061; i &#8211; 1;<\/p>\n<p>            while (j &gt;&#061; left &amp;&amp; arr[j] &gt; key) {<br \/>\n                arr[j &#043; 1] &#061; arr[j];<br \/>\n                j&#8211;;<br \/>\n            }<br \/>\n            arr[j &#043; 1] &#061; key;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    private static void swap(int[] arr, int i, int j) {<br \/>\n        int temp &#061; arr[i];<br \/>\n        arr[i] &#061; arr[j];<br \/>\n        arr[j] &#061; temp;<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        int[] arr &#061; {10, 7, 8, 9, 1, 5};<br \/>\n        System.out.println(&#034;\u539f\u59cb\u6570\u7ec4: &#034; &#043; Arrays.toString(arr));<br \/>\n        quickSort(arr);<br \/>\n        System.out.println(&#034;\u5feb\u901f\u6392\u5e8f\u540e: &#034; &#043; Arrays.toString(arr));<\/p>\n<p>        int[] arr2 &#061; {64, 34, 25, 12, 22, 11, 90, 45, 33, 78};<br \/>\n        System.out.println(&#034;\\\\n\u539f\u59cb\u6570\u7ec4: &#034; &#043; Arrays.toString(arr2));<br \/>\n        quickSortOptimized(arr2);<br \/>\n        System.out.println(&#034;\u4f18\u5316\u5feb\u901f\u6392\u5e8f\u540e: &#034; &#043; Arrays.toString(arr2));<br \/>\n    }<br \/>\n} <\/p>\n<h3>6. \u5f52\u5e76\u6392\u5e8f (Merge Sort)<\/h3>\n<p>java<\/p>\n<p>public class MergeSort {<br \/>\n    \/**<br \/>\n     * \u5f52\u5e76\u6392\u5e8f &#8211; \u9012\u5f52\u5b9e\u73b0<br \/>\n     * \u65f6\u95f4\u590d\u6742\u5ea6&#xff1a;O(nlogn)<br \/>\n     * \u7a7a\u95f4\u590d\u6742\u5ea6&#xff1a;O(n)<br \/>\n     * \u7a33\u5b9a\u6392\u5e8f<br \/>\n     *\/<\/p>\n<p>    \/**<br \/>\n     * \u5f52\u5e76\u6392\u5e8f\u4e3b\u51fd\u6570<br \/>\n     *\/<br \/>\n    public static void mergeSort(int[] arr) {<br \/>\n        if (arr &#061;&#061; null || arr.length &lt;&#061; 1) return;<\/p>\n<p>        int[] temp &#061; new int[arr.length];<br \/>\n        mergeSort(arr, 0, arr.length &#8211; 1, temp);<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u5f52\u5e76\u6392\u5e8f\u9012\u5f52\u51fd\u6570<br \/>\n     *\/<br \/>\n    private static void mergeSort(int[] arr, int left, int right, int[] temp) {<br \/>\n        if (left &lt; right) {<br \/>\n            int mid &#061; left &#043; (right &#8211; left) \/ 2;<\/p>\n<p>            \/\/ \u9012\u5f52\u6392\u5e8f\u5de6\u534a\u90e8\u5206<br \/>\n            mergeSort(arr, left, mid, temp);<br \/>\n            \/\/ \u9012\u5f52\u6392\u5e8f\u53f3\u534a\u90e8\u5206<br \/>\n            mergeSort(arr, mid &#043; 1, right, temp);<\/p>\n<p>            \/\/ \u5408\u5e76\u5df2\u6392\u5e8f\u7684\u4e24\u90e8\u5206<br \/>\n            merge(arr, left, mid, right, temp);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u6570\u7ec4<br \/>\n     *\/<br \/>\n    private static void merge(int[] arr, int left, int mid, int right, int[] temp) {<br \/>\n        int i &#061; left;     \/\/ \u5de6\u534a\u90e8\u5206\u8d77\u59cb\u7d22\u5f15<br \/>\n        int j &#061; mid &#043; 1;  \/\/ \u53f3\u534a\u90e8\u5206\u8d77\u59cb\u7d22\u5f15<br \/>\n        int k &#061; 0;        \/\/ \u4e34\u65f6\u6570\u7ec4\u7d22\u5f15<\/p>\n<p>        \/\/ \u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u6570\u7ec4\u5230temp<br \/>\n        while (i &lt;&#061; mid &amp;&amp; j &lt;&#061; right) {<br \/>\n            if (arr[i] &lt;&#061; arr[j]) {<br \/>\n                temp[k&#043;&#043;] &#061; arr[i&#043;&#043;];<br \/>\n            } else {<br \/>\n                temp[k&#043;&#043;] &#061; arr[j&#043;&#043;];<br \/>\n            }<br \/>\n        }<\/p>\n<p>        \/\/ \u590d\u5236\u5de6\u534a\u90e8\u5206\u5269\u4f59\u5143\u7d20<br \/>\n        while (i &lt;&#061; mid) {<br \/>\n            temp[k&#043;&#043;] &#061; arr[i&#043;&#043;];<br \/>\n        }<\/p>\n<p>        \/\/ \u590d\u5236\u53f3\u534a\u90e8\u5206\u5269\u4f59\u5143\u7d20<br \/>\n        while (j &lt;&#061; right) {<br \/>\n            temp[k&#043;&#043;] &#061; arr[j&#043;&#043;];<br \/>\n        }<\/p>\n<p>        \/\/ \u5c06temp\u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4<br \/>\n        System.arraycopy(temp, 0, arr, left, k);<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u5f52\u5e76\u6392\u5e8f &#8211; \u8fed\u4ee3\u5b9e\u73b0&#xff08;\u81ea\u5e95\u5411\u4e0a&#xff09;<br \/>\n     *\/<br \/>\n    public static void mergeSortIterative(int[] arr) {<br \/>\n        if (arr &#061;&#061; null || arr.length &lt;&#061; 1) return;<\/p>\n<p>        int n &#061; arr.length;<br \/>\n        int[] temp &#061; new int[n];<\/p>\n<p>        \/\/ size\u8868\u793a\u6bcf\u6b21\u5408\u5e76\u7684\u5b50\u6570\u7ec4\u5927\u5c0f<br \/>\n        for (int size &#061; 1; size &lt; n; size *&#061; 2) {<br \/>\n            \/\/ left\u8868\u793a\u6bcf\u4e2a\u5408\u5e76\u533a\u95f4\u7684\u8d77\u59cb\u4f4d\u7f6e<br \/>\n            for (int left &#061; 0; left &lt; n &#8211; size; left &#043;&#061; 2 * size) {<br \/>\n                int mid &#061; left &#043; size &#8211; 1;<br \/>\n                int right &#061; Math.min(left &#043; 2 * size &#8211; 1, n &#8211; 1);<br \/>\n                merge(arr, left, mid, right, temp);<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u5f52\u5e76\u6392\u5e8f &#8211; \u9488\u5bf9\u94fe\u8868\u6570\u636e\u7ed3\u6784\u7684\u5b9e\u73b0\u601d\u8def<br \/>\n     *\/<br \/>\n    public static class ListNode {<br \/>\n        int val;<br \/>\n        ListNode next;<br \/>\n        ListNode(int x) { val &#061; x; }<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u94fe\u8868\u7684\u5f52\u5e76\u6392\u5e8f<br \/>\n     *\/<br \/>\n    public static ListNode mergeSortList(ListNode head) {<br \/>\n        if (head &#061;&#061; null || head.next &#061;&#061; null) {<br \/>\n            return head;<br \/>\n        }<\/p>\n<p>        \/\/ \u4f7f\u7528\u5feb\u6162\u6307\u9488\u627e\u5230\u4e2d\u70b9<br \/>\n        ListNode slow &#061; head;<br \/>\n        ListNode fast &#061; head.next;<\/p>\n<p>        while (fast !&#061; null &amp;&amp; fast.next !&#061; null) {<br \/>\n            slow &#061; slow.next;<br \/>\n            fast &#061; fast.next.next;<br \/>\n        }<\/p>\n<p>        \/\/ \u5206\u5272\u94fe\u8868<br \/>\n        ListNode mid &#061; slow.next;<br \/>\n        slow.next &#061; null;<\/p>\n<p>        \/\/ \u9012\u5f52\u6392\u5e8f<br \/>\n        ListNode left &#061; mergeSortList(head);<br \/>\n        ListNode right &#061; mergeSortList(mid);<\/p>\n<p>        \/\/ \u5408\u5e76<br \/>\n        return mergeList(left, right);<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868<br \/>\n     *\/<br \/>\n    private static ListNode mergeList(ListNode l1, ListNode l2) {<br \/>\n        ListNode dummy &#061; new ListNode(0);<br \/>\n        ListNode current &#061; dummy;<\/p>\n<p>        while (l1 !&#061; null &amp;&amp; l2 !&#061; null) {<br \/>\n            if (l1.val &lt;&#061; l2.val) {<br \/>\n                current.next &#061; l1;<br \/>\n                l1 &#061; l1.next;<br \/>\n            } else {<br \/>\n                current.next &#061; l2;<br \/>\n                l2 &#061; l2.next;<br \/>\n            }<br \/>\n            current &#061; current.next;<br \/>\n        }<\/p>\n<p>        if (l1 !&#061; null) {<br \/>\n            current.next &#061; l1;<br \/>\n        } else {<br \/>\n            current.next &#061; l2;<br \/>\n        }<\/p>\n<p>        return dummy.next;<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        int[] arr &#061; {12, 11, 13, 5, 6, 7};<br \/>\n        System.out.println(&#034;\u539f\u59cb\u6570\u7ec4: &#034; &#043; Arrays.toString(arr));<br \/>\n        mergeSort(arr);<br \/>\n        System.out.println(&#034;\u5f52\u5e76\u6392\u5e8f\u540e: &#034; &#043; Arrays.toString(arr));<\/p>\n<p>        int[] arr2 &#061; {38, 27, 43, 3, 9, 82, 10};<br \/>\n        System.out.println(&#034;\\\\n\u539f\u59cb\u6570\u7ec4: &#034; &#043; Arrays.toString(arr2));<br \/>\n        mergeSortIterative(arr2);<br \/>\n        System.out.println(&#034;\u8fed\u4ee3\u5f52\u5e76\u6392\u5e8f\u540e: &#034; &#043; Arrays.toString(arr2));<br \/>\n    }<br \/>\n} <\/p>\n<h3>7. \u57fa\u6570\u6392\u5e8f (Radix Sort)<\/h3>\n<p>java<\/p>\n<p>public class RadixSort {<br \/>\n    \/**<br \/>\n     * \u57fa\u6570\u6392\u5e8f &#8211; LSD&#xff08;\u6700\u4f4e\u4f4d\u4f18\u5148&#xff09;\u5b9e\u73b0<br \/>\n     * \u65f6\u95f4\u590d\u6742\u5ea6&#xff1a;O(d*(n&#043;k))&#xff0c;d\u662f\u6700\u5927\u4f4d\u6570&#xff0c;k\u662f\u57fa\u6570&#xff08;\u901a\u5e38\u4e3a10&#xff09;<br \/>\n     * \u7a7a\u95f4\u590d\u6742\u5ea6&#xff1a;O(n&#043;k)<br \/>\n     * \u7a33\u5b9a\u6392\u5e8f<br \/>\n     *\/<\/p>\n<p>    \/**<br \/>\n     * \u57fa\u6570\u6392\u5e8f\u4e3b\u51fd\u6570 &#8211; \u9488\u5bf9\u6b63\u6574\u6570<br \/>\n     *\/<br \/>\n    public static void radixSort(int[] arr) {<br \/>\n        if (arr &#061;&#061; null || arr.length &lt;&#061; 1) return;<\/p>\n<p>        \/\/ \u627e\u5230\u6570\u7ec4\u4e2d\u7684\u6700\u5927\u503c&#xff0c;\u786e\u5b9a\u6700\u5927\u4f4d\u6570<br \/>\n        int max &#061; getMax(arr);<\/p>\n<p>        \/\/ \u4ece\u6700\u4f4e\u4f4d\u5230\u6700\u9ad8\u4f4d\u8fdb\u884c\u8ba1\u6570\u6392\u5e8f<br \/>\n        for (int exp &#061; 1; max \/ exp &gt; 0; exp *&#061; 10) {<br \/>\n            countingSortByDigit(arr, exp);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u57fa\u6570\u6392\u5e8f &#8211; \u652f\u6301\u8d1f\u6574\u6570<br \/>\n     *\/<br \/>\n    public static void radixSortWithNegative(int[] arr) {<br \/>\n        if (arr &#061;&#061; null || arr.length &lt;&#061; 1) return;<\/p>\n<p>        \/\/ \u5206\u79bb\u6b63\u6570\u548c\u8d1f\u6570<br \/>\n        List&lt;Integer&gt; positive &#061; new ArrayList&lt;&gt;();<br \/>\n        List&lt;Integer&gt; negative &#061; new ArrayList&lt;&gt;();<\/p>\n<p>        for (int num : arr) {<br \/>\n            if (num &gt;&#061; 0) {<br \/>\n                positive.add(num);<br \/>\n            } else {<br \/>\n                negative.add(-num); \/\/ \u5c06\u8d1f\u6570\u8f6c\u4e3a\u6b63\u6570\u5904\u7406<br \/>\n            }<br \/>\n        }<\/p>\n<p>        \/\/ \u5206\u522b\u6392\u5e8f\u6b63\u6570\u548c\u8d1f\u6570<br \/>\n        int[] posArr &#061; positive.stream().mapToInt(i -&gt; i).toArray();<br \/>\n        int[] negArr &#061; negative.stream().mapToInt(i -&gt; i).toArray();<\/p>\n<p>        if (posArr.length &gt; 0) radixSort(posArr);<br \/>\n        if (negArr.length &gt; 0) radixSort(negArr);<\/p>\n<p>        \/\/ \u5408\u5e76\u7ed3\u679c&#xff08;\u6ce8\u610f\u8d1f\u6570\u8981\u53cd\u8f6c\u5e76\u6062\u590d\u8d1f\u53f7&#xff09;<br \/>\n        int index &#061; 0;<br \/>\n        for (int i &#061; negArr.length &#8211; 1; i &gt;&#061; 0; i&#8211;) {<br \/>\n            arr[index&#043;&#043;] &#061; -negArr[i];<br \/>\n        }<br \/>\n        System.arraycopy(posArr, 0, arr, index, posArr.length);<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u57fa\u6570\u6392\u5e8f &#8211; MSD&#xff08;\u6700\u9ad8\u4f4d\u4f18\u5148&#xff09;\u9012\u5f52\u5b9e\u73b0<br \/>\n     *\/<br \/>\n    public static void radixSortMSD(int[] arr) {<br \/>\n        if (arr &#061;&#061; null || arr.length &lt;&#061; 1) return;<\/p>\n<p>        int max &#061; getMax(arr);<br \/>\n        int maxDigit &#061; getMaxDigit(max);<\/p>\n<p>        radixSortMSD(arr, 0, arr.length &#8211; 1, maxDigit);<br \/>\n    }<\/p>\n<p>    private static void radixSortMSD(int[] arr, int left, int right, int digit) {<br \/>\n        if (digit &#061;&#061; 0 || left &gt;&#061; right) return;<\/p>\n<p>        \/\/ 10\u4e2a\u6876<br \/>\n        int[][] buckets &#061; new int[10][right &#8211; left &#043; 1];<br \/>\n        int[] bucketCount &#061; new int[10];<\/p>\n<p>        \/\/ \u5206\u914d\u5143\u7d20\u5230\u6876\u4e2d<br \/>\n        int divisor &#061; (int) Math.pow(10, digit &#8211; 1);<br \/>\n        for (int i &#061; left; i &lt;&#061; right; i&#043;&#043;) {<br \/>\n            int digitNum &#061; (arr[i] \/ divisor) % 10;<br \/>\n            buckets[digitNum][bucketCount[digitNum]&#043;&#043;] &#061; arr[i];<br \/>\n        }<\/p>\n<p>        \/\/ \u5c06\u6876\u4e2d\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4<br \/>\n        int index &#061; left;<br \/>\n        for (int i &#061; 0; i &lt; 10; i&#043;&#043;) {<br \/>\n            if (bucketCount[i] &gt; 0) {<br \/>\n                System.arraycopy(buckets[i], 0, arr, index, bucketCount[i]);<\/p>\n<p>                \/\/ \u9012\u5f52\u5bf9\u6bcf\u4e2a\u6876\u8fdb\u884c\u6392\u5e8f<br \/>\n                if (digit &gt; 1) {<br \/>\n                    radixSortMSD(arr, index, index &#043; bucketCount[i] &#8211; 1, digit &#8211; 1);<br \/>\n                }<\/p>\n<p>                index &#043;&#061; bucketCount[i];<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u6839\u636e\u6307\u5b9a\u4f4d\u6570\u8fdb\u884c\u8ba1\u6570\u6392\u5e8f<br \/>\n     *\/<br \/>\n    private static void countingSortByDigit(int[] arr, int exp) {<br \/>\n        int n &#061; arr.length;<br \/>\n        int[] output &#061; new int[n];<br \/>\n        int[] count &#061; new int[10];<\/p>\n<p>        \/\/ \u7edf\u8ba1\u6bcf\u4e2a\u6570\u5b57\u51fa\u73b0\u7684\u6b21\u6570<br \/>\n        for (int num : arr) {<br \/>\n            int digit &#061; (num \/ exp) % 10;<br \/>\n            count[digit]&#043;&#043;;<br \/>\n        }<\/p>\n<p>        \/\/ \u5c06\u8ba1\u6570\u8f6c\u6362\u4e3a\u4f4d\u7f6e\u7d22\u5f15<br \/>\n        for (int i &#061; 1; i &lt; 10; i&#043;&#043;) {<br \/>\n            count[i] &#043;&#061; count[i &#8211; 1];<br \/>\n        }<\/p>\n<p>        \/\/ \u6784\u5efa\u8f93\u51fa\u6570\u7ec4&#xff08;\u4ece\u540e\u5f80\u524d\u4fdd\u8bc1\u7a33\u5b9a\u6027&#xff09;<br \/>\n        for (int i &#061; n &#8211; 1; i &gt;&#061; 0; i&#8211;) {<br \/>\n            int digit &#061; (arr[i] \/ exp) % 10;<br \/>\n            output[count[digit] &#8211; 1] &#061; arr[i];<br \/>\n            count[digit]&#8211;;<br \/>\n        }<\/p>\n<p>        \/\/ \u5c06\u6392\u5e8f\u7ed3\u679c\u590d\u5236\u56de\u539f\u6570\u7ec4<br \/>\n        System.arraycopy(output, 0, arr, 0, n);<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u83b7\u53d6\u6570\u7ec4\u6700\u5927\u503c<br \/>\n     *\/<br \/>\n    private static int getMax(int[] arr) {<br \/>\n        int max &#061; arr[0];<br \/>\n        for (int num : arr) {<br \/>\n            if (num &gt; max) {<br \/>\n                max &#061; num;<br \/>\n            }<br \/>\n        }<br \/>\n        return max;<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u83b7\u53d6\u6570\u5b57\u7684\u4f4d\u6570<br \/>\n     *\/<br \/>\n    private static int getMaxDigit(int num) {<br \/>\n        if (num &#061;&#061; 0) return 1;<\/p>\n<p>        int digits &#061; 0;<br \/>\n        while (num &gt; 0) {<br \/>\n            digits&#043;&#043;;<br \/>\n            num \/&#061; 10;<br \/>\n        }<br \/>\n        return digits;<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        int[] arr &#061; {170, 45, 75, 90, 802, 24, 2, 66};<br \/>\n        System.out.println(&#034;\u539f\u59cb\u6570\u7ec4: &#034; &#043; Arrays.toString(arr));<br \/>\n        radixSort(arr);<br \/>\n        System.out.println(&#034;\u57fa\u6570\u6392\u5e8f\u540e: &#034; &#043; Arrays.toString(arr));<\/p>\n<p>        int[] arr2 &#061; {-5, 10, -3, 8, -1, 4, 0, 12};<br \/>\n        System.out.println(&#034;\\\\n\u539f\u59cb\u6570\u7ec4: &#034; &#043; Arrays.toString(arr2));<br \/>\n        radixSortWithNegative(arr2);<br \/>\n        System.out.println(&#034;\u5305\u542b\u8d1f\u6570\u7684\u57fa\u6570\u6392\u5e8f\u540e: &#034; &#043; Arrays.toString(arr2));<br \/>\n    }<br \/>\n} <\/p>\n<h3>8. \u5806\u6392\u5e8f (Heap Sort)<\/h3>\n<p>java<\/p>\n<p>public class HeapSort {<br \/>\n    \/**<br \/>\n     * \u5806\u6392\u5e8f &#8211; \u57fa\u4e8e\u4e8c\u53c9\u5806\u7684\u9009\u62e9\u6392\u5e8f<br \/>\n     * \u65f6\u95f4\u590d\u6742\u5ea6&#xff1a;O(nlogn)<br \/>\n     * \u7a7a\u95f4\u590d\u6742\u5ea6&#xff1a;O(1)<br \/>\n     * \u4e0d\u7a33\u5b9a\u6392\u5e8f<br \/>\n     *\/<\/p>\n<p>    \/**<br \/>\n     * \u5806\u6392\u5e8f\u4e3b\u51fd\u6570 &#8211; \u5347\u5e8f\u6392\u5e8f&#xff08;\u4f7f\u7528\u6700\u5927\u5806&#xff09;<br \/>\n     *\/<br \/>\n    public static void heapSort(int[] arr) {<br \/>\n        if (arr &#061;&#061; null || arr.length &lt;&#061; 1) return;<\/p>\n<p>        int n &#061; arr.length;<\/p>\n<p>        \/\/ 1. \u6784\u5efa\u6700\u5927\u5806<br \/>\n        \/\/ \u4ece\u6700\u540e\u4e00\u4e2a\u975e\u53f6\u5b50\u8282\u70b9\u5f00\u59cb\u5411\u4e0a\u8c03\u6574<br \/>\n        for (int i &#061; n \/ 2 &#8211; 1; i &gt;&#061; 0; i&#8211;) {<br \/>\n            heapify(arr, n, i);<br \/>\n        }<\/p>\n<p>        \/\/ 2. \u9010\u4e2a\u63d0\u53d6\u5143\u7d20<br \/>\n        for (int i &#061; n &#8211; 1; i &gt; 0; i&#8211;) {<br \/>\n            \/\/ \u5c06\u5806\u9876\u5143\u7d20&#xff08;\u6700\u5927\u503c&#xff09;\u4e0e\u5f53\u524d\u672b\u5c3e\u5143\u7d20\u4ea4\u6362<br \/>\n            swap(arr, 0, i);<\/p>\n<p>            \/\/ \u8c03\u6574\u5269\u4f59\u5143\u7d20\u4e3a\u6700\u5927\u5806<br \/>\n            heapify(arr, i, 0);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u5806\u6392\u5e8f &#8211; \u964d\u5e8f\u6392\u5e8f&#xff08;\u4f7f\u7528\u6700\u5c0f\u5806&#xff09;<br \/>\n     *\/<br \/>\n    public static void heapSortDesc(int[] arr) {<br \/>\n        if (arr &#061;&#061; null || arr.length &lt;&#061; 1) return;<\/p>\n<p>        int n &#061; arr.length;<\/p>\n<p>        \/\/ 1. \u6784\u5efa\u6700\u5c0f\u5806<br \/>\n        for (int i &#061; n \/ 2 &#8211; 1; i &gt;&#061; 0; i&#8211;) {<br \/>\n            heapifyMin(arr, n, i);<br \/>\n        }<\/p>\n<p>        \/\/ 2. \u9010\u4e2a\u63d0\u53d6\u5143\u7d20<br \/>\n        for (int i &#061; n &#8211; 1; i &gt; 0; i&#8211;) {<br \/>\n            swap(arr, 0, i);<br \/>\n            heapifyMin(arr, i, 0);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u5c06\u6307\u5b9a\u8282\u70b9\u4e3a\u6839\u7684\u5b50\u6811\u8c03\u6574\u4e3a\u6700\u5927\u5806<br \/>\n     *\/<br \/>\n    private static void heapify(int[] arr, int n, int i) {<br \/>\n        int largest &#061; i;        \/\/ \u521d\u59cb\u5316\u6700\u5927\u503c\u4e3a\u6839\u8282\u70b9<br \/>\n        int left &#061; 2 * i &#043; 1;   \/\/ \u5de6\u5b50\u8282\u70b9<br \/>\n        int right &#061; 2 * i &#043; 2;  \/\/ \u53f3\u5b50\u8282\u70b9<\/p>\n<p>        \/\/ \u5982\u679c\u5de6\u5b50\u8282\u70b9\u6bd4\u6839\u5927<br \/>\n        if (left &lt; n &amp;&amp; arr[left] &gt; arr[largest]) {<br \/>\n            largest &#061; left;<br \/>\n        }<\/p>\n<p>        \/\/ \u5982\u679c\u53f3\u5b50\u8282\u70b9\u6bd4\u5f53\u524d\u6700\u5927\u503c\u5927<br \/>\n        if (right &lt; n &amp;&amp; arr[right] &gt; arr[largest]) {<br \/>\n            largest &#061; right;<br \/>\n        }<\/p>\n<p>        \/\/ \u5982\u679c\u6700\u5927\u503c\u4e0d\u662f\u6839\u8282\u70b9<br \/>\n        if (largest !&#061; i) {<br \/>\n            swap(arr, i, largest);<\/p>\n<p>            \/\/ \u9012\u5f52\u8c03\u6574\u53d7\u5f71\u54cd\u7684\u5b50\u6811<br \/>\n            heapify(arr, n, largest);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u5c06\u6307\u5b9a\u8282\u70b9\u4e3a\u6839\u7684\u5b50\u6811\u8c03\u6574\u4e3a\u6700\u5c0f\u5806<br \/>\n     *\/<br \/>\n    private static void heapifyMin(int[] arr, int n, int i) {<br \/>\n        int smallest &#061; i;       \/\/ \u521d\u59cb\u5316\u6700\u5c0f\u503c\u4e3a\u6839\u8282\u70b9<br \/>\n        int left &#061; 2 * i &#043; 1;<br \/>\n        int right &#061; 2 * i &#043; 2;<\/p>\n<p>        if (left &lt; n &amp;&amp; arr[left] &lt; arr[smallest]) {<br \/>\n            smallest &#061; left;<br \/>\n        }<\/p>\n<p>        if (right &lt; n &amp;&amp; arr[right] &lt; arr[smallest]) {<br \/>\n            smallest &#061; right;<br \/>\n        }<\/p>\n<p>        if (smallest !&#061; i) {<br \/>\n            swap(arr, i, smallest);<br \/>\n            heapifyMin(arr, n, smallest);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u5806\u6392\u5e8f &#8211; \u8fed\u4ee3\u5b9e\u73b0&#xff08;\u975e\u9012\u5f52&#xff09;<br \/>\n     *\/<br \/>\n    public static void heapSortIterative(int[] arr) {<br \/>\n        if (arr &#061;&#061; null || arr.length &lt;&#061; 1) return;<\/p>\n<p>        int n &#061; arr.length;<\/p>\n<p>        \/\/ \u6784\u5efa\u6700\u5927\u5806<br \/>\n        for (int i &#061; n \/ 2 &#8211; 1; i &gt;&#061; 0; i&#8211;) {<br \/>\n            heapifyIterative(arr, n, i);<br \/>\n        }<\/p>\n<p>        \/\/ \u9010\u4e2a\u63d0\u53d6\u5143\u7d20<br \/>\n        for (int i &#061; n &#8211; 1; i &gt; 0; i&#8211;) {<br \/>\n            swap(arr, 0, i);<br \/>\n            heapifyIterative(arr, i, 0);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u8fed\u4ee3\u5b9e\u73b0\u5806\u8c03\u6574<br \/>\n     *\/<br \/>\n    private static void heapifyIterative(int[] arr, int n, int i) {<br \/>\n        int current &#061; i;<\/p>\n<p>        while (true) {<br \/>\n            int largest &#061; current;<br \/>\n            int left &#061; 2 * current &#043; 1;<br \/>\n            int right &#061; 2 * current &#043; 2;<\/p>\n<p>            if (left &lt; n &amp;&amp; arr[left] &gt; arr[largest]) {<br \/>\n                largest &#061; left;<br \/>\n            }<\/p>\n<p>            if (right &lt; n &amp;&amp; arr[right] &gt; arr[largest]) {<br \/>\n                largest &#061; right;<br \/>\n            }<\/p>\n<p>            if (largest &#061;&#061; current) {<br \/>\n                break;<br \/>\n            }<\/p>\n<p>            swap(arr, current, largest);<br \/>\n            current &#061; largest;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u4f18\u5148\u961f\u5217&#xff08;\u57fa\u4e8e\u5806&#xff09;\u7684\u5b9e\u73b0<br \/>\n     *\/<br \/>\n    public static class PriorityQueue {<br \/>\n        private int[] heap;<br \/>\n        private int size;<br \/>\n        private int capacity;<\/p>\n<p>        public PriorityQueue(int capacity) {<br \/>\n            this.capacity &#061; capacity;<br \/>\n            this.heap &#061; new int[capacity];<br \/>\n            this.size &#061; 0;<br \/>\n        }<\/p>\n<p>        public void insert(int value) {<br \/>\n            if (size &#061;&#061; capacity) {<br \/>\n                throw new IllegalStateException(&#034;Priority queue is full&#034;);<br \/>\n            }<\/p>\n<p>            \/\/ \u5c06\u65b0\u5143\u7d20\u63d2\u5165\u5230\u672b\u5c3e<br \/>\n            heap[size] &#061; value;<br \/>\n            int current &#061; size;<br \/>\n            size&#043;&#043;;<\/p>\n<p>            \/\/ \u4e0a\u6d6e\u8c03\u6574<br \/>\n            while (current &gt; 0 &amp;&amp; heap[current] &gt; heap[parent(current)]) {<br \/>\n                swap(heap, current, parent(current));<br \/>\n                current &#061; parent(current);<br \/>\n            }<br \/>\n        }<\/p>\n<p>        public int extractMax() {<br \/>\n            if (size &#061;&#061; 0) {<br \/>\n                throw new IllegalStateException(&#034;Priority queue is empty&#034;);<br \/>\n            }<\/p>\n<p>            int max &#061; heap[0];<br \/>\n            heap[0] &#061; heap[size &#8211; 1];<br \/>\n            size&#8211;;<\/p>\n<p>            \/\/ \u4e0b\u6c89\u8c03\u6574<br \/>\n            heapify(heap, size, 0);<\/p>\n<p>            return max;<br \/>\n        }<\/p>\n<p>        private int parent(int i) {<br \/>\n            return (i &#8211; 1) \/ 2;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    private static void swap(int[] arr, int i, int j) {<br \/>\n        int temp &#061; arr[i];<br \/>\n        arr[i] &#061; arr[j];<br \/>\n        arr[j] &#061; temp;<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        int[] arr &#061; {12, 11, 13, 5, 6, 7};<br \/>\n        System.out.println(&#034;\u539f\u59cb\u6570\u7ec4: &#034; &#043; Arrays.toString(arr));<br \/>\n        heapSort(arr);<br \/>\n        System.out.println(&#034;\u5806\u6392\u5e8f\u540e: &#034; &#043; Arrays.toString(arr));<\/p>\n<p>        int[] arr2 &#061; {4, 10, 3, 5, 1};<br \/>\n        System.out.println(&#034;\\\\n\u539f\u59cb\u6570\u7ec4: &#034; &#043; Arrays.toString(arr2));<br \/>\n        heapSortIterative(arr2);<br \/>\n        System.out.println(&#034;\u8fed\u4ee3\u5806\u6392\u5e8f\u540e: &#034; &#043; Arrays.toString(arr2));<br \/>\n    }<br \/>\n} <\/p>\n<h3>\u5b8c\u6574\u6d4b\u8bd5\u7c7b<\/h3>\n<p>java<\/p>\n<p>import java.util.*;<\/p>\n<p>public class AllSortingAlgorithms {<br \/>\n    public static void main(String[] args) {<br \/>\n        int[] original &#061; {64, 34, 25, 12, 22, 11, 90, 45};<\/p>\n<p>        System.out.println(&#034;&#061;&#061;&#061; \u516b\u5927\u6392\u5e8f\u7b97\u6cd5\u5b8c\u6574\u6d4b\u8bd5 &#061;&#061;&#061;\\\\n&#034;);<\/p>\n<p>        \/\/ 1. \u6d4b\u8bd5\u5192\u6ce1\u6392\u5e8f<br \/>\n        testSorting(&#034;\u5192\u6ce1\u6392\u5e8f&#034;, original.clone(),<br \/>\n                   arr -&gt; BubbleSort.bubbleSortOptimized(arr));<\/p>\n<p>        \/\/ 2. \u6d4b\u8bd5\u9009\u62e9\u6392\u5e8f<br \/>\n        testSorting(&#034;\u9009\u62e9\u6392\u5e8f&#034;, original.clone(),<br \/>\n                   arr -&gt; SelectionSort.selectionSortBidirectional(arr));<\/p>\n<p>        \/\/ 3. \u6d4b\u8bd5\u63d2\u5165\u6392\u5e8f<br \/>\n        testSorting(&#034;\u63d2\u5165\u6392\u5e8f&#034;, original.clone(),<br \/>\n                   arr -&gt; InsertionSort.insertionSort(arr));<\/p>\n<p>        \/\/ 4. \u6d4b\u8bd5\u5e0c\u5c14\u6392\u5e8f<br \/>\n        testSorting(&#034;\u5e0c\u5c14\u6392\u5e8f&#034;, original.clone(),<br \/>\n                   arr -&gt; ShellSort.shellSortKnuth(arr));<\/p>\n<p>        \/\/ 5. \u6d4b\u8bd5\u5feb\u901f\u6392\u5e8f<br \/>\n        testSorting(&#034;\u5feb\u901f\u6392\u5e8f&#034;, original.clone(),<br \/>\n                   arr -&gt; QuickSort.quickSortOptimized(arr));<\/p>\n<p>        \/\/ 6. \u6d4b\u8bd5\u5f52\u5e76\u6392\u5e8f<br \/>\n        testSorting(&#034;\u5f52\u5e76\u6392\u5e8f&#034;, original.clone(),<br \/>\n                   arr -&gt; MergeSort.mergeSort(arr));<\/p>\n<p>        \/\/ 7. \u6d4b\u8bd5\u57fa\u6570\u6392\u5e8f<br \/>\n        testSorting(&#034;\u57fa\u6570\u6392\u5e8f&#034;, new int[]{170, 45, 75, 90, 802, 24, 2, 66},<br \/>\n                   arr -&gt; RadixSort.radixSort(arr));<\/p>\n<p>        \/\/ 8. \u6d4b\u8bd5\u5806\u6392\u5e8f<br \/>\n        testSorting(&#034;\u5806\u6392\u5e8f&#034;, original.clone(),<br \/>\n                   arr -&gt; HeapSort.heapSort(arr));<br \/>\n    }<\/p>\n<p>    private static void testSorting(String name, int[] arr, SortingAlgorithm algorithm) {<br \/>\n        System.out.println(name &#043; &#034;\u524d: &#034; &#043; Arrays.toString(arr));<br \/>\n        algorithm.sort(arr);<br \/>\n        System.out.println(name &#043; &#034;\u540e: &#034; &#043; Arrays.toString(arr));<br \/>\n        System.out.println();<br \/>\n    }<\/p>\n<p>    &#064;FunctionalInterface<br \/>\n    interface SortingAlgorithm {<br \/>\n        void sort(int[] arr);<br \/>\n    }<br \/>\n} <\/p>\n<h3>\u7b97\u6cd5\u7279\u6027\u603b\u7ed3\u8868<\/h3>\n<table>\n<tr>\u6392\u5e8f\u7b97\u6cd5\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u6700\u597d\u60c5\u51b5\u6700\u574f\u60c5\u51b5\u7a7a\u95f4\u590d\u6742\u5ea6\u7a33\u5b9a\u6027\u539f\u5730\u6392\u5e8f\u9002\u7528\u573a\u666f<\/tr>\n<tbody>\n<tr>\n<td>\u5192\u6ce1\u6392\u5e8f<\/td>\n<td>O(n\u00b2)<\/td>\n<td>O(n)<\/td>\n<td>O(n\u00b2)<\/td>\n<td>O(1)<\/td>\n<td>\u7a33\u5b9a<\/td>\n<td>\u662f<\/td>\n<td>\u6559\u5b66\u3001\u5c0f\u6570\u636e<\/td>\n<\/tr>\n<tr>\n<td>\u9009\u62e9\u6392\u5e8f<\/td>\n<td>O(n\u00b2)<\/td>\n<td>O(n\u00b2)<\/td>\n<td>O(n\u00b2)<\/td>\n<td>O(1)<\/td>\n<td>\u4e0d\u7a33\u5b9a<\/td>\n<td>\u662f<\/td>\n<td>\u5c0f\u6570\u636e\u3001\u4ea4\u6362\u6210\u672c\u9ad8<\/td>\n<\/tr>\n<tr>\n<td>\u63d2\u5165\u6392\u5e8f<\/td>\n<td>O(n\u00b2)<\/td>\n<td>O(n)<\/td>\n<td>O(n\u00b2)<\/td>\n<td>O(1)<\/td>\n<td>\u7a33\u5b9a<\/td>\n<td>\u662f<\/td>\n<td>\u57fa\u672c\u6709\u5e8f\u5c0f\u6570\u636e<\/td>\n<\/tr>\n<tr>\n<td>\u5e0c\u5c14\u6392\u5e8f<\/td>\n<td>O(n^1.3)<\/td>\n<td>O(n)<\/td>\n<td>O(n\u00b2)<\/td>\n<td>O(1)<\/td>\n<td>\u4e0d\u7a33\u5b9a<\/td>\n<td>\u662f<\/td>\n<td>\u4e2d\u7b49\u89c4\u6a21\u6570\u636e<\/td>\n<\/tr>\n<tr>\n<td>\u5feb\u901f\u6392\u5e8f<\/td>\n<td>O(nlogn)<\/td>\n<td>O(nlogn)<\/td>\n<td>O(n\u00b2)<\/td>\n<td>O(logn)<\/td>\n<td>\u4e0d\u7a33\u5b9a<\/td>\n<td>\u662f<\/td>\n<td>\u5927\u89c4\u6a21\u901a\u7528\u6570\u636e<\/td>\n<\/tr>\n<tr>\n<td>\u5f52\u5e76\u6392\u5e8f<\/td>\n<td>O(nlogn)<\/td>\n<td>O(nlogn)<\/td>\n<td>O(nlogn)<\/td>\n<td>O(n)<\/td>\n<td>\u7a33\u5b9a<\/td>\n<td>\u5426<\/td>\n<td>\u5927\u89c4\u6a21\u6570\u636e\u3001\u5916\u90e8\u6392\u5e8f<\/td>\n<\/tr>\n<tr>\n<td>\u57fa\u6570\u6392\u5e8f<\/td>\n<td>O(d*(n&#043;k))<\/td>\n<td>O(d*(n&#043;k))<\/td>\n<td>O(d*(n&#043;k))<\/td>\n<td>O(n&#043;k)<\/td>\n<td>\u7a33\u5b9a<\/td>\n<td>\u5426<\/td>\n<td>\u6574\u6570\u3001\u5b57\u7b26\u4e32\u6392\u5e8f<\/td>\n<\/tr>\n<tr>\n<td>\u5806\u6392\u5e8f<\/td>\n<td>O(nlogn)<\/td>\n<td>O(nlogn)<\/td>\n<td>O(nlogn)<\/td>\n<td>O(1)<\/td>\n<td>\u4e0d\u7a33\u5b9a<\/td>\n<td>\u662f<\/td>\n<td>TopK\u95ee\u9898\u3001\u4f18\u5148\u7ea7\u961f\u5217<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u9009\u62e9\u5efa\u8bae<\/h3>\n<li>\n<p>\u5c0f\u6570\u636e\u91cf&#xff08;n &lt; 50&#xff09;&#xff1a;\u63d2\u5165\u6392\u5e8f\u6700\u4f73<\/p>\n<\/li>\n<li>\n<p>\u57fa\u672c\u6709\u5e8f\u6570\u636e&#xff1a;\u63d2\u5165\u6392\u5e8f\u6216\u5192\u6ce1\u6392\u5e8f<\/p>\n<\/li>\n<li>\n<p>\u5927\u6570\u636e\u91cf\u901a\u7528\u6392\u5e8f&#xff1a;\u5feb\u901f\u6392\u5e8f&#xff08;\u9700\u4f18\u5316&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u9700\u8981\u7a33\u5b9a\u6392\u5e8f&#xff1a;\u5f52\u5e76\u6392\u5e8f\u3001\u63d2\u5165\u6392\u5e8f<\/p>\n<\/li>\n<li>\n<p>\u5185\u5b58\u6709\u9650&#xff1a;\u5806\u6392\u5e8f\u3001\u5e0c\u5c14\u6392\u5e8f<\/p>\n<\/li>\n<li>\n<p>\u6574\u6570\u6392\u5e8f&#xff1a;\u57fa\u6570\u6392\u5e8f&#xff08;\u5c24\u5176\u9002\u5408\u4f4d\u6570\u5c11\u7684\u6574\u6570&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u94fe\u8868\u6392\u5e8f&#xff1a;\u5f52\u5e76\u6392\u5e8f<\/p>\n<\/li>\n<li>\n<p>\u5916\u90e8\u6392\u5e8f&#xff08;\u6570\u636e\u5728\u78c1\u76d8&#xff09;&#xff1a;\u5f52\u5e76\u6392\u5e8f<\/p>\n<\/li>\n<li>\n<p>\u5b9e\u65f6\u7cfb\u7edf&#xff1a;\u5806\u6392\u5e8f&#xff08;\u65f6\u95f4\u590d\u6742\u5ea6\u7a33\u5b9a&#xff09;<\/p>\n<\/li>\n<li>\n<p>Java\u5185\u7f6e\u6392\u5e8f&#xff1a;Arrays.sort()\u4f7f\u7528\u53cc\u8f74\u5feb\u901f\u6392\u5e8f\u548c\u5f52\u5e76\u6392\u5e8f<\/p>\n<\/li>\n<h3>\u6027\u80fd\u6bd4\u8f83<\/h3>\n<p>java<\/p>\n<p>\/\/ \u6027\u80fd\u6d4b\u8bd5\u793a\u4f8b<br \/>\npublic class SortingBenchmark {<br \/>\n    public static void main(String[] args) {<br \/>\n        int[] sizes &#061; {1000, 5000, 10000, 50000};<\/p>\n<p>        for (int size : sizes) {<br \/>\n            System.out.println(&#034;\\\\n&#061;&#061;&#061; \u6570\u636e\u91cf: &#034; &#043; size &#043; &#034; &#061;&#061;&#061;&#034;);<br \/>\n            int[] arr &#061; generateRandomArray(size);<\/p>\n<p>            testAlgorithm(&#034;\u5feb\u901f\u6392\u5e8f&#034;, arr.clone(), QuickSort::quickSortOptimized);<br \/>\n            testAlgorithm(&#034;\u5f52\u5e76\u6392\u5e8f&#034;, arr.clone(), MergeSort::mergeSort);<br \/>\n            testAlgorithm(&#034;\u5806\u6392\u5e8f&#034;, arr.clone(), HeapSort::heapSort);<br \/>\n            testAlgorithm(&#034;\u5e0c\u5c14\u6392\u5e8f&#034;, arr.clone(), ShellSort::shellSortKnuth);<br \/>\n            testAlgorithm(&#034;Arrays.sort()&#034;, arr.clone(), Arrays::sort);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    private static int[] generateRandomArray(int size) {<br \/>\n        Random rand &#061; new Random();<br \/>\n        int[] arr &#061; new int[size];<br \/>\n        for (int i &#061; 0; i &lt; size; i&#043;&#043;) {<br \/>\n            arr[i] &#061; rand.nextInt(10000);<br \/>\n        }<br \/>\n        return arr;<br \/>\n    }<\/p>\n<p>    private static void testAlgorithm(String name, int[] arr, SortingAlgorithm algorithm) {<br \/>\n        long startTime &#061; System.currentTimeMillis();<br \/>\n        algorithm.sort(arr);<br \/>\n        long endTime &#061; System.currentTimeMillis();<br \/>\n        System.out.printf(&#034;%-15s: %5d ms\\\\n&#034;, name, endTime &#8211; startTime);<br \/>\n    }<\/p>\n<p>    &#064;FunctionalInterface<br \/>\n    interface SortingAlgorithm {<br \/>\n        void sort(int[] arr);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u8fd9\u4e9b\u6392\u5e8f\u7b97\u6cd5\u662f\u8ba1\u7b97\u673a\u79d1\u5b66\u7684\u57fa\u7840&#xff0c;\u7406\u89e3\u5b83\u4eec\u7684\u539f\u7406\u548c\u5b9e\u73b0\u5bf9\u4e8e\u7f16\u7a0b\u80fd\u529b\u7684\u63d0\u5347\u81f3\u5173\u91cd\u8981\u3002\u6bcf\u79cd\u7b97\u6cd5\u90fd\u6709\u5176\u9002\u7528\u7684\u573a\u666f&#xff0c;\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u5e94\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u7b97\u6cd5\u3002<\/p>\n<h4 id=\"_1\u3001\u5192\u6ce1\u6392\u5e8f\"> \u5341\u4e03\u3001\u5f02\u5e38\u673a\u5236<\/h4>\n<h3 id=\"\u5f02\u5e38\u6982\u5ff5\">\u5f02\u5e38\u6982\u5ff5<\/h3>\n<p>\u5728\u6211\u4eec\u65e5\u5e38\u751f\u6d3b\u4e2d&#xff0c;\u6709\u65f6\u4f1a\u51fa\u73b0\u5404\u79cd\u5404\u6837\u7684\u5f02\u5e38\u3002\u4f8b\u5982&#xff1a;\u804c\u5de5\u5c0f\u738b\u5f00\u8f66\u53bb\u4e0a\u73ed&#xff0c;\u5728\u6b63\u5e38\u60c5\u51b5\u4e0b&#xff0c;\u5c0f\u738b\u4f1a\u51c6\u65f6\u5230\u8fbe\u5355\u4f4d\u3002\u4f46\u662f\u5929\u6709\u4e0d\u6d4b\u98ce\u4e91&#xff0c;\u5728\u5c0f\u738b\u53bb\u4e0a\u73ed\u65f6&#xff0c;\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u5f02\u5e38\u60c5\u51b5&#xff0c;\u6bd4\u5982\u5c0f\u738b\u7684\u8f66\u5b50\u51fa\u4e86\u6545\u969c&#xff0c;\u5c0f\u738b\u53ea\u80fd\u6539\u4e3a\u6b65\u884c\u3002<\/p>\n<p>\u5b9e\u9645\u5de5\u4f5c\u4e2d&#xff0c;\u9047\u5230\u7684\u60c5\u51b5\u4e0d\u53ef\u80fd\u662f\u975e\u5e38\u5b8c\u7f8e\u7684\u3002\u6bd4\u5982&#xff1a;\u4f60\u5199\u7684\u67d0\u4e2a\u6a21\u5757&#xff0c;\u7528\u6237\u8f93\u5165\u4e0d\u4e00\u5b9a\u7b26\u5408\u4f60\u7684\u8981\u6c42\u3001\u4f60\u7684\u7a0b\u5e8f\u8981\u6253\u5f00\u67d0\u4e2a\u6587\u4ef6&#xff0c;\u8fd9\u4e2a\u6587\u4ef6\u53ef\u80fd\u4e0d\u5b58\u5728\u6216\u8005\u6587\u4ef6\u683c\u5f0f\u4e0d\u5bf9&#xff0c;\u4f60\u8981\u8bfb\u53d6\u6570\u636e\u5e93\u7684\u6570\u636e&#xff0c;\u6570\u636e\u53ef\u80fd\u662f\u7a7a\u7684\u7b49\u3002\u6211\u4eec\u7684\u7a0b\u5e8f\u518d\u8dd1\u7740&#xff0c;\u5185\u5b58\u6216\u786c\u76d8\u53ef\u80fd\u6ee1\u4e86\u3002\u7b49\u7b49\u3002<\/p>\n<p>\u8f6f\u4ef6\u7a0b\u5e8f\u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d&#xff0c;\u975e\u5e38\u53ef\u80fd\u9047\u5230\u521a\u521a\u63d0\u5230\u7684\u8fd9\u4e9b\u5f02\u5e38\u95ee\u9898&#xff0c;\u6211\u4eec\u53eb\u5f02\u5e38&#xff0c;\u82f1\u6587\u662f&#xff1a;Exception&#xff0c; \u610f\u601d\u662f\u4f8b\u5916\u3002\u8fd9\u4e9b&#xff0c;\u4f8b\u5916\u60c5\u51b5&#xff0c;\u6216\u8005\u53eb\u5f02\u5e38&#xff0c;\u600e\u4e48\u8ba9\u6211\u4eec\u5199\u7684\u7a0b\u5e8f\u505a\u51fa\u5408\u7406\u7684\u5904\u7406\u3002\u800c\u4e0d\u81f3\u4e8e\u7a0b\u5e8f\u5d29\u6e83\u3002<\/p>\n<p>\u5f02\u5e38&#xff1a;\u6307\u7a0b\u5e8f\u8fd0\u884c\u4e2d\u51fa\u73b0\u7684\u4e0d\u671f\u800c\u81f3\u7684\u5404\u79cd\u72b6\u51b5&#xff0c;\u5982:\u6587\u4ef6\u627e\u4e0d\u5230\u3001\u7f51\u7edc\u8fde\u63a5\u5931\u8d25\u3001\u975e\u6cd5\u53c2\u6570\u7b49\u3002 \u5f02\u5e38\u53d1\u751f\u5728\u7a0b\u5e8f\u8fd0\u884c\u671f\u95f4&#xff0c;\u5b83\u5f71\u54cd\u4e86\u6b63\u5e38\u7684\u7a0b\u5e8f\u6267\u884c\u6d41\u7a0b\u3002<\/p>\n<p>\u6bd4\u5982\u8bf4&#xff0c;\u4f60\u7684\u4ee3\u7801\u5c11\u4e86\u4e00\u4e2a\u5206\u53f7&#xff0c;\u90a3\u4e48\u8fd0\u884c\u51fa\u6765\u7ed3\u679c\u662f\u63d0\u793a\u662f\u9519\u8bef\u00a0java.lang.Error\u00a0&#xff1b;<\/p>\n<p>\u5982\u679c\u4f60\u7528\u00a0System.out.println(11\/0)\u00a0&#xff0c;\u56e0\u4e3a\u4f60\u75280\u505a\u4e86\u9664\u6570&#xff0c;\u4f1a\u629b\u51fa\u00a0java.lang.ArithmeticException\u00a0\u7684\u5f02\u5e38\u3002<\/p>\n<p>\u5f02\u5e38\u53d1\u751f\u7684\u539f\u56e0\u6709\u5f88\u591a&#xff0c;\u901a\u5e38\u5305\u542b\u4ee5\u4e0b\u51e0\u5927\u7c7b&#xff1a;<\/p>\n<ul>\n<li>\u7528\u6237\u8f93\u5165\u4e86\u975e\u6cd5\u6570\u636e\u3002<\/li>\n<li>\u8981\u6253\u5f00\u7684\u6587\u4ef6\u4e0d\u5b58\u5728\u3002<\/li>\n<li>\u7f51\u7edc\u901a\u4fe1\u65f6\u8fde\u63a5\u4e2d\u65ad&#xff0c;\u6216\u8005JVM\u5185\u5b58\u6ea2\u51fa\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e9b\u5f02\u5e38\u6709\u7684\u662f\u56e0\u4e3a\u7528\u6237\u9519\u8bef\u5f15\u8d77&#xff0c;\u6709\u7684\u662f\u7a0b\u5e8f\u9519\u8bef\u5f15\u8d77\u7684&#xff0c;\u8fd8\u6709\u5176\u5b83\u4e00\u4e9b\u662f\u56e0\u4e3a\u7269\u7406\u9519\u8bef\u5f15\u8d77\u7684\u3002<\/p>\n<p>\u8981\u7406\u89e3Java\u5f02\u5e38\u5904\u7406\u662f\u5982\u4f55\u5de5\u4f5c\u7684&#xff0c;\u4f60\u9700\u8981\u638c\u63e1\u4ee5\u4e0b\u4e09\u79cd\u7c7b\u578b\u7684\u5f02\u5e38&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u68c0\u67e5\u6027\u5f02\u5e38&#xff1a;<\/p>\n<p>\u6700\u5177\u4ee3\u8868\u7684\u68c0\u67e5\u6027\u5f02\u5e38\u662f\u7528\u6237\u9519\u8bef\u6216\u95ee\u9898\u5f15\u8d77\u7684\u5f02\u5e38&#xff0c;\u8fd9\u662f\u7a0b\u5e8f\u5458\u65e0\u6cd5\u9884\u89c1\u7684\u3002\u4f8b\u5982&#xff0c;\u8981\u6253\u5f00\u4e00\u4e2a\u4e0d\u5b58\u5728\u6587\u4ef6\u65f6&#xff0c;\u4e00\u4e2a\u5f02\u5e38\u5c31\u53d1\u751f\u4e86&#xff0c;\u8fd9\u4e9b\u5f02\u5e38\u5728\u7f16\u8bd1\u65f6\u4e0d\u80fd\u88ab\u7b80\u5355\u5730\u5ffd\u7565\u3002<\/p>\n<\/li>\n<li>\n<p>\u8fd0\u884c\u65f6\u5f02\u5e38&#xff1a;<\/p>\n<p>\u8fd0\u884c\u65f6\u5f02\u5e38\u662f\u53ef\u80fd\u88ab\u7a0b\u5e8f\u5458\u907f\u514d\u7684\u5f02\u5e38\u3002\u4e0e\u68c0\u67e5\u6027\u5f02\u5e38\u76f8\u53cd&#xff0c;\u8fd0\u884c\u65f6\u5f02\u5e38\u53ef\u4ee5\u5728\u7f16\u8bd1\u65f6\u88ab\u5ffd\u7565\u3002<\/p>\n<\/li>\n<li>\n<p>\u9519\u8bef&#xff1a;<\/p>\n<p>\u9519\u8bef\u4e0d\u662f\u5f02\u5e38&#xff0c;\u800c\u662f\u8131\u79bb\u7a0b\u5e8f\u5458\u63a7\u5236\u7684\u95ee\u9898\u3002\u9519\u8bef\u5728\u4ee3\u7801\u4e2d\u901a\u5e38\u88ab\u5ffd\u7565\u3002\u4f8b\u5982&#xff0c;\u5f53\u6808\u6ea2\u51fa \u65f6&#xff0c;\u4e00\u4e2a\u9519\u8bef\u5c31\u53d1\u751f\u4e86&#xff0c;\u5b83\u4eec\u5728\u7f16\u8bd1\u4e5f\u68c0\u67e5\u4e0d\u5230\u7684\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5f02\u5e38\u6307\u4e0d\u671f\u800c\u81f3\u7684\u5404\u79cd\u72b6\u51b5&#xff0c;\u5982&#xff1a;\u6587\u4ef6\u627e\u4e0d\u5230\u3001\u7f51\u7edc\u8fde\u63a5\u5931\u8d25\u3001\u96640\u64cd\u4f5c\u3001\u975e\u6cd5\u53c2\u6570\u7b49\u3002\u5f02\u5e38\u662f\u4e00\u4e2a \u4e8b\u4ef6&#xff0c;\u5b83\u53d1\u751f\u5728\u7a0b\u5e8f\u8fd0\u884c\u671f\u95f4&#xff0c;\u5e72\u6270\u4e86\u6b63\u5e38\u7684\u6307\u4ee4\u6d41\u7a0b\u3002<\/p>\n<p>Java\u8bed\u8a00\u5728\u8bbe\u8ba1\u7684\u5f53\u521d\u5c31\u8003\u8651\u5230\u8fd9\u4e9b\u95ee\u9898&#xff0c;\u63d0\u51fa\u5f02\u5e38\u5904\u7406\u7684\u6846\u67b6\u7684\u65b9\u6848&#xff0c;\u6240\u6709\u7684\u5f02\u5e38\u90fd\u53ef\u4ee5\u7528\u4e00\u4e2a \u5f02\u5e38\u7c7b \u6765\u8868\u793a&#xff0c;\u4e0d\u540c\u7c7b\u578b\u7684\u5f02\u5e38\u5bf9\u5e94\u4e0d\u540c\u7684\u5b50\u7c7b\u5f02\u5e38&#xff08;\u76ee\u524d\u6211\u4eec\u6240\u8bf4\u7684\u5f02\u5e38\u5305\u62ec\u9519\u8bef\u6982\u5ff5&#xff09;&#xff0c;\u5b9a\u4e49\u5f02\u5e38\u5904\u7406\u7684\u89c4\u8303&#xff0c;\u5728\u00a0JDK1.4\u00a0\u7248\u672c\u4ee5\u540e\u589e\u52a0\u4e86\u5f02\u5e38\u94fe\u673a\u5236&#xff0c;\u4ece\u800c\u4fbf\u4e8e\u8ddf\u8e2a\u5f02\u5e38\u3002<\/p>\n<p>Java\u5f02\u5e38\u662f\u4e00\u4e2a\u63cf\u8ff0\u5728\u4ee3\u7801\u6bb5\u4e2d\u53d1\u751f\u5f02\u5e38\u7684\u5bf9\u8c61&#xff0c;\u5f53\u53d1\u751f\u5f02\u5e38\u60c5\u51b5\u65f6&#xff0c;\u4e00\u4e2a\u4ee3\u8868\u8be5\u5f02\u5e38\u7684\u5bf9\u8c61\u88ab\u521b\u5efa\u5e76\u4e14\u5728\u5bfc\u81f4\u8be5\u5f02\u5e38\u7684\u65b9\u6cd5\u4e2d\u88ab\u629b\u51fa&#xff0c;\u800c\u8be5\u65b9\u6cd5\u53ef\u4ee5\u9009\u62e9\u81ea\u5df1\u5904\u7406\u5f02\u5e38\u6216\u8005\u4f20\u9012\u8be5\u5f02\u5e38\u3002<\/p>\n<h3 id=\"\u5f02\u5e38\u4f53\u7cfb\u7ed3\u6784\">\u5f02\u5e38\u4f53\u7cfb\u7ed3\u6784<\/h3>\n<p>Java\u628a\u5f02\u5e38\u5f53\u4f5c\u5bf9\u8c61\u6765\u5904\u7406&#xff0c;\u5e76\u5b9a\u4e49\u4e00\u4e2a\u57fa\u7c7b\u00a0java.lang.Throwable\u4f5c\u4e3a\u6240\u6709\u5f02\u5e38\u7684\u8d85\u7c7b\u3002<\/p>\n<p>\u5728Java API\u4e2d\u5df2\u7ecf\u5b9a\u4e49\u4e86\u8bb8\u591a\u5f02\u5e38\u7c7b&#xff0c;\u8fd9\u4e9b\u5f02\u5e38\u7c7b\u5206\u4e3a\u4e24\u5927\u7c7b&#xff0c;\u9519\u8befError\u548c\u5f02\u5e38Exception\u3002<\/p>\n<p>Java\u5f02\u5e38\u5c42\u6b21\u7ed3\u6784\u56fe&#xff1a;<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"520\" src=\"2026-01-14azqnbv2rqpq.png\" width=\"832\" \/><\/p>\n<p>\u4ece\u56fe\u4e2d\u53ef\u4ee5\u770b\u51fa\u6240\u6709\u5f02\u5e38\u7c7b\u578b\u90fd\u662f\u5185\u7f6e\u7c7b\u00a0Throwable\u00a0\u7684\u5b50\u7c7b&#xff0c;\u56e0\u800c\u00a0Throwable\u00a0\u5728\u5f02\u5e38\u7c7b\u7684\u5c42\u6b21\u7ed3\u6784\u7684\u9876\u5c42\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u00a0Throwable\u00a0\u5206\u6210\u4e86\u4e24\u4e2a\u4e0d\u540c\u7684\u5206\u652f&#xff0c;\u4e00\u4e2a\u5206\u652f\u662fError&#xff0c;\u5b83\u8868\u793a\u4e0d\u5e0c\u671b\u88ab\u7a0b\u5e8f\u6355\u83b7\u6216\u8005\u662f\u7a0b\u5e8f\u65e0\u6cd5\u5904\u7406\u7684\u9519\u8bef\u3002\u53e6\u4e00\u4e2a\u5206\u652f\u662fException&#xff0c;\u5b83\u8868\u793a\u7528\u6237\u7a0b\u5e8f\u53ef\u80fd\u6355\u6349\u7684\u5f02\u5e38\u60c5\u51b5\u6216\u8005\u8bf4\u662f\u7a0b\u5e8f\u53ef\u4ee5\u5904\u7406\u7684\u5f02\u5e38\u3002<\/p>\n<p>\u5176\u4e2d\u5f02\u5e38\u7c7b\u00a0Exception\u00a0\u53c8\u5206\u4e3a\u8fd0\u884c\u65f6\u5f02\u5e38(\u00a0RuntimeException\u00a0)\u548c\u975e\u8fd0\u884c\u65f6\u5f02\u5e38\u3002Java\u5f02\u5e38\u53c8\u53ef\u4ee5\u5206\u4e3a\u4e0d\u53d7\u68c0\u67e5\u5f02\u5e38&#xff08;\u00a0Unchecked Exception\u00a0&#xff09;\u548c\u68c0\u67e5\u5f02\u5e38&#xff08;\u00a0Checked Exception\u00a0&#xff09;\u3002<\/p>\n<h3 id=\"\u5f02\u5e38\u4e4b\u95f4\u7684\u533a\u522b\u4e0e\u8054\u7cfb\">\u5f02\u5e38\u4e4b\u95f4\u7684\u533a\u522b\u4e0e\u8054\u7cfb<\/h3>\n<h4 id=\"_1\u3001error\">1\u3001Error<\/h4>\n<p>Error\u00a0\u7c7b\u5bf9\u8c61\u7531 Java \u865a\u62df\u673a\u751f\u6210\u5e76\u629b\u51fa&#xff0c;\u5927\u591a\u6570\u9519\u8bef\u4e0e\u4ee3\u7801\u7f16\u5199\u8005\u6240\u6267\u884c\u7684\u64cd\u4f5c\u65e0\u5173\u3002<\/p>\n<p>\u6bd4\u5982\u8bf4&#xff1a;<\/p>\n<p>Java\u865a\u62df\u673a\u8fd0\u884c\u9519\u8bef&#xff08;\u00a0Virtual MachineError\u00a0&#xff09;&#xff0c;\u5f53JVM\u4e0d\u518d\u6709\u7ee7\u7eed\u6267\u884c\u64cd\u4f5c\u6240\u9700\u7684\u5185\u5b58\u8d44\u6e90\u65f6&#xff0c; \u5c06\u51fa\u73b0\u00a0OutOfMemoryError\u00a0\u3002\u8fd9\u4e9b\u5f02\u5e38\u53d1\u751f\u65f6&#xff0c;Java\u865a\u62df\u673a&#xff08;JVM&#xff09;\u4e00\u822c\u4f1a\u9009\u62e9\u7ebf\u7a0b\u7ec8\u6b62&#xff1b;<\/p>\n<p>\u8fd8\u6709\u53d1\u751f\u5728\u865a\u62df\u673a\u8bd5\u56fe\u6267\u884c\u5e94\u7528\u65f6&#xff0c;\u5982\u7c7b\u5b9a\u4e49\u9519\u8bef&#xff08;\u00a0NoClassDefFoundError\u00a0)\u3001\u94fe\u63a5\u9519\u8bef (LinkageError\u00a0) \u8fd9\u4e9b\u9519\u8bef\u662f\u4e0d\u53ef\u67e5\u7684&#xff0c;\u56e0\u4e3a\u5b83\u4eec\u5728\u5e94\u7528\u7a0b\u5e8f\u7684\u63a7\u5236\u548c\u5904\u7406\u80fd\u529b\u4e4b\u5916&#xff0c;\u800c\u4e14\u7edd\u5927\u591a\u6570\u662f\u7a0b\u5e8f\u8fd0\u884c\u65f6\u4e0d\u5141\u8bb8\u51fa\u73b0\u7684\u72b6\u51b5\u3002<\/p>\n<p>\u5bf9\u4e8e\u8bbe\u8ba1\u5408\u7406\u7684\u5e94\u7528\u7a0b\u5e8f\u6765\u8bf4&#xff0c;\u5373\u4f7f\u786e\u5b9e\u53d1\u751f\u4e86\u9519\u8bef&#xff0c;\u672c\u8d28\u4e0a\u4e5f\u4e0d\u5e94\u8be5\u8bd5\u56fe\u53bb\u5904\u7406\u5b83\u6240\u5f15\u8d77\u7684\u5f02\u5e38\u72b6 \u51b5\u3002\u5728Java\u4e2d&#xff0c;\u9519\u8bef\u901a\u5e38\u662f\u4f7f\u7528 Error \u7684\u5b50\u7c7b\u63cf\u8ff0\u3002<\/p>\n<h4 id=\"_2\u3001exception\">2\u3001Exception<\/h4>\n<p>\u5728\u00a0Exception\u00a0\u5206\u652f\u4e2d\u6709\u4e00\u4e2a\u91cd\u8981\u7684\u5b50\u7c7b\u00a0RuntimeException\u00a0&#xff08;\u8fd0\u884c\u65f6\u5f02\u5e38&#xff09;&#xff0c;\u8be5\u7c7b\u578b\u7684\u5f02\u5e38\u81ea\u52a8\u4e3a\u4f60\u6240\u7f16\u5199\u7684\u7a0b\u5e8f\u5b9a\u4e49\u00a0ArrayIndexOutOfBoundsException\u00a0&#xff08;\u6570\u7ec4\u4e0b\u6807\u8d8a\u754c&#xff09;\u3001\u00a0NullPointerException\u00a0&#xff08;\u7a7a\u6307\u9488\u5f02\u5e38&#xff09;\u3001ArithmeticException\u00a0&#xff08;\u7b97\u672f\u5f02\u5e38&#xff09;\u3001\u00a0MissingResourceException\u00a0&#xff08;\u4e22\u5931\u8d44\u6e90&#xff09;\u3001\u00a0ClassNotFoundException\u00a0&#xff08;\u627e\u4e0d\u5230\u7c7b&#xff09;\u7b49\u5f02\u5e38&#xff0c;\u8fd9\u4e9b\u5f02\u5e38\u662f\u4e0d\u68c0\u67e5\u5f02\u5e38&#xff0c;\u7a0b\u5e8f\u4e2d\u53ef\u4ee5\u9009\u62e9\u6355\u83b7\u5904 \u7406&#xff0c;\u4e5f\u53ef\u4ee5\u4e0d\u5904\u7406\u3002<\/p>\n<p>\u8fd9\u4e9b\u5f02\u5e38\u4e00\u822c\u662f\u7531\u7a0b\u5e8f\u903b\u8f91\u9519\u8bef\u5f15\u8d77\u7684&#xff0c;\u7a0b\u5e8f\u5e94\u8be5\u4ece\u903b\u8f91\u89d2\u5ea6\u5c3d\u53ef\u80fd\u907f\u514d\u8fd9\u7c7b\u5f02\u5e38\u7684\u53d1\u751f&#xff1b;\u800c\u00a0RuntimeException\u00a0\u4e4b\u5916\u7684\u5f02\u5e38\u6211\u4eec\u7edf\u79f0\u4e3a\u975e\u8fd0\u884c\u65f6\u5f02\u5e38&#xff0c;\u7c7b\u578b\u4e0a\u5c5e\u4e8e\u00a0Exception\u00a0\u7c7b\u53ca\u5176\u5b50\u7c7b&#xff0c;<\/p>\n<p>\u4ece\u7a0b\u5e8f\u8bed\u6cd5\u89d2\u5ea6\u8bb2\u662f\u5fc5\u987b\u8fdb\u884c\u5904\u7406\u7684\u5f02\u5e38&#xff0c;\u5982\u679c\u4e0d\u5904\u7406&#xff0c;\u7a0b\u5e8f\u5c31\u4e0d\u80fd\u7f16\u8bd1\u901a\u8fc7\u3002\u5982\u00a0IOException\u00a0\u3001\u00a0SQLException\u00a0\u7b49\u4ee5\u53ca\u7528\u6237\u81ea\u5b9a\u4e49\u7684\u00a0Exception\u00a0\u5f02\u5e38&#xff0c;\u4e00\u822c\u60c5\u51b5\u4e0b\u4e0d\u81ea\u5b9a\u4e49\u68c0\u67e5\u5f02\u5e38\u3002<\/p>\n<p>\u6ce8\u610f&#xff1a;\u00a0Error\u00a0\u548c\u00a0Exception\u00a0\u7684\u533a\u522b&#xff1a;\u00a0Error\u00a0\u901a\u5e38\u662f\u707e\u96be\u6027\u7684\u81f4\u547d\u7684\u9519\u8bef&#xff0c;\u662f\u7a0b\u5e8f\u65e0\u6cd5\u63a7\u5236\u548c\u5904\u7406\u7684&#xff0c;\u5f53\u51fa\u73b0\u8fd9\u4e9b\u5f02\u5e38\u65f6&#xff0c;Java\u865a\u62df\u673a&#xff08;JVM&#xff09;\u4e00\u822c\u4f1a\u9009\u62e9\u7ec8\u6b62\u7ebf\u7a0b&#xff1b;\u00a0Exception\u00a0\u901a\u5e38\u60c5\u51b5\u4e0b\u662f\u53ef\u4ee5\u88ab\u7a0b\u5e8f\u5904\u7406\u7684&#xff0c;\u5e76\u4e14\u5728\u7a0b\u5e8f\u4e2d\u5e94\u8be5\u5c3d\u53ef\u80fd\u7684\u53bb\u5904\u7406\u8fd9\u4e9b\u5f02\u5e38\u3002<\/p>\n<h4 id=\"_3\u3001\u68c0\u67e5\u5f02\u5e38\u548c\u4e0d\u53d7\u68c0\u67e5\u5f02\u5e38\">3\u3001\u68c0\u67e5\u5f02\u5e38\u548c\u4e0d\u53d7\u68c0\u67e5\u5f02\u5e38<\/h4>\n<p>\u68c0\u67e5\u5f02\u5e38&#xff1a;\u5728\u6b63\u786e\u7684\u7a0b\u5e8f\u8fd0\u884c\u8fc7\u7a0b\u4e2d&#xff0c;\u5f88\u5bb9\u6613\u51fa\u73b0\u7684\u3001\u60c5\u7406\u53ef\u5bb9\u7684\u5f02\u5e38\u72b6\u51b5&#xff0c;\u5728\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u8fd9\u79cd\u5f02\u5e38\u7684\u53d1\u751f\u662f\u53ef\u4ee5\u9884\u6d4b\u7684&#xff0c;\u5e76\u4e14\u4e00\u65e6\u53d1\u751f\u8be5\u79cd\u5f02\u5e38&#xff0c;\u5c31\u5fc5\u987b\u91c7\u53d6\u67d0\u79cd\u65b9\u5f0f\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<p>\u89e3\u6790&#xff1a;\u9664\u4e86RuntimeException\u53ca\u5176\u5b50\u7c7b\u4ee5\u5916&#xff0c;\u5176\u4ed6\u7684Exception\u7c7b\u53ca\u5176\u5b50\u7c7b\u90fd\u5c5e\u4e8e\u68c0\u67e5\u5f02\u5e38&#xff0c;\u5f53\u7a0b\u5e8f\u4e2d\u53ef\u80fd\u51fa\u73b0\u8fd9\u7c7b\u5f02\u5e38&#xff0c;\u8981\u4e48\u4f7f\u7528try-catch\u8bed\u53e5\u8fdb\u884c\u6355\u83b7&#xff0c;\u8981\u4e48\u7528throws\u5b50\u53e5\u629b\u51fa&#xff0c;\u5426\u5219\u7f16\u8bd1\u65e0\u6cd5\u901a\u8fc7\u3002<\/p>\n<p>\u4e0d\u53d7\u68c0\u67e5\u5f02\u5e38&#xff1a;\u5305\u62ecRuntimeException\u53ca\u5176\u5b50\u7c7b\u548cError\u3002<\/p>\n<p>\u5206\u6790&#xff1a;\u00a0\u4e0d\u53d7\u68c0\u67e5\u5f02\u5e38\u00a0\u4e3a\u7f16\u8bd1\u5668\u4e0d\u8981\u6c42\u5f3a\u5236\u5904\u7406\u7684\u5f02\u5e38&#xff0c;\u00a0\u68c0\u67e5\u5f02\u5e38\u00a0\u5219\u662f\u7f16\u8bd1\u5668\u8981\u6c42\u5fc5\u987b\u5904\u7f6e\u7684\u5f02\u5e38\u3002<\/p>\n<h3 id=\"java\u5f02\u5e38\u5904\u7406\u673a\u5236\">Java\u5f02\u5e38\u5904\u7406\u673a\u5236<\/h3>\n<p>java\u5f02\u5e38\u5904\u7406\u672c\u8d28&#xff1a;\u629b\u51fa\u5f02\u5e38\u548c\u6355\u83b7\u5f02\u5e38<\/p>\n<h4 id=\"_1\u3001\u629b\u51fa\u5f02\u5e38\">1\u3001\u629b\u51fa\u5f02\u5e38<\/h4>\n<p>\u8981\u7406\u89e3\u629b\u51fa\u5f02\u5e38&#xff0c;\u9996\u5148\u8981\u660e\u767d\u4ec0\u4e48\u662f\u5f02\u5e38\u60c5\u5f62&#xff08;exception condition&#xff09;&#xff0c;\u5b83\u662f\u6307\u963b\u6b62\u5f53\u524d\u65b9\u6cd5\u6216\u4f5c\u7528\u57df\u7ee7\u7eed\u6267\u884c\u7684\u95ee\u9898\u3002\u5176\u6b21\u628a\u5f02\u5e38\u60c5\u5f62\u548c\u666e\u901a\u95ee\u9898\u76f8\u533a\u5206&#xff0c;\u666e\u901a\u95ee\u9898\u662f\u6307\u5728\u5f53\u524d\u73af\u5883\u4e0b\u80fd\u5f97\u5230\u8db3\u591f\u7684\u4fe1\u606f&#xff0c; \u603b\u80fd\u5904\u7406\u8fd9\u4e2a\u9519\u8bef\u3002<\/p>\n<p>\u5bf9\u4e8e\u5f02\u5e38\u60c5\u5f62&#xff0c;\u5df2\u7ecf\u65e0\u6cd5\u7ee7\u7eed\u4e0b\u53bb\u4e86&#xff0c;\u56e0\u4e3a\u5728\u5f53\u524d\u73af\u5883\u4e0b\u65e0\u6cd5\u83b7\u5f97\u5fc5\u8981\u7684\u4fe1\u606f\u6765\u89e3\u51b3\u95ee\u9898&#xff0c;\u4f60\u6240\u80fd\u505a\u7684\u5c31\u662f\u4ece\u5f53\u524d\u73af\u5883\u4e2d\u8df3\u51fa&#xff0c;\u5e76\u628a\u95ee\u9898\u63d0\u4ea4\u7ed9\u4e0a\u4e00\u7ea7\u73af\u5883&#xff0c;\u8fd9\u5c31\u662f\u629b\u51fa\u5f02\u5e38\u65f6\u6240\u53d1\u751f\u7684\u4e8b\u60c5\u3002\u629b\u51fa\u5f02\u5e38\u540e&#xff0c;\u4f1a\u6709\u51e0\u4ef6\u4e8b\u968f\u4e4b\u53d1\u751f\u3002<\/p>\n<p>\u9996\u5148&#xff0c;\u662f\u50cf\u521b\u5efa\u666e\u901a\u7684java\u5bf9\u8c61\u4e00\u6837\u5c06\u4f7f\u7528 new \u5728\u5806\u4e0a\u521b\u5efa\u4e00\u4e2a\u5f02\u5e38\u5bf9\u8c61&#xff1b;\u7136\u540e&#xff0c;\u5f53\u524d\u7684\u6267\u884c\u8def\u5f84 &#xff08;\u5df2\u7ecf\u65e0\u6cd5\u7ee7\u7eed\u4e0b\u53bb\u4e86&#xff09;\u88ab\u7ec8\u6b62&#xff0c;\u5e76\u4e14\u4ece\u5f53\u524d\u73af\u5883\u4e2d\u5f39\u51fa\u5bf9\u5f02\u5e38\u5bf9\u8c61\u7684\u5f15\u7528\u3002\u6b64\u65f6&#xff0c;\u5f02\u5e38\u5904\u7406\u673a\u5236\u63a5\u7ba1\u7a0b\u5e8f&#xff0c;\u5e76\u5f00\u59cb\u5bfb\u627e\u4e00\u4e2a\u6070\u5f53\u7684\u5730\u65b9\u7ee7\u7eed\u6267\u884c\u7a0b\u5e8f<\/p>\n<p>\u8fd9\u4e2a\u6070\u5f53\u7684\u5730\u65b9\u5c31\u662f\u5f02\u5e38\u5904\u7406\u7a0b\u5e8f\u6216\u8005\u5f02\u5e38\u5904\u7406\u5668&#xff0c;\u5b83\u7684\u4efb\u52a1\u662f\u5c06\u7a0b\u5e8f\u4ece\u9519\u8bef\u72b6\u6001\u4e2d\u6062\u590d&#xff0c;\u4ee5\u4f7f\u7a0b\u5e8f\u8981 \u4e48\u6362\u4e00\u79cd\u65b9\u5f0f\u8fd0\u884c&#xff0c;\u8981\u4e48\u7ee7\u7eed\u8fd0\u884c\u4e0b\u53bb\u3002<\/p>\n<p>\u4e3e\u4f8b&#xff1a;<\/p>\n<p>\u5047\u4f7f\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u5b66\u751f\u5bf9\u8c61Student\u7684\u4e00\u4e2a\u5f15\u7528stu&#xff0c;\u5728\u8c03\u7528\u7684\u65f6\u5019\u53ef\u80fd\u8fd8\u6ca1\u6709\u521d\u59cb\u5316\u3002\u6240\u4ee5\u5728\u4f7f\u7528\u8fd9\u4e2a\u5bf9\u8c61\u5f15\u7528\u8c03\u7528\u5176\u4ed6\u65b9\u6cd5\u4e4b\u524d&#xff0c;\u8981\u5148\u5bf9\u5b83\u8fdb\u884c\u68c0\u67e5&#xff0c;\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u4ee3\u8868\u9519\u8bef\u4fe1\u606f\u7684\u5bf9\u8c61&#xff0c;\u5e76\u4e14\u5c06\u5b83\u4ece\u5f53\u524d\u73af\u5883\u4e2d\u629b\u51fa&#xff0c;\u8fd9\u6837\u5c31\u628a\u9519\u8bef\u4fe1\u606f\u4f20\u64ad\u5230\u66f4\u5927\u7684\u73af\u5883\u4e2d\u3002<\/p>\n<\/p>\n<p>if(stu &#061;&#061; null){<br \/>\n    throw new NullPointerException();<br \/>\n} <\/p>\n<h4 id=\"_2\u3001\u6355\u83b7\u5f02\u5e38\">2\u3001\u6355\u83b7\u5f02\u5e38<\/h4>\n<p>\u5728\u65b9\u6cd5\u629b\u51fa\u5f02\u5e38\u4e4b\u540e&#xff0c;\u8fd0\u884c\u65f6\u7cfb\u7edf\u5c06\u8f6c\u4e3a\u5bfb\u627e\u5408\u9002\u7684\u5f02\u5e38\u5904\u7406\u5668&#xff08;exception handler&#xff09;\u3002\u6f5c\u5728\u7684\u5f02\u5e38\u5904\u7406\u5668\u662f\u5f02\u5e38\u53d1\u751f\u65f6\u4f9d\u6b21\u5b58\u7559\u5728\u8c03\u7528\u6808\u4e2d\u7684\u65b9\u6cd5\u7684\u96c6\u5408\u3002\u5f53\u5f02\u5e38\u5904\u7406\u5668\u6240\u80fd\u5904\u7406\u7684\u5f02\u5e38\u7c7b\u578b\u4e0e\u65b9\u6cd5\u629b\u51fa\u7684\u5f02\u5e38\u7c7b\u578b\u76f8\u7b26\u65f6&#xff0c;\u5373\u4e3a\u5408\u9002\u7684\u5f02\u5e38\u5904\u7406\u5668\u3002\u8fd0\u884c\u65f6\u7cfb\u7edf\u4ece\u53d1\u751f\u5f02\u5e38\u7684\u65b9\u6cd5\u5f00\u59cb&#xff0c;\u4f9d\u6b21\u56de\u67e5\u8c03\u7528\u6808\u4e2d\u7684\u65b9\u6cd5&#xff0c;\u76f4\u81f3\u627e\u5230\u542b\u6709\u5408\u9002\u5f02\u5e38\u5904\u7406\u5668\u7684\u65b9\u6cd5\u5e76\u6267\u884c\u3002\u5f53\u8fd0\u884c\u65f6\u7cfb\u7edf\u904d\u5386\u8c03\u7528\u6808\u800c\u672a\u627e\u5230\u5408\u9002\u7684\u5f02\u5e38\u5904\u7406\u5668&#xff0c;\u5219\u8fd0\u884c\u65f6\u7cfb\u7edf\u7ec8\u6b62\u3002\u540c\u65f6&#xff0c;\u610f\u5473\u7740Java\u7a0b\u5e8f\u7684\u7ec8\u6b62\u3002<\/p>\n<p>\u6ce8\u610f&#xff1a;<\/p>\n<p>\u5bf9\u4e8e \u8fd0\u884c\u65f6\u5f02\u5e38 \u3001\u9519\u8bef \u548c \u68c0\u67e5\u5f02\u5e38 &#xff0c;Java\u6280\u672f\u6240\u8981\u6c42\u7684\u5f02\u5e38\u5904\u7406\u65b9\u5f0f\u6709\u6240\u4e0d\u540c\u3002<\/p>\n<p>\u7531\u4e8e\u8fd0\u884c\u65f6\u5f02\u5e38\u53ca\u5176\u5b50\u7c7b\u7684\u4e0d\u53ef\u67e5\u6027&#xff0c;\u4e3a\u4e86\u66f4\u5408\u7406\u3001\u66f4\u5bb9\u6613\u5730\u5b9e\u73b0\u5e94\u7528\u7a0b\u5e8f&#xff0c;Java\u89c4\u5b9a&#xff0c;\u8fd0\u884c\u65f6\u5f02\u5e38\u5c06\u7531Java\u8fd0\u884c\u65f6\u7cfb\u7edf\u81ea\u52a8\u629b\u51fa&#xff0c;\u5141\u8bb8\u5e94\u7528\u7a0b\u5e8f\u5ffd\u7565\u8fd0\u884c\u65f6\u5f02\u5e38\u3002<\/p>\n<p>\u5bf9\u4e8e\u65b9\u6cd5\u8fd0\u884c\u4e2d\u53ef\u80fd\u51fa\u73b0\u7684Error\u00a0&#xff0c;\u5f53\u8fd0\u884c\u65b9\u6cd5\u4e0d\u6b32\u6355\u6349\u65f6&#xff0c;Java\u5141\u8bb8\u8be5\u65b9\u6cd5\u4e0d\u505a\u4efb\u4f55\u629b\u51fa\u58f0\u660e\u3002\u56e0\u4e3a&#xff0c;\u5927\u591a\u6570\u00a0Error\u00a0\u5f02\u5e38\u5c5e\u4e8e\u6c38\u8fdc\u4e0d\u80fd\u88ab\u5141\u8bb8\u53d1\u751f\u7684\u72b6\u51b5&#xff0c;\u4e5f\u5c5e\u4e8e\u5408\u7406\u7684\u5e94\u7528\u7a0b\u5e8f\u4e0d\u8be5\u6355\u6349\u7684\u5f02\u5e38\u3002<\/p>\n<p>\u5bf9\u4e8e\u6240\u6709\u7684\u68c0\u67e5\u5f02\u5e38&#xff0c;Java\u89c4\u5b9a&#xff1a;\u4e00\u4e2a\u65b9\u6cd5\u5fc5\u987b\u6355\u6349&#xff0c;\u6216\u8005\u58f0\u660e\u629b\u51fa\u65b9\u6cd5\u4e4b\u5916\u3002\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u5f53\u4e00\u4e2a\u65b9\u6cd5\u9009\u62e9\u4e0d\u6355\u6349\u68c0\u67e5\u5f02\u5e38\u65f6&#xff0c;\u5b83\u5fc5\u987b\u58f0\u660e\u5c06\u629b\u51fa\u5f02\u5e38\u3002<\/p>\n<h4 id=\"_3\u3001\u5f02\u5e38\u5904\u7406\u4e94\u4e2a\u5173\u952e\u5b57\">3\u3001\u5f02\u5e38\u5904\u7406\u4e94\u4e2a\u5173\u952e\u5b57<\/h4>\n<p>\u5206\u522b\u662f&#xff1a;\u00a0try\u00a0\u3001\u00a0catch\u00a0\u3001\u00a0finally\u00a0\u3001\u00a0throw\u00a0\u3001\u00a0throws<\/p>\n<p>try &#xff1a;\u7528\u4e8e\u76d1\u542c\u3002\u5c06\u8981\u88ab\u76d1\u542c\u7684\u4ee3\u7801&#xff08;\u53ef\u80fd\u629b\u51fa\u5f02\u5e38\u7684\u4ee3\u7801&#xff09;\u653e\u5728try\u8bed\u53e5\u5757\u4e4b\u5185&#xff0c;\u5f53try\u8bed\u53e5\u5757\u5185\u53d1\u751f\u5f02\u5e38\u65f6&#xff0c;\u5f02\u5e38\u5c31\u88ab\u629b\u51fa\u3002<\/p>\n<p>catch &#xff1a; \u7528\u4e8e\u6355\u83b7\u5f02\u5e38\u3002catch\u7528\u6765\u6355\u83b7try\u8bed\u53e5\u5757\u4e2d\u53d1\u751f\u7684\u5f02\u5e38\u3002<\/p>\n<p>finally &#xff1a;finally\u8bed\u53e5\u5757\u603b\u662f\u4f1a\u88ab\u6267\u884c\u3002\u5b83\u4e3b\u8981\u7528\u4e8e\u56de\u6536\u5728try\u5757\u91cc\u6253\u5f00\u7684\u7269\u529b\u8d44\u6e90&#xff08;\u5982\u6570\u636e\u5e93\u8fde\u63a5\u3001\u7f51\u7edc \u8fde\u63a5\u548c\u78c1\u76d8\u6587\u4ef6&#xff09;\u3002\u53ea\u6709finally\u5757&#xff0c;\u6267\u884c\u5b8c\u6210\u4e4b\u540e&#xff0c;\u624d\u4f1a\u56de\u6765\u6267\u884ctry\u6216\u8005catch\u5757\u4e2d\u7684return\u6216\u8005throw\u8bed \u53e5&#xff0c;\u5982\u679cfinally\u4e2d\u4f7f\u7528\u4e86return\u6216\u8005throw\u7b49\u7ec8\u6b62\u65b9\u6cd5\u7684\u8bed\u53e5&#xff0c;\u5219\u5c31\u4e0d\u4f1a\u8df3\u56de\u6267\u884c&#xff0c;\u76f4\u63a5\u505c\u6b62\u3002<\/p>\n<p>throw &#xff1a; \u7528\u4e8e\u629b\u51fa\u5f02\u5e38\u3002<\/p>\n<p>throws &#xff1a; \u7528\u5728\u65b9\u6cd5\u7b7e\u540d\u4e2d&#xff0c;\u7528\u4e8e\u58f0\u660e\u8be5\u65b9\u6cd5\u53ef\u80fd\u629b\u51fa\u7684\u5f02\u5e38\u3002<\/p>\n<h3 id=\"\u5904\u7406\u5f02\u5e38\">\u5904\u7406\u5f02\u5e38<\/h3>\n<h4 id=\"_1\u3001try-catch\">1\u3001try -catch<\/h4>\n<\/p>\n<p>try{<br \/>\n\/\/code that might generate exceptions<br \/>\n}catch(Exception e){<br \/>\n\/\/the code of handling exception1<br \/>\n}catch(Exception e){<br \/>\n\/\/the code of handling exception2<br \/>\n} <\/p>\n<p>\u8981\u660e\u767d\u5f02\u5e38\u6355\u83b7&#xff0c;\u8fd8\u8981\u7406\u89e3 \u76d1\u63a7\u533a\u57df &#xff08;guarded region&#xff09;\u7684\u6982\u5ff5\u3002\u5b83\u662f\u4e00\u6bb5\u53ef\u80fd\u4ea7\u751f\u5f02\u5e38\u7684\u4ee3\u7801&#xff0c; \u5e76\u4e14\u540e\u9762\u8ddf\u7740\u5904\u7406\u8fd9\u4e9b\u5f02\u5e38\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u56e0\u800c\u53ef\u77e5&#xff0c;\u4e0a\u8ff0\u00a0try-catch\u00a0\u6240\u63cf\u8ff0\u7684\u5373\u662f\u76d1\u63a7\u533a\u57df&#xff0c;\u5173\u952e\u8bcd\u00a0try\u540e\u7684\u4e00\u5bf9\u5927\u62ec\u53f7\u5c06\u4e00\u5757\u53ef\u80fd\u53d1\u751f\u5f02\u5e38\u7684\u4ee3\u7801\u5305\u8d77\u6765&#xff0c;\u5373\u4e3a\u76d1\u63a7\u533a\u57df\u3002Java\u65b9\u6cd5\u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u53d1\u751f\u4e86\u5f02\u5e38&#xff0c;\u5219\u521b\u5efa\u5f02\u5e38\u5bf9\u8c61\u3002<\/p>\n<p>\u5c06\u5f02\u5e38\u629b\u51fa\u76d1\u63a7\u533a\u57df\u4e4b\u5916&#xff0c;\u7531Java\u8fd0\u884c\u65f6\u7cfb\u7edf\u8d1f\u8d23\u5bfb\u627e\u5339\u914d\u7684 catch \u5b50\u53e5\u6765\u6355\u83b7\u5f02\u5e38\u3002\u82e5\u6709\u4e00\u4e2a catch \u8bed\u53e5\u5339\u914d\u5230\u4e86&#xff0c;\u5219\u6267\u884c\u8be5 catch \u5757\u4e2d\u7684\u5f02\u5e38\u5904\u7406\u4ee3\u7801&#xff0c;\u5c31\u4e0d\u518d\u5c1d\u8bd5\u5339\u914d\u522b\u7684 catch \u5757 \u4e86\u3002<\/p>\n<p>\u5339\u914d\u539f\u5219&#xff1a;\u5982\u679c\u629b\u51fa\u7684\u5f02\u5e38\u5bf9\u8c61\u5c5e\u4e8e catch \u5b50\u53e5\u7684\u5f02\u5e38\u7c7b&#xff0c;\u6216\u8005\u5c5e\u4e8e\u8be5\u5f02\u5e38\u7c7b\u7684\u5b50\u7c7b&#xff0c;\u5219\u8ba4\u4e3a\u751f\u6210\u7684\u5f02\u5e38\u5bf9\u8c61\u4e0e catch \u5757\u6355\u83b7\u7684\u5f02\u5e38\u7c7b\u578b\u76f8\u5339\u914d\u3002<\/p>\n<p>\u3010\u6f14\u793a\u3011<\/p>\n<\/p>\n<p>public class TestException {<br \/>\n    public static void main(String[] args) {<br \/>\n        int a &#061; 1;<br \/>\n        int b &#061; 0;<br \/>\n        try { \/\/ try\u76d1\u63a7\u533a\u57df<br \/>\n            if (b &#061;&#061; 0) throw new ArithmeticException(); \/\/ \u901a\u8fc7throw\u8bed\u53e5\u629b\u51fa<br \/>\n            \u5f02\u5e38<br \/>\n            System.out.println(&#034;a\/b\u7684\u503c\u662f&#xff1a;&#034; &#043; a \/ b);<br \/>\n            System.out.println(&#034;this will not be printed!&#034;);<br \/>\n        }<br \/>\n        catch (ArithmeticException e) { \/\/ catch\u6355\u6349\u5f02\u5e38<br \/>\n            System.out.println(&#034;\u7a0b\u5e8f\u51fa\u73b0\u5f02\u5e38&#xff0c;\u53d8\u91cfb\u4e0d\u80fd\u4e3a0&#xff01;&#034;);<br \/>\n        }<br \/>\n        System.out.println(&#034;\u7a0b\u5e8f\u6b63\u5e38\u7ed3\u675f\u3002&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u8f93\u51fa&#xff1a;<\/p>\n<p>\u7a0b\u5e8f\u51fa\u73b0\u5f02\u5e38&#xff0c;\u53d8\u91cfb\u4e0d\u80fd\u4e3a0&#xff01; \u7a0b\u5e8f\u6b63\u5e38\u7ed3\u675f\u3002<\/p>\n<p>\u6ce8\u610f&#xff1a;\u663e\u793a\u4e00\u4e2a\u5f02\u5e38\u7684\u63cf\u8ff0&#xff0c;\u00a0Throwable\u00a0\u91cd\u8f7d\u4e86\u00a0toString( )\u00a0\u65b9\u6cd5&#xff08;\u7531 Object \u5b9a\u4e49&#xff09;&#xff0c;\u6240\u4ee5 \u5b83\u5c06\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u5f02\u5e38\u63cf\u8ff0\u7684\u5b57\u7b26\u4e32\u3002\u4f8b\u5982&#xff0c;\u5c06\u524d\u9762\u7684\u00a0catch\u00a0\u5757\u91cd\u5199\u6210&#xff1a;<\/p>\n<\/p>\n<p>catch (ArithmeticException e) { \/\/ catch\u6355\u6349\u5f02\u5e38<br \/>\n    System.out.println(&#034;\u7a0b\u5e8f\u51fa\u73b0\u5f02\u5e38&#034; &#043; e);<br \/>\n}<br \/>\n\/\/\u8f93\u51fa<br \/>\n\/\/ \u7a0b\u5e8f\u51fa\u73b0\u5f02\u5e38java.lang.ArithmeticException <\/p>\n<p>\u7b97\u672f\u5f02\u5e38\u5c5e\u4e8e\u8fd0\u884c\u65f6\u5f02\u5e38&#xff0c;\u56e0\u800c\u5b9e\u9645\u4e0a\u8be5\u5f02\u5e38\u4e0d\u9700\u8981\u7a0b\u5e8f\u629b\u51fa&#xff0c;\u8fd0\u884c\u65f6\u7cfb\u7edf\u81ea\u52a8\u629b\u51fa\u3002\u5982\u679c\u4e0d\u7528try-catch\u7a0b\u5e8f\u5c31\u4e0d\u4f1a\u5f80\u4e0b\u6267\u884c\u4e86\u3002<\/p>\n<p>\u3010\u6f14\u793a\u3011<\/p>\n<\/p>\n<p>public class TestException {<br \/>\n    public static void main(String[] args) {<br \/>\n        int a &#061; 1;<br \/>\n        int b &#061; 0;<br \/>\n        System.out.println(&#034;a\/b\u7684\u503c\u662f&#xff1a;&#034; &#043; a \/ b);<br \/>\n        System.out.println(&#034;this will not be printed!&#034;);<br \/>\n    }<br \/>\n}<br \/>\n\/*<br \/>\n\u7ed3\u679c&#xff1a;<br \/>\nException in thread &#034;main&#034; java.lang.ArithmeticException: \/ by zero<br \/>\nat TestException.main(TestException.java:7)<br \/>\n*\/ <\/p>\n<p>\u4f7f\u7528\u591a\u91cd\u7684catch\u8bed\u53e5&#xff1a;\u5f88\u591a\u60c5\u51b5\u4e0b&#xff0c;\u7531\u5355\u4e2a\u7684\u4ee3\u7801\u6bb5\u53ef\u80fd\u5f15\u8d77\u591a\u4e2a\u5f02\u5e38\u3002\u5904\u7406\u8fd9\u79cd\u60c5\u51b5&#xff0c;\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u4e24\u4e2a\u6216\u8005\u66f4\u591a\u7684 catch \u5b50\u53e5&#xff0c;\u6bcf\u4e2a\u5b50\u53e5\u6355\u83b7\u4e00\u79cd\u7c7b\u578b\u7684\u5f02\u5e38&#xff0c;\u5f53\u5f02\u5e38\u88ab\u5f15\u53d1\u65f6&#xff0c;\u6bcf\u4e2a catch \u5b50 \u53e5\u88ab\u4f9d\u6b21\u68c0\u67e5&#xff0c;\u7b2c\u4e00\u4e2a\u5339\u914d\u5f02\u5e38\u7c7b\u578b\u7684\u5b50\u53e5\u6267\u884c&#xff0c;\u5f53\u4e00\u4e2a catch \u5b50\u53e5\u6267\u884c\u4ee5\u540e&#xff0c;\u5176\u4ed6\u7684\u5b50\u53e5\u5c06\u88ab\u65c1\u8def\u3002<\/p>\n<p>\u7f16\u5199\u591a\u91cdcatch\u8bed\u53e5\u5757\u6ce8\u610f\u4e8b\u9879&#xff1a;<\/p>\n<p>\u987a\u5e8f\u95ee\u9898&#xff1a;\u5148\u5c0f\u540e\u5927&#xff0c;\u5373\u5148\u5b50\u7c7b\u540e\u7236\u7c7b<\/p>\n<p>\u6ce8\u610f&#xff1a;<\/p>\n<p>Java\u901a\u8fc7\u5f02\u5e38\u7c7b\u63cf\u8ff0\u5f02\u5e38\u7c7b\u578b\u3002\u5bf9\u4e8e\u6709\u591a\u4e2a catch \u5b50\u53e5\u7684\u5f02\u5e38\u7a0b\u5e8f\u800c\u8a00&#xff0c;\u5e94\u8be5\u5c3d\u91cf\u5c06\u6355\u83b7\u5e95\u5c42\u5f02\u5e38\u7c7b\u7684 catch \u5b50\u53e5\u653e\u5728\u524d\u9762&#xff0c;\u540c\u65f6\u5c3d\u91cf\u5c06\u6355\u83b7\u76f8\u5bf9\u9ad8\u5c42\u7684\u5f02\u5e38\u7c7b\u7684 catch \u5b50\u53e5\u653e\u5728\u540e\u9762\u3002\u5426\u5219&#xff0c;\u6355\u83b7 \u5e95\u5c42\u5f02\u5e38\u7c7b\u7684 catch \u5b50\u53e5\u5c06\u53ef\u80fd\u4f1a\u88ab\u5c4f\u853d\u3002<\/p>\n<p>\u5d4c\u5957try\u8bed\u53e5&#xff1a; try \u8bed\u53e5\u53ef\u4ee5\u88ab\u5d4c\u5957\u3002\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u4e00\u4e2a try \u8bed\u53e5\u53ef\u4ee5\u5728\u53e6\u4e00\u4e2a try \u5757\u7684\u5185\u90e8\u3002\u6bcf\u6b21\u8fdb\u5165 try \u8bed\u53e5&#xff0c;\u5f02\u5e38\u7684\u524d\u540e\u5173\u7cfb\u90fd\u4f1a\u88ab\u63a8\u5165\u5806\u6808\u3002\u5982\u679c\u4e00\u4e2a\u5185\u90e8\u7684 try \u8bed\u53e5\u4e0d\u542b\u7279\u6b8a\u5f02\u5e38\u7684 catch \u5904\u7406\u7a0b\u5e8f&#xff0c;\u5806\u6808\u5c06\u5f39\u51fa&#xff0c;\u4e0b\u4e00\u4e2a try \u8bed\u53e5\u7684 catch \u5904\u7406\u7a0b\u5e8f\u5c06\u68c0\u67e5\u662f\u5426\u4e0e\u4e4b\u5339\u914d\u3002\u8fd9\u4e2a \u8fc7\u7a0b\u5c06\u7ee7\u7eed\u76f4\u5230\u4e00\u4e2a catch \u8bed\u53e5\u88ab\u5339\u914d\u6210\u529f&#xff0c;\u6216\u8005\u662f\u76f4\u5230\u6240\u6709\u7684\u5d4c\u5957 try \u8bed\u53e5\u88ab\u68c0\u67e5\u5b8c\u6bd5\u3002\u5982\u679c\u6ca1\u6709 catch \u8bed\u53e5\u5339\u914d&#xff0c;Java\u8fd0\u884c\u65f6\u7cfb\u7edf\u5c06\u5904\u7406\u8fd9\u4e2a\u5f02\u5e38\u3002<\/p>\n<p>\u3010\u6f14\u793a\u3011<\/p>\n<\/p>\n<p>public class NestTry {<br \/>\n    public static void main(String[] args) {<br \/>\n        try {<br \/>\n            int a &#061; args.length;<br \/>\n            int b &#061; 42 \/ a;<br \/>\n            System.out.println(&#034;a &#061; &#034; &#043; a);<br \/>\n            try {<br \/>\n                if (a &#061;&#061; 1) {<br \/>\n                    a &#061; a \/ (a &#8211; a);<br \/>\n                }<br \/>\n                if (a &#061;&#061; 2) {<br \/>\n                    int c[] &#061; {1};<br \/>\n                    c[42] &#061; 99;<br \/>\n                }<br \/>\n            } catch (ArrayIndexOutOfBoundsException e) {<br \/>\n                System.out.println(&#034;ArrayIndexOutOfBounds :&#034; &#043; e);<br \/>\n            }<br \/>\n        } catch (ArithmeticException e) {<br \/>\n            System.out.println(&#034;Divide by 0&#034; &#043; e);<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<p>\u5206\u6790\u8fd0\u884c&#xff1a;<\/p>\n<p>javac NestTry.java<\/p>\n<p>java NestTry one a &#061; 1 Divide by 0java.lang.ArithmeticException: \/ by zero<\/p>\n<p>java NestTry one two a &#061; 2 ArrayIndexOutOfBounds :java.lang.ArrayIndexOutOfBoundsException: 42<\/p>\n<p>\u5206\u6790&#xff1a;\u6b63\u5982\u7a0b\u5e8f\u4e2d\u6240\u663e\u793a\u7684&#xff0c;\u8be5\u7a0b\u5e8f\u5728\u4e00\u4e2atry\u5757\u4e2d\u5d4c\u5957\u4e86\u53e6\u4e00\u4e2a try \u5757\u3002\u7a0b\u5e8f\u5de5\u4f5c\u5982\u4e0b&#xff1a;\u5f53\u4f60\u5728\u6ca1\u6709\u547d\u4ee4\u884c\u53c2\u6570\u7684\u60c5\u51b5\u4e0b\u6267\u884c\u8be5\u7a0b\u5e8f&#xff0c;\u5916\u9762\u7684 try \u5757\u5c06\u4ea7\u751f\u4e00\u4e2a\u88ab0\u9664\u7684\u5f02\u5e38\u3002<\/p>\n<p>\u7a0b\u5e8f\u5728\u6709\u4e00\u4e2a\u547d\u4ee4\u884c\u53c2\u6570\u6761\u4ef6\u4e0b\u6267\u884c&#xff0c;\u7531\u5d4c\u5957\u7684 try \u5757\u4ea7\u751f\u4e00\u4e2a\u88ab0\u9664\u7684\u5f02\u5e38&#xff0c;\u7531\u4e8e\u5185\u90e8\u7684 catch \u5757\u4e0d\u5339\u914d\u8fd9\u4e2a\u5f02\u5e38&#xff0c;\u5b83\u5c06\u628a\u5f02\u5e38\u4f20\u7ed9\u5916\u90e8\u7684 try \u5757&#xff0c;\u5728\u5916\u90e8\u5f02\u5e38\u88ab\u5904\u7406\u3002\u5982\u679c\u4f60\u5728\u5177\u6709\u4e24\u4e2a\u547d\u4ee4\u884c\u53c2\u6570\u7684\u6761\u4ef6\u4e0b\u6267\u884c\u8be5\u7a0b\u5e8f&#xff0c;\u5c06\u7531\u5185\u90e8 try \u5757\u4ea7\u751f\u4e00\u4e2a\u6570\u7ec4\u8fb9\u754c\u5f02\u5e38\u3002<\/p>\n<p>\u6ce8\u610f&#xff1a;\u5f53\u6709\u65b9\u6cd5\u8c03\u7528\u65f6&#xff0c; try \u8bed\u53e5\u7684\u5d4c\u5957\u53ef\u4ee5\u5f88\u9690\u853d\u7684\u53d1\u751f\u3002\u4f8b\u5982&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5c06\u5bf9\u65b9\u6cd5\u7684\u8c03\u7528\u653e\u5728\u4e00 \u4e2a try \u5757\u4e2d\u3002\u5728\u8be5\u65b9\u6cd5\u7684\u5185\u90e8&#xff0c;\u6709\u53e6\u4e00\u4e2a try \u8bed\u53e5\u3002<\/p>\n<p>\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b&#xff0c;\u65b9\u6cd5\u5185\u90e8\u7684 try \u4ecd\u7136\u662f\u5d4c\u5957\u5728\u5916\u90e8\u8c03\u7528\u8be5\u65b9\u6cd5\u7684 try \u5757\u4e2d\u7684\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u5bf9\u4e0a\u8ff0\u4f8b\u5b50\u8fdb\u884c\u4fee\u6539&#xff0c;\u5d4c\u5957\u7684 try \u5757\u79fb\u5230\u65b9\u6cd5nesttry()\u7684\u5185\u90e8&#xff1a;\u7ed3\u679c\u4f9d\u65e7\u76f8\u540c&#xff01;<\/p>\n<\/p>\n<p>public class NestTry {<br \/>\n    static void nesttry(int a) {<br \/>\n        try {<br \/>\n            if (a &#061;&#061; 1) {<br \/>\n                a &#061; a \/ (a &#8211; a);<br \/>\n            }<br \/>\n            if (a &#061;&#061; 2) {<br \/>\n                int c[] &#061; {1};<br \/>\n                c[42] &#061; 99;<br \/>\n            }<br \/>\n        } catch (ArrayIndexOutOfBoundsException e) {<br \/>\n            System.out.println(&#034;ArrayIndexOutOfBounds :&#034; &#043; e);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        try {<br \/>\n            int a &#061; args.length;<br \/>\n            int b &#061; 42 \/ a;<br \/>\n            System.out.println(&#034;a &#061; &#034; &#043; a);<br \/>\n            nesttry(a);<br \/>\n        } catch (ArithmeticException e) {<br \/>\n            System.out.println(&#034;Divide by 0&#034; &#043; e);<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<h4 id=\"_2\u3001thorw\">2\u3001thorw<\/h4>\n<p>\u5230\u76ee\u524d\u4e3a\u6b62&#xff0c;\u6211\u4eec\u53ea\u662f\u83b7\u53d6\u4e86\u88abJava\u8fd0\u884c\u65f6\u7cfb\u7edf\u5f15\u53d1\u7684\u5f02\u5e38\u3002\u7136\u800c&#xff0c;\u6211\u4eec\u8fd8\u53ef\u4ee5\u7528throw\u8bed\u53e5\u629b\u51fa\u660e\u786e\u7684\u5f02\u5e38\u3002<\/p>\n<p>\u8bed\u6cd5\u5f62\u5f0f&#xff1a;throw ThrowableInstance;<\/p>\n<p>\u8fd9\u91cc\u7684ThrowableInstance\u4e00\u5b9a\u662f Throwable \u7c7b\u7c7b\u578b\u6216\u8005 Throwable \u5b50\u7c7b\u7c7b\u578b\u7684\u4e00\u4e2a\u5bf9\u8c61\u3002\u7b80\u5355\u7684\u6570\u636e\u7c7b\u578b&#xff0c;\u4f8b\u5982 int ,char \u4ee5\u53ca\u975e Throwable \u7c7b&#xff0c;\u4f8b\u5982 String \u6216 Object &#xff0c;\u4e0d\u80fd\u7528\u4f5c\u5f02\u5e38\u3002<\/p>\n<p>\u6709\u4e24\u79cd\u65b9\u6cd5\u53ef\u4ee5\u83b7\u53d6 Throwable \u5bf9\u8c61&#xff1a;\u5728 catch \u5b50\u53e5\u4e2d\u4f7f\u7528\u53c2\u6570\u6216\u8005\u4f7f\u7528 new \u64cd\u4f5c\u7b26\u521b\u5efa\u3002\u7a0b\u5e8f\u6267\u884c\u5b8c throw \u8bed\u53e5\u4e4b\u540e\u7acb\u5373\u505c\u6b62&#xff1b;throw \u540e\u9762\u7684\u4efb\u4f55\u8bed\u53e5\u4e0d\u88ab\u6267\u884c&#xff0c;\u6700\u90bb\u8fd1\u7684 try \u5757\u7528\u6765\u68c0 \u67e5\u5b83\u662f\u5426\u542b\u6709\u4e00\u4e2a\u4e0e\u5f02\u5e38\u7c7b\u578b\u5339\u914d\u7684 catch \u8bed\u53e5\u3002<\/p>\n<p>\u5982\u679c\u53d1\u73b0\u4e86\u5339\u914d\u7684\u5757&#xff0c;\u63a7\u5236\u8f6c\u5411\u8be5\u8bed\u53e5&#xff1b;\u5982\u679c\u6ca1\u6709\u53d1\u73b0&#xff0c;\u6b21\u5305\u56f4\u7684 try \u5757\u6765\u68c0\u67e5&#xff0c;\u4ee5\u6b64\u7c7b\u63a8\u3002\u5982\u679c\u6ca1\u6709\u53d1\u73b0\u5339\u914d\u7684 catch \u5757&#xff0c;\u9ed8\u8ba4\u5f02\u5e38\u5904\u7406\u7a0b\u5e8f\u4e2d\u65ad\u7a0b\u5e8f\u7684\u6267\u884c\u5e76\u4e14\u6253\u5370\u5806\u6808\u8f68\u8ff9\u3002<\/p>\n<\/p>\n<p>class TestThrow {<br \/>\n    static void proc() {<br \/>\n        try {<br \/>\n            throw new NullPointerException(&#034;demo&#034;);<br \/>\n        } catch (NullPointerException e) {<br \/>\n            System.out.println(&#034;Caught inside proc&#034;);<br \/>\n            throw e;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        try {<br \/>\n            proc();<br \/>\n        } catch (NullPointerException e) {<br \/>\n            System.out.println(&#034;Recaught: &#034; &#043; e);<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<p>\u8be5\u7a0b\u5e8f\u4e24\u6b21\u5904\u7406\u76f8\u540c\u7684\u9519\u8bef&#xff0c;\u9996\u5148&#xff0c; main() \u65b9\u6cd5\u8bbe\u7acb\u4e86\u4e00\u4e2a\u5f02\u5e38\u5173\u7cfb\u7136\u540e\u8c03\u7528proc( )\u3002proc( )\u65b9\u6cd5\u8bbe\u7acb\u4e86\u53e6\u4e00\u4e2a\u5f02\u5e38\u5904\u7406\u5173\u7cfb\u5e76\u4e14\u7acb\u5373\u629b\u51fa\u4e00\u4e2a\u00a0NullPointerException\u00a0\u5b9e\u4f8b&#xff0c;NullPointerException\u00a0\u5728 main() \u4e2d\u88ab\u518d\u6b21\u6355\u83b7\u3002<\/p>\n<p>\u8be5\u7a0b\u5e8f\u9610\u8ff0\u4e86\u600e\u6837\u521b\u5efaJava\u7684\u6807\u51c6\u5f02\u5e38\u5bf9\u8c61&#xff0c;\u7279\u522b\u6ce8\u610f\u8fd9\u4e00\u884c&#xff1a;<\/p>\n<\/p>\n<p>throw new NullPointerException(&#034;demo&#034;); <\/p>\n<p>\u5206\u6790&#xff1a;\u6b64\u5904 new \u7528\u6765\u6784\u9020\u4e00\u4e2a\u00a0NullPointerException\u00a0\u5b9e\u4f8b&#xff0c;\u6240\u6709\u7684Java\u5185\u7f6e\u7684\u8fd0\u884c\u65f6\u5f02\u5e38\u6709\u4e24\u4e2a\u6784\u9020\u65b9\u6cd5&#xff1a;\u4e00\u4e2a\u6ca1\u6709\u53c2\u6570&#xff0c;\u4e00\u4e2a\u5e26\u6709\u4e00\u4e2a\u5b57\u7b26\u4e32\u53c2\u6570\u3002<\/p>\n<p>\u5f53\u7528\u7b2c\u4e8c\u79cd\u5f62\u5f0f\u65f6&#xff0c;\u53c2\u6570\u6307\u5b9a\u63cf\u8ff0\u5f02\u5e38\u7684\u5b57\u7b26\u4e32\u3002\u5982\u679c\u5bf9\u8c61\u7528\u4f5c print( ) \u6216\u8005 println( ) \u7684\u53c2\u6570 \u65f6&#xff0c;\u8be5\u5b57\u7b26\u4e32\u88ab\u663e\u793a\u3002\u8fd9\u540c\u6837\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528getMessage( )\u6765\u5b9e\u73b0&#xff0c;getMessage( )\u662f\u7531 Throwable \u5b9a\u4e49\u7684\u3002<\/p>\n<h4 id=\"_3\u3001throws\">3\u3001throws<\/h4>\n<p>\u5982\u679c\u4e00\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u5bfc\u81f4\u4e00\u4e2a\u5f02\u5e38\u4f46\u4e0d\u5904\u7406\u5b83&#xff0c;\u5b83\u5fc5\u987b\u6307\u5b9a\u8fd9\u79cd\u884c\u4e3a\u4ee5\u4f7f\u65b9\u6cd5\u7684\u8c03\u7528\u8005\u53ef\u4ee5\u4fdd\u62a4\u5b83\u4eec\u81ea\u5df1\u800c\u4e0d\u53d1\u751f\u5f02\u5e38\u3002\u8981\u505a\u5230\u8fd9\u70b9&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5728\u65b9\u6cd5\u58f0\u660e\u4e2d\u5305\u542b\u4e00\u4e2a\u00a0throws\u00a0\u5b50\u53e5\u3002<\/p>\n<p>\u4e00\u4e2a throws \u5b50\u53e5\u5217\u4e3e\u4e86\u4e00\u4e2a\u65b9\u6cd5\u53ef\u80fd\u5f15\u53d1\u7684\u6240\u6709\u5f02\u5e38\u7c7b\u578b\u3002\u8fd9\u5bf9\u4e8e\u9664\u4e86 Error \u6216 RuntimeException \u53ca\u5b83\u4eec\u5b50\u7c7b\u4ee5\u5916\u7c7b\u578b\u7684\u6240\u6709\u5f02\u5e38\u662f\u5fc5\u8981\u7684\u3002\u4e00\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u5f15\u53d1\u7684\u6240\u6709\u5176\u4ed6\u7c7b\u578b\u7684\u5f02\u5e38\u5fc5\u987b\u5728 throws \u5b50\u53e5\u4e2d\u58f0\u660e&#xff0c;\u5426\u5219\u4f1a\u5bfc\u81f4\u7f16\u8bd1\u9519\u8bef\u3002<\/p>\n<\/p>\n<p>public void info() throws Exception<br \/>\n{<br \/>\n    \/\/body of method<br \/>\n} <\/p>\n<p>Exception \u662f\u8be5\u65b9\u6cd5\u53ef\u80fd\u5f15\u53d1\u7684\u6240\u6709\u7684\u5f02\u5e38&#xff0c;\u4e5f\u53ef\u4ee5\u662f\u5f02\u5e38\u5217\u8868&#xff0c;\u4e2d\u95f4\u4ee5\u9017\u53f7\u9694\u5f00\u3002<\/p>\n<p>\u3010\u4f8b\u5b50\u3011<\/p>\n<\/p>\n<p>class TestThrows{<br \/>\n    static void throw1(){<br \/>\n        System.out.println(&#034;Inside throw1 . &#034;);<br \/>\n        throw new IllegalAccessException(&#034;demo&#034;);<br \/>\n    }<\/p>\n<p>    public static void main(String[] args){<br \/>\n        throw1();<br \/>\n    }<br \/>\n} <\/p>\n<p>\u4e0a\u8ff0\u4f8b\u5b50\u4e2d\u6709\u4e24\u4e2a\u5730\u65b9\u5b58\u5728\u9519\u8bef&#xff0c;\u4f60\u770b\u51fa\u6765\u4e86\u5417&#xff1f;<\/p>\n<p>\u8be5\u4f8b\u5b50\u4e2d\u5b58\u5728\u4e24\u4e2a\u9519\u8bef&#xff0c;\u9996\u5148&#xff0c;throw1( )\u65b9\u6cd5\u4e0d\u60f3\u5904\u7406\u6240\u5bfc\u81f4\u7684\u5f02\u5e38&#xff0c;\u56e0\u800c\u5b83\u5fc5\u987b\u58f0\u660e throws \u5b50\u53e5 \u6765\u5217\u4e3e\u53ef\u80fd\u5f15\u53d1\u7684\u5f02\u5e38\u5373 IllegalAccessException &#xff1b;\u5176\u6b21&#xff0c; main() \u65b9\u6cd5\u5fc5\u987b\u5b9a\u4e49 try\/catch \u8bed\u53e5\u6765\u6355\u83b7\u8be5\u5f02\u5e38\u3002<\/p>\n<p>\u6b63\u786e\u4f8b\u5b50\u5982\u4e0b&#xff1a;<\/p>\n<\/p>\n<p>class TestThrows {<br \/>\n    static void throw1() throws IllegalAccessException {<br \/>\n        System.out.println(&#034;Inside throw1 . &#034;);<br \/>\n        throw new IllegalAccessException(&#034;demo&#034;);<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        try {<br \/>\n            throw1();<br \/>\n        } catch (IllegalAccessException e) {<br \/>\n            System.out.println(&#034;Caught &#034; &#043; e);<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<p>throws \u629b\u51fa\u5f02\u5e38\u7684\u89c4\u5219&#xff1a;<\/p>\n<ul>\n<li>\u5982\u679c\u662f\u4e0d\u53d7\u68c0\u67e5\u5f02\u5e38&#xff08; unchecked exception &#xff09;&#xff0c;\u5373 Error \u3001 RuntimeException \u6216\u5b83\u4eec\u7684\u5b50\u7c7b&#xff0c;\u90a3\u4e48\u53ef\u4ee5\u4e0d\u4f7f\u7528 throws \u5173\u952e\u5b57\u6765\u58f0\u660e\u8981\u629b\u51fa\u7684\u5f02\u5e38&#xff0c;\u7f16\u8bd1\u4ecd\u80fd\u987a\u5229\u901a\u8fc7&#xff0c;\u4f46\u5728\u8fd0\u884c\u65f6\u4f1a\u88ab\u7cfb\u7edf\u629b\u51fa\u3002<\/li>\n<li>\u5fc5\u987b\u58f0\u660e\u65b9\u6cd5\u53ef\u629b\u51fa\u7684\u4efb\u4f55\u68c0\u67e5\u5f02\u5e38&#xff08; checked exception &#xff09;\u3002\u5373\u5982\u679c\u4e00\u4e2a\u65b9\u6cd5\u53ef\u80fd\u51fa\u73b0\u53d7\u53ef\u67e5\u5f02\u5e38&#xff0c;\u8981\u4e48\u7528 try-catch \u8bed\u53e5\u6355\u83b7&#xff0c;\u8981\u4e48\u7528 throws \u5b50\u53e5\u58f0\u660e\u5c06\u5b83\u629b\u51fa&#xff0c;\u5426\u5219\u4f1a\u5bfc\u81f4\u7f16\u8bd1\u9519\u8bef<\/li>\n<li>\u4ec5\u5f53\u629b\u51fa\u4e86\u5f02\u5e38&#xff0c;\u8be5\u65b9\u6cd5\u7684\u8c03\u7528\u8005\u624d\u5fc5\u987b\u5904\u7406\u6216\u8005\u91cd\u65b0\u629b\u51fa\u8be5\u5f02\u5e38\u3002\u5f53\u65b9\u6cd5\u7684\u8c03\u7528\u8005\u65e0\u529b\u5904\u7406\u8be5\u5f02\u5e38\u7684\u65f6\u5019&#xff0c;\u5e94\u8be5\u7ee7\u7eed\u629b\u51fa&#xff0c;\u800c\u4e0d\u662f\u56eb\u56f5\u541e\u67a3\u3002<\/li>\n<li>\u8c03\u7528\u65b9\u6cd5\u5fc5\u987b\u9075\u5faa\u4efb\u4f55\u53ef\u67e5\u5f02\u5e38\u7684\u5904\u7406\u548c\u58f0\u660e\u89c4\u5219\u3002\u82e5\u8986\u76d6\u4e00\u4e2a\u65b9\u6cd5&#xff0c;\u5219\u4e0d\u80fd\u58f0\u660e\u4e0e\u8986\u76d6\u65b9\u6cd5\u4e0d\u540c\u7684\u5f02\u5e38\u3002\u58f0\u660e\u7684\u4efb\u4f55\u5f02\u5e38\u5fc5\u987b\u662f\u88ab\u8986\u76d6\u65b9\u6cd5\u6240\u58f0\u660e\u5f02\u5e38\u7684\u540c\u7c7b\u6216\u5b50\u7c7b\u3002<\/li>\n<\/ul>\n<h4 id=\"_4\u3001finally\">4\u3001finally<\/h4>\n<p>\u5f53\u5f02\u5e38\u53d1\u751f\u65f6&#xff0c;\u901a\u5e38\u65b9\u6cd5\u7684\u6267\u884c\u5c06\u505a\u4e00\u4e2a\u9661\u5ced\u7684\u975e\u7ebf\u6027\u7684\u8f6c\u5411&#xff0c;\u5b83\u751a\u81f3\u4f1a\u8fc7\u65e9\u7684\u5bfc\u81f4\u65b9\u6cd5\u8fd4\u56de\u3002\u4f8b\u5982&#xff0c; \u5982\u679c\u4e00\u4e2a\u65b9\u6cd5\u6253\u5f00\u4e86\u4e00\u4e2a\u6587\u4ef6\u5e76\u5173\u95ed&#xff0c;\u7136\u540e\u9000\u51fa&#xff0c;\u4f60\u4e0d\u5e0c\u671b\u5173\u95ed\u6587\u4ef6\u7684\u4ee3\u7801\u88ab\u5f02\u5e38\u5904\u7406\u673a\u5236\u65c1\u8def\u3002\u00a0finally\u00a0\u5173\u952e\u5b57\u4e3a\u5904\u7406\u8fd9\u79cd\u610f\u5916\u800c\u8bbe\u8ba1\u3002<\/p>\n<p>finally \u521b\u5efa\u7684\u4ee3\u7801\u5757\u5728 try\/catch \u5757\u5b8c\u6210\u4e4b\u540e\u53e6\u4e00\u4e2a try\/catch \u51fa\u73b0\u4e4b\u524d\u6267\u884c\u3002 finally \u5757\u65e0\u8bba\u6709\u6ca1\u6709\u5f02\u5e38\u629b\u51fa\u90fd\u4f1a\u6267\u884c\u3002\u5982\u679c\u629b\u51fa\u5f02\u5e38&#xff0c;\u5373\u4f7f\u6ca1\u6709 catch \u5b50\u53e5\u5339\u914d&#xff0c; finally \u4e5f\u4f1a\u6267\u884c\u3002<\/p>\n<p>\u4e00\u4e2a\u65b9\u6cd5\u5c06\u4ece\u4e00\u4e2a try\/catch \u5757\u8fd4\u56de\u5230\u8c03\u7528\u7a0b\u5e8f\u7684\u4efb\u4f55\u65f6\u5019&#xff0c;\u7ecf\u8fc7\u4e00\u4e2a\u672a\u6355\u83b7\u7684\u5f02\u5e38\u6216\u8005\u662f\u4e00\u4e2a\u660e\u786e\u7684\u8fd4\u56de\u8bed\u53e5&#xff0c; finally \u5b50\u53e5\u5728\u65b9\u6cd5\u8fd4\u56de\u4e4b\u524d\u4ecd\u5c06\u6267\u884c\u3002\u8fd9\u5728\u5173\u95ed\u6587\u4ef6\u53e5\u67c4\u548c\u91ca\u653e\u4efb\u4f55\u5728\u65b9\u6cd5\u5f00\u59cb\u65f6\u88ab\u5206\u914d\u7684\u5176\u4ed6\u8d44\u6e90\u662f\u5f88\u6709\u7528\u3002<\/p>\n<p>\u6ce8\u610f&#xff1a; finally \u5b50\u53e5\u662f\u53ef\u9009\u9879&#xff0c;\u53ef\u4ee5\u6709\u4e5f\u53ef\u4ee5\u65e0&#xff0c;\u4f46\u662f\u6bcf\u4e2a try \u8bed\u53e5\u81f3\u5c11\u9700\u8981\u4e00\u4e2a catch \u6216 \u8005 finally \u5b50\u53e5\u3002<\/p>\n<p>\u3010\u4f8b\u5b50\u3011<\/p>\n<\/p>\n<p>class TestFinally {<br \/>\n    static void proc1() {<br \/>\n        try {<br \/>\n            System.out.println(&#034;inside proc1&#034;);<br \/>\n            throw new RuntimeException(&#034;demo&#034;);<br \/>\n        } finally {<br \/>\n            System.out.println(&#034;proc1&#039;s finally&#034;);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    static void proc2() {<br \/>\n        try {<br \/>\n            System.out.println(&#034;inside proc2&#034;);<br \/>\n            return;<br \/>\n        } finally {<br \/>\n            System.out.println(&#034;proc2&#039;s finally&#034;);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    static void proc3() {<br \/>\n        try {<br \/>\n            System.out.println(&#034;inside proc3&#034;);<br \/>\n        } finally {<br \/>\n            System.out.println(&#034;proc3&#039;s finally&#034;);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        try {<br \/>\n            proc1();<br \/>\n        } catch (Exception e) {<br \/>\n            System.out.println(&#034;Exception caught&#034;);<br \/>\n        }<br \/>\n        proc2();<br \/>\n        proc3();<br \/>\n    }<br \/>\n} <\/p>\n<p>\u6267\u884c\u7ed3\u679c&#xff1a;<\/p>\n<p>inside proc1 proc1&#039;s finally Exception caught inside proc2 proc2&#039;s finally inside proc3 proc3&#039;s finally<\/p>\n<p>\u6ce8&#xff1a;\u5982\u679c finally \u5757\u4e0e\u4e00\u4e2a try \u8054\u5408\u4f7f\u7528&#xff0c; finally \u5757\u5c06\u5728 try \u7ed3\u675f\u4e4b\u524d\u6267\u884c\u3002<\/p>\n<h4 id=\"\u6267\u884c\u987a\u5e8f\">\u6267\u884c\u987a\u5e8f<\/h4>\n<p>try, catch,finally ,return \u6267\u884c\u987a\u5e8f<\/p>\n<li>\u6267\u884ctry&#xff0c;catch &#xff0c; \u7ed9\u8fd4\u56de\u503c\u8d4b\u503c<\/li>\n<li>\u6267\u884cfinally<\/li>\n<li>return<\/li>\n<h3 id=\"\u81ea\u5b9a\u4e49\u5f02\u5e38\">\u81ea\u5b9a\u4e49\u5f02\u5e38<\/h3>\n<p>\u4f7f\u7528Java\u5185\u7f6e\u7684\u5f02\u5e38\u7c7b\u53ef\u4ee5\u63cf\u8ff0\u5728\u7f16\u7a0b\u65f6\u51fa\u73b0\u7684\u5927\u90e8\u5206\u5f02\u5e38\u60c5\u51b5\u3002\u9664\u6b64\u4e4b\u5916&#xff0c;\u7528\u6237\u8fd8\u53ef\u4ee5\u81ea\u5b9a\u4e49\u5f02\u5e38\u3002 \u7528\u6237\u81ea\u5b9a\u4e49\u5f02\u5e38\u7c7b&#xff0c;\u53ea\u9700\u7ee7\u627f\u00a0Exception\u00a0\u7c7b\u5373\u53ef\u3002<\/p>\n<p>\u5728\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u81ea\u5b9a\u4e49\u5f02\u5e38\u7c7b&#xff0c;\u5927\u4f53\u53ef\u5206\u4e3a\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4&#xff1a;<\/p>\n<ul>\n<li>\u521b\u5efa\u81ea\u5b9a\u4e49\u5f02\u5e38\u7c7b\u3002<\/li>\n<li>\u5728\u65b9\u6cd5\u4e2d\u901a\u8fc7 throw \u5173\u952e\u5b57\u629b\u51fa\u5f02\u5e38\u5bf9\u8c61\u3002<\/li>\n<li>\u5982\u679c\u5728\u5f53\u524d\u629b\u51fa\u5f02\u5e38\u7684\u65b9\u6cd5\u4e2d\u5904\u7406\u5f02\u5e38&#xff0c;\u53ef\u4ee5\u4f7f\u7528 try-catch \u8bed\u53e5\u6355\u83b7\u5e76\u5904\u7406&#xff1b;\u5426\u5219\u5728\u65b9\u6cd5\u7684\u58f0\u660e\u5904\u901a\u8fc7 throws \u5173\u952e\u5b57\u6307\u660e\u8981\u629b\u51fa\u7ed9\u65b9\u6cd5\u8c03\u7528\u8005\u7684\u5f02\u5e38&#xff0c;\u7ee7\u7eed\u8fdb\u884c\u4e0b\u4e00\u6b65\u64cd\u4f5c\u3002<\/li>\n<li>\u5728\u51fa\u73b0\u5f02\u5e38\u65b9\u6cd5\u7684\u8c03\u7528\u8005\u4e2d\u6355\u83b7\u5e76\u5904\u7406\u5f02\u5e38\u3002<\/li>\n<\/ul>\n<p>\u3010\u4e3e\u4f8b\u3011<\/p>\n<\/p>\n<p>class MyException extends Exception {<br \/>\n    private int detail;<br \/>\n    MyException(int a){<br \/>\n        detail &#061; a;<br \/>\n    }<br \/>\n    public String toString(){<br \/>\n        return &#034;MyException [&#034;&#043; detail &#043; &#034;]&#034;;<br \/>\n    }<br \/>\n} <\/p>\n<p>public class TestMyException {<br \/>\n    static void compute(int a) throws MyException {<br \/>\n        System.out.println(&#034;Called compute(&#034; &#043; a &#043; &#034;)&#034;);<br \/>\n        if (a &gt; 10) {<br \/>\n            throw new MyException(a);<br \/>\n        }<br \/>\n        System.out.println(&#034;Normal exit!&#034;);<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        try {<br \/>\n            compute(1);<br \/>\n            compute(20);<br \/>\n        } catch (MyException me) {<br \/>\n            System.out.println(&#034;Caught &#034; &#043; me);<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<p>\u8f93\u51fa&#xff1a;<\/p>\n<p>Called compute(1) Normal exit! Called compute(20) Caught MyException [20]<\/p>\n<p>\u4e3e\u4f8b\u4e8c&#xff1a;\u8f93\u5165\u5e74\u9f84\u65f6&#xff0c;\u5e74\u9f84\u4e0d\u80fd\u4e3a\u8d1f\u6570&#xff0c;\u5426\u5219\u5c31\u62a5\u9519<\/p>\n<\/p>\n<p>public class AgeException extends Exception{<br \/>\n    public AgeException() {<br \/>\n    }<\/p>\n<p>    public AgeException(String message) {<br \/>\n        super(message);<br \/>\n    }<br \/>\n} <\/p>\n<p>public class Demo {<br \/>\n    public static void main(String[] args) {<br \/>\n        try {<br \/>\n            check(-10);<br \/>\n        } catch (AgeException e) {<br \/>\n            e.printStackTrace();<br \/>\n        }<br \/>\n    }<\/p>\n<p>    public static void check(int age) throws AgeException {<br \/>\n        if (age &lt; 0) {<br \/>\n            throw new AgeException(&#034;\u5e74\u9f84\u4e0d\u80fd\u5c0f\u4e8e0&#034;);<br \/>\n        } else {<br \/>\n            System.out.println(age);<br \/>\n        }<\/p>\n<p>    }<br \/>\n} <\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"187\" src=\"2026-01-14nwe0u2sw2sb.png\" width=\"659\" \/><\/p>\n<h3 id=\"\u603b\u7ed3\">\u603b\u7ed3<\/h3>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"656\" src=\"2026-01-1454bpeu0x4y0.png\" width=\"831\" \/><\/p>\n<p>\u5b9e\u9645\u5e94\u7528\u4e2d\u7684\u7ecf\u9a8c\u4e0e\u603b\u7ed3<\/p>\n<li>\n<p>\u5904\u7406\u8fd0\u884c\u65f6\u5f02\u5e38\u65f6&#xff0c;\u91c7\u7528\u903b\u8f91\u53bb\u5408\u7406\u89c4\u907f\u540c\u65f6\u8f85\u52a9try-catch\u5904\u7406<\/p>\n<\/li>\n<li>\n<p>\u5728\u591a\u91cdcatch\u5757\u540e\u9762&#xff0c;\u53ef\u4ee5\u52a0\u4e00\u4e2acatch ( Exception )\u6765\u5904\u7406\u53ef\u80fd\u4f1a\u88ab\u9057\u6f0f\u7684\u5f02\u5e38<\/p>\n<\/li>\n<li>\n<p>\u5bf9\u4e8e\u4e0d\u786e\u5b9a\u7684\u4ee3\u7801&#xff0c;\u4e5f\u53ef\u4ee5\u52a0\u4e0atry-catch&#xff0c;\u5904\u7406\u6f5c\u5728\u7684\u5f02\u5e38<\/p>\n<\/li>\n<li>\n<p>\u5c3d\u91cf\u53bb\u5904\u7406\u5f02\u5e38&#xff0c;\u5207\u5fcc\u53ea\u662f\u7b80\u5355\u7684\u8c03\u7528printStackTrace)\u53bb\u6253\u5370\u8f93\u51fa<\/p>\n<\/li>\n<li>\n<p>\u5177\u4f53\u5982\u4f55\u5904\u7406\u5f02\u5e38&#xff0c;\u8981\u6839\u636e\u4e0d\u540c\u7684\u4e1a\u52a1\u9700\u6c42\u548c\u5f02\u5e38\u7c7b\u578b\u53bb\u51b3\u5b9a<\/p>\n<\/li>\n<li>\n<p>\u5c3d\u91cf\u6dfb\u52a0finally\u8bed\u53e5\u5757\u53bb\u91ca\u653e\u5360\u7528\u7684\u8d44\u6e90<\/p>\n<\/li>\n<h2>\u5341\u516b\u3001\u9762\u5411\u5bf9\u8c61<\/h2>\n<h3 id=\"\u9762\u5411\u8fc7\u7a0b-\u9762\u5411\u5bf9\u8c61\">\u9762\u5411\u8fc7\u7a0b&amp;\u9762\u5411\u5bf9\u8c61<\/h3>\n<p>\u8bed\u8a00\u7684\u8fdb\u5316\u53d1\u5c55\u8ddf\u751f\u7269\u7684\u8fdb\u5316\u53d1\u5c55\u5176\u5b9e\u662f\u4e00\u56de\u4e8b&#xff0c;\u90fd\u662f\u201d\u7269\u4ee5\u7c7b\u805a\u201d\u3002\u76f8\u8fd1\u7684\u611f\u5149\u7ec6\u80de\u805a\u5230\u4e00\u8d77\u53d8\u6210\u4e86\u6211\u4eec\u7684\u773c\u775b&#xff0c;\u76f8\u8fd1\u7684\u55c5\u89c9\u7ec6\u80de\u805a\u5230\u4e00\u8d77\u53d8\u6210\u4e86\u6211\u4eec\u7684\u9f3b\u5b50\u3002<\/p>\n<p>\u8bed\u53e5\u591a\u4e86&#xff0c;\u6211\u4eec\u5c06\u5b8c\u6210\u540c\u6837\u529f\u80fd\u7684\u76f8\u8fd1\u7684\u8bed\u53e5&#xff0c;\u805a\u5230\u4e86\u4e00\u5757\u513f&#xff0c;\u4fbf\u4e8e\u6211\u4eec\u4f7f\u7528\u3002\u4e8e\u662f&#xff0c;\u65b9\u6cd5\u51fa\u73b0\u4e86&#xff01;<\/p>\n<p>\u53d8\u91cf\u591a\u4e86&#xff0c;\u6211\u4eec\u5c06\u529f\u80fd\u76f8\u8fd1\u7684\u53d8\u91cf\u7ec4\u5728\u4e00\u8d77&#xff0c;\u805a\u5230\u4e00\u8d77\u5f52\u7c7b&#xff0c;\u4fbf\u4e8e\u6211\u4eec\u8c03\u7528\u3002\u4e8e\u662f&#xff0c;\u7ed3\u6784\u4f53\u51fa\u73b0\u4e86&#xff01;<\/p>\n<p>\u518d\u540e\u6765&#xff0c;\u65b9\u6cd5\u591a\u4e86&#xff0c;\u53d8\u91cf\u591a\u4e86&#xff01;\u7ed3\u6784\u4f53\u4e0d\u591f\u7528\u4e86&#xff01;\u6211\u4eec\u5c31\u5c06\u529f\u80fd\u76f8\u8fd1\u7684\u53d8\u91cf\u548c\u65b9\u6cd5\u805a\u5230\u4e86\u4e00\u8d77&#xff0c;\u4e8e\u662f\u7c7b\u548c\u5bf9\u8c61\u51fa\u73b0\u4e86&#xff01;<\/p>\n<p>\u5be5\u5be5\u6570\u8bed&#xff0c;\u5c31\u6df1\u523b\u7684\u5c55\u793a\u4e86\u8bed\u8a00\u7684\u8fdb\u5316\u5386\u53f2&#xff01;\u5176\u5b9e&#xff0c;\u90fd\u975e\u5e38\u81ea\u7136&#xff0c;\u201d\u7269\u4ee5\u7c7b\u805a\u201d\u3002\u5e0c\u671b\u5927\u5bb6\u80fd\u8bb0\u4f4f\u8fd9\u53e5\u8bdd\u3002<\/p>\n<p>\u4f01\u4e1a\u7684\u53d1\u5c55\u4e5f\u662f\u201d\u7269\u4ee5\u7c7b\u805a\u201d\u7684\u8fc7\u7a0b&#xff0c;\u5b8c\u6210\u5e02\u573a\u63a8\u5e7f\u7684\u4eba\u5458\u805a\u5230\u4e00\u8d77\u5f62\u6210\u4e86\u5e02\u573a\u90e8\u3002\u5b8c\u6210\u6280\u672f\u5f00\u53d1\u7684\u4eba\u5458\u805a\u5230\u4e00\u8d77\u5f62\u6210\u4e86\u5f00\u53d1\u90e8&#xff01;<\/p>\n<p>\u9762\u5411\u8fc7\u7a0b\u7684\u601d\u7ef4\u6a21\u5f0f<\/p>\n<p>\u9762\u5411\u8fc7\u7a0b\u7684\u601d\u7ef4\u6a21\u5f0f\u662f\u7b80\u5355\u7684\u7ebf\u6027\u601d\u7ef4&#xff0c;\u601d\u8003\u95ee\u9898\u9996\u5148\u9677\u5165\u7b2c\u4e00\u6b65\u505a\u4ec0\u4e48\u3001\u7b2c\u4e8c\u6b65\u505a\u4ec0\u4e48\u7684\u7ec6\u8282\u4e2d\u3002\u8fd9\u79cd\u601d\u7ef4\u6a21\u5f0f\u9002\u5408\u5904\u7406\u7b80\u5355\u7684\u4e8b\u60c5&#xff0c;\u6bd4\u5982&#xff1a;\u4e0a\u5395\u6240\u3002<\/p>\n<p>\u5982\u679c\u9762\u5bf9\u590d\u6742\u7684\u4e8b\u60c5&#xff0c;\u8fd9\u79cd\u601d\u7ef4\u6a21\u5f0f\u4f1a\u9677\u5165\u4ee4\u4eba\u53d1\u75af\u7684\u72b6\u6001&#xff01;\u6bd4\u5982&#xff1a;\u5982\u4f55\u9020\u795e\u821f\u5341\u53f7&#xff01;<\/p>\n<p>\u9762\u5411\u5bf9\u8c61\u7684\u601d\u7ef4\u6a21\u5f0f<\/p>\n<p>\u9762\u5411\u5bf9\u8c61\u7684\u601d\u7ef4\u6a21\u5f0f\u8bf4\u767d\u4e86\u5c31\u662f\u5206\u7c7b\u601d\u7ef4\u6a21\u5f0f\u3002\u601d\u8003\u95ee\u9898\u9996\u5148\u4f1a\u89e3\u51b3\u95ee\u9898\u9700\u8981\u54ea\u4e9b\u5206\u7c7b&#xff0c;\u7136\u540e\u5bf9\u8fd9\u4e9b\u5206\u7c7b\u8fdb\u884c\u5355\u72ec\u601d\u8003\u3002\u6700\u540e&#xff0c;\u624d\u5bf9\u67d0\u4e2a\u5206\u7c7b\u4e0b\u7684\u7ec6\u8282\u8fdb\u884c\u9762\u5411\u8fc7\u7a0b\u7684\u601d\u7d22\u3002<\/p>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u5f62\u6210\u5f88\u597d\u7684\u534f\u4f5c\u5206\u5de5\u3002\u6bd4\u5982&#xff1a;\u8bbe\u8ba1\u5e08\u5206\u4e8610\u4e2a\u7c7b&#xff0c;\u7136\u540e\u5c0610\u4e2a\u7c7b\u4ea4\u7ed9\u4e8610\u4e2a\u4eba\u5206\u522b\u8fdb\u884c\u8be6\u7ec6\u8bbe\u8ba1\u548c\u7f16\u7801&#xff01;<\/p>\n<p>\u663e\u7136&#xff0c;\u9762\u5411\u5bf9\u8c61\u9002\u5408\u5904\u7406\u590d\u6742\u7684\u95ee\u9898&#xff0c;\u9002\u5408\u5904\u7406\u9700\u8981\u591a\u4eba\u534f\u4f5c\u7684\u95ee\u9898&#xff01;<\/p>\n<p>\u5982\u679c\u4e00\u4e2a\u95ee\u9898\u9700\u8981\u591a\u4eba\u534f\u4f5c\u4e00\u8d77\u89e3\u51b3&#xff0c;\u90a3\u4e48\u4f60\u4e00\u5b9a\u8981\u7528\u9762\u5411\u5bf9\u8c61\u7684\u65b9\u5f0f\u6765\u601d\u8003&#xff01;<\/p>\n<p>\u5bf9\u4e8e\u63cf\u8ff0\u590d\u6742\u7684\u4e8b\u7269&#xff0c;\u4e3a\u4e86\u4ece\u5b8f\u89c2\u4e0a\u628a\u63e1\u3001\u4ece\u6574\u4f53\u4e0a\u5408\u7406\u5206\u6790&#xff0c;\u6211\u4eec\u9700\u8981\u4f7f\u7528\u9762\u5411\u5bf9\u8c61\u7684\u601d\u8def\u6765\u5206\u6790\u6574 \u4e2a\u7cfb\u7edf\u3002\u4f46\u662f&#xff0c;\u5177\u4f53\u5230\u5fae\u89c2\u64cd\u4f5c&#xff0c;\u4ecd\u7136\u9700\u8981\u9762\u5411\u8fc7\u7a0b\u7684\u601d\u8def\u53bb\u5904\u7406\u3002<\/p>\n<h3 id=\"oop\u8be6\u89e3\">OOP\u8be6\u89e3<\/h3>\n<h4 id=\"_1\u3001\u4ec0\u4e48\u662f\u9762\u5411\u5bf9\u8c61\">1\u3001\u4ec0\u4e48\u662f\u9762\u5411\u5bf9\u8c61<\/h4>\n<p>Java\u7684\u7f16\u7a0b\u8bed\u8a00\u662f\u9762\u5411\u5bf9\u8c61\u7684&#xff0c;\u91c7\u7528\u8fd9\u79cd\u8bed\u8a00\u8fdb\u884c\u7f16\u7a0b\u79f0\u4e3a\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b(Object-Oriented Programming, OOP)\u3002<\/p>\n<p>\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7684\u672c\u8d28\u5c31\u662f&#xff1a;\u4ee5\u7c7b\u7684\u65b9\u5f0f\u7ec4\u7ec7\u4ee3\u7801&#xff0c;\u4ee5\u5bf9\u8c61\u7684\u7ec4\u7ec7(\u5c01\u88c5)\u6570\u636e\u3002<\/p>\n<p>\u62bd\u8c61(abstract)<\/p>\n<p>\u5ffd\u7565\u4e00\u4e2a\u4e3b\u9898\u4e2d\u4e0e\u5f53\u524d\u76ee\u6807\u65e0\u5173\u7684\u90a3\u4e9b\u65b9\u9762&#xff0c;\u4ee5\u4fbf\u66f4\u5145\u5206\u5730\u6ce8\u610f\u4e0e\u5f53\u524d\u76ee\u6807\u6709\u5173\u7684\u65b9\u9762\u3002\u62bd\u8c61\u5e76\u4e0d\u6253\u7b97\u4e86 \u89e3\u5168\u90e8\u95ee\u9898&#xff0c;\u800c\u53ea\u662f\u9009\u62e9\u5176\u4e2d\u7684\u4e00\u90e8\u5206&#xff0c;\u6682\u65f6\u4e0d\u7528\u5173\u6ce8\u7ec6\u8282\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;\u8981\u8bbe\u8ba1\u4e00\u4e2a\u5b66\u751f\u6210\u7ee9\u7ba1\u7406\u7cfb\u7edf&#xff0c;\u90a3\u4e48\u5bf9\u4e8e\u5b66\u751f&#xff0c;\u53ea\u5173\u5fc3\u4ed6\u7684\u73ed\u7ea7\u3001\u5b66\u53f7\u3001\u6210\u7ee9\u7b49&#xff0c;\u800c\u4e0d\u7528\u53bb\u5173\u5fc3\u4ed6\u7684 \u8eab\u9ad8\u3001\u4f53\u91cd\u8fd9\u4e9b\u4fe1\u606f\u3002 \u62bd\u8c61\u662f\u4ec0\u4e48&#xff1f;\u5c31\u662f\u5c06\u591a\u4e2a\u7269\u4f53\u5171\u540c\u70b9\u5f52\u7eb3\u51fa\u6765&#xff0c;\u5c31\u662f\u62bd\u51fa\u50cf\u7684\u90e8\u5206&#xff01;<\/p>\n<p>\u5c01\u88c5(Encapsulation)<\/p>\n<p>\u5c01\u88c5\u662f\u9762\u5411\u5bf9\u8c61\u7684\u7279\u5f81\u4e4b\u4e00&#xff0c;\u662f\u5bf9\u8c61\u548c\u7c7b\u6982\u5ff5\u7684\u4e3b\u8981\u7279\u6027\u3002\u5c01\u88c5\u662f\u628a\u8fc7\u7a0b\u548c\u6570\u636e\u5305\u56f4\u8d77\u6765&#xff0c;\u5bf9\u6570\u636e\u7684\u8bbf \u95ee\u53ea\u80fd\u901a\u8fc7\u6307\u5b9a\u7684\u65b9\u5f0f\u3002<\/p>\n<p>\u5728\u5b9a\u4e49\u4e00\u4e2a\u5bf9\u8c61\u7684\u7279\u6027\u7684\u65f6\u5019&#xff0c;\u6709\u5fc5\u8981\u51b3\u5b9a\u8fd9\u4e9b\u7279\u6027\u7684\u53ef\u89c1\u6027&#xff0c;\u5373\u54ea\u4e9b\u7279\u6027\u5bf9\u5916\u90e8\u662f\u53ef\u89c1\u7684&#xff0c;\u54ea\u4e9b\u7279\u6027\u7528\u4e8e\u8868\u793a\u5185\u90e8\u72b6\u6001\u3002<\/p>\n<p>\u901a\u5e38&#xff0c;\u5e94\u7981\u6b62\u76f4\u63a5\u8bbf\u95ee\u4e00\u4e2a\u5bf9\u8c61\u4e2d\u6570\u636e\u7684\u5b9e\u9645\u8868\u793a&#xff0c;\u800c\u5e94\u901a\u8fc7\u64cd\u4f5c\u63a5\u53e3\u6765\u8bbf\u95ee&#xff0c;\u8fd9\u79f0\u4e3a\u4fe1\u606f\u9690\u85cf\u3002<\/p>\n<p>\u4fe1\u606f\u9690\u85cf\u662f\u7528\u6237\u5bf9\u5c01\u88c5\u6027\u7684\u8ba4\u8bc6&#xff0c;\u5c01\u88c5\u5219\u4e3a\u4fe1\u606f\u9690\u85cf\u63d0\u4f9b\u652f\u6301\u3002<\/p>\n<p>\u5c01\u88c5\u4fdd\u8bc1\u4e86\u6a21\u5757\u5177\u6709\u8f83\u597d\u7684\u72ec\u7acb\u6027&#xff0c;\u4f7f\u5f97\u7a0b\u5e8f\u7ef4\u62a4\u4fee\u6539\u8f83\u4e3a\u5bb9\u6613\u3002\u5bf9\u5e94\u7528\u7a0b\u5e8f\u7684\u4fee\u6539\u4ec5\u9650\u4e8e\u7c7b\u7684\u5185\u90e8&#xff0c; \u56e0\u800c\u53ef\u4ee5\u5c06\u5e94\u7528\u7a0b\u5e8f\u4fee\u6539\u5e26\u6765\u7684\u5f71\u54cd\u51cf\u5c11\u5230\u6700\u4f4e\u9650\u5ea6\u3002<\/p>\n<p>\u7ee7\u627f(inheritance)<\/p>\n<p>\u7ee7\u627f\u662f\u4e00\u79cd\u8054\u7ed3\u7c7b\u7684\u5c42\u6b21\u6a21\u578b&#xff0c;\u5e76\u4e14\u5141\u8bb8\u548c\u652f\u6301\u7c7b\u7684\u91cd\u7528&#xff0c;\u5b83\u63d0\u4f9b\u4e86\u4e00\u79cd\u660e\u786e\u8868\u8ff0\u5171\u6027\u7684\u65b9\u6cd5<\/p>\n<p>\u65b0\u7c7b\u7ee7\u627f\u4e86\u539f\u59cb\u7c7b\u540e,\u65b0\u7c7b\u5c31\u7ee7\u627f\u4e86\u539f\u59cb\u7c7b\u7684\u7279\u6027&#xff0c;\u65b0\u7c7b\u79f0\u4e3a\u539f\u59cb\u7c7b\u7684\u6d3e\u751f\u7c7b(\u5b50\u7c7b)&#xff0c;\u800c\u539f\u59cb\u7c7b\u79f0\u4e3a\u65b0\u7c7b\u7684\u57fa\u7c7b(\u7236\u7c7b)\u3002<\/p>\n<p>\u6d3e\u751f\u7c7b(\u5b50\u7c7b)\u53ef\u4ee5\u4ece\u5b83\u7684\u57fa\u7c7b(\u7236\u7c7b)\u90a3\u91cc\u7ee7\u627f\u65b9\u6cd5\u548c\u5b9e\u4f8b\u53d8\u91cf&#xff0c;\u5e76\u4e14\u6d3e\u751f\u7c7b(\u5b50\u7c7b)\u4e2d\u53ef\u4ee5\u4fee\u6539\u6216\u589e\u52a0\u65b0\u7684\u65b9\u6cd5\u4f7f\u4e4b\u66f4\u9002\u5408\u7279\u6b8a\u7684\u9700\u8981\u7ee7\u627f\u6027\u5f88\u597d\u7684\u89e3\u51b3\u4e86\u8f6f\u4ef6\u7684\u53ef\u91cd\u7528\u6027\u95ee\u9898\u3002\u6bd4\u5982\u8bf4&#xff0c;\u6240\u6709\u7684Windows\u5e94\u7528\u7a0b\u5e8f\u90fd\u6709\u4e00\u4e2a\u7a97\u53e3&#xff0c;\u5b83\u4eec\u53ef\u4ee5\u770b\u4f5c\u90fd\u662f\u4ece\u4e00\u4e2a\u7a97\u53e3\u7c7b\u6d3e\u751f\u51fa\u6765\u7684\u3002\u4f46\u662f\u6709\u7684\u5e94\u7528\u7a0b\u5e8f\u7528\u4e8e\u6587\u5b57\u5904\u7406&#xff0c;\u6709\u7684\u5e94\u7528\u7a0b\u5e8f\u7528\u4e8e\u7ed8\u56fe&#xff0c;\u8fd9\u662f\u7531\u4e8e\u6d3e\u751f\u51fa\u4e86\u4e0d\u540c\u7684\u5b50\u7c7b&#xff0c;\u5404\u4e2a\u5b50\u7c7b\u6dfb\u52a0\u4e86\u4e0d\u540c\u7684\u7279\u6027\u3002<\/p>\n<p>\u591a\u6001(polymorphism)<\/p>\n<p>\u591a\u6001\u6027\u662f\u6307\u5141\u8bb8\u4e0d\u540c\u7c7b\u7684\u5bf9\u8c61\u5bf9\u540c\u4e00\u6d88\u606f\u4f5c\u51fa\u54cd\u5e94\u3002<\/p>\n<p>\u591a\u6001\u6027\u8bed\u8a00\u5177\u6709\u7075\u6d3b\u3001\u62bd\u8c61\u3001\u884c\u4e3a\u5171\u4eab\u3001\u4ee3\u7801\u5171\u4eab\u7684\u4f18\u52bf&#xff0c;\u5f88\u597d\u7684\u89e3\u51b3\u4e86\u5e94\u7528\u7a0b\u5e8f\u51fd\u6570\u540c\u540d\u95ee\u9898\u3002<\/p>\n<p>\u76f8\u540c\u7c7b\u57df\u7684\u4e0d\u540c\u5bf9\u8c61,\u8c03\u7528\u76f8\u540c\u65b9\u6cd5,\u8868\u73b0\u51fa\u4e0d\u540c\u7684\u7ed3\u679c<\/p>\n<p>\u4ece\u8ba4\u8bc6\u8bba\u89d2\u5ea6\u8003\u8651\u662f\u5148\u6709\u5bf9\u8c61\u540e\u6709\u7c7b\u3002\u5bf9\u8c61&#xff0c;\u662f\u5177\u4f53\u7684\u4e8b\u7269\u3002\u7c7b&#xff0c;\u662f\u62bd\u8c61\u7684&#xff0c;\u662f\u5bf9\u5bf9\u8c61\u7684\u62bd\u8c61\u3002<\/p>\n<p>\u4ece\u4ee3\u7801\u8fd0\u884c\u89d2\u5ea6\u8003\u8651\u662f\u5148\u6709\u7c7b\u540e\u6709\u5bf9\u8c61\u3002\u7c7b\u662f\u5bf9\u8c61\u7684\u6a21\u677f\u3002<\/p>\n<h4 id=\"_2\u3001\u7c7b\u4e0e\u5bf9\u8c61\u7684\u5173\u7cfb\">2\u3001\u7c7b\u4e0e\u5bf9\u8c61\u7684\u5173\u7cfb<\/h4>\n<p>\u7c7b\u662f\u4e00\u79cd\u62bd\u8c61\u7684\u6570\u636e\u7c7b\u578b,\u5b83\u662f\u5bf9\u67d0\u4e00\u7c7b\u4e8b\u7269\u6574\u4f53\u63cf\u8ff0\/\u5b9a\u4e49,\u4f46\u662f\u5e76\u4e0d\u80fd\u4ee3\u8868\u67d0\u4e00\u4e2a\u5177\u4f53\u7684\u4e8b\u7269<\/p>\n<p>\u4f8b\u5982&#xff1a;\u6211\u4eec\u751f\u6d3b\u4e2d\u6240\u8bf4\u7684\u8bcd\u8bed&#xff1a;\u52a8\u7269\u3001\u690d\u7269\u3001\u624b\u673a\u3001\u7535\u8111\u7b49\u7b49\u3002\u8fd9\u4e9b\u4e5f\u90fd\u662f\u62bd\u8c61\u7684\u6982\u5ff5&#xff0c;\u800c\u4e0d\u662f\u6307\u7684\u67d0\u4e00\u4e2a \u5177\u4f53\u7684\u4e1c\u897f\u3002<\/p>\n<p>\u4f8b\u5982: Person\u7c7b\u3001Pet\u7c7b\u3001Car\u7c7b\u7b49&#xff0c;\u8fd9\u4e9b\u7c7b\u90fd\u662f\u7528\u6765 \u63cf\u8ff0\/\u5b9a\u4e49 \u67d0\u4e00\u7c7b\u5177\u4f53\u7684\u4e8b\u7269\u5e94\u8be5\u5177\u5907\u7684\u7279\u70b9\u548c\u884c\u4e3a<\/p>\n<p>\u5bf9\u8c61\u662f\u62bd\u8c61\u6982\u5ff5\u7684\u5177\u4f53\u5b9e\u4f8b<\/p>\n<p>\u4f8b\u5982&#xff1a;\u5f20\u4e09\u5c31\u662f\u4eba\u7684\u4e00\u4e2a\u5177\u4f53\u5b9e\u4f8b&#xff0c;\u5f20\u4e09\u5bb6\u91cc\u7684\u65fa\u8d22\u5c31\u662f\u72d7\u7684\u4e00\u4e2a\u5177\u4f53\u5b9e\u4f8b\u3002\u80fd\u591f\u4f53\u73b0\u51fa\u7279\u70b9&#xff0c;\u5c55\u73b0\u51fa\u529f\u80fd\u7684\u662f\u5177\u4f53\u7684\u5b9e\u4f8b&#xff0c;\u800c\u4e0d\u662f\u4e00\u4e2a\u62bd\u8c61\u7684\u6982\u5ff5\u3002<\/p>\n<p>\u3010\u793a\u4f8b\u3011<\/p>\n<\/p>\n<p>Student s &#061; new Student(1,&#034;tom&#034;,20);<br \/>\ns.study();<\/p>\n<p>Car c &#061; new Car(1,&#034;BWM&#034;,500000);<br \/>\nc.run(); <\/p>\n<p>\u5bf9\u8c61s\u5c31\u662fStudent\u7c7b\u7684\u4e00\u4e2a\u5b9e\u4f8b&#xff0c;\u5bf9\u8c61c\u5c31\u662fCar\u7c7b\u7684\u4e00\u4e2a\u5177\u4f53\u5b9e\u4f8b&#xff0c;\u80fd\u591f\u4f7f\u7528\u7684\u662f\u5177\u4f53\u5b9e\u4f8b&#xff0c;\u800c\u4e0d\u662f\u7c7b\u3002\u7c7b\u53ea\u662f\u7ed9\u5bf9\u8c61\u7684\u521b\u5efa\u63d0\u4f9b\u4e86\u4e00\u4e2a\u53c2\u8003\u7684\u6a21\u677f\u800c\u5df2\u3002<\/p>\n<p>\u4f46\u662f\u5728java\u4e2d&#xff0c;\u6ca1\u6709\u7c7b\u5c31\u6ca1\u6709\u5bf9\u8c61&#xff0c;\u7136\u800c\u7c7b\u53c8\u662f\u6839\u636e\u5177\u4f53\u7684\u529f\u80fd\u9700\u6c42&#xff0c;\u8fdb\u884c\u5b9e\u9645\u7684\u5206\u6790&#xff0c;\u6700\u7ec8\u62bd\u8c61\u51fa\u6765\u7684\u3002<\/p>\n<h4 id=\"_3\u3001\u5bf9\u8c61\u548c\u5f15\u7528\u7684\u5173\u7cfb\">3\u3001\u5bf9\u8c61\u548c\u5f15\u7528\u7684\u5173\u7cfb<\/h4>\n<p>\u5f15\u7528 &#034;\u6307\u5411&#034; \u5bf9\u8c61<\/p>\n<p>\u4f7f\u7528\u7c7b\u7c7b\u578b\u3001\u6570\u7ec4\u7c7b\u578b\u3001\u63a5\u53e3\u7c7b\u578b\u58f0\u660e\u51fa\u7684\u53d8\u91cf&#xff0c;\u90fd\u53ef\u4ee5\u6307\u5411\u5bf9\u8c61&#xff0c;\u8fd9\u79cd\u53d8\u91cf\u5c31\u662f\u5f15\u7528\u7c7b\u578b\u53d8\u91cf&#xff0c;\u7b80\u79f0\u5f15\u7528\u3002<\/p>\n<p>\u5728\u7a0b\u5e8f\u4e2d&#xff0c;\u521b\u5efa\u51fa\u5bf9\u8c61\u540e&#xff0c;\u76f4\u63a5\u4f7f\u7528\u5e76\u4e0d\u65b9\u4fbf&#xff0c;\u6240\u4ee5\u4e00\u822c\u4f1a\u7528\u4e00\u4e2a\u5f15\u7528\u7c7b\u578b\u7684\u53d8\u91cf\u53bb\u63a5\u6536\u8fd9\u4e2a\u5bf9\u8c61&#xff0c;\u8fd9\u4e2a\u5c31\u662f\u6240\u8bf4\u7684\u5f15\u7528\u6307\u5411\u5bf9\u8c61\u3002<\/p>\n<p>\u603b\u7ed3&#xff1a;\u5bf9\u8c61\u548c\u5f15\u7528\u7684\u5173\u7cfb&#xff0c;\u5c31\u5982\u7535\u89c6\u673a\u548c\u9065\u63a7\u5668&#xff0c;\u98ce\u7b5d\u548c\u7ebf\u7684\u5173\u7cfb\u4e00\u6837\u3002<\/p>\n<h3 id=\"\u65b9\u6cd5\u56de\u987e\u53ca\u52a0\u6df1\">\u65b9\u6cd5\u56de\u987e\u53ca\u52a0\u6df1<\/h3>\n<p>\u65b9\u6cd5\u4e00\u5b9a\u662f\u5b9a\u4e49\u5728\u7c7b\u4e2d\u7684&#xff0c;\u5c5e\u4e8e\u7c7b\u7684\u6210\u5458\u3002<\/p>\n<h4 id=\"_1\u3001\u65b9\u6cd5\u7684\u5b9a\u4e49\">1\u3001\u65b9\u6cd5\u7684\u5b9a\u4e49<\/h4>\n<p>\u683c\u5f0f&#xff1a; \u4fee\u9970\u7b26 \u8fd4\u56de\u7c7b\u578b \u65b9\u6cd5\u540d(\u53c2\u6570\u5217\u8868)\u5f02\u5e38\u629b\u51fa\u7c7b\u578b<\/p>\n<li>\n<p>\u4fee\u9970\u7b26<\/p>\n<p>public\u3001static\u3001abstract\u3001final\u7b49\u7b49\u90fd\u662f\u4fee\u9970\u7b26&#xff0c;\u4e00\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u6709\u591a\u4e2a\u4fee\u9970\u7b26\u3002\u4f8b\u5982\u7a0b\u5e8f\u5165\u53e3 main\u65b9\u6cd5&#xff0c;\u5c31\u4f7f\u7528\u4e86public static\u8fd9\u4e2a\u4fe9\u4e2a\u4fee\u9970\u7b26<\/p>\n<p>\u6ce8&#xff1a;\u5982\u679c\u4e00\u4e2a\u65b9\u6cd5\u6216\u8005\u5c5e\u6027\u6709\u591a\u4e2a\u4fee\u9970\u7b26&#xff0c;\u8fd9\u591a\u4e2a\u4fee\u9970\u7b26\u662f\u6ca1\u6709\u5148\u540e\u987a\u5e8f\u7684<\/p>\n<\/li>\n<li>\n<p>\u8fd4\u56de\u7c7b\u578b<\/p>\n<p>\u65b9\u6cd5\u6267\u884c\u5b8c\u5982\u679c\u6709\u8981\u8fd4\u56de\u7684\u6570\u636e&#xff0c;\u90a3\u4e48\u5c31\u8981\u58f0\u660e\u8fd4\u56de\u6570\u636e\u7684\u7c7b\u578b&#xff0c;\u5982\u679c\u6ca1\u6709\u8fd4\u56de\u7684\u6570\u636e&#xff0c;\u90a3\u4e48\u8fd4\u56de\u7c7b\u578b\u5c31\u5fc5\u987b\u5199void<\/p>\n<p>\u53ea\u6709\u6784\u9020\u65b9\u6cd5(\u6784\u9020\u5668)\u4e0d\u5199\u4efb\u4f55\u8fd4\u56de\u7c7b\u578b\u4e5f\u4e0d\u5199void<\/p>\n<p>\u3010\u793a\u4f8b\u3011<\/p>\n<p> public String sayHello(){<br \/>\n    return &#034;hello&#034;;<br \/>\n}<br \/>\npublic int max(int a,int b){<br \/>\n    return a&gt;b?a:b;<br \/>\n}<br \/>\npublic void print(String msg){<br \/>\n    System.out.println(msg);<br \/>\n} <\/p>\n<p>\u601d\u8003&#xff1a;\u58f0\u660e\u8fd4\u56de\u7c7b\u578b\u7684\u65b9\u6cd5\u4e2d\u4e00\u5b9a\u8981\u51fa\u73b0return\u8bed\u53e5&#xff0c;\u90a3\u4e48\u6ca1\u6709\u8fd4\u56de\u7c7b\u578b(void)\u7684\u65b9\u6cd5\u4e2d&#xff0c;\u80fd\u4e0d\u80fd\u51fa\u73b0 return\u8bed\u53e5?<\/p>\n<p>break\u548creturn\u7684\u533a\u522b<\/p>\n<p>return \u8bed\u53e5\u7684\u4f5c\u7528<\/p>\n<p>(1) return \u4ece\u5f53\u524d\u7684\u65b9\u6cd5\u4e2d\u9000\u51fa,\u8fd4\u56de\u5230\u8be5\u8c03\u7528\u7684\u65b9\u6cd5\u7684\u8bed\u53e5\u5904,\u7ee7\u7eed\u6267\u884c\u3002 (2) return \u8fd4\u56de\u4e00\u4e2a\u503c\u7ed9\u8c03\u7528\u8be5\u65b9\u6cd5\u7684\u8bed\u53e5&#xff0c;\u8fd4\u56de\u503c\u7684\u6570\u636e\u7c7b\u578b\u5fc5\u987b\u4e0e\u65b9\u6cd5\u7684\u58f0\u660e\u4e2d\u7684\u8fd4\u56de\u503c\u7684\u7c7b\u578b\u4e00\u81f4\u3002 (3) return\u540e\u9762\u4e5f\u53ef\u4ee5\u4e0d\u5e26\u53c2\u6570&#xff0c;\u4e0d\u5e26\u53c2\u6570\u5c31\u662f\u8fd4\u56de\u7a7a&#xff0c;\u5176\u5b9e\u4e3b\u8981\u76ee\u7684\u5c31\u662f\u7528\u4e8e\u60f3\u4e2d\u65ad\u51fd\u6570\u6267\u884c&#xff0c;\u8fd4\u56de \u8c03\u7528\u51fd\u6570\u5904\u3002<\/p>\n<p>break\u8bed\u53e5\u7684\u4f5c\u7528<\/p>\n<p>(1)break\u5728\u5faa\u73af\u4f53\u5185&#xff0c;\u5f3a\u884c\u7ed3\u675f\u5faa\u73af\u7684\u6267\u884c&#xff0c;\u4e5f\u5c31\u662f\u7ed3\u675f\u6574\u4e2a\u5faa\u73af\u8fc7\u7a0b&#xff0c;\u4e0d\u5728\u5224\u65ad\u6267\u884c\u5faa\u73af\u7684\u6761\u4ef6\u662f\u5426\u6210\u7acb&#xff0c;\u76f4\u63a5\u8f6c\u5411\u5faa\u73af\u8bed\u53e5\u4e0b\u9762\u7684\u8bed\u53e5\u3002<\/p>\n<p>(2)\u5f53break\u51fa\u73b0\u5728\u5faa\u73af\u4f53\u4e2d\u7684switch\u8bed\u53e5\u4f53\u5185\u65f6&#xff0c;\u5176\u4f5c\u7528\u53ea\u662f\u8df3\u51fa\u8be5switch\u8bed\u53e5\u4f53\u3002<\/p>\n<\/li>\n<li>\n<p>\u65b9\u6cd5\u540d<\/p>\n<p>\u9075\u5b88java\u4e2d\u6807\u793a\u7b26\u7684\u547d\u540d\u89c4\u5219\u5373\u53ef.<\/p>\n<\/li>\n<li>\n<p>\u53c2\u6570\u5217\u8868<\/p>\n<p>\u6839\u636e\u9700\u6c42\u5b9a\u4e49,\u65b9\u6cd5\u53ef\u4ee5\u662f\u65e0\u53c2\u7684,\u4e5f\u53ef\u4ee5\u6709\u4e00\u4e2a\u53c2\u6570,\u4e5f\u53ef\u4ee5\u6709\u591a\u4e2a\u53c2\u6570<\/p>\n<\/li>\n<li>\n<p>\u5f02\u5e38\u629b\u51fa\u7c7b\u578b<\/p>\n<p>\u5982\u679c\u65b9\u6cd5\u4e2d\u7684\u4ee3\u7801\u5728\u6267\u884c\u8fc7\u7a0b\u4e2d&#xff0c;\u53ef\u80fd\u4f1a\u51fa\u73b0\u4e00\u4e9b\u5f02\u5e38\u60c5\u51b5&#xff0c;\u90a3\u4e48\u5c31\u53ef\u4ee5\u5728\u65b9\u6cd5\u4e0a\u628a\u8fd9\u4e9b\u5f02\u5e38\u58f0\u660e\u5e76\u629b\u51fa&#xff0c; \u4e5f\u53ef\u4ee5\u540c\u65f6\u58f0\u660e\u629b\u51fa\u591a\u4e2a\u5f02\u5e38&#xff0c;\u4f7f\u7528\u9017\u53f7\u9694\u5f00\u5373\u53ef\u3002<\/p>\n<p> public void readFile(String file)throws IOException{<br \/>\n}<\/p>\n<p>public void readFile(String file)throws IOException,ClassNotFoundException{<br \/>\n} <\/p>\n<\/li>\n<h4 id=\"_2\u3001\u65b9\u6cd5\u8c03\u7528\">2\u3001\u65b9\u6cd5\u8c03\u7528<\/h4>\n<p>\u5728\u7c7b\u4e2d\u5b9a\u4e49\u4e86\u65b9\u6cd5&#xff0c;\u8fd9\u4e2a\u65b9\u6cd5\u4e2d\u7684\u4ee3\u7801\u5e76\u4e0d\u4f1a\u6267\u884c&#xff0c;\u5f53\u8fd9\u4e2a\u65b9\u6cd5\u88ab\u8c03\u7528\u7684\u65f6\u5019&#xff0c;\u65b9\u6cd5\u4e2d\u7684\u4ee3\u7801\u624d\u4f1a\u88ab\u4e00\u884c\u4e00 \u884c\u987a\u5e8f\u6267\u884c\u3002<\/p>\n<li>\n<p>\u975e\u9759\u6001\u65b9\u6cd5<\/p>\n<p>\u6ca1\u6709\u4f7f\u7528static\u4fee\u9970\u7b26\u4fee\u9970\u7684\u65b9\u6cd5&#xff0c;\u5c31\u662f\u975e\u9759\u6001\u65b9\u6cd5\u3002<\/p>\n<p>\u8c03\u7528\u8fd9\u79cd\u65b9\u6cd5\u7684\u65f6\u5019&#xff0c;\u662f&#034;\u4e00\u5b9a&#034;\u8981\u4f7f\u7528\u5bf9\u8c61\u7684\u8c03\u7528\u3002\u56e0\u4e3a\u975e\u9759\u6001\u65b9\u6cd5\u662f\u5c5e\u4e8e\u5bf9\u8c61\u7684\u3002(\u975e\u9759\u6001\u5c5e\u6027\u4e5f\u662f\u4e00\u6837\u7684)<\/p>\n<p>\u3010\u4f8b\u5b50\u3011<\/p>\n<p>public class Student{ public void say(){} }<\/p>\n<p>main:<\/p>\n<p>Student s &#061; new Student();<\/p>\n<p>s.say();<\/p>\n<\/li>\n<li>\n<p>\u9759\u6001\u65b9\u6cd5<\/p>\n<p>\u4f7f\u7528static\u4fee\u9970\u7b26\u4fee\u9970\u7684\u65b9\u6cd5,\u5c31\u662f\u9759\u6001\u65b9\u6cd5\u3002<\/p>\n<p>\u8c03\u7528\u8fd9\u79cd\u65b9\u6cd5\u7684\u65f6\u5019&#xff0c;&#034;\u53ef\u4ee5&#034;\u4f7f\u7528\u5bf9\u8c61\u8c03\u7528&#xff0c;\u4e5f&#034;\u53ef\u4ee5&#034;\u4f7f\u7528\u7c7b\u6765\u8c03\u7528&#xff0c;\u4f46\u662f\u63a8\u8350\u4f7f\u7528\u7c7b\u8fdb\u884c\u8c03\u7528\u3002\u56e0\u4e3a\u9759\u6001\u65b9\u6cd5\u662f\u5c5e\u4e8e\u7c7b\u7684\u3002(\u9759\u6001\u5c5e\u6027\u4e5f\u662f\u4e00\u6837\u7684)<\/p>\n<p>\u3010\u4f8b\u5b50\u3011<\/p>\n<p>public class Student{ public static void say(){} }<\/p>\n<p>main:<\/p>\n<p>Student.say();<\/p>\n<\/li>\n<li>\n<p>\u7c7b\u4e2d\u65b9\u6cd5\u4e4b\u95f4\u7684\u8c03\u7528<\/p>\n<p>\u5047\u8bbe\u540c\u4e00\u4e2a\u7c7b\u4e2d\u6709\u4fe9\u4e2a\u65b9\u6cd5&#xff0c;a\u65b9\u6cd5\u548cb\u65b9\u6cd5&#xff0c;a\u548cb\u90fd\u662f\u975e\u9759\u6001\u65b9\u6cd5&#xff0c;\u76f8\u4e92\u4e4b\u95f4\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528\u3002<\/p>\n<p> public void a(){<br \/>\n    b();<br \/>\n}<br \/>\npublic void b(){<\/p>\n<p>} <\/p>\n<p>a\u548cb\u90fd\u662f\u9759\u6001\u65b9\u6cd5,\u76f8\u4e92\u4e4b\u95f4\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528<\/p>\n<p> public static void a(){<br \/>\n    b();<br \/>\n}<br \/>\npublic static void b(){<\/p>\n<p>} <\/p>\n<p>a\u9759\u6001\u65b9\u6cd5&#xff0c;b\u662f\u975e\u9759\u6001\u65b9\u6cd5&#xff0c;a\u65b9\u6cd5\u4e2d\u4e0d\u80fd\u76f4\u63a5\u8c03\u7528b\u65b9\u6cd5&#xff0c;\u4f46\u662fb\u65b9\u6cd5\u4e2d\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528a\u65b9\u6cd5\u3002\u9759\u6001\u65b9\u6cd5\u4e0d\u80fd \u8c03\u7528\u975e\u9759\u6001\u65b9\u6cd5&#xff01;<\/p>\n<p> public static void a(){<br \/>\n    \/\/b();\u62a5\u9519<br \/>\n}<br \/>\npublic void b(){<br \/>\n    a();<br \/>\n} <\/p>\n<p>\u53e6\u5916&#xff1a;\u5728\u540c\u4e00\u4e2a\u7c7b\u4e2d&#xff0c;\u9759\u6001\u65b9\u6cd5\u5185\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u5230\u7c7b\u4e2d\u7684\u975e\u9759\u6001\u5c5e\u6027\u3002<\/p>\n<p>\u603b\u7ed3&#xff1a;\u7c7b\u4e2d\u65b9\u6cd5\u4e2d\u7684\u8c03\u7528&#xff0c;\u4e24\u4e2a\u65b9\u6cd5\u90fd\u662f\u9759\u6001\u6216\u8005\u975e\u9759\u6001\u90fd\u53ef\u4ee5\u4e92\u76f8\u8c03\u7528&#xff0c;\u5f53\u4e00\u4e2a\u65b9\u6cd5\u662f\u9759\u6001&#xff0c;\u4e00\u4e2a\u65b9 \u6cd5\u662f\u975e\u9759\u6001\u7684\u65f6\u5019&#xff0c;\u975e\u9759\u6001\u65b9\u6cd5\u53ef\u4ee5\u8c03\u7528\u9759\u6001\u65b9\u6cd5&#xff0c;\u53cd\u4e4b\u4e0d\u80fd\u3002<\/p>\n<\/li>\n<h4 id=\"_3\u3001\u8c03\u7528\u65b9\u6cd5\u65f6\u7684\u4f20\u53c2\">3\u3001\u8c03\u7528\u65b9\u6cd5\u65f6\u7684\u4f20\u53c2<\/h4>\n<p>1\u3001\u5f62\u53c2\u548c\u5b9e\u53c2<\/p>\n<\/p>\n<p>public static void test(int a){<\/p>\n<p>}<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int x &#061; 1;<br \/>\n    test(x);<br \/>\n} <\/p>\n<p>\u53c2\u6570\u5217\u8868\u4e2d\u7684a\u662f\u65b9\u6cd5test\u7684\u5f62\u53c2(\u5f62\u5f0f\u4e0a\u7684\u53c2\u6570) \u8c03\u7528\u65b9\u6cd5\u65f6\u7684x\u662f\u65b9\u6cd5test\u7684\u5b9e\u53c2(\u5b9e\u9645\u4e0a\u7684\u53c2\u6570)<\/p>\n<p>\u6ce8\u610f&#xff1a;\u5f62\u53c2\u7684\u540d\u5b57\u548c\u5b9e\u53c2\u7684\u540d\u5b57\u90fd\u53ea\u662f\u4e00\u4e2a\u53d8\u91cf\u7684\u540d\u5b57,\u662f\u53ef\u4ee5\u968f\u4fbf\u5199\u7684,\u6211\u4eec\u5e76\u4e0d\u5173\u5fc3\u8fd9\u4e2a\u540d\u5b57,\u800c\u662f\u5173 \u5fc3\u53d8\u91cf\u7684\u7c7b\u578b\u4ee5\u53ca\u53d8\u91cf\u63a5\u6536\u7684\u503c\u3002<\/p>\n<p>2\u3001\u503c\u4f20\u9012\u548c\u5f15\u7528\u4f20\u9012<\/p>\n<p>\u8c03\u7528\u65b9\u6cd5\u8fdb\u884c\u4f20\u53c2\u65f6&#xff0c;\u5206\u4e3a\u503c\u4f20\u9012\u548c\u5f15\u7528\u4f20\u9012\u4e24\u79cd\u3002<\/p>\n<p>\u5982\u679c\u53c2\u6570\u7684\u7c7b\u578b\u662f\u57fa\u672c\u6570\u636e\u7c7b\u578b&#xff0c;\u90a3\u4e48\u5c31\u662f\u503c\u4f20\u9012\u3002<\/p>\n<p>\u5982\u679c\u53c2\u6570\u7684\u7c7b\u578b\u662f\u5f15\u7528\u6570\u636e\u7c7b\u578b&#xff0c;\u90a3\u4e48\u5c31\u662f\u5f15\u7528\u4f20\u9012\u3002<\/p>\n<p>\u503c\u4f20\u9012\u662f\u5b9e\u53c2\u628a\u81ea\u5df1\u53d8\u91cf\u672c\u8eab\u5b58\u7684\u7b80\u5355\u6570\u503c\u8d4b\u503c\u7ed9\u5f62\u53c2\u3002 \u5f15\u7528\u4f20\u9012\u662f\u5b9e\u53c2\u628a\u81ea\u5df1\u53d8\u91cf\u672c\u8eab\u5b58\u7684\u5bf9\u8c61\u5185\u5b58\u5730\u5740\u503c\u8d4b\u503c\u7ed9\u5f62\u53c2\u3002<\/p>\n<p>\u6240\u4ee5\u503c\u4f20\u9012\u548c\u5f15\u7528\u4f20\u9012\u672c\u8d28\u4e0a\u662f\u4e00\u56de\u4e8b&#xff0c;\u53ea\u4e0d\u8fc7\u4f20\u9012\u7684\u4e1c\u897f\u7684\u610f\u4e49\u4e0d\u540c\u800c\u5df2\u3002<\/p>\n<p>\u3010\u793a\u4f8b&#xff1a;\u503c\u4f20\u9012\u3011<\/p>\n<\/p>\n<p>public static void changeNum(int a) {<br \/>\n    a &#061; 10;<br \/>\n}<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int a &#061; 1;<br \/>\n    System.out.println(&#034;before: a &#061; &#034; &#043; a); \/\/1<br \/>\n    changeNum(a);<br \/>\n    System.out.println(&#034;after: a &#061; &#034; &#043; a); \/\/1<br \/>\n} <\/p>\n<p>\u3010\u793a\u4f8b&#xff1a;\u5f15\u7528\u4f20\u9012\u3011<\/p>\n<\/p>\n<p>public class Test {<br \/>\n    public static void changeName(Student s) {<br \/>\n        s.name &#061; &#034;tom&#034;;<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        Student s &#061; new Student();<br \/>\n        System.out.println(&#034;before: name &#061; &#034; &#043; s.name); \/\/null<br \/>\n        changeName(s);<br \/>\n        System.out.println(&#034;after: name &#061; &#034; &#043; s.name); \/\/tom<br \/>\n    }<\/p>\n<p>    static class Student {<br \/>\n        String name;<br \/>\n    }<\/p>\n<p>} <\/p>\n<h4 id=\"_4\u3001this\u5173\u952e\u5b57\">4\u3001this\u5173\u952e\u5b57<\/h4>\n<p>\u5728\u7c7b\u4e2d&#xff0c;\u53ef\u4ee5\u4f7f\u7528this\u5173\u952e\u5b57\u8868\u793a\u4e00\u4e9b\u7279\u6b8a\u7684\u4f5c\u7528\u3002<\/p>\n<p>1\u3001this\u5728\u7c7b\u4e2d\u7684\u4f5c\u7528<\/p>\n<p>\u533a\u522b\u6210\u5458\u53d8\u91cf\u548c\u5c40\u90e8\u53d8\u91cf<\/p>\n<\/p>\n<p>public class Student{<br \/>\n    private String name;<br \/>\n    public void setName(String name){<br \/>\n        \/\/this.name\u8868\u793a\u7c7b\u4e2d\u7684\u5c5e\u6027name<br \/>\n        this.name &#061; name;<br \/>\n    }<br \/>\n} <\/p>\n<p>\u8c03\u7528\u7c7b\u4e2d\u7684\u5176\u4ed6\u65b9\u6cd5<\/p>\n<\/p>\n<p>public class Student{<br \/>\n    private String name;<br \/>\n    public void setName(String name){<br \/>\n        this.name &#061; name;<br \/>\n    }<br \/>\n    public void print(){<br \/>\n        \/\/\u8868\u793a\u8c03\u7528\u5f53\u524d\u7c7b\u4e2d\u7684setName\u65b9\u6cd5<br \/>\n        this.setName(&#034;tom&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u6ce8&#xff1a;\u9ed8\u8ba4\u60c5\u51b5\u4e0b&#xff0c;setName(&#034;tom&#034;)\u548cthis.setName(&#034;tom&#034;)\u7684\u6548\u679c\u662f\u4e00\u6837\u7684\u3002<\/p>\n<p>\u8c03\u7528\u7c7b\u4e2d\u7684\u5176\u4ed6\u6784\u9020\u5668<\/p>\n<\/p>\n<p>public class Student{<br \/>\n    private String name;<br \/>\n    public Student(){<br \/>\n        \/\/\u8c03\u7528\u4e00\u4e2a\u53c2\u6570\u7684\u6784\u9020\u5668,\u5e76\u4e14\u53c2\u6570\u7684\u7c7b\u578b\u662fString<br \/>\n        this(&#034;tom&#034;);<br \/>\n    }<br \/>\n    public Student(String name){<br \/>\n        this.name &#061; name;<br \/>\n    }<br \/>\n} <\/p>\n<p>\u6ce8&#xff1a;this\u7684\u8fd9\u79cd\u7528\u6cd5&#xff0c;\u53ea\u80fd\u5728\u6784\u9020\u5668\u4e2d\u4f7f\u7528\u3002\u666e\u901a\u7684\u65b9\u6cd5\u662f\u4e0d\u80fd\u7528\u7684\u3002\u5e76\u4e14\u8fd9\u5c40\u8c03\u7528\u7684\u4ee3\u7801\u53ea\u80fd\u51fa\u73b0\u5728\u6784\u9020\u5668\u4e2d\u7684\u7b2c\u4e00\u53e5\u3002<\/p>\n<p>\u3010\u793a\u4f8b\u3011<\/p>\n<\/p>\n<p>public class Student{<br \/>\n    private String name;<br \/>\n    \/\/\u7f16\u8bd1\u62a5\u9519,\u56e0\u4e3athis(&#034;tom&#034;)\u4e0d\u662f\u6784\u9020\u5668\u4e2d\u7684\u7b2c\u4e00\u53e5\u4ee3\u7801.<br \/>\n    public Student(){<br \/>\n        System.out.println(&#034;hello&#034;);<br \/>\n        this(&#034;tom&#034;);<br \/>\n    }<br \/>\n    public Student(String name){<br \/>\n        this.name &#061; name;<br \/>\n    }<br \/>\n} <\/p>\n<p>2\u3001this\u5173\u952e\u5b57\u5728\u7c7b\u4e2d\u7684\u610f\u4e49<\/p>\n<p>this\u5728\u7c7b\u4e2d\u8868\u793a\u5f53\u524d\u7c7b\u5c06\u6765\u521b\u5efa\u51fa\u7684\u5bf9\u8c61\u3002<\/p>\n<p>\u3010\u4f8b\u5b50\u3011<\/p>\n<\/p>\n<p>public class Student {<br \/>\n    private String name;<\/p>\n<p>    public Student() {<br \/>\n        System.out.println(&#034;this &#061; &#034; &#043; this);<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        Student s &#061; new Student();<br \/>\n        System.out.println(&#034;s &#061; &#034; &#043; s);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u8fd0\u884c\u540e\u770b\u7ed3\u679c\u53ef\u77e5&#xff0c;this\u548cs\u6253\u5370\u7684\u7ed3\u679c\u662f\u4e00\u6837\u7684&#xff0c;\u90a3\u4e48\u5176\u5b9e\u4e5f\u5c31\u662f\u53d8\u91cfs\u662f\u4ece\u5bf9\u8c61\u7684\u5916\u90e8\u6267\u884c\u5bf9\u8c61&#xff0c;\u800cthis\u662f\u5728\u5bf9\u8c61\u7684\u5185\u90e8\u6267\u884c\u5bf9\u8c61\u672c\u8eab\u3002<\/p>\n<p>\u8fd9\u6837\u4e5f\u5c31\u80fd\u7406\u89e3\u4e3a\u4ec0\u4e48this.name\u4ee3\u8868\u7684\u662f\u6210\u5458\u53d8\u91cf&#xff0c;this.setName(&#034;tom&#034;)\u4ee3\u8868\u7684\u662f\u8c03\u7528\u6210\u5458\u65b9\u6cd5\u3002\u56e0\u4e3a\u8fd9\u4fe9\u53e5\u4ee3\u7801\u4ece\u672c\u8d28\u4e0a\u8bb2&#xff0c;\u548c\u5728\u5bf9\u8c61\u5916\u90e8\u4f7f\u7528\u53d8\u91cfs\u6765\u8c03\u7528\u662f\u4e00\u6837\u7684&#xff0c;s.name\u548cs.setName(&#034;tom&#034;)<\/p>\n<p>\u3010this\u548cs\u6253\u5370\u51fa\u6765\u7684\u5185\u5b58\u5730\u5740\u662f\u4e00\u6837\u7684&#xff0c;\u4f7f\u7528&#061;&#061;\u6bd4\u8f83\u7684\u7ed3\u679c\u4e3atrue\u3002\u3011<\/p>\n<\/p>\n<p>public class Student{<br \/>\n    public Student getStudent(){<br \/>\n        return this;<br \/>\n    }<br \/>\n    public static void main(String[] args) {<br \/>\n        Student s1 &#061; new Student();<br \/>\n        Student s2 &#061; s1.getStudent();<br \/>\n        System.out.println(s1 &#061;&#061; s2);\/\/true<br \/>\n    }<br \/>\n} <\/p>\n<p>\u3010\u8c03\u7528\u7c7b\u4e2d\u7684this&#xff0c;s1\u548cs2\u4e0d\u76f8\u7b49\u3011<\/p>\n<\/p>\n<p>public class Student{<br \/>\n    private String name;<br \/>\n    public void test(){<br \/>\n        System.out.println(this);<br \/>\n    }<br \/>\n    public static void main(String[] args) {<br \/>\n        Student s1 &#061; new Student();<br \/>\n        Student s2 &#061; new Student();<br \/>\n        s1.test();<br \/>\n        s2.test();<br \/>\n    }<br \/>\n} <\/p>\n<p>\u6ce8&#xff1a;\u8fd9\u53e5\u8bdd\u662f\u8981\u8fd9\u4e48\u6765\u63cf\u8ff0\u7684&#xff0c;s1\u5bf9\u8c61\u4e2d\u7684this\u548cs1\u76f8\u7b49&#xff0c;s2\u5bf9\u8c61\u4e2d\u7684this\u548cs2\u76f8\u7b49&#xff0c;\u56e0\u4e3a\u7c7b\u662f\u6a21\u677f&#xff0c;\u6a21\u677f\u4e2d\u5199\u7684this\u5e76\u4e0d\u662f\u53ea\u6709\u4e00\u4e2a&#xff0c;\u6bcf\u4e2a\u5bf9\u8c61\u4e2d\u90fd\u6709\u4e00\u4e2a\u5c5e\u4e8e\u81ea\u5df1\u7684this&#xff0c;\u5c31\u662f\u6bcf\u4e2a\u5bf9\u8c61\u4e2d\u90fd\u4e00\u4e2a\u5c5e\u4e8e\u81ea\u5df1\u7684name\u5c5e\u6027\u4e00\u6837\u3002<\/p>\n<h3 id=\"\u521b\u5efa\u4e0e\u521d\u59cb\u5316\u5bf9\u8c61\">\u521b\u5efa\u4e0e\u521d\u59cb\u5316\u5bf9\u8c61<\/h3>\n<p>\u4f7f\u7528new\u5173\u952e\u5b57\u521b\u5efa\u5bf9\u8c61<\/p>\n<p>\u4f7f\u7528new\u5173\u952e\u5b57\u521b\u5efa\u7684\u65f6\u5019&#xff0c;\u9664\u4e86\u5206\u914d\u5185\u5b58\u7a7a\u95f4\u4e4b\u5916&#xff0c;\u8fd8\u4f1a\u7ed9\u521b\u5efa\u597d\u7684\u5bf9\u8c61\u8fdb\u884c\u9ed8\u8ba4\u7684\u521d\u59cb\u5316&#xff0c;\u4ee5\u53ca\u5bf9\u7c7b\u4e2d\u6784\u9020\u5668\u7684\u8c03\u7528\u3002<\/p>\n<p>\u90a3\u4e48\u5bf9main\u65b9\u6cd5\u4e2d\u7684\u4ee5\u4e0b\u4ee3\u7801&#xff1a;Student s &#061; new Student();<\/p>\n<p>1&#xff09; \u4e3a\u5bf9\u8c61\u5206\u914d\u5185\u5b58\u7a7a\u95f4&#xff0c;\u5c06\u5bf9\u8c61\u7684\u5b9e\u4f8b\u53d8\u91cf\u81ea\u52a8\u521d\u59cb\u5316\u9ed8\u8ba4\u503c\u4e3a0\/false\/null\u3002(\u5b9e\u4f8b\u53d8\u91cf\u7684\u9690\u5f0f\u8d4b\u503c)<\/p>\n<p>2&#xff09; \u5982\u679c\u4ee3\u7801\u4e2d\u5b9e\u4f8b\u53d8\u91cf\u6709\u663e\u5f0f\u8d4b\u503c&#xff0c;\u90a3\u4e48\u5c31\u5c06\u4e4b\u524d\u7684\u9ed8\u8ba4\u503c\u8986\u76d6\u6389\u3002(\u4e4b\u540e\u53ef\u4ee5\u901a\u8fc7\u4f8b\u5b50\u770b\u5230\u8fd9\u4e2a\u73b0\u8c61)<\/p>\n<p>\u4f8b\u5982&#xff1a;\u663e\u5f0f\u8d4b\u503c&#xff0c;private String name &#061; &#034;tom&#034;;<\/p>\n<p>3&#xff09; \u8c03\u7528\u6784\u9020\u5668<\/p>\n<p>4&#xff09; \u628a\u5bf9\u8c61\u5185\u5b58\u5730\u5740\u503c\u8d4b\u503c\u7ed9\u53d8\u91cf\u3002(&#061;\u53f7\u8d4b\u503c\u64cd\u4f5c)<\/p>\n<h3 id=\"\u6784\u9020\u5668\">\u6784\u9020\u5668<\/h3>\n<p>\u7c7b\u4e2d\u7684\u6784\u9020\u5668\u4e5f\u79f0\u4e3a\u6784\u9020\u65b9\u6cd5&#xff0c;\u662f\u5728\u8fdb\u884c\u521b\u5efa\u5bf9\u8c61\u7684\u65f6\u5019\u5fc5\u987b\u8981\u8c03\u7528\u7684\u3002\u5e76\u4e14\u6784\u9020\u5668\u6709\u4ee5\u4e0b\u4fe9\u4e2a\u7279\u70b9:<\/p>\n<li>\u5fc5\u987b\u548c\u7c7b\u7684\u540d\u5b57\u76f8\u540c<\/li>\n<li>\u5fc5\u987b\u6ca1\u6709\u8fd4\u56de\u7c7b\u578b,\u4e5f\u4e0d\u80fd\u5199void<\/li>\n<p>\u6784\u9020\u5668\u7684\u4f5c\u7528:<\/p>\n<li>\u4f7f\u7528new\u521b\u5efa\u5bf9\u8c61\u7684\u65f6\u5019\u5fc5\u987b\u4f7f\u7528\u7c7b\u7684\u6784\u9020\u5668<\/li>\n<li>\u6784\u9020\u5668\u4e2d\u7684\u4ee3\u7801\u6267\u884c\u540e&#xff0c;\u53ef\u4ee5\u7ed9\u5bf9\u8c61\u4e2d\u7684\u5c5e\u6027\u521d\u59cb\u5316\u8d4b\u503c<\/li>\n<p>\u3010\u6f14\u793a\u3011<\/p>\n<\/p>\n<p>public class Student{<br \/>\n    private String name;<\/p>\n<p>    public Student(){<br \/>\n        name &#061; &#034;tom&#034;;<br \/>\n    }<br \/>\n} <\/p>\n<p>\u6784\u9020\u5668\u91cd\u8f7d<\/p>\n<p>\u9664\u4e86\u65e0\u53c2\u6784\u9020\u5668\u4e4b\u5916&#xff0c;\u5f88\u591a\u65f6\u5019\u6211\u4eec\u8fd8\u4f1a\u4f7f\u7528\u6709\u53c2\u6784\u9020\u5668&#xff0c;\u5728\u521b\u5efa\u5bf9\u8c61\u65f6\u5019\u53ef\u4ee5\u7ed9\u5c5e\u6027\u8d4b\u503c\u3002<\/p>\n<p>\u3010\u4f8b\u5b50\u3011<\/p>\n<\/p>\n<p>public class Student{<br \/>\n    private String name;<br \/>\n    public Student(){<br \/>\n        name &#061; &#034;tom&#034;;<br \/>\n    }<br \/>\n    public Student(String name){<br \/>\n        this.name &#061; name;<br \/>\n    }<br \/>\n} <\/p>\n<p>\u6784\u9020\u5668\u4e4b\u95f4\u7684\u8c03\u7528<\/p>\n<p>\u4f7f\u7528this\u5173\u952e\u5b57&#xff0c;\u5728\u4e00\u4e2a\u6784\u9020\u5668\u4e2d\u53ef\u4ee5\u8c03\u7528\u53e6\u4e00\u4e2a\u6784\u9020\u5668\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u6ce8\u610f&#xff1a;this\u7684\u8fd9\u79cd\u7528\u6cd5\u4e0d\u4f1a\u4ea7\u751f\u65b0\u7684\u5bf9\u8c61&#xff0c;\u53ea\u662f\u8c03\u7528\u4e86\u6784\u9020\u5668\u4e2d\u7684\u4ee3\u7801\u800c\u5df2\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\u53ea\u6709\u4f7f\u7528new\u5173\u952e\u5b57\u624d\u4f1a\u521b\u5efa\u65b0\u5bf9\u8c61\u3002<\/p>\n<p>\u3010\u6f14\u793a\u3011<\/p>\n<\/p>\n<p>public class Student{<br \/>\n    private String name;<br \/>\n    public Student(){<br \/>\n        this();<br \/>\n    }<br \/>\n    public Student(String name){<br \/>\n        this.name &#061; name;<br \/>\n    }<br \/>\n} <\/p>\n<p>\u9ed8\u8ba4\u6784\u9020\u5668<\/p>\n<p>\u5728java\u4e2d&#xff0c;\u5373\u4f7f\u6211\u4eec\u5728\u7f16\u5199\u7c7b\u7684\u65f6\u5019\u6ca1\u6709\u5199\u6784\u9020\u5668&#xff0c;\u90a3\u4e48\u5728\u7f16\u8bd1\u4e4b\u540e\u4e5f\u4f1a\u81ea\u52a8\u7684\u6dfb\u52a0\u4e00\u4e2a\u65e0\u53c2\u6784\u9020\u5668&#xff0c;\u8fd9\u4e2a\u65e0\u53c2\u6784\u9020\u5668\u4e5f\u88ab\u79f0\u4e3a\u9ed8\u8ba4\u7684\u6784\u9020\u5668\u3002<\/p>\n<p>\u3010\u793a\u4f8b\u3011<\/p>\n<\/p>\n<p>public class Student{<\/p>\n<p>}<\/p>\n<p>main:<br \/>\n\/\/\u7f16\u8bd1\u901a\u8fc7,\u56e0\u4e3a\u6709\u65e0\u53c2\u6784\u9020\u5668<br \/>\nStudent s &#061; new Student(); <\/p>\n<p>\u4f46\u662f,\u5982\u679c\u6211\u4eec\u624b\u52a8\u7684\u7f16\u5199\u4e86\u4e00\u4e2a\u6784\u9020\u5668,\u90a3\u4e48\u7f16\u8bd1\u540e\u5c31\u4e0d\u4f1a\u6dfb\u52a0\u4efb\u4f55\u6784\u9020\u5668\u4e86<\/p>\n<p>\u3010\u793a\u4f8b\u3011<\/p>\n<\/p>\n<p>public class Student{<br \/>\n    private String name;<br \/>\n    public Student(String name){<br \/>\n        this.name &#061; name;<br \/>\n    }<br \/>\n}<\/p>\n<p>main:<br \/>\n\/\/\u7f16\u8bd1\u62a5\u9519,\u56e0\u4e3a\u6ca1\u6709\u65e0\u53c2\u6784\u9020\u5668<br \/>\nStudent s &#061; new Student(); <\/p>\n<h3 id=\"\u5185\u5b58\u5206\u6790\">\u5185\u5b58\u5206\u6790<\/h3>\n<p>JAVA\u7a0b\u5e8f\u8fd0\u884c\u7684\u5185\u5b58\u5206\u6790<\/p>\n<p>\u6808 stack&#xff1a;<\/p>\n<li>\u6bcf\u4e2a\u7ebf\u7a0b\u79c1\u6709&#xff0c;\u4e0d\u80fd\u5b9e\u73b0\u7ebf\u7a0b\u95f4\u7684\u5171\u4eab&#xff01;<\/li>\n<li>\u5c40\u90e8\u53d8\u91cf\u653e\u7f6e\u4e8e\u6808\u4e2d\u3002<\/li>\n<li>\u6808\u662f\u7531\u7cfb\u7edf\u81ea\u52a8\u5206\u914d&#xff0c;\u901f\u5ea6\u5feb&#xff01;\u6808\u662f\u4e00\u4e2a\u8fde\u7eed\u7684\u5185\u5b58\u7a7a\u95f4&#xff01;<\/li>\n<p>\u5806 heap&#xff1a;<\/p>\n<li>\u653e\u7f6enew\u51fa\u6765\u7684\u5bf9\u8c61&#xff01;<\/li>\n<li>\u5806\u662f\u4e00\u4e2a\u4e0d\u8fde\u7eed\u7684\u5185\u5b58\u7a7a\u95f4&#xff0c;\u5206\u914d\u7075\u6d3b&#xff0c;\u901f\u5ea6\u6162&#xff01;<\/li>\n<p>\u65b9\u6cd5\u533a(\u4e5f\u662f\u5806)&#xff1a;<\/p>\n<li>\u88ab\u6240\u6709\u7ebf\u7a0b\u5171\u4eab&#xff01;<\/li>\n<li>\u7528\u6765\u5b58\u653e\u7a0b\u5e8f\u4e2d\u6c38\u8fdc\u662f\u4e0d\u53d8\u6216\u552f\u4e00\u7684\u5185\u5bb9\u3002&#xff08;\u7c7b\u4ee3\u7801\u4fe1\u606f\u3001\u9759\u6001\u53d8\u91cf\u3001\u5b57\u7b26\u4e32\u5e38\u91cf&#xff09;<\/li>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"475\" src=\"2026-01-14k4ulniezyt4.png\" width=\"1098\" \/><\/p>\n<p>\u6ce8\u610f&#xff1a;\u672c\u6b21\u5185\u5b58\u5206\u6790&#xff0c;\u6211\u4eec\u7684\u4e3b\u8981\u76ee\u7684\u662f\u8ba9\u5927\u5bb6\u4e86\u89e3\u57fa\u672c\u7684\u5185\u5b58\u6982\u5ff5\u3002\u7c7b\u52a0\u8f7d\u5668\u3001Class\u5bf9\u8c61\u8fd9\u4e9b\u66f4\u52a0\u8be6\u7ec6\u7684\u5185\u5bb9&#xff0c;\u6211\u4eec\u5c06\u5728\u540e\u9762\u4e13\u95e8\u8bb2\u53cd\u5c04\u7684\u8bfe\u7a0b\u91cc\u9762\u8bb2\u3002<\/p>\n<p>\u5f15\u7528\u7c7b\u578b\u7684\u6982\u5ff5<\/p>\n<li>java\u4e2d&#xff0c;\u9664\u4e86\u57fa\u672c\u6570\u636e\u7c7b\u578b\u4e4b\u5916\u7684\u5176\u4ed6\u7c7b\u578b\u79f0\u4e4b\u4e3a\u5f15\u7528\u7c7b\u578b\u3002<\/li>\n<li>java\u4e2d\u7684\u5bf9\u8c61\u662f\u901a\u8fc7\u5f15\u7528\u6765\u64cd\u4f5c\u7684\u3002(\u5f15\u7528&#xff1a;reference)\u8bf4\u767d\u4e86&#xff0c;\u5f15\u7528\u6307\u7684\u5c31\u662f\u5bf9\u8c61\u7684\u5730\u5740&#xff01;<\/li>\n<p>\u5c5e\u6027&#xff08;field&#xff0c;\u6216\u8005\u53eb\u6210\u5458\u53d8\u91cf&#xff09;<\/p>\n<li>\n<p>\u5c5e\u6027\u7528\u4e8e\u5b9a\u4e49\u8be5\u7c7b\u6216\u8be5\u7c7b\u5bf9\u8c61\u5305\u542b\u7684\u6570\u636e\u6216\u8005\u8bf4\u9759\u6001\u5c5e\u6027\u3002<\/p>\n<\/li>\n<li>\n<p>\u5c5e\u6027\u4f5c\u7528\u8303\u56f4\u662f\u6574\u4e2a\u7c7b\u4f53\u3002<\/p>\n<\/li>\n<li>\n<p>\u5c5e\u6027\u7684\u9ed8\u8ba4\u521d\u59cb\u5316&#xff1a;<\/p>\n<\/li>\n<p>\u5728\u5b9a\u4e49\u6210\u5458\u53d8\u91cf\u65f6\u53ef\u4ee5\u5bf9\u5176\u521d\u59cb\u5316&#xff0c;\u5982\u679c\u4e0d\u5bf9\u5176\u521d\u59cb\u5316&#xff0c;Java\u4f7f\u7528\u9ed8\u8ba4\u7684\u503c\u5bf9\u5176\u521d\u59cb\u5316(\u6570\u503c&#xff1a;0,0.0 char&#xff1a;u0000, boolean&#xff1a;false, \u6240\u6709\u5f15\u7528\u7c7b\u578b&#xff1a;null)<\/p>\n<li>\n<p>\u5c5e\u6027\u5b9a\u4e49\u683c\u5f0f&#xff1a;<\/p>\n<p>[\u4fee\u9970\u7b26] \u5c5e\u6027\u7c7b\u578b \u5c5e\u6027\u540d &#061; [\u9ed8\u8ba4\u503c]<\/p>\n<\/li>\n<p>\u7c7b\u7684\u65b9\u6cd5<\/p>\n<p>\u65b9\u6cd5\u662f\u7c7b\u548c\u5bf9\u8c61\u52a8\u6001\u884c\u4e3a\u7279\u5f81\u7684\u62bd\u8c61\u3002\u65b9\u6cd5\u5f88\u7c7b\u4f3c\u4e8e\u9762\u5411\u8fc7\u7a0b\u4e2d\u7684\u51fd\u6570\u3002\u9762\u5411\u8fc7\u7a0b\u4e2d&#xff0c;\u51fd\u6570\u662f\u6700\u57fa\u672c\u5355\u4f4d&#xff0c;\u6574\u4e2a\u7a0b\u5e8f\u6709\u4e00\u4e2a\u4e2a\u51fd\u6570\u8c03\u7528\u7ec4\u6210&#xff1b;\u9762\u5411\u5bf9\u8c61\u4e2d&#xff0c;\u6574\u4e2a\u7a0b\u5e8f\u7684\u57fa\u672c\u5355\u4f4d\u662f\u7c7b&#xff0c;\u65b9\u6cd5\u662f\u4ece\u5c5e\u4e8e\u7c7b\u6216\u5bf9\u8c61\u7684\u3002<\/p>\n<p>\u65b9\u6cd5\u5b9a\u4e49\u683c\u5f0f&#xff1a;<\/p>\n<\/p>\n<p>[\u4fee\u9970\u7b26] \u65b9\u6cd5\u8fd4\u56de\u503c\u7c7b\u578b \u65b9\u6cd5\u540d(\u5f62\u53c2\u5217\u8868) {<br \/>\n    \/\/ n\u6761\u8bed\u53e5<br \/>\n} <\/p>\n<p>java\u5bf9\u8c61\u7684\u521b\u5efa\u548c\u4f7f\u7528<\/p>\n<ul>\n<li>\n<p>\u5fc5\u987b\u4f7f\u7528 new \u5173\u952e\u5b57\u521b\u5efa\u5bf9\u8c61\u3002<\/p>\n<p>Person person&#061; new Person ();<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528\u5bf9\u8c61&#xff08;\u5f15\u7528&#xff09;.\u6210\u5458\u53d8\u91cf\u6765\u5f15\u7528\u5bf9\u8c61\u7684\u6210\u5458\u53d8\u91cf\u3002<\/p>\n<p>person.age<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528\u5bf9\u8c61&#xff08;\u5f15\u7528&#xff09;. \u65b9\u6cd5&#xff08;\u53c2\u6570\u5217\u8868&#xff09;\u6765\u8c03\u7528\u5bf9\u8c61\u7684\u65b9\u6cd5<\/p>\n<p>person.setAge(18)<\/p>\n<\/li>\n<\/ul>\n<p>\u7c7b\u4e2d\u5c31\u662f&#xff1a;\u9759\u6001\u7684\u6570\u636e \u52a8\u6001\u7684\u884c\u4e3a<\/p>\n<p>\u5b66\u4e60\u5b8c\u7c7b\u4e0e\u5bf9\u8c61\u7ec8\u4e8e\u8ba4\u8bc6\u5230\u4ec0\u4e48\u662f\u7c7b&#xff0c;\u4ec0\u4e48\u662f\u5bf9\u8c61\u4e86\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u8981\u770b\u7684\u5c31\u662fjava\u7684\u4e09\u5927\u7279\u5f81&#xff1a;\u7ee7\u627f\u3001\u5c01 \u88c5\u3001\u591a\u6001\u3002<\/p>\n<h3 id=\"\u5c01\u88c5\">\u5c01\u88c5<\/h3>\n<p>\u6211\u8981\u770b\u7535\u89c6&#xff0c;\u53ea\u9700\u8981\u6309\u4e00\u4e0b\u5f00\u5173\u548c\u6362\u53f0\u5c31\u53ef\u4ee5\u4e86\u3002\u6709\u5fc5\u8981\u4e86\u89e3\u7535\u89c6\u673a\u5185\u90e8\u7684\u7ed3\u6784\u5417&#xff1f;\u6709\u5fc5\u8981\u78b0\u78b0\u663e\u50cf\u7ba1\u5417&#xff1f;<\/p>\n<p>\u5236\u9020\u5382\u5bb6\u4e3a\u4e86\u65b9\u4fbf\u6211\u4eec\u4f7f\u7528\u7535\u89c6&#xff0c;\u628a\u590d\u6742\u7684\u5185\u90e8\u7ec6\u8282\u5168\u90e8\u5c01\u88c5\u8d77\u6765&#xff0c;\u53ea\u7ed9\u6211\u4eec\u66b4\u9732\u7b80\u5355\u7684\u63a5\u53e3&#xff0c;\u6bd4\u5982&#xff1a; \u7535\u6e90\u5f00\u5173\u3002\u9700\u8981\u8ba9\u7528\u6237\u77e5\u9053\u7684\u66b4\u9732\u51fa\u6765&#xff0c;\u4e0d\u9700\u8981\u8ba9\u7528\u6237\u4e86\u89e3\u7684\u5168\u90e8\u9690\u85cf\u8d77\u6765\u3002\u8fd9\u5c31\u662f\u5c01\u88c5\u3002<\/p>\n<p>\u767d\u8bdd&#xff1a;\u8be5\u9732\u7684\u9732&#xff0c;\u8be5\u85cf\u7684\u85cf<\/p>\n<p>\u4e13\u4e1a&#xff1a;\u6211\u4eec\u7a0b\u5e8f\u8bbe\u8ba1\u8981\u8ffd\u6c42\u201c\u9ad8\u5185\u805a&#xff0c;\u4f4e\u8026\u5408\u201d\u3002\u9ad8\u5185\u805a\u5c31\u662f\u7c7b\u7684\u5185\u90e8\u6570\u636e\u64cd\u4f5c\u7ec6\u8282\u81ea\u5df1\u5b8c\u6210&#xff0c;\u4e0d\u5141\u8bb8\u5916\u90e8\u5e72\u6d89&#xff1b;\u4f4e\u8026\u5408&#xff1a;\u4ec5\u66b4\u9732\u5c11\u91cf\u7684\u65b9\u6cd5\u7ed9\u5916\u90e8\u4f7f\u7528\u3002<\/p>\n<p>\u5c01\u88c5&#xff08;\u6570\u636e\u7684\u9690\u85cf&#xff09;<\/p>\n<p>\u5728\u5b9a\u4e49\u4e00\u4e2a\u5bf9\u8c61\u7684\u7279\u6027\u7684\u65f6\u5019&#xff0c;\u6709\u5fc5\u8981\u51b3\u5b9a\u8fd9\u4e9b\u7279\u6027\u7684\u53ef\u89c1\u6027&#xff0c;\u5373\u54ea\u4e9b\u7279\u6027\u5bf9\u5916\u90e8\u662f\u53ef\u89c1\u7684&#xff0c;\u54ea\u4e9b\u7279\u6027\u7528\u4e8e\u8868\u793a\u5185\u90e8\u72b6\u6001\u3002<\/p>\n<p>\u901a\u5e38&#xff0c;\u5e94\u7981\u6b62\u76f4\u63a5\u8bbf\u95ee\u4e00\u4e2a\u5bf9\u8c61\u4e2d\u6570\u636e\u7684\u5b9e\u9645\u8868\u793a&#xff0c;\u800c\u5e94\u901a\u8fc7\u64cd\u4f5c\u63a5\u53e3\u6765\u8bbf\u95ee&#xff0c;\u8fd9\u79f0\u4e3a\u4fe1\u606f\u9690\u85cf\u3002<\/p>\n<h4 id=\"_1\u3001\u5c01\u88c5\u7684\u6b65\u9aa4\">1\u3001\u5c01\u88c5\u7684\u6b65\u9aa4<\/h4>\n<li>\n<p>\u4f7f\u7528private \u4fee\u9970\u9700\u8981\u5c01\u88c5\u7684\u6210\u5458\u53d8\u91cf\u3002<\/p>\n<\/li>\n<li>\n<p>\u63d0\u4f9b\u4e00\u4e2a\u516c\u5f00\u7684\u65b9\u6cd5\u8bbe\u7f6e\u6216\u8005\u8bbf\u95ee\u79c1\u6709\u7684\u5c5e\u6027<\/p>\n<p>\u8bbe\u7f6e \u901a\u8fc7set\u65b9\u6cd5&#xff0c;\u547d\u540d\u683c\u5f0f&#xff1a; set\u5c5e\u6027\u540d&#xff08;&#xff09;; \u5c5e\u6027\u7684\u9996\u5b57\u6bcd\u8981\u5927\u5199<\/p>\n<p>\u8bbf\u95ee \u901a\u8fc7get\u65b9\u6cd5&#xff0c;\u547d\u540d\u683c\u5f0f&#xff1a; get\u5c5e\u6027\u540d&#xff08;&#xff09;; \u5c5e\u6027\u7684\u9996\u5b57\u6bcd\u8981\u5927\u5199<\/p>\n<\/li>\n<p>\u3010\u6f14\u793a\u3011<\/p>\n<\/p>\n<p>\/\/\u5bf9\u8c61\u80fd\u5728\u7c7b\u7684\u5916\u90e8&#034;\u76f4\u63a5&#034;\u8bbf\u95ee<br \/>\npublic class Student{<br \/>\n    public String name;<br \/>\n    public void println(){<br \/>\n        System.out.println(this.name);<br \/>\n    }<br \/>\n}<br \/>\npublic class Test{<br \/>\n    public static void main(String[] args){<br \/>\n        Student s &#061; new Student();<br \/>\n        s.name &#061; &#034;tom&#034;;<br \/>\n    }<br \/>\n} <\/p>\n<p>\u5728\u7c7b\u4e2d\u4e00\u822c\u4e0d\u4f1a\u628a\u6570\u636e\u76f4\u63a5\u66b4\u9732\u5728\u5916\u90e8\u7684&#xff0c;\u800c\u4f7f\u7528private(\u79c1\u6709)\u5173\u952e\u5b57\u628a\u6570\u636e\u9690\u85cf\u8d77\u6765<\/p>\n<p>\u3010\u6f14\u793a\u3011<\/p>\n<\/p>\n<p>public class Student{<br \/>\n    private String name;<br \/>\n}<br \/>\npublic class Test{<br \/>\n    public static void main(String[] args){<br \/>\n        Student s &#061; new Student();<br \/>\n        \/\/\u7f16\u8bd1\u62a5\u9519,\u5728\u7c7b\u7684\u5916\u90e8\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u7c7b\u4e2d\u7684\u79c1\u6709\u6210\u5458<br \/>\n        s.name &#061; &#034;tom&#034;;<br \/>\n    }<br \/>\n} <\/p>\n<p>\u5982\u679c\u5728\u7c7b\u7684\u5916\u90e8\u9700\u8981\u8bbf\u95ee\u8fd9\u4e9b\u79c1\u6709\u5c5e\u6027,\u90a3\u4e48\u53ef\u4ee5\u5728\u7c7b\u4e2d\u63d0\u4f9b\u5bf9\u4e8e\u7684get\u548cset\u65b9\u6cd5,\u4ee5\u4fbf\u8ba9\u7528\u6237\u5728\u7c7b\u7684\u5916\u90e8 \u53ef\u4ee5\u95f4\u63a5\u7684\u8bbf\u95ee\u5230\u79c1\u6709\u5c5e\u6027<\/p>\n<p>\u3010\u793a\u4f8b\u3011<\/p>\n<\/p>\n<p>\/\/set\u8d1f\u8d23\u7ed9\u5c5e\u6027\u8d4b\u503c<br \/>\n\/\/get\u8d1f\u8d23\u8fd4\u56de\u5c5e\u6027\u7684\u503c<br \/>\npublic class Student{<br \/>\n    private String name;<br \/>\n    public void setName(String name){<br \/>\n    this.name &#061; name;<br \/>\n}<br \/>\npublic String getName(){<br \/>\n        return this.name;<br \/>\n}<br \/>\n}<br \/>\npublic class Test{<br \/>\n    public static void main(String[] args){<br \/>\n        Student s &#061; new Student();<br \/>\n        s.setName(&#034;tom&#034;);<br \/>\n        System.out.println(s.getName());<br \/>\n    }<br \/>\n} <\/p>\n<h4 id=\"_2\u3001\u4f5c\u7528\u548c\u610f\u4e49\">2\u3001\u4f5c\u7528\u548c\u610f\u4e49<\/h4>\n<li>\u63d0\u9ad8\u7a0b\u5e8f\u7684\u5b89\u5168\u6027&#xff0c;\u4fdd\u62a4\u6570\u636e\u3002<\/li>\n<li>\u9690\u85cf\u4ee3\u7801\u7684\u5b9e\u73b0\u7ec6\u8282<\/li>\n<li>\u7edf\u4e00\u7528\u6237\u7684\u8c03\u7528\u63a5\u53e3<\/li>\n<li>\u63d0\u9ad8\u7cfb\u7edf\u7684\u53ef\u7ef4\u62a4\u6027<\/li>\n<li>\u4fbf\u4e8e\u8c03\u7528\u8005\u8c03\u7528\u3002<\/li>\n<p>\u826f\u597d\u7684\u5c01\u88c5&#xff0c;\u4fbf\u4e8e\u4fee\u6539\u5185\u90e8\u4ee3\u7801&#xff0c;\u63d0\u9ad8\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<p>\u826f\u597d\u7684\u5c01\u88c5&#xff0c;\u53ef\u8fdb\u884c\u6570\u636e\u5b8c\u6574\u6027\u68c0\u6d4b&#xff0c;\u4fdd\u8bc1\u6570\u636e\u7684\u6709\u6548\u6027\u3002<\/p>\n<h4 id=\"_3\u3001\u65b9\u6cd5\u91cd\u8f7d\">3\u3001\u65b9\u6cd5\u91cd\u8f7d<\/h4>\n<p>\u7c7b\u4e2d\u6709\u591a\u4e2a\u65b9\u6cd5&#xff0c;\u6709\u7740\u76f8\u540c\u7684\u65b9\u6cd5\u540d&#xff0c;\u4f46\u662f\u65b9\u6cd5\u7684\u53c2\u6570\u5404\u4e0d\u76f8\u540c,\u8fd9\u79cd\u60c5\u51b5\u88ab\u79f0\u4e3a\u65b9\u6cd5\u7684\u91cd\u8f7d\u3002\u65b9\u6cd5\u7684\u91cd\u8f7d\u53ef\u4ee5\u63d0\u4f9b\u65b9\u6cd5\u8c03\u7528\u7684\u7075\u6d3b\u6027\u3002<\/p>\n<p>\u601d\u8003&#xff1a;HelloWorld\u4e2d\u7684System.out.println()\u65b9\u6cd5&#xff0c;\u4e3a\u4ec0\u4e48\u53ef\u4ee5\u628a\u4e0d\u540c\u7c7b\u578b\u7684\u53c2\u6570\u4f20\u7ed9\u8fd9\u4e2a\u65b9\u6cd5?<\/p>\n<p>\u3010\u6f14\u793a&#xff1a;\u67e5\u770bprintln\u65b9\u6cd5\u7684\u91cd\u8f7d\u3011 idea\u4e2dctrl&#043;\u5de6\u952e\u70b9\u51fbprintln<\/p>\n<p>\u4f8b\u5982:<\/p>\n<\/p>\n<p>public class Test{<br \/>\n    public void test(String str){<\/p>\n<p>    }<br \/>\n    public void test(int a){<\/p>\n<p>    }<br \/>\n} <\/p>\n<p>\u65b9\u6cd5\u91cd\u8f7d\u5fc5\u987b\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6<\/p>\n<li>\n<p>\u65b9\u6cd5\u540d\u5fc5\u987b\u76f8\u540c<\/p>\n<\/li>\n<li>\n<p>\u53c2\u6570\u5217\u8868\u5fc5\u987b\u4e0d\u540c(\u53c2\u6570\u7684\u7c7b\u578b\u3001\u4e2a\u6570\u3001\u987a\u5e8f\u7684\u4e0d\u540c)<\/p>\n<p> public void test(Strig str){}<br \/>\npublic void test(int a){}<\/p>\n<p>public void test(Strig str,double d){}<br \/>\npublic void test(Strig str){}<\/p>\n<p>public void test(Strig str,double d){}<br \/>\npublic void test(double d,Strig str){} <\/p>\n<\/li>\n<li>\n<p>\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u53ef\u4ee5\u4e0d\u540c&#xff0c;\u4e5f\u53ef\u4ee5\u76f8\u540c\u3002<\/p>\n<\/li>\n<p>\u5728java\u4e2d&#xff0c;\u5224\u65ad\u4e00\u4e2a\u7c7b\u4e2d\u7684\u4fe9\u4e2a\u65b9\u6cd5\u662f\u5426\u76f8\u540c&#xff0c;\u4e3b\u8981\u53c2\u8003\u4fe9\u4e2a\u65b9\u9762&#xff1a;\u65b9\u6cd5\u540d\u5b57\u548c\u53c2\u6570\u5217\u8868<\/p>\n<h3 id=\"\u7ee7\u627f\">\u7ee7\u627f<\/h3>\n<p>\u7ee7\u627f&#xff1a;extands<\/p>\n<p>\u73b0\u5b9e\u4e16\u754c\u4e2d\u7684\u7ee7\u627f\u65e0\u5904\u4e0d\u5728\u3002\u6bd4\u5982&#xff1a;<\/p>\n<p>\u52a8\u7269&#xff1a;\u54fa\u4e73\u52a8\u7269\u3001\u722c\u884c\u52a8\u7269<\/p>\n<p>\u54fa\u4e73\u52a8\u7269&#xff1a;\u7075\u957f\u76ee\u3001\u9cb8\u76ee\u7b49\u3002<\/p>\n<p>\u7ee7\u627f\u7684\u672c\u8d28\u662f\u5bf9\u67d0\u4e00\u6279\u7c7b\u7684\u62bd\u8c61&#xff0c;\u4ece\u800c\u5b9e\u73b0\u5bf9\u73b0\u5b9e\u4e16\u754c\u66f4\u597d\u7684\u5efa\u6a21\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48\u9700\u8981\u7ee7\u627f&#xff1f;\u7ee7\u627f\u7684\u4f5c\u7528&#xff1f;<\/p>\n<p>\u7b2c\u4e00\u597d\u5904&#xff1a;\u7ee7\u627f\u7684\u672c\u8d28\u5728\u4e8e\u62bd\u8c61\u3002\u7c7b\u662f\u5bf9\u5bf9\u8c61\u7684\u62bd\u8c61&#xff0c;\u7ee7\u627f\u662f\u5bf9\u67d0\u4e00\u6279\u7c7b\u7684\u62bd\u8c61\u3002<\/p>\n<p>\u7b2c\u4e8c\u597d\u5904&#xff1a;\u4e3a\u4e86\u63d0\u9ad8\u4ee3\u7801\u7684\u590d\u7528\u6027\u3002<\/p>\n<p>extands\u7684\u610f\u601d\u662f\u201c\u6269\u5c55\u201d\u3002\u5b50\u7c7b\u662f\u7236\u7c7b\u7684\u6269\u5c55\u3002<\/p>\n<p>\u3010\u6ce8\u3011JAVA\u4e2d\u7c7b\u53ea\u6709\u5355\u7ee7\u627f&#xff0c;\u6ca1\u6709\u591a\u7ee7\u627f&#xff01; \u63a5\u53e3\u53ef\u4ee5\u591a\u7ee7\u627f&#xff01;<\/p>\n<h4 id=\"_1\u3001\u7ee7\u627f\">1\u3001\u7ee7\u627f<\/h4>\n<li>\n<p>\u7ee7\u627f\u662f\u7c7b\u548c\u7c7b\u4e4b\u95f4\u7684\u4e00\u79cd\u5173\u7cfb\u3002\u9664\u6b64\u4e4b\u5916,\u7c7b\u548c\u7c7b\u4e4b\u95f4\u7684\u5173\u7cfb\u8fd8\u6709\u4f9d\u8d56\u3001\u7ec4\u5408\u3001\u805a\u5408\u7b49\u3002<\/p>\n<\/li>\n<li>\n<p>\u7ee7\u627f\u5173\u7cfb\u7684\u4fe9\u4e2a\u7c7b&#xff0c;\u4e00\u4e2a\u4e3a\u5b50\u7c7b(\u6d3e\u751f\u7c7b),\u4e00\u4e2a\u4e3a\u7236\u7c7b(\u57fa\u7c7b)\u3002\u5b50\u7c7b\u7ee7\u627f\u7236\u7c7b&#xff0c;\u4f7f\u7528\u5173\u952e\u5b57extends\u6765\u8868\u793a\u3002<\/p>\n<p> public class student extends Person{<br \/>\n} <\/p>\n<\/li>\n<li>\n<p>\u5b50\u7c7b\u548c\u7236\u7c7b\u4e4b\u95f4&#xff0c;\u4ece\u610f\u4e49\u4e0a\u8bb2\u5e94\u8be5\u5177\u6709&#034;is a&#034;\u7684\u5173\u7cfb\u3002<\/p>\n<p>student is a person<\/p>\n<p>dog is a animal<\/p>\n<\/li>\n<li>\n<p>\u7c7b\u548c\u7c7b\u4e4b\u95f4\u7684\u7ee7\u627f\u662f\u5355\u7ee7\u627f<\/p>\n<p>\u4e00\u4e2a\u5b50\u7c7b\u53ea\u80fd&#034;\u76f4\u63a5&#034;\u7ee7\u627f\u4e00\u4e2a\u7236\u7c7b,\u5c31\u50cf\u662f\u4e00\u4e2a\u4eba\u53ea\u80fd\u6709\u4e00\u4e2a\u4eb2\u751f\u7236\u4eb2 \u4e00\u4e2a\u7236\u7c7b\u53ef\u4ee5\u88ab\u591a\u5b50\u7c7b\u7ee7\u627f,\u5c31\u50cf\u4e00\u4e2a\u7236\u4eb2\u53ef\u4ee5\u6709\u591a\u4e2a\u5b69\u5b50<\/p>\n<p>\u6ce8:java\u4e2d\u63a5\u53e3\u548c\u63a5\u53e3\u4e4b\u95f4,\u6709\u53ef\u4ee5\u7ee7\u627f,\u5e76\u4e14\u662f\u591a\u7ee7\u627f\u3002<\/p>\n<\/li>\n<li>\n<p>\u7236\u7c7b\u4e2d\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u53ef\u4ee5\u88ab\u5b50\u7c7b\u7ee7\u627f<\/p>\n<p>\u5b50\u7c7b\u4e2d\u7ee7\u627f\u4e86\u7236\u7c7b\u4e2d\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u540e,\u5728\u5b50\u7c7b\u4e2d\u80fd\u4e0d\u80fd\u76f4\u63a5\u4f7f\u7528\u8fd9\u4e9b\u5c5e\u6027\u548c\u65b9\u6cd5,\u662f\u548c\u8fd9\u4e9b\u5c5e\u6027\u548c\u65b9\u6cd5\u539f\u6709 \u7684\u4fee\u9970\u7b26(public protected default private)\u76f8\u5173\u7684\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>\u7236\u7c7b\u4e2d\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u4f7f\u7528public\u4fee\u9970&#xff0c;\u5728\u5b50\u7c7b\u4e2d\u7ee7\u627f\u540e&#034;\u53ef\u4ee5\u76f4\u63a5&#034;\u4f7f\u7528 \u7236\u7c7b\u4e2d\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u4f7f\u7528private\u4fee\u9970&#xff0c;\u5728\u5b50\u7c7b\u4e2d\u7ee7\u627f\u540e&#034;\u4e0d\u53ef\u4ee5\u76f4\u63a5&#034;\u4f7f\u7528<\/p>\n<p>\u6ce8&#xff1a;\u5177\u4f53\u7ec6\u5219\u5728\u4fee\u9970\u7b26\u90e8\u5206\u8be6\u7ec6\u8bf4\u660e<\/p>\n<p>\u7236\u7c7b\u4e2d\u7684\u6784\u9020\u5668\u662f\u4e0d\u80fd\u88ab\u5b50\u7c7b\u7ee7\u627f\u7684&#xff0c;\u4f46\u662f\u5b50\u7c7b\u7684\u6784\u9020\u5668\u4e2d&#xff0c;\u4f1a\u9690\u5f0f\u7684\u8c03\u7528\u7236\u7c7b\u4e2d\u7684\u65e0\u53c2\u6784\u9020\u5668&#xff08;\u9ed8\u8ba4\u4f7f\u7528 super\u5173\u952e\u5b57&#xff09;\u3002<\/p>\n<p>\u6ce8:\u5177\u4f53\u7ec6\u8282\u5728super\u5173\u952e\u5b57\u90e8\u5206\u8be6\u7ec6\u8bf4\u660e<\/p>\n<\/li>\n<h4 id=\"_2\u3001object\u7c7b\">2\u3001Object\u7c7b<\/h4>\n<p>java\u4e2d\u7684\u6bcf\u4e00\u4e2a\u7c7b\u90fd\u662f&#034;\u76f4\u63a5&#034; \u6216\u8005 &#034;\u95f4\u63a5&#034;\u7684\u7ee7\u627f\u4e86Object\u7c7b\u3002\u6240\u4ee5\u6bcf\u4e00\u4e2a\u5bf9\u8c61\u90fd\u548cObject\u7c7b\u6709&#034;is a&#034;\u7684\u5173\u7cfb\u3002\u4eceAPI\u6587\u6863\u4e2d&#xff0c;\u53ef\u4ee5\u770b\u5230\u4efb\u4f55\u4e00\u4e2a\u7c7b\u6700\u4e0a\u5c42\u7684\u7236\u7c7b\u90fd\u662fObject\u3002(Object\u7c7b\u672c\u8eab\u9664\u5916)AnyClass is a Object\u3002<\/p>\n<p>System.out.println(\u4efb\u4f55\u5bf9\u8c61 instanceof Object);<\/p>\n<p>\u8f93\u51fa\u7ed3\u679c:true \u6ce8:\u4efb\u4f55\u5bf9\u8c61\u4e5f\u5305\u542b\u6570\u7ec4\u5bf9\u8c61<\/p>\n<p>\u4f8b\u5982:<\/p>\n<\/p>\n<p>\/\/\u7f16\u8bd1\u540e,Person\u7c7b\u4f1a\u9ed8\u8ba4\u7ee7\u627fObject<br \/>\npublic class Person{}<\/p>\n<p>\/\/Student\u662f\u95f4\u63a5\u7684\u7ee7\u627f\u4e86Object<br \/>\npublic class Student extends Person{} <\/p>\n<p>\u5728Object\u7c7b\u4e2d&#xff0c;\u63d0\u4f9b\u4e86\u4e00\u4e9b\u65b9\u6cd5\u88ab\u5b50\u7c7b\u7ee7\u627f&#xff0c;\u90a3\u4e48\u5c31\u610f\u5473\u7740&#xff0c;\u5728java\u4e2d&#xff0c;\u4efb\u4f55\u4e00\u4e2a\u5bf9\u8c61\u90fd\u53ef\u4ee5\u8c03\u7528\u8fd9\u4e9b\u88ab\u7ee7\u627f\u8fc7\u6765\u7684\u65b9\u6cd5\u3002(\u56e0\u4e3aObject\u662f\u6240\u4ee5\u7c7b\u7684\u7236\u7c7b)<\/p>\n<p>\u4f8b\u5982&#xff1a;toString\u65b9\u6cd5\u3001equals\u65b9\u6cd5\u3001getClass\u65b9\u6cd5\u7b49<\/p>\n<h4 id=\"_3\u3001super\u5173\u952e\u5b57\">3\u3001Super\u5173\u952e\u5b57<\/h4>\n<p>\u5b50\u7c7b\u7ee7\u627f\u7236\u7c7b\u4e4b\u540e&#xff0c;\u5728\u5b50\u7c7b\u4e2d\u53ef\u4ee5\u4f7f\u7528this\u6765\u8868\u793a\u8bbf\u95ee\u6216\u8c03\u7528\u5b50\u7c7b\u4e2d\u7684\u5c5e\u6027\u6216\u65b9\u6cd5&#xff0c;\u4f7f\u7528super\u5c31\u8868\u793a\u8bbf\u95ee\u6216\u8c03\u7528\u7236\u7c7b\u4e2d\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002<\/p>\n<p>1\u3001super\u7684\u4f7f\u7528<\/p>\n<p>\u3010\u8bbf\u95ee\u7236\u7c7b\u4e2d\u7684\u5c5e\u6027\u3011<\/p>\n<\/p>\n<p>public class Person{<br \/>\n    protected String name &#061; &#034;zs&#034;;<br \/>\n} <\/p>\n<\/p>\n<p>public class Student extends Person{<br \/>\n    private String name &#061; &#034;lisi&#034;;<br \/>\n    public void tes(String name){<br \/>\n        System.out.println(name);<br \/>\n        System.out.println(this.name);<br \/>\n        System.out.println(super.name);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u3010\u8c03\u7528\u7236\u7c7b\u4e2d\u7684\u65b9\u6cd5\u3011<\/p>\n<\/p>\n<p>public class Person{<br \/>\n    public void print(){<br \/>\n        System.out.println(&#034;Person&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<\/p>\n<p>public class Student extends Person{<br \/>\n    public void print(){<br \/>\n        System.out.println(&#034;Student&#034;);<br \/>\n    }<br \/>\n    public void test(){<br \/>\n        print();<br \/>\n        this.print();<br \/>\n        super.print();<br \/>\n    }<br \/>\n} <\/p>\n<p>\u3010\u8c03\u7528\u7236\u7c7b\u4e2d\u7684\u6784\u9020\u5668\u3011<\/p>\n<\/p>\n<p>public class Person{<br \/>\n}<\/p>\n<p>public class Student extends Person{<br \/>\n    \/\/\u7f16\u8bd1\u901a\u8fc7,\u5b50\u7c7b\u6784\u9020\u5668\u4e2d\u4f1a\u9690\u5f0f\u7684\u8c03\u7528\u7236\u7c7b\u7684\u65e0\u53c2\u6784\u9020\u5668<br \/>\n    \/\/super();<br \/>\n    public Student(){<br \/>\n    }<br \/>\n} <\/p>\n<p>\u7236\u7c7b\u6ca1\u6709\u65e0\u53c2\u6784\u9020<\/p>\n<\/p>\n<p>public class Person{<br \/>\n    protected String name;<br \/>\n    public Person(String name){<br \/>\n        this.name &#061; name;<br \/>\n    }<br \/>\n}<br \/>\npublic class Student extends Person{<br \/>\n    \/\/\u7f16\u8bd1\u62a5\u9519,\u5b50\u7c7b\u6784\u9020\u5668\u4e2d\u4f1a\u9690\u5f0f\u7684\u8c03\u7528\u7236\u7c7b\u7684\u65e0\u53c2\u6784\u9020\u5668,\u4f46\u662f\u7236\u7c7b\u4e2d\u6ca1\u6709\u65e0\u53c2\u6784\u9020\u5668<br \/>\n    \/\/super();<br \/>\n    public Student(){<\/p>\n<p>    }<br \/>\n} <\/p>\n<p>\u3010\u663e\u5f0f\u7684\u8c03\u7528\u7236\u7c7b\u7684\u6709\u53c2\u6784\u9020\u5668\u3011<\/p>\n<\/p>\n<p>public class Person{<br \/>\n    protected String name;<br \/>\n    public Person(String name){<br \/>\n    this.name &#061; name;<br \/>\n}<br \/>\n}<\/p>\n<p>public class Student extends Person{<br \/>\n    \/\/\u7f16\u8bd1\u901a\u8fc7,\u5b50\u7c7b\u6784\u9020\u5668\u4e2d\u663e\u5f0f\u7684\u8c03\u7528\u7236\u7c7b\u7684\u6709\u53c2\u6784\u9020\u5668<br \/>\n    public Student(){<br \/>\n        super(&#034;tom&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u6ce8&#xff1a;\u4e0d\u7ba1\u662f\u663e\u5f0f\u8fd8\u662f\u9690\u5f0f\u7684\u7236\u7c7b\u7684\u6784\u9020\u5668&#xff0c;super\u8bed\u53e5\u4e00\u5b9a\u8981\u51fa\u73b0\u5728\u5b50\u7c7b\u6784\u9020\u5668\u4e2d\u7b2c\u4e00\u884c\u4ee3\u7801\u3002\u6240\u4ee5this\u548c super\u4e0d\u53ef\u80fd\u540c\u65f6\u4f7f\u7528\u5b83\u4eec\u8c03\u7528\u6784\u9020\u5668\u7684\u529f\u80fd&#xff0c;\u56e0\u4e3a\u5b83\u4eec\u90fd\u8981\u51fa\u73b0\u5728\u7b2c\u4e00\u884c\u4ee3\u7801\u4f4d\u7f6e\u3002<\/p>\n<p>\u3010\u4f8b\u5b50\u3011<\/p>\n<\/p>\n<p>public class Person{<br \/>\n    protected String name;<br \/>\n    public Person(String name){<br \/>\n        this.name &#061; name;<br \/>\n    }<br \/>\n}<\/p>\n<p>public class Student extends Person{<br \/>\n    \/\/\u7f16\u8bd1\u62a5\u9519,super\u8c03\u7528\u6784\u9020\u5668\u7684\u8bed\u53e5\u4e0d\u662f\u7b2c\u4e00\u884c\u4ee3\u7801<br \/>\n    public Student(){<br \/>\n        System.out.println(&#034;Student&#034;);<br \/>\n        super(&#034;tom&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u3010\u4f8b\u5b50\u3011<\/p>\n<\/p>\n<p>public class Person{<br \/>\n    protected String name;<br \/>\n    public Person(String name){<br \/>\n        this.name &#061; name;<br \/>\n    }<br \/>\n}<br \/>\n\/\/\u7f16\u8bd1\u901a\u8fc7<br \/>\npublic class Student extends Person{<br \/>\n    private int age;<br \/>\n    public Student(){<br \/>\n        this(20);<br \/>\n    }<br \/>\n    public Student(int age){<br \/>\n        super(&#034;tom&#034;);<br \/>\n        this.age &#061; age;<br \/>\n    }<br \/>\n} <\/p>\n<p>super\u4f7f\u7528\u7684\u6ce8\u610f\u7684\u5730\u65b9<\/p>\n<ul>\n<li>\u7528super\u8c03\u7528\u7236\u7c7b\u6784\u9020\u65b9\u6cd5&#xff0c;\u5fc5\u987b\u662f\u6784\u9020\u65b9\u6cd5\u4e2d\u7684\u7b2c\u4e00\u4e2a\u8bed\u53e5\u3002<\/li>\n<li>super\u53ea\u80fd\u51fa\u73b0\u5728\u5b50\u7c7b\u7684\u65b9\u6cd5\u6216\u8005\u6784\u9020\u65b9\u6cd5\u4e2d<\/li>\n<li>super \u548c this \u4e0d\u80fd\u591f\u540c\u65f6\u8c03\u7528\u6784\u9020\u65b9\u6cd5\u3002&#xff08;\u56e0\u4e3athis\u4e5f\u662f\u5728\u6784\u9020\u65b9\u6cd5\u7684\u7b2c\u4e00\u4e2a\u8bed\u53e5&#xff09;<\/li>\n<\/ul>\n<p>super \u548c this \u7684\u533a\u522b<\/p>\n<li>\n<p>\u4ee3\u8868\u7684\u4e8b\u7269\u4e0d\u4e00\u6837&#xff1a;<\/p>\n<p>this&#xff1a;\u4ee3\u8868\u6240\u5c5e\u65b9\u6cd5\u7684\u8c03\u7528\u8005\u5bf9\u8c61\u3002<\/p>\n<p>super&#xff1a;\u4ee3\u8868\u7236\u7c7b\u5bf9\u8c61\u7684\u5f15\u7528\u7a7a\u95f4\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528\u524d\u63d0\u4e0d\u4e00\u81f4&#xff1a;<\/p>\n<p>this&#xff1a;\u5728\u975e\u7ee7\u627f\u7684\u6761\u4ef6\u4e0b\u4e5f\u53ef\u4ee5\u4f7f\u7528\u3002<\/p>\n<p>super&#xff1a;\u53ea\u80fd\u5728\u7ee7\u627f\u7684\u6761\u4ef6\u4e0b\u624d\u80fd\u4f7f\u7528\u3002<\/p>\n<\/li>\n<li>\n<p>\u8c03\u7528\u6784\u9020\u65b9\u6cd5&#xff1a;<\/p>\n<p>this&#xff1a;\u8c03\u7528\u672c\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\u3002<\/p>\n<p>super&#xff1a;\u8c03\u7528\u7684\u7236\u7c7b\u7684\u6784\u9020\u65b9\u6cd5<\/p>\n<\/li>\n<h4 id=\"_4\u3001\u65b9\u6cd5\u91cd\u5199\">4\u3001\u65b9\u6cd5\u91cd\u5199<\/h4>\n<p>\u65b9\u6cd5\u7684\u91cd\u5199&#xff08;override&#xff09;<\/p>\n<ul>\n<li>\u65b9\u6cd5\u91cd\u5199\u53ea\u5b58\u5728\u4e8e\u5b50\u7c7b\u548c\u7236\u7c7b(\u5305\u62ec\u76f4\u63a5\u7236\u7c7b\u548c\u95f4\u63a5\u7236\u7c7b)\u4e4b\u95f4\u3002\u5728\u540c\u4e00\u4e2a\u7c7b\u4e2d\u65b9\u6cd5\u53ea\u80fd\u88ab\u91cd\u8f7d&#xff0c;\u4e0d\u80fd\u88ab\u91cd\u5199<\/li>\n<li>\u9759\u6001\u65b9\u6cd5\u4e0d\u80fd\u91cd\u5199\n<li>\u7236\u7c7b\u7684\u9759\u6001\u65b9\u6cd5\u4e0d\u80fd\u88ab\u5b50\u7c7b\u91cd\u5199\u4e3a\u975e\u9759\u6001\u65b9\u6cd5 \/\/\u7f16\u8bd1\u51fa\u9519<\/li>\n<li>\u7236\u7c7b\u7684\u975e\u9759\u6001\u65b9\u6cd5\u4e0d\u80fd\u88ab\u5b50\u7c7b\u91cd\u5199\u4e3a\u9759\u6001\u65b9\u6cd5&#xff1b;\/\/\u7f16\u8bd1\u51fa\u9519<\/li>\n<li>\u5b50\u7c7b\u53ef\u4ee5\u5b9a\u4e49\u4e0e\u7236\u7c7b\u7684\u9759\u6001\u65b9\u6cd5\u540c\u540d\u7684\u9759\u6001\u65b9\u6cd5(\u4f46\u662f\u8fd9\u4e2a\u4e0d\u662f\u8986\u76d6)<\/li>\n<\/li>\n<\/ul>\n<p>\u3010\u4f8b\u5b50\u3011<\/p>\n<p>A\u7c7b\u7ee7\u627fB\u7c7b A\u548cB\u4e2d\u90fd\u4e00\u4e2a\u76f8\u540c\u7684\u9759\u6001\u65b9\u6cd5test<\/p>\n<p>B a &#061; new A(); a.test();\/\/\u8c03\u7528\u5230\u7684\u662fB\u7c7b\u4e2d\u7684\u9759\u6001\u65b9\u6cd5test<\/p>\n<p>A a &#061; new A(); a.test();\/\/\u8c03\u7528\u5230\u7684\u662fA\u7c7b\u4e2d\u7684\u9759\u6001\u65b9\u6cd5test<\/p>\n<p>\u53ef\u4ee5\u770b\u51fa\u9759\u6001\u65b9\u6cd5\u7684\u8c03\u7528\u53ea\u548c\u53d8\u91cf\u58f0\u660e\u7684\u7c7b\u578b\u76f8\u5173 \u8fd9\u4e2a\u548c\u975e\u9759\u6001\u65b9\u6cd5\u7684\u91cd\u5199\u4e4b\u540e\u7684\u6548\u679c\u5b8c\u5168\u4e0d\u540c<\/p>\n<p>\u79c1\u6709\u65b9\u6cd5\u4e0d\u80fd\u88ab\u5b50\u7c7b\u91cd\u5199&#xff0c;\u5b50\u7c7b\u7ee7\u627f\u7236\u7c7b\u540e,\u662f\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u7236\u7c7b\u4e2d\u7684\u79c1\u6709\u65b9\u6cd5\u7684,\u90a3\u4e48\u5c31\u66f4\u8c08\u4e0d\u4e0a\u91cd\u5199\u4e86<\/p>\n<\/p>\n<p>public class Person{<br \/>\n    private void run(){}<\/p>\n<p>}<\/p>\n<p>\/\/\u7f16\u8bd1\u901a\u8fc7,\u4f46\u8fd9\u4e0d\u662f\u91cd\u5199,\u53ea\u662f\u4fe9\u4e2a\u7c7b\u4e2d\u5206\u522b\u6709\u81ea\u5df1\u7684\u79c1\u6709\u65b9\u6cd5<br \/>\npublic class Student extends Person{<br \/>\n    private void run(){}<br \/>\n} <\/p>\n<p>\u91cd\u5199\u7684\u8bed\u6cd5<\/p>\n<li>\n<p>\u65b9\u6cd5\u540d\u5fc5\u987b\u76f8\u540c<\/p>\n<\/li>\n<li>\n<p>\u53c2\u6570\u5217\u8868\u5fc5\u987b\u76f8\u540c<\/p>\n<\/li>\n<li>\n<p>\u8bbf\u95ee\u63a7\u5236\u4fee\u9970\u7b26\u53ef\u4ee5\u88ab\u6269\u5927&#xff0c;\u4f46\u662f\u4e0d\u80fd\u88ab\u7f29\u5c0f&#xff1a; public protected default private<\/p>\n<\/li>\n<li>\n<p>\u629b\u51fa\u5f02\u5e38\u7c7b\u578b\u7684\u8303\u56f4\u53ef\u4ee5\u88ab\u7f29\u5c0f,\u4f46\u662f\u4e0d\u80fd\u88ab\u6269\u5927<\/p>\n<p>ClassNotFoundException &#8212;&gt; Exception&#xff08;\u4e0d\u80fd\u6269\u5927&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u8fd4\u56de\u7c7b\u578b\u53ef\u4ee5\u76f8\u540c&#xff0c;\u4e5f\u53ef\u4ee5\u4e0d\u540c\u3002<\/p>\n<p>\u5982\u679c\u4e0d\u540c\u7684\u8bdd&#xff0c;\u5b50\u7c7b\u91cd\u5199\u540e\u7684\u65b9\u6cd5\u8fd4\u56de\u7c7b\u578b\u5fc5\u987b\u662f\u7236\u7c7b\u65b9\u6cd5\u8fd4\u56de\u7c7b\u578b\u7684\u5b50\u7c7b\u578b\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;\u7236\u7c7b\u65b9\u6cd5\u7684\u8fd4\u56de\u7c7b\u578b\u662fPerson&#xff0c;\u5b50\u7c7b\u91cd\u5199\u540e\u7684\u8fd4\u56de\u7c7b\u53ef\u4ee5\u662fPerson\u4e5f\u53ef\u4ee5\u662fPerson\u7684\u5b50\u7c7b\u578b<\/p>\n<\/li>\n<p>\u6ce8&#xff1a;\u4e00\u822c\u60c5\u51b5\u4e0b&#xff0c;\u91cd\u5199\u7684\u65b9\u6cd5\u4f1a\u548c\u7236\u7c7b\u4e2d\u7684\u65b9\u6cd5\u7684\u58f0\u660e\u5b8c\u5168\u4fdd\u6301\u4e00\u81f4&#xff0c;\u53ea\u6709\u65b9\u6cd5\u7684\u5b9e\u73b0\u4e0d\u540c\u3002(\u4e5f\u5c31\u662f\u5927\u62ec\u53f7\u4e2d\u4ee3\u7801\u4e0d\u4e00\u6837)<\/p>\n<\/p>\n<p>public class Person{<br \/>\n    public void run(){}<br \/>\n    protected Object test()throws Exception{<br \/>\n        return null;<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/\u7f16\u8bd1\u901a\u8fc7,\u5b50\u7c7b\u7ee7\u627f\u7236\u7c7b,\u91cd\u5199\u4e86run\u548ctest\u65b9\u6cd5.<br \/>\npublic class Student extends Person{<br \/>\n    public void run(){}<br \/>\n    public String test(){<br \/>\n        return &#034;&#034;;<br \/>\n    }<br \/>\n} <\/p>\n<p>\u4e3a\u4ec0\u4e48\u8981\u91cd\u5199&#xff1f;<\/p>\n<p>\u5b50\u7c7b\u7ee7\u627f\u7236\u7c7b&#xff0c;\u7ee7\u627f\u4e86\u7236\u7c7b\u4e2d\u7684\u65b9\u6cd5&#xff0c;\u4f46\u662f\u7236\u7c7b\u4e2d\u7684\u65b9\u6cd5\u5e76\u4e0d\u4e00\u5b9a\u80fd\u6ee1\u8db3\u5b50\u7c7b\u4e2d\u7684\u529f\u80fd\u9700\u8981&#xff0c;\u6240\u4ee5\u5b50\u7c7b\u4e2d\u9700\u8981\u628a\u65b9\u6cd5\u8fdb\u884c\u91cd\u5199\u3002<\/p>\n<p>\u603b\u7ed3&#xff1a;<\/p>\n<li>\u65b9\u6cd5\u91cd\u5199\u7684\u65f6\u5019&#xff0c;\u5fc5\u987b\u5b58\u5728\u7ee7\u627f\u5173\u7cfb\u3002<\/li>\n<li>\u65b9\u6cd5\u91cd\u5199\u7684\u65f6\u5019&#xff0c;\u65b9\u6cd5\u540d\u548c\u5f62\u5f0f\u53c2\u6570\u5fc5\u987b\u8ddf\u7236\u7c7b\u662f\u4e00\u81f4\u7684\u3002<\/li>\n<li>\u65b9\u6cd5\u91cd\u5199\u7684\u65f6\u5019&#xff0c;\u5b50\u7c7b\u7684\u6743\u9650\u4fee\u9970\u7b26\u5fc5\u987b\u8981\u5927\u4e8e\u6216\u8005\u7b49\u4e8e\u7236\u7c7b\u7684\u6743\u9650\u4fee\u9970\u7b26\u3002( private &lt; protected &lt; public&#xff0c;friendly &lt; public )<\/li>\n<li>\u65b9\u6cd5\u91cd\u5199\u7684\u65f6\u5019&#xff0c;\u5b50\u7c7b\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u5fc5\u987b\u5c0f\u4e8e\u6216\u8005\u7b49\u4e8e\u7236\u7c7b\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u3002( \u5b50\u7c7b &lt; \u7236\u7c7b ) \u6570\u636e\u7c7b\u578b\u6ca1\u6709\u660e\u786e\u7684\u4e0a\u4e0b\u7ea7\u5173\u7cfb<\/li>\n<li>\u65b9\u6cd5\u91cd\u5199\u7684\u65f6\u5019&#xff0c;\u5b50\u7c7b\u7684\u5f02\u5e38\u7c7b\u578b\u8981\u5c0f\u4e8e\u6216\u8005\u7b49\u4e8e\u7236\u7c7b\u7684\u5f02\u5e38\u7c7b\u578b\u3002<\/li>\n<h3 id=\"\u591a\u6001\">\u591a\u6001<\/h3>\n<h4 id=\"_1\u3001\u8ba4\u8bc6\u591a\u6001\">1\u3001\u8ba4\u8bc6\u591a\u6001<\/h4>\n<p>\u591a\u6001\u6027\u662fOOP\u4e2d\u7684\u4e00\u4e2a\u91cd\u8981\u7279\u6027&#xff0c;\u4e3b\u8981\u662f\u7528\u6765\u5b9e\u73b0\u52a8\u6001\u8054\u7f16\u7684&#xff0c;\u6362\u53e5\u8bdd\u8bf4&#xff0c;\u5c31\u662f\u7a0b\u5e8f\u7684\u6700\u7ec8\u72b6\u6001\u53ea\u6709\u5728\u6267\u884c\u8fc7\u7a0b\u4e2d\u624d\u88ab\u51b3\u5b9a\u800c\u975e\u5728\u7f16\u8bd1\u671f\u95f4\u5c31\u51b3\u5b9a\u4e86\u3002\u8fd9\u5bf9\u4e8e\u5927\u578b\u7cfb\u7edf\u6765\u8bf4\u80fd\u63d0\u9ad8\u7cfb\u7edf\u7684\u7075\u6d3b\u6027\u548c\u6269\u5c55\u6027\u3002<\/p>\n<p>\u591a\u6001\u53ef\u4ee5\u8ba9\u6211\u4eec\u4e0d\u7528\u5173\u5fc3\u67d0\u4e2a\u5bf9\u8c61\u5230\u5e95\u662f\u4ec0\u4e48\u5177\u4f53\u7c7b\u578b&#xff0c;\u5c31\u53ef\u4ee5\u4f7f\u7528\u8be5\u5bf9\u8c61\u7684\u67d0\u4e9b\u65b9\u6cd5&#xff0c;\u4ece\u800c\u5b9e\u73b0\u66f4\u52a0\u7075\u6d3b\u7684\u7f16\u7a0b&#xff0c;\u63d0\u9ad8\u7cfb\u7edf\u7684\u53ef\u6269\u5c55\u6027\u3002<\/p>\n<p>\u5141\u8bb8\u4e0d\u540c\u7c7b\u7684\u5bf9\u8c61\u5bf9\u540c\u4e00\u6d88\u606f\u505a\u51fa\u54cd\u5e94\u3002\u5373\u540c\u4e00\u6d88\u606f\u53ef\u4ee5\u6839\u636e\u53d1\u9001\u5bf9\u8c61\u7684\u4e0d\u540c\u800c\u91c7\u7528\u591a\u79cd\u4e0d\u540c\u7684\u884c\u4e3a\u65b9\u5f0f\u3002<\/p>\n<p>\u76f8\u540c\u7c7b\u57df\u7684\u4e0d\u540c\u5bf9\u8c61,\u8c03\u7528\u76f8\u540c\u7684\u65b9\u6cd5,\u6267\u884c\u7ed3\u679c\u662f\u4e0d\u540c\u7684<\/p>\n<li>\n<p>\u4e00\u4e2a\u5bf9\u8c61\u7684\u5b9e\u9645\u7c7b\u578b\u662f\u786e\u5b9a\u7684<\/p>\n<p>\u4f8b\u5982: new Student(); new Person();\u7b49<\/p>\n<\/li>\n<li>\n<p>\u53ef\u4ee5\u6307\u5411\u5bf9\u8c61\u7684\u5f15\u7528\u7684\u7c7b\u578b\u6709\u5f88\u591a<\/p>\n<p>\u4e00\u4e2a\u5bf9\u8c61\u7684\u5b9e\u73b0\u7c7b\u578b\u867d\u7136\u662f\u786e\u5b9a\u7684&#xff0c;\u4f46\u662f\u8fd9\u4e2a\u5bf9\u8c61\u6240\u5c5e\u7684\u7c7b\u578b\u53ef\u80fd\u6709\u5f88\u591a\u79cd\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;Student\u7ee7\u627f\u4e86Person\u7c7b<\/p>\n<p> Student s1 &#061; new Student();<br \/>\nPerson s2 &#061; new Student();<br \/>\nObject s3 &#061; new Student(); <\/p>\n<p>\u56e0\u4e3aPerson\u548cObject\u90fd\u662fStudent\u7684\u7236\u7c7b\u578b<\/p>\n<\/li>\n<p>\u6ce8&#xff1a;\u4e00\u4e2a\u5bf9\u8c61\u7684\u5b9e\u9645\u7c7b\u578b\u662f\u786e\u5b9a&#xff0c;\u4f46\u662f\u53ef\u4ee5\u6307\u5411\u8fd9\u4e2a\u5bf9\u8c61\u7684\u5f15\u7528\u7684\u7c7b\u578b&#xff0c;\u5374\u662f\u53ef\u4ee5\u662f\u8fd9\u5bf9\u8c61\u5b9e\u9645\u7c7b\u578b\u7684\u4efb\u610f\u7236\u7c7b\u578b\u3002<\/p>\n<p>\u4e00\u4e2a\u7236\u7c7b\u5f15\u7528\u53ef\u4ee5\u6307\u5411\u5b83\u7684\u4efb\u4f55\u4e00\u4e2a\u5b50\u7c7b\u5bf9\u8c61<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<\/p>\n<p>Object o &#061; new AnyClass();<br \/>\nPerson p &#061; null;<br \/>\np &#061; new Student();<br \/>\np &#061; new Teacher();<br \/>\np &#061; new Person(); <\/p>\n<p>\u591a\u6001\u4e2d\u7684\u65b9\u6cd5\u8c03\u7528<\/p>\n<\/p>\n<p>public class Person{<br \/>\n    public void run(){}<br \/>\n}<\/p>\n<p>public class Student extends Person{<\/p>\n<p>} <\/p>\n<p>\u8c03\u7528\u5230\u7684run\u65b9\u6cd5,\u662fStudent\u4ecePerson\u7ee7\u627f\u8fc7\u6765\u7684run\u65b9\u6cd5<\/p>\n<\/p>\n<p>Person p &#061; new Student();<br \/>\np.run(); <\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<\/p>\n<p>public class Person{<br \/>\n    public void run(){}<br \/>\n}<\/p>\n<p>public class Student extends Person{<br \/>\n    public void run(){<br \/>\n    \/\/\u91cd\u5199run\u65b9\u6cd5<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/\u8c03\u7528\u5230\u7684run\u65b9\u6cd5,\u662fStudent\u4e2d\u91cd\u5199\u7684run\u65b9\u6cd5<br \/>\npublic static void main(String[] args) {<br \/>\n    Person p &#061; new Student();<br \/>\n    p.run();<br \/>\n} <\/p>\n<p>\u6ce8&#xff1a;\u5b50\u7c7b\u7ee7\u627f\u7236\u7c7b,\u8c03\u7528a\u65b9\u6cd5&#xff0c;\u5982\u679ca\u65b9\u6cd5\u5728\u5b50\u7c7b\u4e2d\u6ca1\u6709\u91cd\u5199,\u90a3\u4e48\u5c31\u662f\u8c03\u7528\u7684\u662f\u5b50\u7c7b\u7ee7\u627f\u7236\u7c7b\u7684a\u65b9\u6cd5, \u5982\u679c\u91cd\u5199\u4e86,\u90a3\u4e48\u8c03\u7528\u7684\u5c31\u662f\u91cd\u5199\u4e4b\u540e\u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u5b50\u7c7b\u4e2d\u72ec\u6709\u65b9\u6cd5\u7684\u8c03\u7528<\/p>\n<\/p>\n<p>public class Person{<br \/>\n    public void run(){}<br \/>\n}<\/p>\n<p>public class Student extends Person{<br \/>\n    public void test(){<br \/>\n    }<br \/>\n}<\/p>\n<p>main:<br \/>\nPerson p &#061; new Student();<br \/>\n\/\/\u8c03\u7528\u5230\u7ee7\u627f\u7684run\u65b9\u6cd5<br \/>\np.run();<\/p>\n<p>\/\/\u7f16\u8bd1\u62a5\u9519,\u56e0\u4e3a\u7f16\u8bd1\u5668\u68c0\u67e5\u53d8\u91cfp\u7684\u7c7b\u578b\u662fPerson,\u4f46\u662f\u5728Person\u7c7b\u4e2d\u5e76\u6ca1\u6709\u53d1\u73b0test\u65b9\u6cd5,\u6240\u4ee5\u7f16\u8bd1\u62a5\u9519.<br \/>\np.test(); <\/p>\n<p>\u6ce8&#xff1a;\u4e00\u4e2a\u53d8\u91cfx&#xff0c;\u8c03\u7528\u4e00\u4e2a\u65b9\u6cd5test&#xff0c;\u7f16\u8bd1\u5668\u662f\u5426\u80fd\u8ba9\u5176\u7f16\u8bd1\u901a\u8fc7&#xff0c;\u4e3b\u8981\u662f\u770b\u58f0\u660e\u53d8\u91cfx\u7684\u7c7b\u578b\u4e2d\u6709\u6ca1\u6709\u5b9a\u4e49 test\u65b9\u6cd5&#xff0c;\u5982\u679c\u6709\u5219\u7f16\u8bd1\u901a\u8fc7&#xff0c;\u5982\u679c\u6ca1\u6709\u5219\u7f16\u8bd1\u62a5\u9519\u3002\u800c\u4e0d\u662f\u770bx\u6240\u6307\u5411\u7684\u5bf9\u8c61\u4e2d\u6709\u6ca1\u6709test\u65b9\u6cd5\u3002<\/p>\n<p>\u539f\u7406&#xff1a;\u7f16\u8bd1\u770b\u5de6\u8fb9&#xff0c;\u8fd0\u884c\u4e0d\u4e00\u5b9a\u770b\u53f3\u8fb9\u3002<\/p>\n<p>\u7f16\u8bd1\u770b\u5de6\u8fb9\u7684\u610f\u601d&#xff1a;java \u7f16\u8bd1\u5668\u5728\u7f16\u8bd1\u7684\u65f6\u5019\u4f1a\u68c0\u6d4b\u5f15\u7528\u7c7b\u578b\u4e2d\u542b\u6709\u6307\u5b9a\u7684\u6210\u5458&#xff0c;\u5982\u679c\u6ca1\u6709\u5c31\u4f1a\u62a5\u9519\u3002 \u5b50\u7c7b\u7684\u6210\u5458\u662f\u7279\u6709\u7684&#xff0c;\u7236\u7c7b\u7684\u6ca1\u6709\u7684&#xff0c;\u6240\u4ee5\u4ed6\u662f\u627e\u4e0d\u5230\u7684\u3002<\/p>\n<p>\u6240\u4ee5\u770b\u5de6\u8fb9&#xff0c;Person \u4e2d\u6ca1\u6709test()\u65b9\u6cd5&#xff0c;\u4e8e\u662f\u7f16\u8bd1\u62a5\u9519<\/p>\n<p>\u5b50\u7c7b\u5f15\u7528\u548c\u7236\u7c7b\u5f15\u7528\u6307\u5411\u5bf9\u8c61\u7684\u533a\u522b<\/p>\n<\/p>\n<p>Student s &#061; new Student();<br \/>\nPerson p &#061; new Student(); <\/p>\n<p>\u53d8\u91cfs\u80fd\u8c03\u7528\u7684\u65b9\u6cd5\u662fStudent\u4e2d\u6709\u7684\u65b9\u6cd5(\u5305\u62ec\u7ee7\u627f\u8fc7\u6765\u7684)&#xff0c;\u53d8\u91cfp\u80fd\u8c03\u7528\u7684\u65b9\u6cd5\u662fPerson\u4e2d\u6709\u7684\u65b9\u6cd5(\u5305\u62ec\u7ee7\u627f\u8fc7\u6765\u7684)\u3002<\/p>\n<p>\u4f46\u662f\u53d8\u91cfp\u662f\u7236\u7c7b\u578b\u7684&#xff0c;p\u4e0d\u4ec5\u53ef\u4ee5\u6307\u5411Student\u5bf9\u8c61&#xff0c;\u8fd8\u53ef\u4ee5\u6307\u5411Teacher\u7c7b\u578b\u5bf9\u8c61\u7b49&#xff0c;\u4f46\u662f\u53d8\u91cfs\u53ea\u80fd\u6307 Studnet\u7c7b\u578b\u5bf9\u8c61&#xff0c;\u53caStudent\u5b50\u7c7b\u578b\u5bf9\u8c61\u3002\u53d8\u91cfp\u80fd\u6307\u5411\u5bf9\u8c61\u7684\u8303\u56f4\u662f\u6bd4\u53d8\u91cfs\u5927\u7684\u3002<\/p>\n<p>Object\u7c7b\u578b\u7684\u53d8\u91cfo&#xff0c;\u80fd\u6307\u5411\u6240\u6709\u5bf9\u8c61&#xff0c;\u5b83\u7684\u8303\u56f4\u6700\u5927&#xff0c;\u4f46\u662f\u4f7f\u7528\u53d8\u91cfo\u80fd\u8c03\u7528\u5230\u7684\u65b9\u6cd5\u4e5f\u662f\u6700\u5c11\u7684&#xff0c;\u53ea\u80fd\u8c03\u7528\u5230Object\u4e2d\u7684\u58f0\u660e\u7684\u65b9\u6cd5&#xff0c;\u56e0\u4e3a\u53d8\u91cfo\u58f0\u660e\u7684\u7c7b\u578b\u5c31\u662fObject\u3002<\/p>\n<p>\u6ce8&#xff1a;java\u4e2d\u7684\u65b9\u6cd5\u8c03\u7528,\u662f\u8fd0\u884c\u65f6\u52a8\u6001\u548c\u5bf9\u8c61\u7ed1\u5b9a\u7684,\u4e0d\u5230\u8fd0\u884c\u7684\u65f6\u5019,\u662f\u4e0d\u77e5\u9053\u5230\u5e95\u54ea\u4e2a\u65b9\u6cd5\u88ab\u8c03\u7528\u7684\u3002<\/p>\n<p>\u591a\u6001\u7684\u597d\u5904\u4e0e\u5f0a\u7aef<\/p>\n<ul>\n<li>\n<p>\u597d\u5904&#xff1a;\u63d0\u9ad8\u4e86\u7a0b\u5e8f\u7684\u62d3\u5c55\u6027<\/p>\n<p>\u5177\u4f53\u8868\u73b0&#xff1a;\u5b9a\u4e49\u65b9\u6cd5\u7684\u65f6\u5019&#xff0c;\u4f7f\u7528\u7236\u7c7b\u578b\u4f5c\u4e3a\u53c2\u6570&#xff0c;\u5c06\u6765\u5728\u4f7f\u7528\u7684\u65f6\u5019&#xff0c;\u4f7f\u7528\u5177\u4f53\u7684\u5b50\u7c7b\u578b\u53c2\u4e0e\u64cd\u4f5c<\/p>\n<\/li>\n<li>\n<p>\u5f0a\u7aef&#xff1a;\u4e0d\u80fd\u4f7f\u7528\u5b50\u7c7b\u7684\u7279\u6709\u529f\u80fd<\/p>\n<\/li>\n<\/ul>\n<h4 id=\"_2\u3001\u91cd\u5199\u3001\u91cd\u8f7d\u548c\u591a\u6001\u7684\u5173\u7cfb\">2\u3001\u91cd\u5199\u3001\u91cd\u8f7d\u548c\u591a\u6001\u7684\u5173\u7cfb<\/h4>\n<p>\u91cd\u8f7d\u662f\u7f16\u8bd1\u65f6\u591a\u6001<\/p>\n<p>\u8c03\u7528\u91cd\u8f7d\u7684\u65b9\u6cd5,\u5728\u7f16\u8bd1\u671f\u95f4\u5c31\u8981\u786e\u5b9a\u8c03\u7528\u7684\u65b9\u6cd5\u662f\u8c01,\u5982\u679c\u4e0d\u80fd\u786e\u5b9a\u5219\u7f16\u8bd1\u62a5\u9519<\/p>\n<p>\u91cd\u5199\u662f\u8fd0\u884c\u65f6\u591a\u6001<\/p>\n<p>\u8c03\u7528\u91cd\u5199\u7684\u65b9\u6cd5&#xff0c;\u5728\u8fd0\u884c\u671f\u95f4\u624d\u80fd\u786e\u5b9a\u8fd9\u4e2a\u65b9\u6cd5\u5230\u5e95\u662f\u54ea\u4e2a\u5bf9\u8c61\u4e2d\u7684\u3002\u8fd9\u4e2a\u53d6\u51b3\u4e8e\u8c03\u7528\u65b9\u6cd5\u7684\u5f15\u7528&#xff0c;\u5728\u8fd0\u884c \u671f\u95f4\u6240\u6307\u5411\u7684\u5bf9\u8c61\u662f\u8c01&#xff0c;\u8fd9\u4e2a\u5f15\u7528\u6307\u5411\u54ea\u4e2a\u5bf9\u8c61\u90a3\u4e48\u8c03\u7528\u7684\u5c31\u662f\u54ea\u4e2a\u5bf9\u8c61\u4e2d\u7684\u65b9\u6cd5\u3002(java\u4e2d\u7684\u65b9\u6cd5\u8c03\u7528&#xff0c;\u662f\u8fd0\u884c\u65f6\u52a8\u6001\u548c\u5bf9\u8c61\u7ed1\u5b9a\u7684)<\/p>\n<h4 id=\"_3\u3001\u591a\u6001\u7684\u6ce8\u610f\u4e8b\u9879\">3\u3001\u591a\u6001\u7684\u6ce8\u610f\u4e8b\u9879<\/h4>\n<li>\u591a\u6001\u662f\u65b9\u6cd5\u7684\u591a\u6001&#xff0c;\u5c5e\u6027\u6ca1\u6709\u591a\u6001\u6027\u3002<\/li>\n<li>\u7f16\u5199\u7a0b\u5e8f\u65f6&#xff0c;\u5982\u679c\u60f3\u8c03\u7528\u8fd0\u884c\u65f6\u7c7b\u578b\u7684\u65b9\u6cd5&#xff0c;\u53ea\u80fd\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u3002\u4e0d\u7136\u901a\u4e0d\u8fc7\u7f16\u8bd1\u5668\u7684\u68c0\u67e5\u3002\u4f46\u662f\u5982\u679c\u4e24\u4e2a\u6ca1\u6709\u5173\u8054\u7684\u7c7b\u8fdb\u884c\u5f3a\u5236\u8f6c\u6362&#xff0c;\u4f1a\u62a5&#xff1a;ClassCastException\u3002 \u6bd4\u5982&#xff1a;\u672c\u6765\u662f\u72d7&#xff0c;\u6211\u628a\u5b83\u8f6c\u6210\u732b\u3002\u5c31\u4f1a\u62a5\u8fd9\u4e2a\u5f02\u5e38\u3002<\/li>\n<li>\u591a\u6001\u7684\u5b58\u5728\u8981\u67093\u4e2a\u5fc5\u8981\u6761\u4ef6&#xff1a;\u8981\u6709\u7ee7\u627f&#xff0c;\u8981\u6709\u65b9\u6cd5\u91cd\u5199&#xff0c;\u7236\u7c7b\u5f15\u7528\u6307\u5411\u5b50\u7c7b\u5bf9\u8c61<\/li>\n<h4 id=\"_4\u3001\u591a\u6001\u5b58\u5728\u7684\u6761\u4ef6\">4\u3001\u591a\u6001\u5b58\u5728\u7684\u6761\u4ef6<\/h4>\n<ul>\n<li>\u6709\u7ee7\u627f\u5173\u7cfb<\/li>\n<li>\u5b50\u7c7b\u91cd\u5199\u7236\u7c7b\u65b9\u6cd5<\/li>\n<li>\u7236\u7c7b\u5f15\u7528\u6307\u5411\u5b50\u7c7b\u5bf9\u8c61<\/li>\n<\/ul>\n<p>\u8865\u5145\u4e00\u4e0b\u7b2c\u4e8c\u70b9&#xff0c;\u65e2\u7136\u591a\u6001\u5b58\u5728\u5fc5\u987b\u8981\u6709\u201c\u5b50\u7c7b\u91cd\u5199\u7236\u7c7b\u65b9\u6cd5\u201d\u8fd9\u4e00\u6761\u4ef6&#xff0c;\u90a3\u4e48\u4ee5\u4e0b\u4e09\u79cd\u7c7b\u578b\u7684\u65b9\u6cd5\u662f\u6ca1\u6709\u529e\u6cd5\u8868\u73b0\u51fa\u591a\u6001\u7279\u6027\u7684&#xff08;\u56e0\u4e3a\u4e0d\u80fd\u88ab\u91cd\u5199&#xff09;&#xff1a;<\/p>\n<li>static\u65b9\u6cd5&#xff0c;\u56e0\u4e3a\u88abstatic\u4fee\u9970\u7684\u65b9\u6cd5\u662f\u5c5e\u4e8e\u7c7b\u7684&#xff0c;\u800c\u4e0d\u662f\u5c5e\u4e8e\u5b9e\u4f8b\u7684<\/li>\n<li>final\u65b9\u6cd5&#xff0c;\u56e0\u4e3a\u88abfinal\u4fee\u9970\u7684\u65b9\u6cd5\u65e0\u6cd5\u88ab\u5b50\u7c7b\u91cd\u5199<\/li>\n<li>private\u65b9\u6cd5\u548cprotected\u65b9\u6cd5&#xff0c;\u524d\u8005\u662f\u56e0\u4e3a\u88abprivate\u4fee\u9970\u7684\u65b9\u6cd5\u5bf9\u5b50\u7c7b\u4e0d\u53ef\u89c1&#xff0c;\u540e\u8005\u662f\u56e0\u4e3a\u5c3d\u7ba1\u88ab protected\u4fee\u9970\u7684\u65b9\u6cd5\u53ef\u4ee5\u88ab\u5b50\u7c7b\u89c1\u5230&#xff0c;\u4e5f\u53ef\u4ee5\u88ab\u5b50\u7c7b\u91cd\u5199&#xff0c;\u4f46\u662f\u5b83\u662f\u65e0\u6cd5\u88ab\u5916\u90e8\u6240\u5f15\u7528\u7684&#xff0c;\u4e00\u4e2a\u4e0d\u80fd\u88ab\u5916\u90e8\u5f15\u7528\u7684\u65b9\u6cd5&#xff0c;\u600e\u4e48\u80fd\u8c08\u591a\u6001\u5462<\/li>\n<h4 id=\"_5\u3001\u65b9\u6cd5\u7ed1\u5b9a-method-binding\">5\u3001\u65b9\u6cd5\u7ed1\u5b9a(method binding)<\/h4>\n<p>\u6267\u884c\u8c03\u7528\u65b9\u6cd5\u65f6&#xff0c;\u7cfb\u7edf\u6839\u636e\u76f8\u5173\u4fe1\u606f&#xff0c;\u80fd\u591f\u6267\u884c\u5185\u5b58\u5730\u5740\u4e2d\u4ee3\u8868\u8be5\u65b9\u6cd5\u7684\u4ee3\u7801\u3002\u5206\u4e3a\u9759\u6001\u7ed1\u5b9a\u548c\u52a8\u6001\u7ed1\u5b9a\u3002<\/p>\n<p>\u9759\u6001\u7ed1\u5b9a&#xff1a;<\/p>\n<p>\u5728\u7f16\u8bd1\u671f\u5b8c\u6210&#xff0c;\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u6267\u884c\u901f\u5ea6\u3002<\/p>\n<p>\u52a8\u6001\u7ed1\u5b9a&#xff1a;<\/p>\n<p>\u901a\u8fc7\u5bf9\u8c61\u8c03\u7528\u7684\u65b9\u6cd5&#xff0c;\u91c7\u7528\u52a8\u6001\u7ed1\u5b9a\u673a\u5236\u3002\u8fd9\u867d\u7136\u8ba9\u6211\u4eec\u7f16\u7a0b\u7075\u6d3b&#xff0c;\u4f46\u662f\u964d\u4f4e\u4e86\u4ee3\u7801\u7684\u6267\u884c\u901f\u5ea6\u3002\u8fd9\u4e5f\u662fJAVA\u6bd4C\/C&#043;&#043;\u901f\u5ea6\u6162\u7684\u4e3b\u8981\u56e0\u7d20\u4e4b\u4e00\u3002JAVA\u4e2d\u9664\u4e86final\u7c7b\u3001final\u65b9\u3001static\u65b9\u6cd5&#xff0c;\u6240\u6709\u65b9\u6cd5\u90fd\u662fJVM\u5728\u8fd0\u884c\u671f\u624d\u8fdb\u884c\u52a8\u6001\u7ed1\u5b9a\u7684\u3002<\/p>\n<p>\u591a\u6001&#xff1a;\u5982\u679c\u7f16\u8bd1\u65f6\u7c7b\u578b\u548c\u8fd0\u884c\u65f6\u7c7b\u578b\u4e0d\u4e00\u81f4&#xff0c;\u5c31\u4f1a\u9020\u6210\u591a\u6001\u3002<\/p>\n<h4 id=\"_6\u3001instanceof\u548c\u7c7b\u578b\u8f6c\u6362\">6\u3001instanceof\u548c\u7c7b\u578b\u8f6c\u6362<\/h4>\n<p>1\u3001instanceof<\/p>\n<p>\u4e09\u4e2a\u4e0d\u540cjava\u6587\u4ef6<\/p>\n<\/p>\n<p>public class Person{<br \/>\n    public void run(){}<br \/>\n}<\/p>\n<p>public class Student extends Person{<br \/>\n}<\/p>\n<p>public class Teacher extends Person{<br \/>\n} <\/p>\n<p>main&#xff1a;\u65b9\u6cd5\u4e0b<\/p>\n<\/p>\n<p>Object o &#061; new Student();<br \/>\nSystem.out.println(o instanceof Student);\/\/true<br \/>\nSystem.out.println(o instanceof Person);\/\/true<br \/>\nSystem.out.println(o instanceof Object);\/\/true<br \/>\nSystem.out.println(o instanceof Teacher);\/\/false<br \/>\nSystem.out.println(o instanceof String);\/\/false <\/p>\n<\/p>\n<p>Person o &#061; new Student();<br \/>\nSystem.out.println(o instanceof Student);\/\/true<br \/>\nSystem.out.println(o instanceof Person);\/\/true<br \/>\nSystem.out.println(o instanceof Object);\/\/true<br \/>\nSystem.out.println(o instanceof Teacher);\/\/false<br \/>\n\/\/\u7f16\u8bd1\u62a5\u9519<br \/>\nSystem.out.println(o instanceof String); <\/p>\n<\/p>\n<p>Student o &#061; new Student();<br \/>\nSystem.out.println(o instanceof Student);\/\/true<br \/>\nSystem.out.println(o instanceof Person);\/\/true<br \/>\nSystem.out.println(o instanceof Object);\/\/true<br \/>\n\/\/\u7f16\u8bd1\u62a5\u9519<br \/>\nSystem.out.println(o instanceof Teacher);<br \/>\n\/\/\u7f16\u8bd1\u62a5\u9519<br \/>\nSystem.out.println(o instanceof String); <\/p>\n<p>System.out.println(x instanceof Y);<\/p>\n<p>\u3010\u5206\u67901\u3011<\/p>\n<p>\u8be5\u4ee3\u7801\u80fd\u5426\u7f16\u8bd1\u901a\u8fc7&#xff0c;\u4e3b\u8981\u662f\u770b\u58f0\u660e\u53d8\u91cfx\u7684\u7c7b\u578b\u548cY\u662f\u5426\u5b58\u5728\u5b50\u7236\u7c7b\u7684\u5173\u7cfb\u3002\u6709&#034;\u5b50\u7236\u7c7b\u5173&#034;\u7cfb\u5c31\u7f16\u8bd1\u901a\u8fc7&#xff0c;\u6ca1\u6709\u5b50\u7236\u7c7b\u5173\u7cfb\u5c31\u662f\u7f16\u8bd1\u62a5\u9519\u3002<\/p>\n<p>\u4e4b\u540e\u5b66\u4e60\u5230\u7684\u63a5\u53e3\u7c7b\u578b\u548c\u8fd9\u4e2a\u662f\u6709\u70b9\u533a\u522b\u7684\u3002<\/p>\n<p>\u3010\u5206\u67902\u3011<\/p>\n<p>\u8f93\u51fa\u7ed3\u679c\u662ftrue\u8fd8\u662ffalse,\u4e3b\u8981\u662f\u770b\u53d8\u91cfx\u6240\u6307\u5411\u7684\u5bf9\u8c61\u5b9e\u9645\u7c7b\u578b\u662f\u4e0d\u662fY\u7c7b\u578b\u7684&#034;\u5b50\u7c7b\u578b&#034;.<\/p>\n<\/p>\n<p>Object o &#061; new Person();<br \/>\nSystem.out.println(o instanceof Student);\/\/false<br \/>\nSystem.out.println(o instanceof Person);\/\/true<br \/>\nSystem.out.println(o instanceof Object);\/\/true<br \/>\nSystem.out.println(o instanceof Teacher);\/\/false<br \/>\nSystem.out.println(o instanceof String);\/\/false <\/p>\n<p>2\u3001\u7c7b\u578b\u8f6c\u6362<\/p>\n<\/p>\n<p>public class Person{<br \/>\n    public void run(){}<br \/>\n}<\/p>\n<p>public class Student extends Person{<br \/>\n    public void go(){}<br \/>\n}<\/p>\n<p>public class Teacher extends Person{<br \/>\n} <\/p>\n<p>\u4e3a\u4ec0\u4e48\u8981\u7c7b\u578b\u8f6c\u6362<\/p>\n<\/p>\n<p>\/\/\u7f16\u8bd1\u62a5\u9519,\u56e0\u4e3ap\u58f0\u660e\u7684\u7c7b\u578bPerson\u4e2d\u6ca1\u6709go\u65b9\u6cd5<br \/>\nPerson p &#061; new Student();<br \/>\np.go();<\/p>\n<p>\/\/\u9700\u8981\u628a\u53d8\u91cfp\u7684\u7c7b\u578b\u8fdb\u884c\u8f6c\u6362<br \/>\nPerson p &#061; new Student();<br \/>\nStudent s &#061; (Student)p;<br \/>\ns.go();<\/p>\n<p>\/\/\u6216\u8005<br \/>\n\/\/\u6ce8\u610f\u8fd9\u79cd\u5f62\u5f0f\u524d\u9762\u5fc5\u987b\u8981\u4fe9\u4e2a\u5c0f\u62ec\u53f7<br \/>\nPerson p &#061; new Student();<br \/>\n((Student)p).go(); <\/p>\n<p>\u7c7b\u578b\u8f6c\u6362\u4e2d\u7684\u95ee\u9898<\/p>\n<\/p>\n<p>\/\/\u7f16\u8bd1\u901a\u8fc7 \u8fd0\u884c\u6ca1\u95ee\u9898<br \/>\nObject o &#061; new Student();<br \/>\nPerson p &#061; (Person)o;<\/p>\n<p>\/\/\u7f16\u8bd1\u901a\u8fc7 \u8fd0\u884c\u6ca1\u95ee\u9898<br \/>\nObject o &#061; new Student();<br \/>\nStudent s &#061; (Student)o;<\/p>\n<p>\/\/\u7f16\u8bd1\u901a\u8fc7,\u8fd0\u884c\u62a5\u9519<br \/>\nObject o &#061; new Teacher();<br \/>\nStudent s &#061; (Student)o; <\/p>\n<p>\u5373: X x &#061; (X)o;<\/p>\n<p>\u8fd0\u884c\u662f\u5426\u62a5\u9519&#xff0c;\u4e3b\u8981\u662f\u53d8\u91cfo\u6240\u6307\u5411\u7684\u5bf9\u8c61\u5b9e\u73b0\u7c7b\u578b&#xff0c;\u662f\u4e0d\u662fX\u7c7b\u578b\u7684\u5b50\u7c7b\u578b&#xff0c;\u5982\u679c\u4e0d\u662f\u5219\u8fd0\u884c\u5c31\u4f1a\u62a5\u9519\u3002<\/p>\n<p>\u3010\u603b\u7ed3\u3011<\/p>\n<li>\n<p>\u7236\u7c7b\u5f15\u7528\u53ef\u4ee5\u6307\u5411\u5b50\u7c7b\u5bf9\u8c61&#xff0c;\u5b50\u7c7b\u5f15\u7528\u4e0d\u80fd\u6307\u5411\u7236\u7c7b\u5bf9\u8c61\u3002<\/p>\n<\/li>\n<li>\n<p>\u628a\u5b50\u7c7b\u5bf9\u8c61\u76f4\u63a5\u8d4b\u7ed9\u7236\u7c7b\u5f15\u7528\u53eb\u5411\u4e0a\u8f6c\u578b&#xff08;upcasting&#xff09;&#xff0c;\u4e0d\u7528\u5f3a\u5236\u8f6c\u578b\u3002<\/p>\n<p>\u5982Father father &#061; new Son();<\/p>\n<\/li>\n<li>\n<p>\u628a\u6307\u5411\u5b50\u7c7b\u5bf9\u8c61\u7684\u7236\u7c7b\u5f15\u7528\u8d4b\u7ed9\u5b50\u7c7b\u5f15\u7528\u53eb\u5411\u4e0b\u8f6c\u578b&#xff08;downcasting&#xff09;&#xff0c;\u8981\u5f3a\u5236\u8f6c\u578b\u3002<\/p>\n<p>\u5982father\u5c31\u662f\u4e00\u4e2a\u6307\u5411\u5b50\u7c7b\u5bf9\u8c61\u7684\u7236\u7c7b\u5f15\u7528&#xff0c;\u628afather\u8d4b\u7ed9\u5b50\u7c7b\u5f15\u7528son<\/p>\n<p>\u5373Son son &#061;&#xff08;Son&#xff09; father&#xff1b;<\/p>\n<p>\u5176\u4e2dfather\u524d\u9762\u7684&#xff08;Son&#xff09;\u5fc5\u987b\u6dfb\u52a0&#xff0c;\u8fdb\u884c\u5f3a\u5236\u8f6c\u6362\u3002<\/p>\n<\/li>\n<li>\n<p>upcasting \u4f1a\u4e22\u5931\u5b50\u7c7b\u7279\u6709\u7684\u65b9\u6cd5&#xff0c;\u4f46\u662f\u5b50\u7c7boverriding \u7236\u7c7b\u7684\u65b9\u6cd5&#xff0c;\u5b50\u7c7b\u65b9\u6cd5\u6709\u6548<\/p>\n<\/li>\n<li>\n<p>\u5411\u4e0a\u8f6c\u578b\u7684\u4f5c\u7528&#xff0c;\u51cf\u5c11\u91cd\u590d\u4ee3\u7801&#xff0c;\u7236\u7c7b\u4e3a\u53c2\u6570&#xff0c;\u8c03\u6709\u65f6\u7528\u5b50\u7c7b\u4f5c\u4e3a\u53c2\u6570&#xff0c;\u5c31\u662f\u5229\u7528\u4e86\u5411\u4e0a\u8f6c\u578b\u3002\u8fd9\u6837\u4f7f\u4ee3\u7801\u53d8\u5f97\u7b80\u6d01\u3002\u4f53\u73b0\u4e86JAVA\u7684\u62bd\u8c61\u7f16\u7a0b\u601d\u60f3\u3002<\/p>\n<\/li>\n<h3 id=\"\u4fee\u9970\u7b26\">\u4fee\u9970\u7b26<\/h3>\n<h4 id=\"_1\u3001static\u4fee\u9970\u7b26\">1\u3001static\u4fee\u9970\u7b26<\/h4>\n<p>1\u3001static\u53d8\u91cf<\/p>\n<p>\u5728\u7c7b\u4e2d,\u4f7f\u7528static\u4fee\u9970\u7684\u6210\u5458\u53d8\u91cf,\u5c31\u662f\u9759\u6001\u53d8\u91cf,\u53cd\u4e4b\u4e3a\u975e\u9759\u6001\u53d8\u91cf\u3002<\/p>\n<p>\u9759\u6001\u53d8\u91cf\u548c\u975e\u9759\u6001\u53d8\u91cf\u7684\u533a\u522b<\/p>\n<p>\u9759\u6001\u53d8\u91cf\u5c5e\u4e8e\u7c7b\u7684&#xff0c;&#034;\u53ef\u4ee5&#034;\u4f7f\u7528\u7c7b\u540d\u6765\u8bbf\u95ee&#xff0c;\u975e\u9759\u6001\u53d8\u91cf\u662f\u5c5e\u4e8e\u5bf9\u8c61\u7684&#xff0c;&#034;\u5fc5\u987b&#034;\u4f7f\u7528\u5bf9\u8c61\u6765\u8bbf\u95ee\u3002<\/p>\n<\/p>\n<p>public class Student{<br \/>\n    private static int age;<br \/>\n    private double score;<br \/>\n    public static void main(String[] args) {<br \/>\n        Student s &#061; new Student();<br \/>\n        \/\/\u63a8\u8350\u4f7f\u7528\u7c7b\u540d\u8bbf\u95ee\u9759\u6001\u6210\u5458<br \/>\n        System.out.println(Student.age);<br \/>\n        System.out.println(s.age);<\/p>\n<p>        System.out.println(s.score);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u9759\u6001\u53d8\u91cf\u5bf9\u4e8e\u7c7b\u800c\u8a00\u5728\u5185\u5b58\u4e2d\u53ea\u6709\u4e00\u4e2a&#xff0c;\u80fd\u88ab\u7c7b\u7684\u6240\u6709\u5b9e\u4f8b\u6240\u5171\u4eab\u3002\u5b9e\u4f8b\u53d8\u91cf\u5bf9\u4e8e\u7c7b\u7684\u6bcf\u4e2a\u5b9e\u4f8b\u90fd\u6709\u4e00\u4efd, \u5b83\u4eec\u4e4b\u95f4\u4e92\u4e0d\u5f71\u54cd\u3002&#xff08;\u5728\u57fa\u7840\u8bed\u6cd5\u4e2d\u7c97\u7565\u89e3\u91ca\u8fc7\u9759\u6001\u53d8\u91cf&#xff09;<\/p>\n<\/p>\n<p>public class Student {<br \/>\n    private static int count;<br \/>\n    private int num;<\/p>\n<p>    public Student() {<br \/>\n        count&#043;&#043;;<br \/>\n        num&#043;&#043;;<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        Student s1 &#061; new Student();<br \/>\n        Student s2 &#061; new Student();<br \/>\n        Student s3 &#061; new Student();<br \/>\n        Student s4 &#061; new Student();<br \/>\n        \/\/\u56e0\u4e3a\u8fd8\u662f\u5728\u7c7b\u4e2d,\u6240\u4ee5\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95ee\u79c1\u6709\u5c5e\u6027<br \/>\n        System.out.println(s1.num);\/\/1<br \/>\n        System.out.println(s2.num);<br \/>\n        System.out.println(s3.num);<br \/>\n        System.out.println(s4.num);<br \/>\n        System.out.println(Student.count);<\/p>\n<p>        System.out.println(s1.count);\/\/4<br \/>\n        System.out.println(s2.count);<br \/>\n        System.out.println(s3.count);<br \/>\n        System.out.println(s4.count);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u5728\u52a0\u8f7d\u7c7b\u7684\u8fc7\u7a0b\u4e2d\u4e3a\u9759\u6001\u53d8\u91cf\u5206\u914d\u5185\u5b58&#xff0c;\u5b9e\u4f8b\u53d8\u91cf\u5728\u521b\u5efa\u5bf9\u8c61\u65f6\u5206\u914d\u5185\u5b58&#xff0c;\u6240\u4ee5\u9759\u6001\u53d8\u91cf\u53ef\u4ee5\u4f7f\u7528\u7c7b\u540d\u6765\u76f4\u63a5\u8bbf\u95ee&#xff0c;\u800c\u4e0d\u9700\u8981\u4f7f\u7528\u5bf9\u8c61\u6765\u8bbf\u95ee\u3002<\/p>\n<p>2\u3001static\u65b9\u6cd5<\/p>\n<p>\u5728\u7c7b\u4e2d&#xff0c;\u4f7f\u7528static\u4fee\u9970\u7684\u6210\u5458\u65b9\u6cd5&#xff0c;\u5c31\u662f\u9759\u6001\u65b9\u6cd5&#xff0c;\u53cd\u4e4b\u4e3a\u975e\u9759\u6001\u65b9\u6cd5\u3002<\/p>\n<p>\u9759\u6001\u65b9\u6cd5\u548c\u975e\u9759\u6001\u65b9\u6cd5\u7684\u533a\u522b<\/p>\n<p>\u9759\u6001\u65b9\u6cd5\u6570\u5c5e\u4e8e\u7c7b\u7684&#xff0c;&#034;\u53ef\u4ee5&#034;\u4f7f\u7528\u7c7b\u540d\u6765\u8c03\u7528&#xff0c;\u975e\u9759\u6001\u65b9\u6cd5\u662f\u5c5e\u4e8e\u5bf9\u8c61\u7684&#xff0c;&#034;\u5fc5\u987b&#034;\u4f7f\u7528\u5bf9\u8c61\u6765\u8c03\u7528\u3002<\/p>\n<p>\u9759\u6001\u65b9\u6cd5&#034;\u4e0d\u53ef\u4ee5&#034;\u76f4\u63a5\u8bbf\u95ee\u7c7b\u4e2d\u7684\u975e\u9759\u6001\u53d8\u91cf\u548c\u975e\u9759\u6001\u65b9\u6cd5&#xff0c;\u4f46\u662f&#034;\u53ef\u4ee5&#034;\u76f4\u63a5\u8bbf\u95ee\u7c7b\u4e2d\u7684\u9759\u6001\u53d8\u91cf\u548c\u9759\u6001\u65b9\u6cd5<\/p>\n<p>\u6ce8\u610f&#xff1a;this\u548csuper\u5728\u7c7b\u4e2d\u5c5e\u4e8e\u975e\u9759\u6001\u7684\u53d8\u91cf.(\u9759\u6001\u65b9\u6cd5\u4e2d\u4e0d\u80fd\u4f7f\u7528)<\/p>\n<\/p>\n<p>public class Student {<br \/>\n    private static int count;<br \/>\n    private int num;<br \/>\n    public void run(){}<br \/>\n    public static void go(){}<br \/>\n    public static void test(){<br \/>\n        \/\/\u7f16\u8bd1\u901a\u8fc7<br \/>\n        System.out.println(count);<br \/>\n        go();<\/p>\n<p>        \/\/\u7f16\u8bd1\u62a5\u9519<br \/>\n        System.out.println(num);<br \/>\n        run();<br \/>\n    }<br \/>\n} <\/p>\n<p>\u975e\u9759\u6001\u65b9\u6cd5&#034;\u53ef\u4ee5&#034;\u76f4\u63a5\u8bbf\u95ee\u7c7b\u4e2d\u7684\u975e\u9759\u6001\u53d8\u91cf\u548c\u975e\u9759\u6001\u65b9\u6cd5&#xff0c;\u4e5f&#034;\u53ef\u4ee5&#034;\u76f4\u63a5\u8bbf\u95ee\u7c7b\u4e2d\u7684\u9759\u6001\u53d8\u91cf\u548c\u9759\u6001\u65b9\u6cd5<\/p>\n<\/p>\n<p>public class Student {<br \/>\n    private static int count;<br \/>\n    private int num;<\/p>\n<p>    public void run() {<br \/>\n    }<\/p>\n<p>    public static void go() {<br \/>\n    }<br \/>\n    public void test() {<br \/>\n        \/\/\u7f16\u8bd1\u901a\u8fc7<br \/>\n        System.out.println(count);<br \/>\n        go();<br \/>\n        \/\/\u7f16\u8bd1\u901a\u8fc7<br \/>\n        System.out.println(num);<br \/>\n        run();<br \/>\n    }<br \/>\n} <\/p>\n<p>\u601d\u8003&#xff1a;\u4e3a\u4ec0\u4e48\u9759\u6001\u65b9\u6cd5\u548c\u975e\u9759\u6001\u65b9\u6cd5\u4e0d\u80fd\u76f4\u63a5\u76f8\u4e92\u8bbf\u95ee&#xff1f; \u52a0\u8f7d\u987a\u5e8f\u7684\u95ee\u9898&#xff01;<\/p>\n<p>\u7236\u7c7b\u7684\u9759\u6001\u65b9\u6cd5\u53ef\u4ee5\u88ab\u5b50\u7c7b\u7ee7\u627f&#xff0c;\u4f46\u662f\u4e0d\u80fd\u88ab\u5b50\u7c7b\u91cd\u5199<\/p>\n<\/p>\n<p>public class Person {<br \/>\n    public static void method() {}<br \/>\n}<\/p>\n<p>\/\/\u7f16\u8bd1\u62a5\u9519<br \/>\npublic class Student extends Person {<br \/>\n    public void method(){}<br \/>\n} <\/p>\n<p>public class Person {<br \/>\n    public static void test() {<br \/>\n        System.out.println(&#034;Person&#034;);<br \/>\n    }<br \/>\n}<br \/>\n\/\/\u7f16\u8bd1\u901a\u8fc7,\u4f46\u4e0d\u662f\u91cd\u5199<br \/>\npublic class Student extends Person {<br \/>\n    public static void test(){<br \/>\n        System.out.println(&#034;Student&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<\/p>\n<p>\/\/main:<br \/>\nPerosn p &#061; new Student();<br \/>\np.test();\/\/\u8f93\u51faPerson<br \/>\np &#061; new Person();<br \/>\np.test();\/\/\u8f93\u51faPerosn <\/p>\n<p>\u7236\u7c7b\u7684\u975e\u9759\u6001\u65b9\u6cd5\u4e0d\u80fd\u88ab\u5b50\u7c7b\u91cd\u5199\u4e3a\u9759\u6001\u65b9\u6cd5 &#xff1b;<\/p>\n<\/p>\n<p>public class Person {<br \/>\n    public void test() {<br \/>\n        System.out.println(&#034;Person&#034;);<br \/>\n    }<br \/>\n}<br \/>\n\/\/\u7f16\u8bd1\u62a5\u9519<br \/>\npublic class Student extends Person {<br \/>\n    public static void test(){<br \/>\n        System.out.println(&#034;Student&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<p>3\u3001\u4ee3\u7801\u5757\u548c\u9759\u6001\u4ee3\u7801\u5757<\/p>\n<p>\u3010\u7c7b\u4e2d\u53ef\u4ee5\u7f16\u5199\u4ee3\u7801\u5757\u548c\u9759\u6001\u4ee3\u7801\u5757\u3011<\/p>\n<\/p>\n<p>public class Person {<br \/>\n    {<br \/>\n        \/\/\u4ee3\u7801\u5757(\u533f\u540d\u4ee3\u7801\u5757)<br \/>\n    }<br \/>\n    static{<br \/>\n        \/\/\u9759\u6001\u4ee3\u7801\u5757<br \/>\n    }<br \/>\n} <\/p>\n<p>\u3010\u533f\u540d\u4ee3\u7801\u5757\u548c\u9759\u6001\u4ee3\u7801\u5757\u7684\u6267\u884c\u3011<\/p>\n<p>\u56e0\u4e3a\u6ca1\u6709\u540d\u5b57,\u5728\u7a0b\u5e8f\u5e76\u4e0d\u80fd\u4e3b\u52a8\u8c03\u7528\u8fd9\u4e9b\u4ee3\u7801\u5757\u3002<\/p>\n<p>\u533f\u540d\u4ee3\u7801\u5757\u662f\u5728\u521b\u5efa\u5bf9\u8c61\u7684\u65f6\u5019\u81ea\u52a8\u6267\u884c\u7684&#xff0c;\u5e76\u4e14\u5728\u6784\u9020\u5668\u6267\u884c\u4e4b\u524d&#xff0c;\u5728\u9759\u6001\u4ee3\u7801\u5757\u4e4b\u540e\u3002\u540c\u65f6\u533f\u540d\u4ee3\u7801\u5757\u5728\u6bcf\u6b21\u521b\u5efa\u5bf9\u8c61\u7684\u65f6\u5019\u90fd\u4f1a\u81ea\u52a8\u6267\u884c\u3002<\/p>\n<p>\u9759\u6001\u4ee3\u7801\u5757\u662f\u5728\u7c7b\u52a0\u8f7d\u5b8c\u6210\u4e4b\u540e\u5c31\u81ea\u52a8\u6267\u884c&#xff0c;\u5e76\u4e14\u53ea\u6267\u884c\u4e00\u6b21\u3002<\/p>\n<p>\u6ce8&#xff1a;\u6bcf\u4e2a\u7c7b\u5728\u7b2c\u4e00\u6b21\u88ab\u4f7f\u7528\u7684\u65f6\u5019\u5c31\u4f1a\u88ab\u52a0\u8f7d&#xff0c;\u5e76\u4e14\u4e00\u822c\u53ea\u4f1a\u52a0\u8f7d\u4e00\u6b21\u3002<\/p>\n<\/p>\n<p>public class Student {<br \/>\n    {<br \/>\n        System.out.println(&#034;\u533f\u540d\u4ee3\u7801\u5757&#034;);<br \/>\n    }<\/p>\n<p>    static{<br \/>\n        System.out.println(&#034;\u9759\u6001\u4ee3\u7801\u5757&#034;);<br \/>\n    }<\/p>\n<p>    public Student(){<br \/>\n        System.out.println(&#034;\u6784\u9020\u5668&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<\/p>\n<p>\/\/main:<br \/>\nStudent s1 &#061; new Student();<br \/>\nStudent s2 &#061; new Student();<br \/>\nStudent s3 &#061; new Student(); <\/p>\n<p>\u8f93\u51fa&#xff1a;<\/p>\n<p>\u9759\u6001\u4ee3\u7801\u5757 \u533f\u540d\u4ee3\u7801\u5757 \u6784\u9020\u5668<\/p>\n<p>\u533f\u540d\u4ee3\u7801\u5757 \u6784\u9020\u5668<\/p>\n<p>\u533f\u540d\u4ee3\u7801\u5757 \u6784\u9020\u5668<\/p>\n<p>\u3010\u533f\u540d\u4ee3\u7801\u5757\u548c\u9759\u6001\u4ee3\u7801\u5757\u7684\u4f5c\u7528\u3011<\/p>\n<p>\u533f\u540d\u4ee3\u7801\u5757\u7684\u4f5c\u7528\u662f\u7ed9\u5bf9\u8c61\u7684\u6210\u5458\u53d8\u91cf\u521d\u59cb\u5316\u8d4b\u503c&#xff0c;\u4f46\u662f\u56e0\u4e3a\u6784\u9020\u5668\u4e5f\u80fd\u5b8c\u6210\u8fd9\u9879\u5de5\u4f5c&#xff0c;\u6240\u4ee5\u533f\u540d\u4ee3\u7801\u5757\u4f7f\u7528\u7684\u5e76\u4e0d\u591a\u3002<\/p>\n<p>\u9759\u6001\u4ee3\u7801\u5757\u7684\u4f5c\u7528\u662f\u7ed9\u7c7b\u4e2d\u7684\u9759\u6001\u6210\u5458\u53d8\u91cf\u521d\u59cb\u5316\u8d4b\u503c\u3002<\/p>\n<\/p>\n<p>public class Person {<br \/>\n    public static String name;<br \/>\n    static{<br \/>\n        name &#061; &#034;tom&#034;;<br \/>\n    }<br \/>\n    public Person(){<br \/>\n        name &#061; &#034;zs&#034;;<br \/>\n    }<br \/>\n} <\/p>\n<p>main: System.out.println( Person.name ); \/\/tom<\/p>\n<p>\u6ce8&#xff1a;\u5728\u6784\u9020\u5668\u4e2d\u7ed9\u9759\u6001\u53d8\u91cf\u8d4b\u503c&#xff0c;\u5e76\u4e0d\u80fd\u4fdd\u8bc1\u80fd\u8d4b\u503c\u6210\u529f&#xff0c;\u56e0\u4e3a\u6784\u9020\u5668\u662f\u5728\u521b\u5efa\u5bf9\u8c61\u7684\u65f6\u5019\u624d\u6307\u5411&#xff0c;\u4f46\u662f\u9759\u6001\u53d8\u91cf\u53ef\u4ee5\u4e0d\u521b\u5efa\u5bf9\u8c61\u800c\u76f4\u63a5\u4f7f\u7528\u7c7b\u540d\u6765\u8bbf\u95ee\u3002<\/p>\n<p>4\u3001\u521b\u5efa\u548c\u521d\u59cb\u5316\u5bf9\u8c61\u7684\u8fc7\u7a0b<\/p>\n<\/p>\n<p>Student s &#061; new Student(); <\/p>\n<p>\u3010Student\u7c7b\u4e4b\u524d\u6ca1\u6709\u8fdb\u884c\u7c7b\u52a0\u8f7d\u7684\u8fc7\u7a0b\u3011<\/p>\n<li>\u7c7b\u52a0\u8f7d&#xff0c;\u540c\u65f6\u521d\u59cb\u5316\u7c7b\u4e2d\u9759\u6001\u7684\u5c5e\u6027<\/li>\n<li>\u6267\u884c\u9759\u6001\u4ee3\u7801\u5757<\/li>\n<li>\u5206\u914d\u5185\u5b58\u7a7a\u95f4&#xff0c;\u540c\u65f6\u521d\u59cb\u5316\u975e\u9759\u6001\u7684\u5c5e\u6027(\u8d4b\u9ed8\u8ba4\u503c,0\/false\/null)<\/li>\n<li>\u8c03\u7528Student\u7684\u7236\u7c7b\u6784\u9020\u5668<\/li>\n<li>\u5bf9Student\u4e2d\u7684\u5c5e\u6027\u8fdb\u884c\u663e\u793a\u8d4b\u503c(\u5982\u679c\u6709\u7684\u8bdd)<\/li>\n<li>\u6267\u884c\u533f\u540d\u4ee3\u7801\u5757<\/li>\n<li>\u6267\u884c\u6784\u9020\u5668<\/li>\n<li>\u8fd4\u56de\u5185\u5b58\u5730\u5740<\/li>\n<p>\u6ce8&#xff1a;\u5b50\u7c7b\u4e2d\u975e\u9759\u6001\u5c5e\u6027\u7684\u663e\u793a\u8d4b\u503c\u662f\u5728\u7236\u7c7b\u6784\u9020\u5668\u6267\u884c\u5b8c\u4e4b\u540e\u548c\u5b50\u7c7b\u4e2d\u7684\u533f\u540d\u4ee3\u7801\u5757\u6267\u884c\u4e4b\u524d\u7684\u65f6\u5019<\/p>\n<\/p>\n<p>public class Person{<br \/>\n    private String name &#061; &#034;zs&#034;;<br \/>\n    public Person() {<br \/>\n        System.out.println(&#034;Person\u6784\u9020\u5668&#034;);<br \/>\n        print();<br \/>\n    }<br \/>\n    public void print(){<br \/>\n        System.out.println(&#034;Person print\u65b9\u6cd5: name &#061; &#034;&#043;name);<br \/>\n    }<br \/>\n} <\/p>\n<\/p>\n<p>public class Student extends Person{<br \/>\n    private String name &#061; &#034;tom&#034;;<br \/>\n    {<br \/>\n        System.out.println(&#034;Student\u533f\u540d\u4ee3\u7801\u5757&#034;);<br \/>\n    }<br \/>\n    static{<br \/>\n        System.out.println(&#034;Student\u9759\u6001\u4ee3\u7801\u5757&#034;);<br \/>\n    }<br \/>\n    public Student(){<br \/>\n        System.out.println(&#034;Student\u6784\u9020\u5668&#034;);<br \/>\n    }<br \/>\n    public void print(){<br \/>\n        System.out.println(&#034;student print\u65b9\u6cd5: name &#061; &#034;&#043;name);<br \/>\n    }<br \/>\n    public static void main(String[] args) {<br \/>\n        new Student();<br \/>\n    }<br \/>\n} <\/p>\n<p>\u8f93\u51fa&#xff1a;<\/p>\n<p>Student\u9759\u6001\u4ee3\u7801\u5757 Person\u6784\u9020\u5668 student print\u65b9\u6cd5: name &#061; null Student\u533f\u540d\u4ee3\u7801\u5757 Student\u6784\u9020\u5668<\/p>\n<\/p>\n<p>Student s &#061; new Student();<br \/>\n\/\/Student\u7c7b\u4e4b\u524d\u5df2\u7ecf\u8fdb\u884c\u4e86\u7c7b\u52a0\u8f7d<br \/>\n\/\/1.\u5206\u914d\u5185\u5b58\u7a7a\u95f4,\u540c\u65f6\u521d\u59cb\u5316\u975e\u9759\u6001\u7684\u5c5e\u6027(\u8d4b\u9ed8\u8ba4\u503c,0\/false\/null)<br \/>\n\/\/2.\u8c03\u7528Student\u7684\u7236\u7c7b\u6784\u9020\u5668<br \/>\n\/\/3.\u5bf9Student\u4e2d\u7684\u5c5e\u6027\u8fdb\u884c\u663e\u793a\u8d4b\u503c(\u5982\u679c\u6709\u7684\u8bdd)<br \/>\n\/\/4.\u6267\u884c\u533f\u540d\u4ee3\u7801\u5757<br \/>\n\/\/5.\u6267\u884c\u6784\u9020\u5668<br \/>\n\/\/6.\u8fd4\u56de\u5185\u5b58\u5730\u5740 <\/p>\n<p>5\u3001\u9759\u6001\u5bfc\u5165<\/p>\n<p>\u9759\u6001\u5bfc\u5305\u5c31\u662fjava\u5305\u7684\u9759\u6001\u5bfc\u5165&#xff0c;\u7528import static\u4ee3\u66ffimport\u9759\u6001\u5bfc\u5165\u5305\u662fJDK1.5\u4e2d\u7684\u65b0\u7279\u6027\u3002<\/p>\n<p>\u610f\u601d\u662f\u5bfc\u5165\u8fd9\u4e2a\u7c7b\u91cc\u7684\u9759\u6001\u65b9\u6cd5\u3002<\/p>\n<p>\u597d\u5904&#xff1a;\u8fd9\u79cd\u65b9\u6cd5\u7684\u597d\u5904\u5c31\u662f\u53ef\u4ee5\u7b80\u5316\u4e00\u4e9b\u64cd\u4f5c&#xff0c;\u4f8b\u5982\u6253\u5370\u64cd\u4f5cSystem.out.println(\u2026);\u5c31\u53ef\u4ee5\u5c06\u5176\u5199\u5165\u4e00 \u4e2a\u9759\u6001\u65b9\u6cd5print(\u2026)&#xff0c;\u5728\u4f7f\u7528\u65f6\u76f4\u63a5print(\u2026)\u5c31\u53ef\u4ee5\u4e86\u3002\u4f46\u662f\u8fd9\u79cd\u65b9\u6cd5\u5efa\u8bae\u5728\u6709\u5f88\u591a\u91cd\u590d\u8c03\u7528\u7684\u65f6\u5019\u4f7f\u7528&#xff0c;\u5982\u679c\u4ec5\u6709\u4e00\u5230\u4e24\u6b21\u8c03\u7528&#xff0c;\u4e0d\u5982\u76f4\u63a5\u5199\u6765\u7684\u65b9\u4fbf\u3002<\/p>\n<\/p>\n<p>import static java.lang.Math.random;<br \/>\nimport static java.lang.Math.PI;<\/p>\n<p>public class Test {<br \/>\n    public static void main(String[] args) {<br \/>\n        \/\/\u4e4b\u524d\u662f\u9700\u8981Math.random()\u8c03\u7528\u7684<br \/>\n        System.out.println(random());<br \/>\n        System.out.println(PI);<br \/>\n    }<br \/>\n} <\/p>\n<h4 id=\"_2\u3001final\u4fee\u9970\u7b26\">2\u3001final\u4fee\u9970\u7b26<\/h4>\n<p>1\u3001\u4fee\u9970\u7c7b<\/p>\n<p>\u7528final\u4fee\u9970\u7684\u7c7b\u4e0d\u80fd\u88ab\u7ee7\u627f&#xff0c;\u6ca1\u6709\u5b50\u7c7b<\/p>\n<p>\u4f8b\u5982&#xff1a;\u6211\u4eec\u662f\u65e0\u6cd5\u5199\u4e00\u4e2a\u7c7b\u53bb\u7ee7\u627fString\u7c7b&#xff0c;\u7136\u540e\u5bf9String\u7c7b\u578b\u6269\u5c55\u7684\u3002\u56e0\u4e3aAPI\u4e2d\u5df2\u7ecf\u88abString\u7c7b\u5b9a\u4e49\u4e3afinal<\/p>\n<p>\u6211\u4eec\u4e5f\u53ef\u4ee5\u5b9a\u4e49final\u4fee\u9970\u7684\u7c7b:<\/p>\n<\/p>\n<p>public final class Action{<\/p>\n<p>}<\/p>\n<p>\/\/\u7f16\u8bd1\u62a5\u9519<br \/>\npublic class Go extends Action{<\/p>\n<p>} <\/p>\n<p>2\u3001\u4fee\u9970\u65b9\u6cd5<\/p>\n<p>\u7528final\u4fee\u9970\u7684\u65b9\u6cd5\u53ef\u4ee5\u88ab\u7ee7\u627f&#xff0c;\u4f46\u662f\u4e0d\u80fd\u88ab\u5b50\u7c7b\u7684\u91cd\u5199\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;\u6bcf\u4e2a\u7c7b\u90fd\u662fObject\u7c7b\u7684\u5b50\u7c7b&#xff0c;\u7ee7\u627f\u4e86Object\u4e2d\u7684\u4f17\u591a\u65b9\u6cd5&#xff0c;\u5728\u5b50\u7c7b\u4e2d\u53ef\u4ee5\u91cd\u5199toString\u65b9\u6cd5\u3001equals\u65b9\u6cd5\u7b49&#xff0c;\u4f46\u662f\u4e0d\u80fd\u91cd\u5199getClass\u65b9\u6cd5\u3001wait\u65b9\u6cd5\u7b49&#xff0c;\u56e0\u4e3a\u8fd9\u4e9b\u65b9\u6cd5\u90fd\u662f\u4f7f\u7528fianl\u4fee\u9970\u7684\u3002<\/p>\n<p>\u6211\u4eec\u4e5f\u53ef\u4ee5\u5b9a\u4e49final\u4fee\u9970\u7684\u65b9\u6cd5&#xff1a;<\/p>\n<\/p>\n<p>public class Person{<br \/>\n    public final void print(){}<br \/>\n}<\/p>\n<p>\/\/\u7f16\u8bd1\u62a5\u9519<br \/>\npublic class Student extends Person{<br \/>\n    public void print(){<br \/>\n    }<br \/>\n} <\/p>\n<p>3\u3001\u4fee\u9970\u53d8\u91cf<\/p>\n<p>\u7528final\u4fee\u9970\u7684\u53d8\u91cf\u8868\u793a\u5e38\u91cf&#xff0c;\u53ea\u80fd\u88ab\u8d4b\u4e00\u6b21\u503c\u3002\u4f7f\u7528final\u4fee\u9970\u7684\u53d8\u91cf\u4e5f\u5c31\u6210\u4e86\u5e38\u91cf\u4e86&#xff0c;\u56e0\u4e3a\u503c\u4e0d\u4f1a\u518d\u53d8\u4e86\u3002<\/p>\n<p>\u3010\u4fee\u9970\u5c40\u90e8\u53d8\u91cf\u3011<\/p>\n<\/p>\n<p>public class Person{<br \/>\n    public void print(final int a){<br \/>\n    \/\/\u7f16\u8bd1\u62a5\u9519,\u4e0d\u80fd\u518d\u6b21\u8d4b\u503c,\u4f20\u53c2\u7684\u65f6\u5019\u5df2\u7ecf\u8d4b\u8fc7\u4e86<br \/>\n    a &#061; 1;<br \/>\n    }<br \/>\n}<\/p>\n<p>public class Person{<br \/>\n    public void print(){<br \/>\n        final int a;<br \/>\n        a &#061; 1;<br \/>\n        \/\/\u7f16\u8bd1\u62a5\u9519,\u4e0d\u80fd\u518d\u6b21\u8d4b\u503c<br \/>\n        a &#061; 2;<br \/>\n    }<br \/>\n} <\/p>\n<p>\u3010\u4fee\u9970\u6210\u5458\u53d8\u91cf-\u975e\u9759\u6001\u6210\u5458\u53d8\u91cf\u3011<\/p>\n<\/p>\n<p>public class Person{<br \/>\n    private final int a;<br \/>\n}<br \/>\n\/*<br \/>\n\u53ea\u6709\u4e00\u6b21\u673a\u4f1a,\u53ef\u4ee5\u7ed9\u6b64\u53d8\u91cfa\u8d4b\u503c\u7684\u4f4d\u7f6e:<br \/>\n\u58f0\u660e\u7684\u540c\u65f6\u8d4b\u503c<br \/>\n\u533f\u540d\u4ee3\u7801\u5757\u4e2d\u8d4b\u503c<br \/>\n\u6784\u9020\u5668\u4e2d\u8d4b\u503c(\u7c7b\u4e2d\u51fa\u73b0\u7684\u6240\u6709\u6784\u9020\u5668\u90fd\u8981\u5199)<br \/>\n*\/ <\/p>\n<p>\u3010\u4fee\u9970\u6210\u5458\u53d8\u91cf-\u9759\u6001\u6210\u5458\u53d8\u91cf\u3011<\/p>\n<\/p>\n<p>public class Person{<br \/>\n    private static final int a;<br \/>\n}<br \/>\n\/*<br \/>\n\u53ea\u6709\u4e00\u6b21\u673a\u4f1a,\u53ef\u4ee5\u7ed9\u6b64\u53d8\u91cfa\u8d4b\u503c\u7684\u4f4d\u7f6e:<br \/>\n\u58f0\u660e\u7684\u540c\u65f6\u8d4b\u503c<br \/>\n\u9759\u6001\u4ee3\u7801\u5757\u4e2d\u8d4b\u503c<br \/>\n*\/ <\/p>\n<p>\u3010\u4fee\u9970\u5f15\u7528\u5bf9\u8c61\u3011<\/p>\n<\/p>\n<p>final Student s &#061; new Student();<br \/>\n\/\/\u7f16\u8bd1\u901a\u8fc7<br \/>\ns.setName(&#034;tom&#034;);<br \/>\ns.setName(&#034;zs&#034;);<\/p>\n<p>\/\/\u7f16\u8bd1\u62a5\u9519,\u4e0d\u80fd\u4fee\u6539\u5f15\u7528s\u6307\u5411\u7684\u5185\u5b58\u5730\u5740<br \/>\ns &#061; new Student(); <\/p>\n<h4 id=\"_3\u3001abstract\u4fee\u9970\u7b26\">3\u3001abstract\u4fee\u9970\u7b26<\/h4>\n<p>abstract\u4fee\u9970\u7b26\u53ef\u4ee5\u7528\u6765\u4fee\u9970\u65b9\u6cd5\u4e5f\u53ef\u4ee5\u4fee\u9970\u7c7b&#xff0c;\u5982\u679c\u4fee\u9970\u65b9\u6cd5&#xff0c;\u90a3\u4e48\u8be5\u65b9\u6cd5\u5c31\u662f\u62bd\u8c61\u65b9\u6cd5\u3002\u5982\u679c\u4fee\u9970\u7c7b&#xff0c;\u90a3\u4e48\u8be5\u7c7b\u5c31\u662f\u62bd\u8c61\u7c7b\u3002<\/p>\n<p>1\u3001\u62bd\u8c61\u7c7b\u548c\u62bd\u8c61\u65b9\u6cd5\u7684\u5173\u7cfb<\/p>\n<p>\u62bd\u8c61\u7c7b\u4e2d\u53ef\u4ee5\u6ca1\u6709\u62bd\u8c61\u65b9\u6cd5&#xff0c;\u4f46\u662f\u6709\u62bd\u8c61\u65b9\u6cd5\u7684\u7c7b\u4e00\u5b9a\u8981\u58f0\u660e\u4e3a\u62bd\u8c61\u7c7b\u3002<\/p>\n<p>2\u3001\u8bed\u6cd5<\/p>\n<\/p>\n<p>public abstract class Action{<br \/>\n    public abstract void doSomething();<br \/>\n}<\/p>\n<p>public void doSomething(){&#8230;} <\/p>\n<p>\u5bf9\u4e8e\u8fd9\u4e2a\u666e\u901a\u65b9\u6cd5\u6765\u8bb2&#xff1a;<\/p>\n<p>&#034;public void doSomething()&#034;\u8fd9\u90e8\u5206\u662f\u65b9\u6cd5\u7684\u58f0\u660e\u3002 &#034;{&#8230;}&#034;\u8fd9\u90e8\u5206\u662f\u65b9\u6cd5\u7684\u5b9e\u73b0,\u5982\u679c\u5927\u62ec\u53f7\u4e2d\u4ec0\u4e48\u90fd\u6ca1\u5199,\u5c31\u53eb\u65b9\u6cd5\u7684\u7a7a\u5b9e\u73b0<\/p>\n<p>\u58f0\u660e\u7c7b\u7684\u540c\u65f6&#xff0c;\u52a0\u4e0aabstract\u4fee\u9970\u7b26\u5c31\u662f\u62bd\u8c61\u7c7b \u58f0\u660e\u65b9\u6cd5\u7684\u65f6\u5019&#xff0c;\u52a0\u4e0aabstract\u4fee\u9970\u7b26&#xff0c;\u5e76\u4e14\u53bb\u6389\u65b9\u6cd5\u7684\u5927\u53e3\u53f7&#xff0c;\u540c\u65f6\u7ed3\u5c3e\u52a0\u4e0a\u5206\u53f7&#xff0c;\u8be5\u65b9\u6cd5\u5c31\u662f\u62bd\u8c61\u65b9\u6cd5\u3002<\/p>\n<h4 id=\"_3\u3001\u7279\u70b9\u53ca\u4f5c\u7528\">3\u3001\u7279\u70b9\u53ca\u4f5c\u7528<\/h4>\n<p>\u62bd\u8c61\u7c7b&#xff0c;\u4e0d\u80fd\u4f7f\u7528new\u5173\u952e\u5b57\u6765\u521b\u5efa\u5bf9\u8c61&#xff0c;\u5b83\u662f\u7528\u6765\u8ba9\u5b50\u7c7b\u7ee7\u627f\u7684\u3002 \u62bd\u8c61\u65b9\u6cd5&#xff0c;\u53ea\u6709\u65b9\u6cd5\u7684\u58f0\u660e&#xff0c;\u6ca1\u6709\u65b9\u6cd5\u7684\u5b9e\u73b0&#xff0c;\u5b83\u662f\u7528\u6765\u8ba9\u5b50\u7c7b\u5b9e\u73b0\u7684\u3002<\/p>\n<p>\u6ce8&#xff1a;\u5b50\u7c7b\u7ee7\u627f\u62bd\u8c61\u7c7b\u540e&#xff0c;\u9700\u8981\u5b9e\u73b0\u62bd\u8c61\u7c7b\u4e2d\u6ca1\u6709\u5b9e\u73b0\u7684\u62bd\u8c61\u65b9\u6cd5&#xff0c;\u5426\u5219\u8fd9\u4e2a\u5b50\u7c7b\u4e5f\u8981\u58f0\u660e\u4e3a\u62bd\u8c61\u7c7b\u3002<\/p>\n<\/p>\n<p>public abstract class Action{<br \/>\n    public abstract void doSomething();<br \/>\n}<\/p>\n<p>main:<br \/>\n\/\/\u7f16\u8bd1\u62a5\u9519,\u62bd\u8c61\u7c7b\u4e0d\u80fdnew\u5bf9\u8c61<br \/>\nAction a &#061; new Action();<\/p>\n<p>\/\/\u5b50\u7c7b\u7ee7\u627f\u62bd\u8c61\u7c7b<br \/>\npublic class Eat extends Action{<br \/>\n    \/\/\u5b9e\u73b0\u7236\u7c7b\u4e2d\u6ca1\u6709\u5b9e\u73b0\u7684\u62bd\u8c61\u65b9\u6cd5<br \/>\n    public void doSomething(){<br \/>\n        \/\/code<br \/>\n    }<br \/>\n}<\/p>\n<p>main:<br \/>\nAction a &#061; new Eat();<br \/>\na.doSomething(); <\/p>\n<p>\u6ce8&#xff1a;\u5b50\u7c7b\u7ee7\u627f\u62bd\u8c61\u7c7b&#xff0c;\u90a3\u4e48\u5c31\u5fc5\u987b\u8981\u5b9e\u73b0\u62bd\u8c61\u7c7b\u6ca1\u6709\u5b9e\u73b0\u7684\u62bd\u8c61\u65b9\u6cd5&#xff0c;\u5426\u5219\u8be5\u5b50\u7c7b\u4e5f\u8981\u58f0\u660e\u4e3a\u62bd\u8c61\u7c7b\u3002<\/p>\n<p>4\u3001\u601d\u8003<\/p>\n<p>\u601d\u80031 : \u62bd\u8c61\u7c7b\u4e0d\u80fdnew\u5bf9\u8c61&#xff0c;\u90a3\u4e48\u62bd\u8c61\u7c7b\u4e2d\u6709\u6ca1\u6709\u6784\u9020\u5668&#xff1f;<\/p>\n<p>\u62bd\u8c61\u7c7b\u662f\u4e0d\u80fd\u88ab\u5b9e\u4f8b\u5316&#xff0c;\u62bd\u8c61\u7c7b\u7684\u76ee\u7684\u5c31\u662f\u4e3a\u5b9e\u73b0\u591a\u6001\u4e2d\u7684\u5171\u540c\u70b9&#xff0c;\u62bd\u8c61\u7c7b\u7684\u6784\u9020\u5668\u4f1a\u5728\u5b50\u7c7b\u5b9e\u4f8b\u5316\u65f6\u8c03\u7528&#xff0c;\u56e0\u6b64\u5b83\u4e5f\u662f\u7528\u6765\u5b9e\u73b0\u591a\u6001\u4e2d\u7684\u5171\u540c\u70b9\u6784\u9020&#xff0c;\u4e0d\u5efa\u8bae\u8fd9\u6837\u4f7f\u7528&#xff01;<\/p>\n<p>\u601d\u80032 : \u62bd\u8c61\u7c7b\u548c\u62bd\u8c61\u65b9\u6cd5\u610f\u4e49&#xff08;\u4e3a\u4ec0\u4e48\u8981\u7f16\u5199\u62bd\u8c61\u7c7b\u3001\u62bd\u8c61\u65b9\u6cd5&#xff09;<\/p>\n<p>\u6253\u4e2a\u6bd4\u65b9&#xff0c;\u8981\u505a\u4e00\u4e2a\u6e38\u620f\u3002\u5982\u679c\u8981\u521b\u5efa\u4e00\u4e2a\u89d2\u8272&#xff0c;\u5982\u679c\u53cd\u590d\u521b\u5efa\u7c7b\u548c\u65b9\u6cd5\u4f1a\u5f88\u7e41\u7410\u548c\u9ebb\u70e6\u3002\u5efa\u4e00\u4e2a\u62bd\u8c61\u7c7b \u540e\u3002\u82e5\u8981\u521b\u5efa\u89d2\u8272\u53ef\u76f4\u63a5\u7ee7\u627f\u62bd\u8c61\u7c7b\u4e2d\u7684\u5b57\u6bb5\u548c\u65b9\u6cd5&#xff0c;\u800c\u62bd\u8c61\u7c7b\u4e2d\u53c8\u6709\u62bd\u8c61\u65b9\u6cd5\u3002\u5982\u679c\u4e00\u4e2a\u89d2\u8272\u6709\u5f88\u591a\u79cd \u804c\u4e1a&#xff0c;\u6bcf\u4e2a\u804c\u4e1a\u53c8\u6709\u5f88\u591a\u6280\u80fd&#xff0c;\u8981\u662f\u4f9d\u6b21\u5b9e\u4f8b\u8fd9\u4e9b\u6280\u80fd\u65b9\u6cd5\u4f1a\u663e\u5f97\u60f3\u5f53\u7b28\u62d9\u3002\u5b9a\u4e49\u62bd\u8c61\u65b9\u6cd5&#xff0c;\u5728\u9700\u8981\u65f6\u7ee7 \u627f\u540e\u91cd\u5199\u8c03\u7528&#xff0c;\u53ef\u4ee5\u7701\u53bb\u5f88\u591a\u4ee3\u7801\u3002<\/p>\n<p>\u603b\u4e4b\u62bd\u8c61\u7c7b\u548c\u62bd\u8c61\u65b9\u6cd5\u8d77\u5230\u4e00\u4e2a\u6846\u67b6\u4f5c\u7528\u3002\u5f88\u65b9\u4fbf\u540e\u671f\u7684\u8c03\u7528\u548c\u91cd\u5199 \u62bd\u8c61\u65b9\u6cd5\u662f\u4e3a\u4e86\u7a0b\u5e8f\u7684\u53ef\u6269\u5c55\u6027\u3002\u91cd\u5199\u62bd\u8c61\u65b9\u6cd5\u65f6\u5373\u53ef\u5b9e\u73b0\u540c\u540d\u65b9\u6cd5\u4f46\u53c8\u975e\u540c\u76ee\u7684\u7684\u8981\u6c42\u3002<\/p>\n<h3 id=\"\u63a5\u53e3\">\u63a5\u53e3<\/h3>\n<h4 id=\"_1\u3001\u63a5\u53e3\u7684\u672c\u8d28\">1\u3001\u63a5\u53e3\u7684\u672c\u8d28<\/h4>\n<p>\u666e\u901a\u7c7b&#xff1a;\u53ea\u6709\u5177\u4f53\u5b9e\u73b0 \u62bd\u8c61\u7c7b&#xff1a;\u5177\u4f53\u5b9e\u73b0\u548c\u89c4\u8303(\u62bd\u8c61\u65b9\u6cd5) \u90fd\u6709&#xff01; \u63a5\u53e3&#xff1a;\u53ea\u6709\u89c4\u8303&#xff01;<\/p>\n<p>\u4e3a\u4ec0\u4e48\u9700\u8981\u63a5\u53e3&#xff1f;\u63a5\u53e3\u548c\u62bd\u8c61\u7c7b\u7684\u533a\u522b&#xff1f;<\/p>\n<ul>\n<li>\u63a5\u53e3\u5c31\u662f\u6bd4\u201c\u62bd\u8c61\u7c7b\u201d\u8fd8\u201c\u62bd\u8c61\u201d\u7684\u201c\u62bd\u8c61\u7c7b\u201d&#xff0c;\u53ef\u4ee5\u66f4\u52a0\u89c4\u8303\u7684\u5bf9\u5b50\u7c7b\u8fdb\u884c\u7ea6\u675f\u3002\u5168\u9762\u5730\u4e13\u4e1a\u5730\u5b9e\u73b0\u4e86&#xff1a;\u89c4\u8303\u548c\u5177\u4f53\u5b9e\u73b0\u7684\u5206\u79bb\u3002<\/li>\n<li>\u62bd\u8c61\u7c7b\u8fd8\u63d0\u4f9b\u67d0\u4e9b\u5177\u4f53\u5b9e\u73b0&#xff0c;\u63a5\u53e3\u4e0d\u63d0\u4f9b\u4efb\u4f55\u5b9e\u73b0&#xff0c;\u63a5\u53e3\u4e2d\u6240\u6709\u65b9\u6cd5\u90fd\u662f\u62bd\u8c61\u65b9\u6cd5\u3002\u63a5\u53e3\u662f\u5b8c\u5168\u9762\u5411\u89c4\u8303\u7684&#xff0c;\u89c4\u5b9a\u4e86\u4e00\u6279\u7c7b\u5177\u6709\u7684\u516c\u5171\u65b9\u6cd5\u89c4\u8303\u3002<\/li>\n<li>\u4ece\u63a5\u53e3\u7684\u5b9e\u73b0\u8005\u89d2\u5ea6\u770b&#xff0c;\u63a5\u53e3\u5b9a\u4e49\u4e86\u53ef\u4ee5\u5411\u5916\u90e8\u63d0\u4f9b\u7684\u670d\u52a1\u3002<\/li>\n<li>\u4ece\u63a5\u53e3\u7684\u8c03\u7528\u8005\u89d2\u5ea6\u770b&#xff0c;\u63a5\u53e3\u5b9a\u4e49\u4e86\u5b9e\u73b0\u8005\u80fd\u63d0\u4f9b\u90a3\u4e9b\u670d\u52a1\u3002<\/li>\n<li>\u63a5\u53e3\u662f\u4e24\u4e2a\u6a21\u5757\u4e4b\u95f4\u901a\u4fe1\u7684\u6807\u51c6&#xff0c;\u901a\u4fe1\u7684\u89c4\u8303\u3002\u5982\u679c\u80fd\u628a\u4f60\u8981\u8bbe\u8ba1\u7684\u7cfb\u7edf\u4e4b\u95f4\u6a21\u5757\u4e4b\u95f4\u7684\u63a5\u53e3\u5b9a\u4e49\u597d&#xff0c;\u5c31\u76f8\u5f53\u4e8e\u5b8c\u6210\u4e86\u7cfb\u7edf\u7684\u8bbe\u8ba1\u5927\u7eb2&#xff0c;\u5269\u4e0b\u7684\u5c31\u662f\u6dfb\u7816\u52a0\u74e6\u7684\u5177\u4f53\u5b9e\u73b0\u4e86\u3002\u5927\u5bb6\u5728\u5de5\u4f5c\u4ee5\u540e&#xff0c;\u505a\u7cfb\u7edf\u65f6\u5f80\u5f80\u5c31\u662f\u4f7f\u7528\u201c\u9762\u5411\u63a5\u53e3\u201d\u7684\u601d\u60f3\u6765\u8bbe\u8ba1\u7cfb\u7edf\u3002<\/li>\n<\/ul>\n<p>\u63a5\u53e3\u7684\u672c\u8d28\u63a2\u8ba8<\/p>\n<ul>\n<li>\u63a5\u53e3\u5c31\u662f\u89c4\u8303&#xff0c;\u5b9a\u4e49\u7684\u662f\u4e00\u7ec4\u89c4\u5219&#xff0c;\u4f53\u73b0\u4e86\u73b0\u5b9e\u4e16\u754c\u4e2d\u201d\u5982\u679c\u4f60\u662f\u2026\u5219\u5fc5\u987b\u80fd\u2026\u201c\u7684\u601d\u60f3\u3002\u5982\u679c\u4f60\u662f\u5929\u4f7f&#xff0c;\u5219\u5fc5\u987b\u80fd\u98de\u3002\u5982\u679c\u4f60\u662f\u6c7d\u8f66&#xff0c;\u5219\u5fc5\u987b\u80fd\u8dd1\u3002<\/li>\n<li>\u63a5\u53e3\u7684\u672c\u8d28\u662f\u5951\u7ea6&#xff0c;\u5c31\u50cf\u6211\u4eec\u4eba\u95f4\u7684\u6cd5\u5f8b\u4e00\u6837\u3002\u5236\u5b9a\u597d\u540e\u5927\u5bb6\u90fd\u9075\u5b88\u3002<\/li>\n<li>OO\u7684\u7cbe\u9ad3&#xff0c;\u662f\u5bf9\u5bf9\u8c61\u7684\u62bd\u8c61&#xff0c;\u6700\u80fd\u4f53\u73b0\u8fd9\u4e00\u70b9\u7684\u5c31\u662f\u63a5\u53e3\u3002\u4e3a\u4ec0\u4e48\u6211\u4eec\u8ba8\u8bba\u8bbe\u8ba1\u6a21\u5f0f\u90fd\u53ea\u9488\u5bf9\u5177\u5907\u4e86\u62bd\u8c61\u80fd\u529b\u7684\u8bed\u8a00&#xff08;\u6bd4\u5982c&#043;&#043;\u3001java\u3001c#\u7b49&#xff09;&#xff0c;\u5c31\u662f\u56e0\u4e3a\u8bbe\u8ba1\u6a21\u5f0f\u6240\u7814\u7a76\u7684&#xff0c;\u5b9e\u9645\u4e0a\u5c31\u662f\u5982\u4f55\u5408\u7406\u7684\u53bb\u62bd\u8c61\u3002<\/li>\n<\/ul>\n<h4 id=\"_2\u3001\u63a5\u53e3\u4e0e\u62bd\u8c61\u7c7b\u7684\u533a\u522b\">2\u3001\u63a5\u53e3\u4e0e\u62bd\u8c61\u7c7b\u7684\u533a\u522b<\/h4>\n<p>\u62bd\u8c61\u7c7b\u4e5f\u662f\u7c7b&#xff0c;\u9664\u4e86\u53ef\u4ee5\u5199\u62bd\u8c61\u65b9\u6cd5\u4ee5\u53ca\u4e0d\u80fd\u76f4\u63a5new\u5bf9\u8c61\u4e4b\u5916&#xff0c;\u5176\u4ed6\u7684\u548c\u666e\u901a\u7c7b\u6ca1\u6709\u4ec0\u4e48\u4e0d\u4e00\u6837\u7684\u3002\u63a5\u53e3\u5df2\u7ecf\u53e6\u4e00\u79cd\u7c7b\u578b\u4e86&#xff0c;\u548c\u7c7b\u662f\u6709\u672c\u8d28\u7684\u533a\u522b\u7684&#xff0c;\u6240\u4ee5\u4e0d\u80fd\u7528\u7c7b\u7684\u6807\u51c6\u53bb\u8861\u91cf\u63a5\u53e3\u3002<\/p>\n<p>\u58f0\u660e\u7c7b\u7684\u5173\u952e\u5b57\u662fclass&#xff0c;\u58f0\u660e\u63a5\u53e3\u7684\u5173\u952e\u5b57\u662finterface\u3002<\/p>\n<p>\u62bd\u8c61\u7c7b\u662f\u7528\u6765\u88ab\u7ee7\u627f\u7684&#xff0c;java\u4e2d\u7684\u7c7b\u662f\u5355\u7ee7\u627f\u3002<\/p>\n<p>\u7c7bA\u7ee7\u627f\u4e86\u62bd\u8c61\u7c7bB&#xff0c;\u90a3\u4e48\u7c7bA\u7684\u5bf9\u8c61\u5c31\u5c5e\u4e8eB\u7c7b\u578b\u4e86&#xff0c;\u53ef\u4ee5\u4f7f\u7528\u591a\u6001 \u4e00\u4e2a\u7236\u7c7b\u7684\u5f15\u7528&#xff0c;\u53ef\u4ee5\u6307\u5411\u8fd9\u4e2a\u7236\u7c7b\u7684\u4efb\u610f\u5b50\u7c7b\u5bf9\u8c61 \u6ce8&#xff1a;\u7ee7\u627f\u7684\u5173\u952e\u5b57\u662fextends<\/p>\n<p>\u63a5\u53e3\u662f\u7528\u6765\u88ab\u7c7b\u5b9e\u73b0\u7684&#xff0c;java\u4e2d\u7684\u63a5\u53e3\u53ef\u4ee5\u88ab\u591a\u5b9e\u73b0\u3002 \u7c7bA\u5b9e\u73b0\u63a5\u53e3B\u3001C\u3001D\u3001E..&#xff0c;\u90a3\u4e48\u7c7bA\u7684\u5bf9\u8c61\u5c31\u5c5e\u4e8eB\u3001C\u3001D\u3001E\u7b49\u7c7b\u578b\u4e86&#xff0c;\u53ef\u4ee5\u4f7f\u7528\u591a\u6001 \u4e00\u4e2a\u63a5\u53e3\u7684\u5f15\u7528&#xff0c;\u53ef\u4ee5\u6307\u5411\u8fd9\u4e2a\u63a5\u53e3\u7684\u4efb\u610f\u5b9e\u73b0\u7c7b\u5bf9\u8c61 \u6ce8&#xff1a;\u5b9e\u73b0\u7684\u5173\u952e\u5b57\u662fimplements<\/p>\n<h4 id=\"_3\u3001\u63a5\u53e3\u4e2d\u7684\u65b9\u6cd5\u90fd\u662f\u62bd\u8c61\u65b9\u6cd5\">3\u3001\u63a5\u53e3\u4e2d\u7684\u65b9\u6cd5\u90fd\u662f\u62bd\u8c61\u65b9\u6cd5<\/h4>\n<p>\u63a5\u53e3\u4e2d\u53ef\u4ee5\u4e0d\u5199\u4efb\u4f55\u65b9\u6cd5&#xff0c;\u4f46\u5982\u679c\u5199\u65b9\u6cd5\u4e86&#xff0c;\u8be5\u65b9\u6cd5\u5fc5\u987b\u662f\u62bd\u8c61\u65b9\u6cd5<\/p>\n<\/p>\n<p>public interface Action{<br \/>\n    public abstract void run();<\/p>\n<p>    \/\/\u9ed8\u8ba4\u5c31\u662fpublic abstract\u4fee\u9970\u7684<br \/>\n    void test();<br \/>\n    public void go();<br \/>\n} <\/p>\n<h4 id=\"_4\u3001\u63a5\u53e3\u4e2d\u7684\u53d8\u91cf\u90fd\u662f\u9759\u6001\u5e38\u91cf\">4\u3001\u63a5\u53e3\u4e2d\u7684\u53d8\u91cf\u90fd\u662f\u9759\u6001\u5e38\u91cf<\/h4>\n<p>public static final\u4fee\u9970<\/p>\n<p>\u63a5\u53e3\u4e2d\u53ef\u4ee5\u4e0d\u5199\u4efb\u4f55\u5c5e\u6027&#xff0c;\u4f46\u5982\u679c\u5199\u5c5e\u6027\u4e86&#xff0c;\u8be5\u5c5e\u6027\u5fc5\u987b\u662fpublic static final\u4fee\u9970\u7684\u9759\u6001\u5e38\u91cf\u3002 \u6ce8&#xff1a;\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u63a5\u53e3\u540d\u8bbf\u95ee\u5176\u5c5e\u6027\u3002\u56e0\u4e3a\u662fpublic static\u4fee\u9970\u7684<\/p>\n<p>\u6ce8&#xff1a;\u58f0\u660e\u7684\u540c\u65f6\u5c31\u5fc5\u987b\u8d4b\u503c(\u56e0\u4e3a\u63a5\u53e3\u4e2d\u4e0d\u80fd\u7f16\u5199\u9759\u6001\u4ee3\u7801\u5757)<\/p>\n<\/p>\n<p>public interface Action{<br \/>\n    public static final String NAME &#061; &#034;tom&#034;;<br \/>\n    \/\/\u9ed8\u8ba4\u5c31\u662fpublic static final\u4fee\u9970\u7684<br \/>\n    int AGE &#061; 20;<br \/>\n}<\/p>\n<p>main:<br \/>\nSystem.out.println(Action.NAME);<br \/>\nSystem.out.println(Action.AGE); <\/p>\n<h4 id=\"_5\u3001\u4e00\u4e2a\u7c7b\u53ef\u4ee5\u5b9e\u73b0\u591a\u4e2a\u63a5\u53e3\">5\u3001\u4e00\u4e2a\u7c7b\u53ef\u4ee5\u5b9e\u73b0\u591a\u4e2a\u63a5\u53e3<\/h4>\n<\/p>\n<p>public class Student implements A,B,C,D{<br \/>\n    \/\/Student\u9700\u8981\u5b9e\u73b0\u63a5\u53e3A B C D\u4e2d\u6240\u6709\u7684\u62bd\u8c61\u65b9\u6cd5<br \/>\n    \/\/\u5426\u5219Student\u7c7b\u5c31\u8981\u58f0\u660e\u4e3a\u62bd\u8c61\u7c7b,\u56e0\u4e3a\u6709\u62bd\u8c61\u65b9\u6cd5\u6ca1\u5b9e\u73b0<br \/>\n}<\/p>\n<p>main:<br \/>\nA s1 &#061; new Student();<br \/>\nB s2 &#061; new Student();<br \/>\nC s3 &#061; new Student();<br \/>\nD s4 &#061; new Student(); <\/p>\n<p>\u6ce8&#xff1a; s1\u53ea\u80fd\u8c03\u7528\u63a5\u53e3A\u4e2d\u58f0\u660e\u7684\u65b9\u6cd5\u4ee5\u53caObject\u4e2d\u7684\u65b9\u6cd5 s2\u53ea\u80fd\u8c03\u7528\u63a5\u53e3B\u4e2d\u58f0\u660e\u7684\u65b9\u6cd5\u4ee5\u53caObject\u4e2d\u7684\u65b9\u6cd5 s3\u53ea\u80fd\u8c03\u7528\u63a5\u53e3C\u4e2d\u58f0\u660e\u7684\u65b9\u6cd5\u4ee5\u53caObject\u4e2d\u7684\u65b9\u6cd5 s4\u53ea\u80fd\u8c03\u7528\u63a5\u53e3D\u4e2d\u58f0\u660e\u7684\u65b9\u6cd5\u4ee5\u53caObject\u4e2d\u7684\u65b9\u6cd5<\/p>\n<p>\u6ce8&#xff1a;\u5fc5\u8981\u65f6\u53ef\u4ee5\u7c7b\u578b\u5f3a\u5236\u8f6c\u6362<\/p>\n<p>\u4f8b\u5982 : \u63a5\u53e3A \u4e2d\u6709test() &#xff0c; \u63a5\u53e3B \u4e2d\u6709run()<\/p>\n<h4 id=\"_6\u3001\u4e00\u4e2a\u63a5\u53e3\u53ef\u4ee5\u7ee7\u627f\u591a\u4e2a\u7236\u63a5\u53e3\">6\u3001\u4e00\u4e2a\u63a5\u53e3\u53ef\u4ee5\u7ee7\u627f\u591a\u4e2a\u7236\u63a5\u53e3<\/h4>\n<\/p>\n<p>public interface A{<br \/>\n    public void testA();<br \/>\n}<\/p>\n<p>public interface B{<br \/>\n    public void testB();<br \/>\n}<\/p>\n<p>\/\/\u63a5\u53e3C\u628a\u63a5\u53e3A B\u4e2d\u7684\u65b9\u6cd5\u90fd\u7ee7\u627f\u8fc7\u6765\u4e86<br \/>\npublic interface C extends A,B{<br \/>\n    public void testC();<br \/>\n}<\/p>\n<p>\/\/Student\u76f8\u5f53\u4e8e\u5b9e\u73b0\u4e86A B C\u4e09\u4e2a\u63a5\u53e3,\u9700\u8981\u5b9e\u73b0\u6240\u6709\u7684\u62bd\u8c61\u65b9\u6cd5<br \/>\n\/\/Student\u7684\u5bf9\u8c61\u4e5f\u5c31\u540c\u65f6\u5c5e\u4e8eA\u7c7b\u578b B\u7c7b\u578b C\u7c7b\u578b<br \/>\npublic class Student implements C{<br \/>\n    public viod testA(){}<br \/>\n    public viod testB(){}<br \/>\n    public viod testC(){}<br \/>\n}<\/p>\n<p>main:<\/p>\n<p>C o &#061; new Student();<br \/>\nSystem.out.println(o instanceof A);\/\/true<br \/>\nSystem.out.println(o instanceof B);\/\/true<br \/>\nSystem.out.println(o instanceof C);\/\/true<br \/>\nSystem.out.println(o instanceof Student);\/\/true<br \/>\nSystem.out.println(o instanceof Object);\/\/true<br \/>\nSystem.out.println(o instanceof Teacher);\/\/false<\/p>\n<p>\/\/\u7f16\u8bd1\u62a5\u9519<br \/>\nSystem.out.println(o instanceof String); <\/p>\n<p>\u6ce8&#xff1a;System.out.println(o instanceof X);<\/p>\n<p>\u5982\u679co\u662f\u4e00\u4e2a\u63a5\u53e3\u7c7b\u578b\u58f0\u660e\u7684\u53d8\u91cf&#xff0c;\u90a3\u4e48\u53ea\u8981X\u4e0d\u662f\u4e00\u4e2afinal\u4fee\u9970\u7684\u7c7b&#xff0c;\u8be5\u4ee3\u7801\u5c31\u80fd\u901a\u8fc7\u7f16\u8bd1&#xff0c;\u81f3\u4e8e\u5176\u7ed3\u679c\u662f\u4e0d\u662ftrue&#xff0c;\u5c31\u8981\u770b\u53d8\u91cfo\u6307\u5411\u7684\u5bf9\u8c61\u7684\u5b9e\u9645\u7c7b\u578b&#xff0c;\u662f\u4e0d\u662fX\u7684\u5b50\u7c7b\u6216\u8005\u5b9e\u73b0\u7c7b\u4e86\u3002<\/p>\n<p>\u6ce8&#xff1a;\u4e00\u4e2a\u5f15\u7528\u6240\u6307\u5411\u7684\u5bf9\u8c61&#xff0c;\u662f\u6709\u53ef\u80fd\u5b9e\u73b0\u4efb\u4f55\u4e00\u4e2a\u63a5\u53e3\u7684\u3002(java\u4e2d\u7684\u591a\u5b9e\u73b0)<\/p>\n<h4 id=\"_7\u3001\u63a5\u53e3\u7684\u4f5c\u7528\">7\u3001\u63a5\u53e3\u7684\u4f5c\u7528<\/h4>\n<p>\u63a5\u53e3\u7684\u6700\u4e3b\u8981\u7684\u4f5c\u7528\u662f\u8fbe\u5230\u7edf\u4e00\u8bbf\u95ee&#xff0c;\u5c31\u662f\u5728\u521b\u5efa\u5bf9\u8c61\u7684\u65f6\u5019\u7528\u63a5\u53e3\u521b\u5efa<\/p>\n<p>\u3010\u63a5\u53e3\u540d\u3011 \u3010\u5bf9\u8c61\u540d\u3011&#061; new \u3010\u5b9e\u73b0\u63a5\u53e3\u7684\u7c7b\u3011<\/p>\n<p>\u8fd9\u6837\u4f60\u50cf\u7528\u54ea\u4e2a\u7c7b\u7684\u5bf9\u8c61\u5c31\u53ef\u4ee5new\u54ea\u4e2a\u5bf9\u8c61\u4e86&#xff0c;\u4e0d\u9700\u8981\u6539\u539f\u6765\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u5047\u5982\u6211\u4eec\u4e24\u4e2a\u7c7b\u4e2d\u90fd\u6709\u4e2afunction()\u7684\u65b9\u6cd5&#xff0c;\u5982\u679c\u6211\u7528\u63a5\u53e3&#xff0c;\u90a3\u6837\u6211new a()&#xff1b;\u5c31\u662f\u7528a\u7684\u65b9\u6cd5&#xff0c;new b() \u5c31\u662f\u7528b\u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u8fd9\u4e2a\u5c31\u53eb\u7edf\u4e00\u8bbf\u95ee&#xff0c;\u56e0\u4e3a\u4f60\u5b9e\u73b0\u8fd9\u4e2a\u63a5\u53e3\u7684\u7c7b\u7684\u65b9\u6cd5\u540d\u76f8\u540c&#xff0c;\u4f46\u662f\u5b9e\u73b0\u5185\u5bb9\u4e0d\u540c<\/p>\n<p>\u603b\u7ed3&#xff1a;<\/p>\n<li>Java\u63a5\u53e3\u4e2d\u7684\u6210\u5458\u53d8\u91cf\u9ed8\u8ba4\u90fd\u662fpublic,static,final\u7c7b\u578b\u7684(\u90fd\u53ef\u7701\u7565)&#xff0c;\u5fc5\u987b\u88ab\u663e\u793a\u521d\u59cb\u5316&#xff0c;\u5373\u63a5\u53e3\u4e2d\u7684\u6210\u5458\u53d8\u91cf\u4e3a\u5e38\u91cf(\u5927\u5199,\u5355\u8bcd\u4e4b\u95f4\u7528&#034;_&#034;\u5206\u9694)<\/li>\n<li>Java\u63a5\u53e3\u4e2d\u7684\u65b9\u6cd5\u9ed8\u8ba4\u90fd\u662fpublic,abstract\u7c7b\u578b\u7684(\u90fd\u53ef\u7701\u7565)&#xff0c;\u6ca1\u6709\u65b9\u6cd5\u4f53,\u4e0d\u80fd\u88ab\u5b9e\u4f8b\u5316<\/li>\n<li>Java\u63a5\u53e3\u4e2d\u53ea\u80fd\u5305\u542bpublic,static,final\u7c7b\u578b\u7684\u6210\u5458\u53d8\u91cf\u548cpublic,abstract\u7c7b\u578b\u7684\u6210\u5458\u65b9\u6cd5<\/li>\n<li>\u63a5\u53e3\u4e2d\u6ca1\u6709\u6784\u9020\u65b9\u6cd5,\u4e0d\u80fd\u88ab\u5b9e\u4f8b\u5316<\/li>\n<li>\u4e00\u4e2a\u63a5\u53e3\u4e0d\u80fd\u5b9e\u73b0(implements)\u53e6\u4e00\u4e2a\u63a5\u53e3,\u4f46\u5b83\u53ef\u4ee5\u7ee7\u627f\u591a\u4e2a\u5176\u5b83\u7684\u63a5\u53e3<\/li>\n<li>Java\u63a5\u53e3\u5fc5\u987b\u901a\u8fc7\u7c7b\u6765\u5b9e\u73b0\u5b83\u7684\u62bd\u8c61\u65b9\u6cd5<\/li>\n<li>\u5f53\u7c7b\u5b9e\u73b0\u4e86\u67d0\u4e2aJava\u63a5\u53e3\u65f6&#xff0c;\u5b83\u5fc5\u987b\u5b9e\u73b0\u63a5\u53e3\u4e2d\u7684\u6240\u6709\u62bd\u8c61\u65b9\u6cd5&#xff0c;\u5426\u5219\u8fd9\u4e2a\u7c7b\u5fc5\u987b\u58f0\u660e\u4e3a\u62bd\u8c61\u7c7b<\/li>\n<li>\u4e0d\u5141\u8bb8\u521b\u5efa\u63a5\u53e3\u7684\u5b9e\u4f8b&#xff08;\u5b9e\u4f8b\u5316&#xff09;&#xff0c;\u4f46\u5141\u8bb8\u5b9a\u4e49\u63a5\u53e3\u7c7b\u578b\u7684\u5f15\u7528\u53d8\u91cf&#xff0c;\u8be5\u5f15\u7528\u53d8\u91cf\u5f15\u7528\u5b9e\u73b0\u4e86\u8fd9\u4e2a\u63a5\u53e3\u7684\u7c7b\u7684\u5b9e\u4f8b<\/li>\n<li>\u4e00\u4e2a\u7c7b\u53ea\u80fd\u7ee7\u627f\u4e00\u4e2a\u76f4\u63a5\u7684\u7236\u7c7b&#xff0c;\u4f46\u53ef\u4ee5\u5b9e\u73b0\u591a\u4e2a\u63a5\u53e3&#xff0c;\u95f4\u63a5\u7684\u5b9e\u73b0\u4e86\u591a\u7ee7\u627f\u3002<\/li>\n<p>interface SwimInterface{<br \/>\n    void swim();<br \/>\n}<\/p>\n<p>class Fish{<br \/>\n    int fins&#061;4;<br \/>\n}<\/p>\n<p>class Duck {<br \/>\n    int leg&#061;2;<br \/>\n    void egg(){};<br \/>\n}<\/p>\n<p>class Goldfish extends Fish implements SwimInterface {<br \/>\n    &#064;Override<br \/>\n    public void swim() {<br \/>\n        System.out.println(&#034;Goldfish can swim &#034;);<br \/>\n    }<br \/>\n}<\/p>\n<p>class SmallDuck extends Duck implements SwimInterface {<br \/>\n    public void egg(){<br \/>\n        System.out.println(&#034;SmallDuck can lay eggs &#034;);<br \/>\n    }<br \/>\n    &#064;Override<br \/>\n    public void swim() {<br \/>\n    System.out.println(&#034;SmallDuck can swim &#034;);<br \/>\n    }<br \/>\n}<\/p>\n<p>public class InterfaceDemo {<br \/>\n    public static void main(String[] args) {<br \/>\n        Goldfish goldfish&#061;new Goldfish();<br \/>\n        goldfish.swim();<\/p>\n<p>        SmallDuck smallDuck&#061; new SmallDuck();<br \/>\n        smallDuck.swim();<br \/>\n        smallDuck.egg();<br \/>\n    }<br \/>\n} <\/p>\n<h3 id=\"\u5185\u90e8\u7c7b\">\u5185\u90e8\u7c7b<\/h3>\n<p>\u4e0a\u4e00\u5c0f\u8282&#xff0c;\u6211\u4eec\u5b66\u4e60\u4e86\u63a5\u53e3&#xff0c;\u5728\u4ee5\u540e\u7684\u5de5\u4f5c\u4e2d\u63a5\u53e3\u662f\u6211\u4eec\u7ecf\u5e38\u8981\u78b0\u5230\u7684&#xff0c;\u6240\u4ee5\u4e00\u5b9a\u8981\u591a\u53bb\u56de\u987e\u3002\u63a5\u4e0b\u6765\u4ecb\u7ecd\u4e00\u4e0b\u5185\u90e8\u7c7b\u3002\u5f88\u591a\u65f6\u5019\u6211\u4eec\u521b\u5efa\u7c7b\u7684\u5bf9\u8c61\u7684\u65f6\u5019\u5e76\u4e0d\u9700\u8981\u4f7f\u7528\u5f88\u591a\u6b21&#xff0c;\u6bcf\u6b21\u53ea\u4f7f\u7528\u4e00\u6b21&#xff0c;\u8fd9\u4e2a\u65f6\u5019\u6211\u4eec\u5c31\u53ef\u4ee5\u4f7f\u7528\u5185\u90e8\u7c7b\u4e86\u3002<\/p>\n<h4 id=\"_1\u3001\u5185\u90e8\u7c7b\u6982\u8ff0\">1\u3001\u5185\u90e8\u7c7b\u6982\u8ff0<\/h4>\n<p>\u5185\u90e8\u7c7b\u5c31\u662f\u5728\u4e00\u4e2a\u7c7b\u7684\u5185\u90e8\u5728\u5b9a\u4e49\u4e00\u4e2a\u7c7b&#xff0c;\u6bd4\u5982&#xff0c;A\u7c7b\u4e2d\u5b9a\u4e49\u4e00\u4e2aB\u7c7b&#xff0c;\u90a3\u4e48B\u7c7b\u76f8\u5bf9A\u7c7b\u6765\u8bf4\u5c31\u79f0\u4e3a\u5185\u90e8\u7c7b&#xff0c;\u800cA\u7c7b\u76f8\u5bf9B\u7c7b\u6765\u8bf4\u5c31\u662f\u5916\u90e8\u7c7b\u4e86\u3002<\/p>\n<p>\u5185\u90e8\u7c7b\u4e0d\u662f\u5728\u4e00\u4e2ajava\u6e90\u6587\u4ef6\u4e2d\u7f16\u5199\u4fe9\u4e2a\u5e73\u884c\u7684\u4fe9\u4e2a\u7c7b&#xff0c;\u800c\u662f\u5728\u4e00\u4e2a\u7c7b\u7684\u5185\u90e8\u518d\u5b9a\u4e49\u53e6\u5916\u4e00\u4e2a\u7c7b\u3002 \u6211\u4eec\u53ef\u4ee5\u628a\u5916\u8fb9\u7684\u7c7b\u79f0\u4e3a\u5916\u90e8\u7c7b&#xff0c;\u5728\u5176\u5185\u90e8\u7f16\u5199\u7684\u7c7b\u79f0\u4e3a\u5185\u90e8\u7c7b\u3002<\/p>\n<p>\u5185\u90e8\u7c7b\u5206\u4e3a\u56db\u79cd&#xff1a;<\/p>\n<li>\u6210\u5458\u5185\u90e8\u7c7b<\/li>\n<li>\u9759\u6001\u5185\u90e8\u7c7b<\/li>\n<li>\u5c40\u90e8\u5185\u90e8\u7c7b<\/li>\n<li>\u533f\u540d\u5185\u90e8\u7c7b<\/li>\n<h4 id=\"_2\u3001\u6210\u5458\u5185\u90e8\u7c7b\">2\u3001\u6210\u5458\u5185\u90e8\u7c7b<\/h4>\n<p>\u6210\u5458\u5185\u90e8\u7c7b&#xff08;\u5b9e\u4f8b\u5185\u90e8\u7c7b\u3001\u975e\u9759\u6001\u5185\u90e8\u7c7b&#xff09;<\/p>\n<p>\u6ce8&#xff1a;\u6210\u5458\u5185\u90e8\u7c7b\u4e2d\u4e0d\u80fd\u5199\u9759\u6001\u5c5e\u6027\u548c\u65b9\u6cd5<\/p>\n<p>\u3010\u5b9a\u4e49\u4e00\u4e2a\u5185\u90e8\u7c7b\u3011<\/p>\n<\/p>\n<p>\/\/\u5728A\u7c7b\u4e2d\u7533\u660e\u4e86\u4e00\u4e2aB\u7c7b&#xff0c;\u6b64B\u7c7b\u5c31\u5728A\u7684\u5185\u90e8&#xff0c;\u5e76\u4e14\u5728\u6210\u5458\u53d8\u91cf\u7684\u4f4d\u7f6e\u4e0a&#xff0c;\u6240\u4ee5\u5c31\u79f0\u4e3a\u6210\u5458\u5185\u90e8\u7c7b<br \/>\npublic class Outer {<br \/>\n    private int id;<br \/>\n    public void out(){<br \/>\n        System.out.println(&#034;\u8fd9\u662f\u5916\u90e8\u7c7b\u65b9\u6cd5&#034;);<br \/>\n    }<\/p>\n<p>    class Inner{<br \/>\n        public void in(){<br \/>\n        System.out.println(&#034;\u8fd9\u662f\u5185\u90e8\u7c7b\u65b9\u6cd5&#034;);<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<p>\u3010\u5b9e\u4f8b\u5316\u5185\u90e8\u7c7b\u3011<\/p>\n<p>\u5b9e\u4f8b\u5316\u5185\u90e8\u7c7b&#xff0c;\u9996\u5148\u9700\u8981\u5b9e\u4f8b\u5316\u5916\u90e8\u7c7b&#xff0c;\u901a\u8fc7\u5916\u90e8\u7c7b\u53bb\u8c03\u7528\u5185\u90e8\u7c7b<\/p>\n<\/p>\n<p>public class Outer {<br \/>\n    private int id;<br \/>\n    public void out(){<br \/>\n    System.out.println(&#034;\u8fd9\u662f\u5916\u90e8\u7c7b\u65b9\u6cd5&#034;);<br \/>\n    }<\/p>\n<p>    class Inner{<br \/>\n        public void in(){<br \/>\n        System.out.println(&#034;\u8fd9\u662f\u5185\u90e8\u7c7b\u65b9\u6cd5&#034;);<br \/>\n    }<br \/>\n    }<br \/>\n}<\/p>\n<p>public class Test{<br \/>\n    public static void main(String[] args) {<br \/>\n        \/\/\u5b9e\u4f8b\u5316\u6210\u5458\u5185\u90e8\u7c7b\u5206\u4e24\u6b65<br \/>\n        \/\/1\u3001\u5b9e\u4f8b\u5316\u5916\u90e8\u7c7b<br \/>\n        Outer outObject &#061; new Outer();<br \/>\n        \/\/2\u3001\u901a\u8fc7\u5916\u90e8\u7c7b\u8c03\u7528\u5185\u90e8\u7c7b<br \/>\n        Outer.Inner inObject &#061; outObject.new Inner();<br \/>\n        \/\/\u6d4b\u8bd5&#xff0c;\u8c03\u7528\u5185\u90e8\u7c7b\u4e2d\u7684\u65b9\u6cd5<br \/>\n        inObject.in();\/\/\u6253\u5370&#xff1a;\u8fd9\u662f\u5185\u90e8\u7c7b\u65b9\u6cd5<br \/>\n    }<br \/>\n} <\/p>\n<p>\u5206\u6790&#xff1a;\u60f3\u60f3\u5982\u679c\u4f60\u8981\u4f7f\u7528\u4e00\u4e2a\u7c7b\u4e2d\u65b9\u6cd5\u6216\u8005\u5c5e\u6027&#xff0c;\u4f60\u5c31\u5fc5\u987b\u8981\u5148\u6709\u8be5\u7c7b\u7684\u4e00\u4e2a\u5bf9\u8c61&#xff0c;\u540c\u7406&#xff0c;\u4e00\u4e2a\u7c7b\u5728\u53e6 \u4e00\u4e2a\u7c7b\u7684\u5185\u90e8&#xff0c;\u90a3\u4e48\u60f3\u8981\u4f7f\u7528\u8fd9\u4e2a\u5185\u90e8\u7c7b&#xff0c;\u5c31\u5fc5\u987b\u5148\u8981\u6709\u5916\u90e8\u7c7b\u7684\u4e00\u4e2a\u5b9e\u4f8b\u5bf9\u8c61&#xff0c;\u7136\u540e\u5728\u901a\u8fc7\u8be5\u5bf9\u8c61\u53bb\u4f7f\u7528\u5185\u90e8\u7c7b\u3002<\/p>\n<p>\u3010\u6210\u5458\u5185\u90e8\u7c7b\u80fd\u5e72\u4ec0\u4e48&#xff1f;\u3011<\/p>\n<ul>\n<li>\u8bbf\u95ee\u5916\u90e8\u7c7b\u7684\u6240\u6709\u5c5e\u6027(\u8fd9\u91cc\u7684\u5c5e\u6027\u5305\u62ec\u79c1\u6709\u7684\u6210\u5458\u53d8\u91cf&#xff0c;\u65b9\u6cd5)<\/li>\n<\/ul>\n<p>public class Outer {<br \/>\n    private int id;<br \/>\n    public void out(){<br \/>\n        System.out.println(&#034;\u8fd9\u662f\u5916\u90e8\u7c7b\u65b9\u6cd5&#034;);<br \/>\n    }<\/p>\n<p>    class Inner{<br \/>\n        public void in(){<br \/>\n            System.out.println(&#034;\u8fd9\u662f\u5185\u90e8\u7c7b\u65b9\u6cd5&#034;);<br \/>\n        }<br \/>\n        \/\/\u5185\u90e8\u7c7b\u8bbf\u95ee\u5916\u90e8\u7c7b\u79c1\u6709\u7684\u6210\u5458\u53d8\u91cf<br \/>\n        public void useId(){<br \/>\n            System.out.println(id&#043;3);\u3002<br \/>\n        }<br \/>\n        \/\/\u5185\u90e8\u7c7b\u8bbf\u95ee\u5916\u90e8\u7c7b\u7684\u65b9\u6cd5<br \/>\n        public void useOut(){<br \/>\n            out();<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>public class Test{<br \/>\n    public static void main(String[] args) {<br \/>\n        \/\/\u5b9e\u4f8b\u5316\u6210\u5458\u5185\u90e8\u7c7b\u5206\u4e24\u6b65<br \/>\n        \/\/1\u3001\u5b9e\u4f8b\u5316\u5916\u90e8\u7c7b<br \/>\n        Outer outObject &#061; new Outer();<br \/>\n        \/\/2\u3001\u901a\u8fc7\u5916\u90e8\u7c7b\u8c03\u7528\u5185\u90e8\u7c7b<br \/>\n        Outer.Inner inObject &#061; outObject.new Inner();<br \/>\n        \/\/\u6d4b\u8bd5<br \/>\n        inObject.useId();\/\/\u6253\u53703&#xff0c;\u56e0\u4e3aid\u521d\u59cb\u5316\u503c\u4e3a0&#xff0c;0&#043;3\u5c31\u4e3a3&#xff0c;\u5176\u4e2d\u5728\u5185\u90e8\u7c7b\u5c31\u4f7f\u7528\u4e86\u5916\u90e8\u7c7b\u7684\u79c1\u6709\u6210\u5458\u53d8\u91cfid\u3002<br \/>\n        inObject.useOut();\/\/\u6253\u5370&#xff1a;\u8fd9\u662f\u5916\u90e8\u7c7b\u65b9\u6cd5<br \/>\n    }<br \/>\n} <\/p>\n<ul>\n<li>\u5982\u679c\u5185\u90e8\u7c7b\u4e2d\u7684\u53d8\u91cf\u540d\u548c\u5916\u90e8\u7c7b\u7684\u6210\u5458\u53d8\u91cf\u540d\u4e00\u6837&#xff0c;\u8981\u901a\u8fc7\u521b\u5efa\u5916\u90e8\u7c7b\u5bf9\u8c61&#034;.&#034;\u5c5e\u6027\u6765\u8bbf\u95ee\u5916\u90e8\u7c7b\u5c5e\u6027&#xff0c;\u901a\u8fc7this.\u5c5e\u6027\u8bbf\u95ee\u5185\u90e8\u7c7b\u6210\u5458\u5c5e\u6027<\/li>\n<\/ul>\n<p>public class Outer {<br \/>\n    private int id;\/\/\u9ed8\u8ba4\u521d\u59cb\u53160<\/p>\n<p>    public void out() {<br \/>\n        System.out.println(&#034;\u8fd9\u662f\u5916\u90e8\u7c7b\u65b9\u6cd5&#034;);<br \/>\n    }<\/p>\n<p>    class Inner {<br \/>\n        private int id &#061; 8; \/\/\u8fd9\u4e2aid\u8ddf\u5916\u90e8\u7c7b\u7684\u5c5e\u6027id\u540d\u79f0\u4e00\u6837\u3002<\/p>\n<p>        public void in() {<br \/>\n            System.out.println(&#034;\u8fd9\u662f\u5185\u90e8\u7c7b\u65b9\u6cd5&#034;);<br \/>\n        }<\/p>\n<p>        public void test() {<br \/>\n            System.out.println(id);\/\/\u8f93\u51fa8&#xff0c;\u5185\u90e8\u7c7b\u4e2d\u7684\u53d8\u91cf\u4f1a\u6682\u65f6\u5c06\u5916\u90e8\u7c7b\u7684\u6210\u5458\u53d8\u91cf\u7ed9\u9690\u85cf<br \/>\n            \/\/ \u5982\u4f55\u8c03\u7528\u5916\u90e8\u7c7b\u7684\u6210\u5458\u53d8\u91cf\u5462&#xff1f;\u901a\u8fc7Outer.this<br \/>\n            \/\/ \u60f3\u8981\u77e5\u9053\u4e3a\u4ec0\u4e48\u80fd\u901a\u8fc7\u8fd9\u4e2a\u6765\u8c03\u7528&#xff0c;\u5c31\u5f97\u660e\u767d\u4e0b\u9762\u8fd9\u4e2a\u539f\u7406<br \/>\n            \/\/ \u60f3\u5b9e\u4f8b\u5316\u5185\u90e8\u7c7b\u5bf9\u8c61&#xff0c;\u5c31\u5fc5\u987b\u901a\u8fc7\u5916\u90e8\u7c7b\u5bf9\u8c61&#xff0c;\u5f53\u5916\u90e8\u7c7b\u5bf9\u8c61\u6765new\u51fa\u5185\u90e8\u7c7b\u5bf9\u8c61\u65f6&#xff0c;\u4f1a\u628a\u81ea\u5df1(\u5916\u90e8\u7c7b\u5bf9\u8c61)\u7684\u5f15\u7528\u4f20\u5230\u4e86\u5185\u90e8\u7c7b\u4e2d&#xff0c;<br \/>\n            \/\/ \u6240\u4ee5\u5185\u90e8\u7c7b\u5c31\u53ef\u4ee5\u901a\u8fc7Outer.this\u6765\u8bbf\u95ee\u5916\u90e8\u7c7b\u7684\u5c5e\u6027\u548c\u65b9\u6cd5<br \/>\n            \/\/ \u5230\u8fd9\u91cc&#xff0c;\u4f60\u4e5f\u5c31\u53ef\u4ee5\u77e5\u9053\u4e3a\u4ec0\u4e48\u5185\u90e8\u7c7b\u53ef\u4ee5\u8bbf\u95ee\u5916\u90e8\u7c7b\u7684\u5c5e\u6027\u548c\u65b9\u6cd5&#xff0c;\u8fd9\u91cc\u7531\u4e8e\u6709\u4e24\u4e2a\u76f8\u540c\u7684\u5c5e\u6027\u540d\u79f0&#xff0c;<\/p>\n<p>            \/\/ \u6240\u4ee5\u9700\u8981\u663e\u793a\u7684\u7528Outer.this\u6765\u8c03\u7528\u5916\u90e8\u7c7b\u7684\u5c5e\u6027&#xff0c;\u5e73\u5e38\u5982\u679c\u5c5e\u6027\u540d\u4e0d\u91cd\u590d<br \/>\n            \/\/ \u90a3\u4e48\u6211\u4eec\u5728\u5185\u90e8\u7c7b\u4e2d\u8c03\u7528\u5916\u90e8\u7c7b\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u65f6&#xff0c;\u524d\u9762\u5c31\u9690\u5f0f\u7684\u8c03\u7528\u4e86Outer.this\u3002<br \/>\n            System.out.println(Outer.this.id);\/\/\u8f93\u51fa\u5916\u90e8\u7c7b\u7684\u5c5e\u6027id\u3002\u4e5f\u5c31\u662f\u8f93\u51fa0<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<p>\u501f\u52a9\u6210\u5458\u5185\u90e8\u7c7b&#xff0c;\u6765\u603b\u7ed3\u5185\u90e8\u7c7b(\u5305\u62ec4\u79cd\u5185\u90e8\u7c7b)\u7684\u901a\u7528\u7528\u6cd5&#xff1a;<\/p>\n<li>\n<p>\u8981\u60f3\u8bbf\u95ee\u5185\u90e8\u7c7b\u4e2d\u7684\u5185\u5bb9&#xff0c;\u5fc5\u987b\u901a\u8fc7\u5916\u90e8\u7c7b\u5bf9\u8c61\u6765\u5b9e\u4f8b\u5316\u5185\u90e8\u7c7b\u3002<\/p>\n<\/li>\n<li>\n<p>\u80fd\u591f\u8bbf\u95ee\u5916\u90e8\u7c7b\u6240\u6709\u7684\u5c5e\u6027\u548c\u65b9\u6cd5&#xff0c;\u539f\u7406\u5c31\u662f\u5728\u901a\u8fc7\u5916\u90e8\u7c7b\u5bf9\u8c61\u5b9e\u4f8b\u5316\u5185\u90e8\u7c7b\u5bf9\u8c61\u65f6&#xff0c;\u5916\u90e8\u7c7b\u5bf9\u8c61\u628a\u81ea\u5df1\u7684\u5f15\u7528\u4f20\u8fdb\u4e86\u5185\u90e8\u7c7b&#xff0c;\u4f7f\u5185\u90e8\u7c7b\u53ef\u4ee5\u7528\u901a\u8fc7Outer.this\u53bb\u8c03\u7528\u5916\u90e8\u7c7b\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002<\/p>\n<p>\u4e00\u822c\u90fd\u662f\u9690\u5f0f\u8c03\u7528\u4e86&#xff0c;\u4f46\u662f\u5f53\u5185\u90e8\u7c7b\u4e2d\u6709\u5c5e\u6027\u6216\u8005\u65b9\u6cd5\u540d\u548c\u5916\u90e8\u7c7b\u4e2d\u7684\u5c5e\u6027\u6216\u65b9\u6cd5\u540d\u76f8\u540c\u7684\u65f6\u5019&#xff0c;\u5c31\u9700\u8981\u901a\u8fc7\u663e\u5f0f\u8c03\u7528Outer.this\u4e86\u3002<\/p>\n<\/li>\n<p>\u3010\u5199\u7684\u4e00\u4e2a\u5c0f\u4f8b\u5b50\u3011<\/p>\n<\/p>\n<p>public class MemberInnerClassTest {<br \/>\n    private String name;<br \/>\n    private static int age;<\/p>\n<p>    public void run() {<br \/>\n    }<\/p>\n<p>    public static void go() {<br \/>\n    }<\/p>\n<p>    public class MemberInnerClass {<br \/>\n        private String name;<\/p>\n<p>        \/\/\u5185\u90e8\u7c7b\u8bbf\u95ee\u5916\u90e8\u7c7b<br \/>\n        public void test(String name) {<br \/>\n            System.out.println(name);<br \/>\n            System.out.println(this.name);<br \/>\n            System.out.println(MemberInnerClassTest.this.name);<br \/>\n            System.out.println(MemberInnerClassTest.age);<br \/>\n            MemberInnerClassTest.this.run();<br \/>\n            MemberInnerClassTest.go();<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/\/\u5916\u90e8\u7c7b\u8bbf\u95ee\u6210\u5458\u5185\u90e8\u7c7b<br \/>\n    \/\/\u6210\u5458\u5185\u90e8\u7c7b\u7684\u5bf9\u8c61\u8981 \u4f9d\u8d56\u4e8e\u5916\u90e8\u7c7b\u7684\u5bf9\u8c61\u7684\u5b58\u5728<br \/>\n    public void test() {<br \/>\n        \/\/MemberInnerClass mic &#061; MemberInnerClassTest.this.new MemberInnerClass();<br \/>\n        \/\/MemberInnerClass mic &#061; this.new MemberInnerClass();<br \/>\n        MemberInnerClass mic &#061; new MemberInnerClass();<br \/>\n        mic.name &#061; &#034;tom&#034;;<br \/>\n        mic.test(&#034;hua&#034;);<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        \/\/MemberInnerClass mic &#061; new MemberInnerClass();\u8fd9\u4e2a\u662f\u4e0d\u884c\u7684&#xff0c;this\u662f\u52a8\u6001\u7684\u3002<br \/>\n        \/\/\u6240\u4ee5\u8981\u4f7f\u7528\u8981\u5148\u521b\u5efa\u5916\u90e8\u7c7b\u5bf9\u8c61&#xff0c;\u624d\u80fd\u4f7f\u7528<br \/>\n        MemberInnerClassTest out &#061; new MemberInnerClassTest();<br \/>\n        MemberInnerClass mic &#061; out.new MemberInnerClass();<br \/>\n        \/\/\u5982\u679c\u5185\u90e8\u7c7b\u662fprivate,\u5219\u4e0d\u80fd\u8bbf\u95ee&#xff0c;\u53ea\u80fd\u94dc\u9f13\u5185\u90e8\u65b9\u6cd5\u6765\u8c03\u7528\u5185\u90e8\u7c7b<br \/>\n        mic.name &#061; &#034;jik&#034;;<br \/>\n        mic.test(&#034;kkk&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<h4 id=\"_3\u3001\u9759\u6001\u5185\u90e8\u7c7b\">3\u3001\u9759\u6001\u5185\u90e8\u7c7b<\/h4>\n<p>\u770b\u5230\u540d\u5b57\u5c31\u77e5\u9053&#xff0c;\u4f7f\u7528static\u4fee\u9970\u7684\u5185\u90e8\u7c7b\u5c31\u53eb\u9759\u6001\u5185\u90e8\u7c7b\u3002<\/p>\n<p>\u65e2\u7136\u63d0\u5230\u4e86static&#xff0c;\u90a3\u6211\u4eec\u5c31\u6765\u590d\u4e60\u4e00\u4e0b\u5b83\u7684\u7528\u6cd5&#xff1a;\u4e00\u822c\u53ea\u4fee\u9970\u53d8\u91cf\u548c\u65b9\u6cd5&#xff0c;\u5e73\u5e38\u4e0d\u53ef\u4ee5\u4fee\u9970\u7c7b&#xff0c;\u4f46\u662f\u5185\u90e8\u7c7b\u5374\u53ef\u4ee5\u88abstatic\u4fee\u9970\u3002<\/p>\n<li>static\u4fee\u9970\u6210\u5458\u53d8\u91cf&#xff1a;\u6574\u4e2a\u7c7b\u7684\u5b9e\u4f8b\u5171\u4eab\u9759\u6001\u53d8\u91cf<\/li>\n<li>static\u4fee\u9970\u65b9\u6cd5&#xff1a;\u9759\u6001\u65b9\u6cd5&#xff0c;\u53ea\u80fd\u591f\u8bbf\u95ee\u7528static\u4fee\u9970\u7684\u5c5e\u6027\u6216\u65b9\u6cd5&#xff0c;\u800c\u975e\u9759\u6001\u65b9\u6cd5\u53ef\u4ee5\u8bbf\u95eestatic\u4fee\u9970\u7684\u65b9\u6cd5\u6216\u5c5e\u6027<\/li>\n<li>\u88abstatic\u4fee\u9970\u4e86\u7684\u6210\u5458\u53d8\u91cf\u548c\u65b9\u6cd5\u80fd\u76f4\u63a5\u88ab\u7c7b\u540d\u8c03\u7528\u3002<\/li>\n<li>static\u4e0d\u80fd\u4fee\u9970\u5c40\u90e8\u53d8\u91cf&#xff0c;\u5207\u8bb0&#xff0c;\u4e0d\u8981\u641e\u6df7\u6dc6\u4e86&#xff0c;static\u5e73\u5e38\u5c31\u7528\u6765\u4fee\u9970\u6210\u5458\u53d8\u91cf\u548c\u65b9\u6cd5\u3002<\/li>\n<p>\u4f8b\u5b50&#xff1a;<\/p>\n<\/p>\n<p>public class StaticInnerClassTest {<\/p>\n<p>    private String name;<br \/>\n    private static int age;<\/p>\n<p>    public void run() {<br \/>\n    }<\/p>\n<p>    public static void go() {<br \/>\n    }<\/p>\n<p>    \/\/\u5916\u90e8\u7c7b\u8bbf\u95ee\u9759\u6001\u5185\u90e8\u7c7b<br \/>\n    public void test() {<br \/>\n        StaticInnerClass sic &#061; new StaticInnerClass(); \/\/\u9759\u6001\u7684\u5185\u90e8\u7c7b\u4e0d\u9700\u8981\u4f9d\u8d56\u5916\u90e8\u7c7b&#xff0c;\u6240\u4ee5\u4e0d\u7528this<br \/>\n        sic.name &#061; &#034;tom&#034;;<\/p>\n<p>        sic.test1(&#034;jack&#034;);<br \/>\n        StaticInnerClass.age &#061; 10;<br \/>\n        StaticInnerClass.test2(&#034;xixi&#034;);<br \/>\n    }<\/p>\n<p>    private static class StaticInnerClass {<br \/>\n        private String name;<br \/>\n        private static int age;<\/p>\n<p>        public void test1(String name) {<br \/>\n            System.out.println(name);<br \/>\n            System.out.println(this.name);<br \/>\n            System.out.println(StaticInnerClass.age);<br \/>\n            System.out.println(StaticInnerClassTest.age);<br \/>\n            \/\/System.out.println(StaticInnerClassTest.this.name);\u9759\u6001\u7c7b\u4e0d\u80fd\u8bbf\u95ee\u975e\u9759\u6001\u5c5e\u6027<br \/>\n            StaticInnerClassTest.go();<br \/>\n            \/\/StaticInnerClassTest.this.run();\u9759\u6001\u7c7b\u4e0d\u80fd\u8bbf\u95ee\u975e\u9759\u6001\u65b9\u6cd5<br \/>\n        }<\/p>\n<p>        public static void test2(String name) {<br \/>\n            \/\/\u53ea\u80fd\u8bbf\u95ee\u81ea\u5df1\u548c\u5916\u90e8\u7c7b\u7684\u9759\u6001\u5c5e\u6027\u548c\u65b9\u6cd5<br \/>\n            System.out.println(name);<br \/>\n            \/\/System.out.println(this.name);\u9759\u6001\u65b9\u6cd5\u91cc\u9762\u8fde\u81ea\u5df1\u7c7b\u7684\u975e\u9759\u6001\u5c5e\u6027\u90fd\u4e0d\u80fd\u8bbf\u95ee<br \/>\n            System.out.println(StaticInnerClass.age);<br \/>\n            System.out.println(StaticInnerClassTest.age);<br \/>\n            \/\/System.out.println(StaticInnerClassTest.this.name);\u9759\u6001\u65b9\u6cd5\u4e0d\u80fd\u8bbf\u95ee\u975e\u9759\u6001\u5c5e\u6027<br \/>\n            StaticInnerClassTest.go();<br \/>\n            \/\/StaticInnerClassTest.this.run();\u9759\u6001\u65b9\u6cd5\u4e0d\u80fd\u8bbf\u95ee\u975e\u9759\u6001\u65b9\u6cd5<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<p>\u6ce8\u610f&#xff1a;<\/p>\n<li>\n<p>\u6211\u4eec\u4e0a\u9762\u8bf4\u7684\u5185\u90e8\u7c7b\u80fd\u591f\u8c03\u7528\u5916\u90e8\u7c7b\u7684\u65b9\u6cd5\u548c\u5c5e\u6027&#xff0c;\u5728\u9759\u6001\u5185\u90e8\u7c7b\u4e2d\u5c31\u884c\u4e86&#xff0c;\u56e0\u4e3a\u9759\u6001\u5185\u90e8\u7c7b\u6ca1\u6709 \u4e86\u6307\u5411\u5916\u90e8\u7c7b\u5bf9\u8c61\u7684\u5f15\u7528\u3002\u9664\u975e\u5916\u90e8\u7c7b\u4e2d\u7684\u65b9\u6cd5\u6216\u8005\u5c5e\u6027\u4e5f\u662f\u9759\u6001\u7684\u3002\u8fd9\u5c31\u56de\u5f52\u5230\u4e86static\u5173\u952e\u5b57\u7684\u7528\u6cd5\u3002<\/p>\n<\/li>\n<li>\n<p>\u9759\u6001\u5185\u90e8\u7c7b\u80fd\u591f\u76f4\u63a5\u88ab\u5916\u90e8\u7c7b\u7ed9\u5b9e\u4f8b\u5316&#xff0c;\u4e0d\u9700\u8981\u4f7f\u7528\u5916\u90e8\u7c7b\u5bf9\u8c61<\/p>\n<p> Outer.Inner inner &#061; new Outer.Inner(); <\/li>\n<li>\n<p>\u9759\u6001\u5185\u90e8\u7c7b\u4e2d\u53ef\u4ee5\u58f0\u660e\u9759\u6001\u65b9\u6cd5\u548c\u9759\u6001\u53d8\u91cf&#xff0c;\u4f46\u662f\u975e\u9759\u6001\u5185\u90e8\u7c7b\u4e2d\u5c31\u4e0d\u53ef\u4ee5\u58f0\u660e\u9759\u6001\u65b9\u6cd5\u548c\u9759\u6001\u53d8\u91cf<\/p>\n<\/li>\n<h4 id=\"_4\u3001\u5c40\u90e8\u5185\u90e8\u7c7b\">4\u3001\u5c40\u90e8\u5185\u90e8\u7c7b<\/h4>\n<p>\u5c40\u90e8\u5185\u90e8\u7c7b\u662f\u5728\u4e00\u4e2a\u65b9\u6cd5\u5185\u90e8\u58f0\u660e\u7684\u4e00\u4e2a\u7c7b \u5c40\u90e8\u5185\u90e8\u7c7b\u4e2d\u53ef\u4ee5\u8bbf\u95ee\u5916\u90e8\u7c7b\u7684\u6210\u5458\u53d8\u91cf\u53ca\u65b9\u6cd5 \u5c40\u90e8\u5185\u90e8\u7c7b\u4e2d\u5982\u679c\u8981\u8bbf\u95ee\u8be5\u5185\u90e8\u7c7b\u6240\u5728\u65b9\u6cd5\u4e2d\u7684\u5c40\u90e8\u53d8\u91cf&#xff0c;\u90a3\u4e48\u8fd9\u4e2a\u5c40\u90e8\u53d8\u91cf\u5c31\u5fc5\u987b\u662ffinal\u4fee\u9970\u7684<\/p>\n<\/p>\n<p>public class Outer {<br \/>\n    private int id;<\/p>\n<p>    \/\/\u5728method01\u65b9\u6cd5\u4e2d\u6709\u4e00\u4e2aInner\u5185\u90e8\u7c7b&#xff0c;\u8fd9\u4e2a\u5185\u90e8\u7c7b\u5c31\u79f0\u4e3a\u5c40\u90e8\u5185\u90e8\u7c7b<br \/>\n    public void method01() {<br \/>\n        class Inner {<br \/>\n            public void in() {<br \/>\n                System.out.println(&#034;\u8fd9\u662f\u5c40\u90e8\u5185\u90e8\u7c7b&#034;);<br \/>\n            }<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<p>\u5c40\u90e8\u5185\u90e8\u7c7b\u4e00\u822c\u7684\u4f5c\u7528\u8ddf\u5728\u6210\u5458\u5185\u90e8\u7c7b\u4e2d\u603b\u7ed3\u7684\u5dee\u4e0d\u591a&#xff0c;\u4f46\u662f\u6709\u4e24\u4e2a\u8981\u6ce8\u610f\u7684\u5730\u65b9&#xff1a;<\/p>\n<p>1\u3001\u5728\u5c40\u90e8\u5185\u90e8\u7c7b\u4e2d&#xff0c;\u5982\u679c\u8981\u8bbf\u95ee\u5c40\u90e8\u53d8\u91cf&#xff0c;\u90a3\u4e48\u8be5\u5c40\u90e8\u53d8\u91cf\u8981\u7528final\u4fee\u9970<\/p>\n<p>\u4e3a\u4ec0\u4e48\u9700\u8981\u4f7f\u7528final&#xff1f;<\/p>\n<p>final\u4fee\u9970\u53d8\u91cf&#xff1a;\u53d8\u4e3a\u5e38\u91cf&#xff0c;\u4f1a\u5728\u5e38\u91cf\u6c60\u4e2d\u653e\u7740&#xff0c;\u9006\u5411\u601d\u7ef4\u60f3\u8fd9\u4e2a\u95ee\u9898&#xff0c;\u5982\u679c\u4e0d\u5b9e\u7528final\u4fee\u9970&#xff0c;\u5f53\u5c40\u90e8\u5185\u90e8\u7c7b\u88ab\u5b9e\u4f8b\u5316\u540e&#xff0c;\u65b9\u6cd5\u5f39\u6808&#xff0c;\u5c40\u90e8\u53d8\u91cf\u968f\u7740\u8ddf\u7740\u6d88\u5931&#xff0c;\u8fd9\u4e2a\u65f6\u5019\u5c40\u90e8\u5185\u90e8\u7c7b\u5bf9\u8c61\u5728\u60f3\u53bb\u8c03\u7528\u8be5\u5c40\u90e8\u53d8\u91cf&#xff0c;\u5c31\u4f1a\u62a5\u9519&#xff0c;\u56e0\u4e3a\u8be5\u5c40\u90e8\u53d8\u91cf\u5df2\u7ecf\u6ca1\u4e86&#xff0c;\u5f53\u5c40\u90e8\u53d8\u91cf\u7528fanal\u4fee\u9970\u540e&#xff0c;\u5c31\u4f1a\u5c06\u5176\u52a0\u5165\u5e38\u91cf\u6c60\u4e2d&#xff0c;\u5373\u4f7f\u65b9\u6cd5\u5f39\u6808\u4e86&#xff0c;\u8be5\u5c40\u90e8\u53d8\u91cf\u8fd8\u5728\u5e38\u91cf\u6c60\u4e2d\u5446\u7740&#xff0c;\u5c40\u90e8\u5185\u90e8\u7c7b\u4e5f\u5c31\u662f\u591f\u8c03\u7528\u3002\u6240\u4ee5\u5c40\u90e8\u5185\u90e8\u7c7b\u60f3\u8981\u8c03\u7528\u5c40\u90e8\u53d8 \u91cf\u65f6&#xff0c;\u9700\u8981\u4f7f\u7528final\u4fee\u9970&#xff0c;\u4e0d\u4f7f\u7528&#xff0c;\u7f16\u8bd1\u5ea6\u901a\u4e0d\u8fc7\u3002<\/p>\n<\/p>\n<p>public class Outer {<br \/>\n    private int id;<\/p>\n<p>    public void method01() {<br \/>\n        \/\/\u8fd9\u4e2a\u5c31\u662f\u5c40\u90e8\u53d8\u91cfcid\u3002\u8981\u8ba9\u5c40\u90e8\u5185\u90e8\u7c7b\u4f7f\u7528&#xff0c;\u5c31\u5f97\u53d8\u4e3afinal\u5e76\u4e14\u8d4b\u503c&#xff0c;\u5982\u679c\u4e0d\u4f7f\u7528final\u4fee\u9970&#xff0c;\u5c31\u4f1a\u62a5\u9519<br \/>\n        final int cid &#061; 3;<br \/>\n        class Inner {<br \/>\n            \/\/\u5185\u90e8\u7c7b\u7684\u7b2c\u4e00\u4e2a\u65b9\u6cd5<br \/>\n            public void in() {<br \/>\n                System.out.println(&#034;\u8fd9\u662f\u5c40\u90e8\u5185\u90e8\u7c7b&#034;);<br \/>\n            }<\/p>\n<p>            \/\/\u5185\u90e8\u7c7b\u4e2d\u7684\u4f7f\u7528\u5c40\u90e8\u53d8\u91cfcid\u7684\u65b9\u6cd5<br \/>\n            public void useCid() {<br \/>\n                System.out.println(cid);<br \/>\n            }<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<p>2\u3001\u5c40\u90e8\u5185\u90e8\u7c7b\u4e0d\u80fd\u901a\u8fc7\u5916\u90e8\u7c7b\u5bf9\u8c61\u76f4\u63a5\u5b9e\u4f8b\u5316&#xff0c;\u800c\u662f\u5728\u65b9\u6cd5\u4e2d\u5b9e\u4f8b\u5316\u51fa\u81ea\u5df1\u6765&#xff0c;\u7136\u540e\u901a\u8fc7\u5185\u90e8\u7c7b\u5bf9\u8c61 \u8c03\u7528\u81ea\u5df1\u7c7b\u4e2d\u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u770b\u4e0b\u9762\u4f8b\u5b50\u5c31\u77e5\u9053\u5982\u4f55\u7528\u4e86\u3002<\/p>\n<\/p>\n<p>public class Outer {<br \/>\n    private int id;<\/p>\n<p>    public void out() {<br \/>\n        System.out.println(&#034;\u5916\u90e8\u7c7b\u65b9\u6cd5&#034;);<br \/>\n    }<\/p>\n<p>    public void method01() {<br \/>\n        class Inner {<br \/>\n            public void in() {<br \/>\n                System.out.println(&#034;\u8fd9\u662f\u5c40\u90e8\u5185\u90e8\u7c7b&#034;);<br \/>\n            }<br \/>\n        }<br \/>\n        \/\/\u5173\u952e\u5728\u8fd9\u91cc&#xff0c;\u5982\u9700\u8981\u5728method01\u65b9\u6cd5\u4e2d\u81ea\u5df1\u521b\u5efa\u5185\u90e8\u7c7b\u5b9e\u4f8b&#xff0c;<br \/>\n        \/\/ \u7136\u540e\u8c03\u7528\u5185\u90e8\u7c7b\u4e2d\u7684\u65b9\u6cd5&#xff0c;\u7b49\u5f85\u5916\u90e8\u7c7b\u8c03\u7528method01\u65b9\u6cd5&#xff0c;<br \/>\n        \/\/ \u5c31\u53ef\u4ee5\u6267\u884c\u5230\u5185\u90e8\u7c7b\u4e2d\u7684\u65b9\u6cd5\u4e86\u3002<br \/>\n        Inner In &#061; new Inner();<br \/>\n        In.in();<br \/>\n    }<br \/>\n} <\/p>\n<p>\u4f7f\u7528\u5c40\u90e8\u5185\u90e8\u7c7b\u9700\u8981\u6ce8\u610f\u7684\u5730\u65b9\u5c31\u521a\u624d\u4e0a\u9762\u8bf4\u7684&#xff1a;<\/p>\n<li>\n<p>\u5728\u5c40\u90e8\u5185\u90e8\u7c7b\u4e2d&#xff0c;\u5982\u679c\u8981\u8bbf\u95ee\u5c40\u90e8\u53d8\u91cf&#xff0c;\u90a3\u4e48\u8be5\u5c40\u90e8\u53d8\u91cf\u8981\u7528final\u4fee\u9970<\/p>\n<\/li>\n<li>\n<p>\u5982\u4f55\u8c03\u7528\u5c40\u90e8\u5185\u90e8\u7c7b\u65b9\u6cd5\u3002<\/p>\n<p> public class LocalInnerClassTest {<br \/>\n    private String name;<br \/>\n    private static int age;<\/p>\n<p>    public void run() {<br \/>\n    }<\/p>\n<p>    public static void go() {<br \/>\n    }<\/p>\n<p>    \/\/\u5c40\u90e8\u5185\u90e8\u7c7b\u8981\u5b9a\u4e49\u5728\u65b9\u6cd5\u4e2d<br \/>\n    public void test() {<br \/>\n        final String myname &#061; &#034;&#034;;<br \/>\n        class LocalInnerClass {<br \/>\n            private String name;<\/p>\n<p>            \/\/ private static int age;\u4e0d\u80fd\u5b9a\u4e49\u9759\u6001\u5c5e\u6027<br \/>\n            public void test(String name) {<br \/>\n                System.out.println(name);<br \/>\n                System.out.println(this.name);<br \/>\n                System.out.println(myname);<br \/>\n                System.out.println(LocalInnerClassTest.this.name);<br \/>\n                LocalInnerClassTest.this.run();<br \/>\n                LocalInnerClassTest.go();<br \/>\n            }<br \/>\n        }<br \/>\n        \/\/ \u5c40\u90e8\u5185\u90e8\u7c7b\u53ea\u80fd\u5728\u81ea\u5df1\u7684\u65b9\u6cd5\u4e2d\u7528<br \/>\n        \/\/ \u56e0\u4e3a\u5c40\u90e8\u5185\u90e8\u7c7b\u76f8\u5f53\u4e8e\u4e00\u4e2a\u5c40\u90e8\u53d8\u91cf&#xff0c;\u51fa\u4e86\u65b9\u6cd5\u5c31\u627e\u4e0d\u5230\u4e86\u3002<br \/>\n        LocalInnerClass lic &#061; new LocalInnerClass();<br \/>\n        lic.name &#061; &#034;tom&#034;;<br \/>\n        lic.test(&#034;test&#034;);<\/p>\n<p>    }<\/p>\n<p>} <\/p>\n<\/li>\n<h4 id=\"_5\u3001\u533f\u540d\u5185\u90e8\u7c7b\">5\u3001\u533f\u540d\u5185\u90e8\u7c7b<\/h4>\n<p>\u5728\u8fd9\u56db\u79cd\u5185\u90e8\u7c7b\u4e2d&#xff0c;\u4ee5\u540e\u7684\u5de5\u4f5c\u53ef\u80fd\u9047\u5230\u6700\u591a\u7684\u662f\u533f\u540d\u5185\u90e8\u7c7b&#xff0c;\u6240\u4ee5\u8bf4\u533f\u540d\u5185\u90e8\u7c7b\u662f\u6700\u5e38\u7528\u7684\u4e00\u79cd \u5185\u90e8\u7c7b\u3002<\/p>\n<p>\u4ec0\u4e48\u662f\u533f\u540d\u5bf9\u8c61&#xff1f;\u5982\u679c\u4e00\u4e2a\u5bf9\u8c61\u53ea\u8981\u4f7f\u7528\u4e00\u6b21&#xff0c;\u90a3\u4e48\u6211\u4eec\u5c31\u662f\u9700\u8981new Object().method()\u3002 \u5c31\u53ef\u4ee5\u4e86&#xff0c;\u800c\u4e0d\u9700\u8981\u7ed9\u8fd9\u4e2a\u5b9e\u4f8b\u4fdd\u5b58\u5230\u8be5\u7c7b\u578b\u53d8\u91cf\u4e2d\u53bb\u3002\u8fd9\u5c31\u662f\u533f\u540d\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p>public class Test {<br \/>\n    public static void main(String[] args) {<br \/>\n        \/\/\u8bb2new\u51fa\u6765\u7684Apple\u5b9e\u4f8b\u8d4b\u7ed9apple\u53d8\u91cf\u4fdd\u5b58\u8d77\u6765&#xff0c;\u4f46\u662f\u6211\u4eec\u53ea\u9700\u8981\u7528\u4e00\u6b21&#xff0c;\u5c31\u53ef\u4ee5\u8fd9\u6837\u5199<br \/>\n        Apple apple &#061; new Apple();<br \/>\n        apple.eat();<br \/>\n        \/\/\u8fd9\u79cd\u5c31\u53eb\u505a\u533f\u540d\u5bf9\u8c61\u7684\u4f7f\u7528&#xff0c;\u4e0d\u628a\u5b9e\u4f8b\u4fdd\u5b58\u5230\u53d8\u91cf\u4e2d\u3002<br \/>\n        new Apple().eat();<br \/>\n    }<br \/>\n}<\/p>\n<p>class Apple{<br \/>\n    public void eat(){<br \/>\n        System.out.println(&#034;\u6211\u8981\u88ab\u5403\u4e86&#034;);<br \/>\n}<br \/>\n} <\/p>\n<p>\u533f\u540d\u5185\u90e8\u7c7b\u8ddf\u533f\u540d\u5bf9\u8c61\u662f\u4e00\u4e2a\u9053\u7406&#xff1a;<\/p>\n<p>\u533f\u540d\u5bf9\u8c61&#xff1a;\u6211\u53ea\u9700\u8981\u7528\u4e00\u6b21&#xff0c;\u90a3\u4e48\u6211\u5c31\u4e0d\u7528\u58f0\u660e\u4e00\u4e2a\u8be5\u7c7b\u578b\u53d8\u91cf\u6765\u4fdd\u5b58\u5bf9\u8c61\u4e86&#xff0c;<\/p>\n<p>\u533f\u540d\u5185\u90e8\u7c7b&#xff1a;\u6211\u4e5f\u53ea\u9700\u8981\u7528\u4e00\u6b21&#xff0c;\u90a3\u6211\u5c31\u4e0d\u9700\u8981\u5728\u7c7b\u4e2d\u5148\u5b9a\u4e49\u4e00\u4e2a\u5185\u90e8\u7c7b&#xff0c;\u800c\u662f\u7b49\u5f85\u9700\u8981\u7528\u7684\u65f6\u5019&#xff0c;\u6211\u5c31\u5728\u4e34\u65f6\u5b9e\u73b0\u8fd9\u4e2a\u5185\u90e8\u7c7b&#xff0c;\u56e0\u4e3a\u7528\u6b21\u6570\u5c11&#xff0c;\u53ef\u80fd\u5c31\u8fd9\u4e00\u6b21&#xff0c;\u90a3\u4e48\u8fd9\u6837\u5199\u5185\u90e8\u7c7b&#xff0c;\u66f4\u65b9\u4fbf\u3002\u4e0d\u7136\u5148\u5199\u51fa\u4e00 \u4e2a\u5185\u90e8\u7c7b\u7684\u5168\u90e8\u5b9e\u73b0\u6765&#xff0c;\u7136\u540e\u5c31\u8c03\u7528\u5b83\u4e00\u6b21&#xff0c;\u5c82\u4e0d\u662f\u7528\u5b8c\u4e4b\u540e\u5c31\u4e00\u76f4\u5c06\u5176\u653e\u5728\u90a3&#xff0c;\u90a3\u5c31\u6ca1\u5fc5\u8981\u90a3\u6837\u3002<\/p>\n<li>\u533f\u540d\u5185\u90e8\u7c7b\u9700\u8981\u4f9d\u6258\u4e8e\u5176\u4ed6\u7c7b\u6216\u8005\u63a5\u53e3\u6765\u521b\u5efa\n<ul>\n<li>\u5982\u679c\u4f9d\u6258\u7684\u662f\u7c7b&#xff0c;\u90a3\u4e48\u521b\u5efa\u51fa\u6765\u7684\u533f\u540d\u5185\u90e8\u7c7b\u5c31\u9ed8\u8ba4\u662f\u8fd9\u4e2a\u7c7b\u7684\u5b50\u7c7b<\/li>\n<li>\u5982\u679c\u4f9d\u6258\u7684\u662f\u63a5\u53e3&#xff0c;\u90a3\u4e48\u521b\u5efa\u51fa\u6765\u7684\u533f\u540d\u5185\u90e8\u7c7b\u5c31\u9ed8\u8ba4\u662f\u8fd9\u4e2a\u63a5\u53e3\u7684\u5b9e\u73b0\u7c7b\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u533f\u540d\u5185\u90e8\u7c7b\u7684\u58f0\u660e\u5fc5\u987b\u662f\u5728\u4f7f\u7528new\u5173\u952e\u5b57\u7684\u65f6\u5019\n<ul>\n<li>\u533f\u540d\u5185\u90e8\u7c7b\u7684\u58f0\u660e\u53ca\u521b\u5efa\u5bf9\u8c61\u5fc5\u987b\u4e00\u6c14\u5475\u6210&#xff0c;\u5e76\u4e14\u4e4b\u540e\u80fd\u53cd\u590d\u4f7f\u7528&#xff0c;\u56e0\u4e3a\u6ca1\u6709\u540d\u5b57<\/li>\n<\/ul>\n<\/li>\n<p>\u3010\u793a\u4f8b\u3011<\/p>\n<p>A\u662f\u4e00\u4e2a\u7c7b(\u666e\u901a\u7c7b\u3001\u62bd\u8c61\u7c7b\u90fd\u53ef\u4ee5)&#xff0c;\u4f9d\u6258\u4e8eA\u7c7b\u521b\u5efa\u4e00\u4e2a\u533f\u540d\u5185\u90e8\u7c7b\u5bf9\u8c61<\/p>\n<\/p>\n<p>main:<\/p>\n<p>A a &#061; new A(){<br \/>\n    \/\/\u5b9e\u73b0A\u4e2d\u7684\u62bd\u8c61\u65b9\u6cd5<br \/>\n    \/\/\u6216\u8005\u91cd\u5199A\u4e2d\u7684\u666e\u901a\u65b9\u6cd5<br \/>\n};<\/p>\n<p>\u6ce8:\u8fd9\u4e2a\u5927\u62ec\u53f7\u91cc\u9762\u5176\u5b9e\u5c31\u662f\u8fd9\u4e2a\u5185\u90e8\u7c7b\u7684\u4ee3\u7801,\u53ea\u4e0d\u8fc7\u662f\u58f0\u660e\u8be5\u5185\u90e8\u7c7b\u7684\u540c\u65f6\u5c31\u662f\u8981new\u521b\u5efa\u4e86\u5176\u5bf9\u8c61,<br \/>\n\u5e76\u4e14\u4e0d\u80fd\u53cd\u590d\u4f7f\u7528,\u56e0\u4e3a\u6ca1\u6709\u540d\u5b57\u3002<\/p>\n<p>\u4f8b\u5982:<br \/>\nB\u662f\u4e00\u4e2a\u63a5\u53e3&#xff0c;\u4f9d\u6258\u4e8eB\u63a5\u53e3\u521b\u5efa\u4e00\u4e2a\u533f\u540d\u5185\u90e8\u7c7b\u5bf9\u8c61<\/p>\n<p>B b &#061; new B(){<br \/>\n\/\/\u5b9e\u73b0B\u4e2d\u7684\u62bd\u8c61\u65b9\u6cd5<br \/>\n}; <\/p>\n<li>\u533f\u540d\u5185\u90e8\u7c7b\u9664\u4e86\u4f9d\u6258\u7684\u7c7b\u6216\u63a5\u53e3\u4e4b\u5916&#xff0c;\u4e0d\u80fd\u6307\u5b9a\u7ee7\u627f\u6216\u8005\u5b9e\u73b0\u5176\u4ed6\u7c7b\u6216\u63a5\u53e3&#xff0c;\u540c\u65f6\u4e5f\u4e0d\u80fd\u88ab\u5176\u4ed6\u7c7b\u6240\u7ee7\u627f&#xff0c;\u56e0\u4e3a\u6ca1\u6709\u540d\u5b57\u3002<\/li>\n<li>\u533f\u540d\u5185\u90e8\u4e2d&#xff0c;\u6211\u4eec\u4e0d\u80fd\u5199\u51fa\u5176\u6784\u9020\u5668&#xff0c;\u56e0\u4e3a\u6ca1\u6709\u540d\u5b57\u3002<\/li>\n<li>\u533f\u540d\u5185\u90e8\u4e2d&#xff0c;\u9664\u4e86\u91cd\u5199\u4e0a\u9762\u7684\u65b9\u6cd5\u5916&#xff0c;\u4e00\u822c\u4e0d\u4f1a\u518d\u5199\u5176\u4ed6\u72ec\u6709\u7684\u65b9\u6cd5&#xff0c;\u56e0\u4e3a\u4ece\u5916\u90e8\u4e0d\u80fd\u76f4\u63a5\u8c03\u7528\u5230\u3002(\u95f4\u63a5\u662f\u8c03\u7528\u5230\u7684)<\/li>\n<p>public interface Work{<br \/>\n    void doWork();<br \/>\n}<\/p>\n<p>public class AnonymousOutterClass{<br \/>\n    private String name;<br \/>\n    private static int age;<br \/>\n    public void say(){}<br \/>\n    public static void go(){}<\/p>\n<p>    public void test(){<br \/>\n        final int i &#061; 90;<\/p>\n<p>        Work w &#061; new Work(){<br \/>\n            public void doWork(){<br \/>\n                System.out.println(AnonymousOutterClass.this.name);<br \/>\n                System.out.println(AnonymousOutterClass.age);<br \/>\n                AnonymousOutterClass.this.say();<br \/>\n                AnonymousOutterClass.go();<\/p>\n<p>                System.out.println(i);<br \/>\n            }<br \/>\n        };<br \/>\n        w.doWork();<br \/>\n    }<br \/>\n} <\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u8bd5\u4e00\u4e0b\u4e0d \u7528\u533f\u540d\u5185\u90e8\u7c7b \u548c \u7528\u533f\u540d\u5185\u90e8\u7c7b \u5b9e\u73b0\u4e00\u4e2a\u63a5\u53e3\u4e2d\u7684\u65b9\u6cd5\u7684\u533a\u522b<\/p>\n<p>\u3010\u4e0d\u7528\u533f\u540d\u5185\u90e8\u7c7b\u3011<\/p>\n<\/p>\n<p>public class Test {<br \/>\n    public static void main(String[] args) {<br \/>\n        \/\/ \u5982\u679c\u6211\u4eec\u9700\u8981\u4f7f\u7528\u63a5\u53e3\u4e2d\u7684\u65b9\u6cd5&#xff0c;\u6211\u4eec\u5c31\u9700\u8981\u8d703\u6b65&#xff0c;<br \/>\n        \/\/ 1\u3001\u5b9e\u73b0\u63a5\u53e3 2\u3001\u521b\u5efa\u5b9e\u73b0\u63a5\u53e3\u7c7b\u7684\u5b9e\u4f8b\u5bf9\u8c61 3\u3001\u901a\u8fc7\u5bf9\u8c61\u8c03\u7528\u65b9\u6cd5<br \/>\n        \/\/\u7b2c\u4e8c\u6b65<br \/>\n        Test02 test &#061; new Test02();<br \/>\n        \/\/\u7b2c\u4e09\u6b65<br \/>\n        test.method();<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/\u63a5\u53e3Test1<br \/>\ninterface Test01{<br \/>\n    public void method();<br \/>\n}<\/p>\n<p>\/\/\u7b2c\u4e00\u6b65\u3001\u5b9e\u73b0Test01\u63a5\u53e3<br \/>\nclass Test02 implements Test01{<br \/>\n    &#064;Override<br \/>\n    public void method() {<br \/>\n        System.out.println(&#034;\u5b9e\u73b0\u4e86Test\u63a5\u53e3\u7684\u65b9\u6cd5&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u3010\u4f7f\u7528\u533f\u540d\u5185\u90e8\u7c7b\u3011<\/p>\n<\/p>\n<p>public class Test {<br \/>\n    public static void main(String[] args) {<br \/>\n\/\/\u5982\u679c\u6211\u4eec\u9700\u8981\u4f7f\u7528\u63a5\u53e3\u4e2d\u7684\u65b9\u6cd5&#xff0c;\u6211\u4eec\u53ea\u9700\u8981\u8d70\u4e00\u6b65&#xff0c;\u5c31\u662f\u4f7f\u7528\u533f\u540d\u5185\u90e8\u7c7b&#xff0c;\u76f4\u63a5\u5c06\u5176\u7c7b\u7684\u5bf9\u8c61\u521b\u5efa\u51fa\u6765\u3002<br \/>\n        new Test1(){<br \/>\n            public void method(){<br \/>\n                System.out.println(&#034;\u5b9e\u73b0\u4e86Test\u63a5\u53e3\u7684\u65b9\u6cd5&#034;);<br \/>\n            }<br \/>\n        }.method();<br \/>\n    }<br \/>\n}<\/p>\n<p>interface Test1{<br \/>\n    public void method();<br \/>\n} <\/p>\n<p>\u89e3\u6790&#xff1a;<\/p>\n<p>\u5176\u5b9e\u53ea\u8981\u660e\u767d\u4e00\u70b9&#xff0c;new Test1( ){ \u5b9e\u73b0\u63a5\u53e3\u4e2d\u65b9\u6cd5\u7684\u4ee3\u7801 };<\/p>\n<p>Test1(){&#8230;} \u8fd9\u4e2a\u7684\u4f5c\u7528\u5c31\u662f\u5c06\u63a5\u53e3\u7ed9\u5b9e\u73b0\u4e86&#xff0c;\u53ea\u4e0d\u8fc7\u8fd9\u91cc\u5b9e\u73b0\u8be5\u63a5\u53e3\u7684\u662f\u4e00\u4e2a\u533f\u540d\u7c7b&#xff0c;\u4e5f\u5c31\u662f\u8bf4\u8fd9\u4e2a\u7c7b\u6ca1\u540d\u5b57&#xff0c;\u53ea\u80fd\u4f7f\u7528\u8fd9\u4e00\u6b21&#xff0c;\u6211\u4eec\u77e5\u9053\u4e86\u8fd9\u662f\u4e00\u4e2a\u7c7b&#xff0c; \u5c06\u5176new\u51fa\u6765&#xff0c;\u5c31\u80fd\u83b7\u5f97\u4e00\u4e2a\u5b9e\u73b0\u4e86Test1\u63a5\u53e3\u7684\u7c7b\u7684\u5b9e\u4f8b\u5bf9\u8c61&#xff0c;\u901a\u8fc7\u8be5\u5b9e\u4f8b\u5bf9\u8c61&#xff0c;\u5c31\u80fd\u8c03\u7528\u8be5\u7c7b\u4e2d\u7684\u65b9\u6cd5\u4e86&#xff0c;\u56e0\u4e3a\u5176\u533f\u540d\u7c7b\u662f\u5728\u4e00\u4e2a\u7c7b\u4e2d\u5b9e\u73b0\u7684&#xff0c;\u6240\u4ee5\u53eb\u5176\u533f\u540d\u5185\u90e8\u7c7b\u3002<\/p>\n<h2>\u5341\u4e5d\u3001\u5e38\u7528\u7c7b<\/h2>\n<h3 id=\"object\u7c7b\">Object\u7c7b<\/h3>\n<p>\u7406\u8bba\u4e0aObject\u7c7b\u662f\u6240\u6709\u7c7b\u7684\u7236\u7c7b&#xff0c;\u5373\u76f4\u63a5\u6216\u95f4\u63a5\u7684\u7ee7\u627fjava.lang.Object\u7c7b\u3002<\/p>\n<p>\u7531\u4e8e\u6240\u6709\u7684\u7c7b\u90fd\u7ee7\u627f\u5728Object\u7c7b&#xff0c;\u56e0\u6b64\u7701\u7565\u4e86extends Object\u5173\u952e\u5b57\u3002<\/p>\n<p>\u8be5\u7c7b\u4e2d\u4e3b\u8981\u6709\u4ee5\u4e0b\u65b9\u6cd5&#xff1a;<\/p>\n<ul>\n<li>toString( )<\/li>\n<li>getClass( )<\/li>\n<li>equals( )<\/li>\n<li>clone( )<\/li>\n<li>finalize( )<\/li>\n<\/ul>\n<p>\u5176\u4e2dtoString()&#xff0c;getClass()&#xff0c;equals\u662f\u5176\u4e2d\u6700\u91cd\u8981\u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u67e5\u770bObject\u7c7b\u6e90\u7801<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"410\" src=\"2026-01-14nnmybqatjay.png\" width=\"355\" \/><\/p>\n<p>\u770b\u56fe\u53ef\u77e5&#xff0c;\u5728jdk15\u4e2d\u6700\u540e\u4e00\u4e2a\u65b9\u6cd5\u8fc7\u65f6\u4e86&#xff0c;\u4f46\u6211\u4eec\u8fd0\u8425\u4e00\u822c\u90fd\u662fjdk1.8<\/p>\n<p>\u6ce8\u610f&#xff1a; Object\u7c7b\u4e2d\u7684getClass(),notify(),notifyAll(),wait()\u7b49\u65b9\u6cd5\u88ab\u5b9a\u4e49\u4e3afinal\u7c7b\u578b&#xff0c;\u56e0\u6b64\u4e0d\u80fd\u91cd\u5199\u3002<\/p>\n<h4 id=\"_1-clone-\u65b9\u6cd5\">1 clone() \u65b9\u6cd5<\/h4>\n<p>\u8be6\u89e3\u6587\u7ae0&#xff1a;https:\/\/youmoxiang.blog.csdn.net\/article\/details\/156786250<\/p>\n<\/p>\n<p> protected native Object clone() throws CloneNotSupportedException; <\/p>\n<p>clone\u987e\u540d\u601d\u4e49\u5c31\u662f\u590d\u5236&#xff0c; \u5728Java\u8bed\u8a00\u4e2d&#xff0c; clone\u65b9\u6cd5\u88ab\u5bf9\u8c61\u8c03\u7528&#xff0c;\u6240\u4ee5\u4f1a\u590d\u5236\u5bf9\u8c61\u3002\u6240\u8c13\u7684\u590d\u5236\u5bf9\u8c61&#xff0c;\u9996\u5148\u8981\u5206\u914d\u4e00\u4e2a\u548c\u6e90\u5bf9\u8c61\u540c\u6837\u5927\u5c0f\u7684\u7a7a\u95f4&#xff0c;\u5728\u8fd9\u4e2a\u7a7a\u95f4\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5bf9\u8c61\u3002\u90a3\u4e48\u5728java\u8bed\u8a00\u4e2d&#xff0c;\u6709\u51e0\u79cd\u65b9\u5f0f\u53ef\u4ee5\u521b\u5efa\u5bf9\u8c61\u5462&#xff1f;<\/p>\n<ul>\n<li>\u4f7f\u7528new\u64cd\u4f5c\u7b26\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61<\/li>\n<li>\u4f7f\u7528clone\u65b9\u6cd5\u590d\u5236\u4e00\u4e2a\u5bf9\u8c61<\/li>\n<\/ul>\n<p>\u90a3\u4e48\u8fd9\u4e24\u79cd\u65b9\u5f0f\u6709\u4ec0\u4e48\u76f8\u540c\u548c\u4e0d\u540c\u5462&#xff1f; new\u64cd\u4f5c\u7b26\u7684\u672c\u610f\u662f\u5206\u914d\u5185\u5b58\u3002\u7a0b\u5e8f\u6267\u884c\u5230new\u64cd\u4f5c\u7b26\u65f6&#xff0c; \u9996\u5148\u53bb\u770bnew\u64cd\u4f5c\u7b26\u540e\u9762\u7684\u7c7b\u578b&#xff0c;\u56e0\u4e3a\u77e5\u9053\u4e86\u7c7b\u578b&#xff0c;\u624d\u80fd\u77e5\u9053\u8981\u5206\u914d\u591a\u5927\u7684\u5185\u5b58\u7a7a\u95f4\u3002\u5206\u914d\u5b8c\u5185\u5b58\u4e4b\u540e&#xff0c; \u518d\u8c03\u7528\u6784\u9020\u51fd\u6570&#xff0c;\u586b\u5145\u5bf9\u8c61\u7684\u5404\u4e2a\u57df&#xff0c;\u8fd9\u4e00\u6b65\u53eb\u505a\u5bf9\u8c61\u7684\u521d\u59cb\u5316&#xff0c;\u6784\u9020\u65b9\u6cd5\u8fd4\u56de\u540e&#xff0c;\u4e00\u4e2a\u5bf9\u8c61\u521b\u5efa\u5b8c\u6bd5&#xff0c;\u53ef\u4ee5\u628a\u4ed6\u7684\u5f15\u7528&#xff08;\u5730\u5740&#xff09;\u53d1\u5e03\u5230\u5916\u90e8&#xff0c;\u5728\u5916\u90e8\u5c31\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u5f15\u7528\u64cd\u7eb5\u8fd9\u4e2a\u5bf9\u8c61\u3002\u800cclone\u5728\u7b2c\u4e00\u6b65\u662f\u548cnew\u76f8\u4f3c\u7684&#xff0c; \u90fd\u662f\u5206\u914d\u5185\u5b58&#xff0c;\u8c03\u7528clone\u65b9\u6cd5\u65f6&#xff0c;\u5206\u914d\u7684\u5185\u5b58\u548c\u6e90\u5bf9\u8c61&#xff08;\u5373\u8c03\u7528clone\u65b9\u6cd5\u7684\u5bf9\u8c61&#xff09;\u76f8\u540c&#xff0c;\u7136\u540e\u518d\u4f7f\u7528\u539f\u5bf9\u8c61\u4e2d\u5bf9\u5e94\u7684\u5404\u4e2a\u57df&#xff0c;\u586b\u5145\u65b0\u5bf9\u8c61\u7684\u57df&#xff0c;\u586b\u5145\u5b8c\u6210\u4e4b\u540e&#xff0c;clone\u65b9\u6cd5\u8fd4\u56de&#xff0c;\u4e00\u4e2a\u65b0\u7684\u76f8\u540c\u7684\u5bf9\u8c61\u88ab\u521b\u5efa&#xff0c;\u540c\u6837\u53ef\u4ee5\u628a\u8fd9\u4e2a\u65b0\u5bf9\u8c61\u7684\u5f15\u7528\u53d1\u5e03\u5230\u5916\u90e8\u3002<\/p>\n<p>clone\u4e0ecopy\u7684\u533a\u522b<\/p>\n<p>\u5047\u8bbe\u73b0\u5728\u6709\u4e00\u4e2aEmployee\u5bf9\u8c61&#xff0c;Employee tobby &#061; new Employee(\u201cCMTobby\u201d,5000)<\/p>\n<p>\u901a\u5e38\u6211\u4eec\u4f1a\u6709\u8fd9\u6837\u7684\u8d4b\u503cEmployee cindyelf &#061; tobby&#xff0c;\u8fd9\u4e2a\u65f6\u5019\u53ea\u662f\u7b80\u5355\u4e86copy\u4e86\u4e00\u4e0breference\u3002cindyelf\u548ctobby\u90fd\u6307\u5411\u5185\u5b58\u4e2d\u540c\u4e00\u4e2aobject&#xff0c;\u8fd9\u6837cindyelf\u6216\u8005tobby\u7684\u4e00\u4e2a\u64cd\u4f5c\u90fd\u53ef\u80fd\u5f71\u54cd\u5230\u5bf9\u65b9\u3002\u6253\u4e2a\u6bd4\u65b9&#xff0c;\u5982\u679c\u6211\u4eec\u901a\u8fc7cindyelf.raiseSalary()\u65b9\u6cd5\u6539\u53d8\u4e86salary\u57df\u7684\u503c&#xff0c;\u90a3\u4e48tobby\u901a\u8fc7getSalary()\u65b9\u6cd5&#xff0c;\u5f97\u5230\u7684\u5c31\u662f\u4fee\u6539\u4e4b\u540e\u7684salary\u57df\u7684\u503c&#xff0c;\u663e\u7136\u8fd9\u4e0d\u662f\u6211\u4eec\u613f\u610f\u770b\u5230\u7684\u3002\u6211\u4eec\u5e0c\u671b\u5f97\u5230tobby\u7684\u4e00\u4e2a\u7cbe\u786e\u62f7\u8d1d&#xff0c;\u540c\u65f6\u4e24\u8005\u4e92\u4e0d\u5f71\u54cd&#xff0c;\u8fd9\u65f6\u5019&#xff0c; \u6211\u4eec\u5c31\u53ef\u4ee5\u4f7f\u7528Clone\u6765\u6ee1\u8db3\u6211\u4eec\u7684\u9700\u6c42\u3002Employee cindy&#061;tobby.clone()&#xff0c;\u8fd9\u65f6\u4f1a\u751f\u6210\u4e00\u4e2a\u65b0\u7684Employee\u5bf9\u8c61&#xff0c;\u5e76\u4e14\u548ctobby\u5177\u6709\u76f8\u540c\u7684\u5c5e\u6027\u503c\u548c\u65b9\u6cd5\u3002<\/p>\n<p>Shallow Clone\u4e0eDeep Clone<\/p>\n<h5>1. \u6838\u5fc3\u533a\u522b<\/h5>\n<p>\u6d45\u514b\u9686&#xff1a;\u53ea\u590d\u5236\u5bf9\u8c61\u672c\u8eab\u548c\u5bf9\u8c61\u4e2d\u7684\u57fa\u672c\u6570\u636e\u7c7b\u578b\u503c&#xff0c;\u4e0d\u590d\u5236\u5bf9\u8c61\u5f15\u7528\u7684\u5176\u4ed6\u5bf9\u8c61 \u6df1\u514b\u9686&#xff1a;\u590d\u5236\u5bf9\u8c61\u672c\u8eab\u4ee5\u53ca\u5bf9\u8c61\u5f15\u7528\u7684\u6240\u6709\u5176\u4ed6\u5bf9\u8c61&#xff0c;\u521b\u5efa\u5b8c\u5168\u72ec\u7acb\u7684\u526f\u672c<\/p>\n<h5>2. \u793a\u4f8b\u5bf9\u6bd4<\/h5>\n<p>javascript<\/p>\n<p>\/\/ \u539f\u59cb\u5bf9\u8c61<br \/>\nconst original &#061; {<br \/>\n  name: &#034;John&#034;,<br \/>\n  age: 30,<br \/>\n  address: {<br \/>\n    city: &#034;New York&#034;,<br \/>\n    zip: &#034;10001&#034;<br \/>\n  },<br \/>\n  hobbies: [&#034;reading&#034;, &#034;gaming&#034;]<br \/>\n};<\/p>\n<p>\/\/ \u6d45\u514b\u9686<br \/>\nconst shallowCopy &#061; Object.assign({}, original);<br \/>\n\/\/ \u6216\u4f7f\u7528\u6269\u5c55\u8fd0\u7b97\u7b26<br \/>\nconst shallowCopy2 &#061; { &#8230;original };<\/p>\n<p>\/\/ \u6df1\u514b\u9686<br \/>\nconst deepCopy &#061; JSON.parse(JSON.stringify(original));<br \/>\n\/\/ \u6216\u4f7f\u7528\u7ed3\u6784\u5316\u514b\u9686&#xff08;\u73b0\u4ee3\u6d4f\u89c8\u5668&#xff09;<br \/>\nconst deepCopy2 &#061; structuredClone(original); <\/p>\n<h5>3. \u5173\u952e\u5dee\u5f02\u8868<\/h5>\n<table>\n<tr>\u7279\u6027\u6d45\u514b\u9686\u6df1\u514b\u9686<\/tr>\n<tbody>\n<tr>\n<td>\u590d\u5236\u5c42\u7ea7<\/td>\n<td>\u4ec5\u7b2c\u4e00\u5c42<\/td>\n<td>\u6240\u6709\u5c42\u7ea7<\/td>\n<\/tr>\n<tr>\n<td>\u5f15\u7528\u7c7b\u578b\u5904\u7406<\/td>\n<td>\u590d\u5236\u5f15\u7528<\/td>\n<td>\u521b\u5efa\u65b0\u5bf9\u8c61<\/td>\n<\/tr>\n<tr>\n<td>\u5185\u5b58\u5360\u7528<\/td>\n<td>\u8f83\u5c11<\/td>\n<td>\u8f83\u591a<\/td>\n<\/tr>\n<tr>\n<td>\u6027\u80fd<\/td>\n<td>\u8f83\u5feb<\/td>\n<td>\u8f83\u6162<\/td>\n<\/tr>\n<tr>\n<td>\u4fee\u6539\u5f71\u54cd<\/td>\n<td>\u5f71\u54cd\u539f\u5bf9\u8c61<\/td>\n<td>\u4e0d\u5f71\u54cd\u539f\u5bf9\u8c61<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>4. \u9a8c\u8bc1\u793a\u4f8b<\/h5>\n<p>javascript<\/p>\n<p>\/\/ \u4fee\u6539\u6d45\u514b\u9686\u540e\u7684\u5f71\u54cd<br \/>\nshallowCopy.name &#061; &#034;Jane&#034;;  \/\/ \u2705 \u4e0d\u5f71\u54cd\u539f\u5bf9\u8c61<br \/>\nshallowCopy.address.city &#061; &#034;Boston&#034;;  \/\/ \u274c \u5f71\u54cd\u539f\u5bf9\u8c61&#xff01;<br \/>\nshallowCopy.hobbies.push(&#034;swimming&#034;);  \/\/ \u274c \u5f71\u54cd\u539f\u5bf9\u8c61&#xff01;<\/p>\n<p>\/\/ \u4fee\u6539\u6df1\u514b\u9686\u540e\u7684\u5f71\u54cd<br \/>\ndeepCopy.name &#061; &#034;Jane&#034;;  \/\/ \u2705 \u4e0d\u5f71\u54cd\u539f\u5bf9\u8c61<br \/>\ndeepCopy.address.city &#061; &#034;Boston&#034;;  \/\/ \u2705 \u4e0d\u5f71\u54cd\u539f\u5bf9\u8c61<br \/>\ndeepCopy.hobbies.push(&#034;swimming&#034;);  \/\/ \u2705 \u4e0d\u5f71\u54cd\u539f\u5bf9\u8c61 <\/p>\n<h5>5. \u5b9e\u73b0\u65b9\u6cd5<\/h5>\n<h6>\u6d45\u514b\u9686\u5b9e\u73b0&#xff1a;<\/h6>\n<p>javascript<\/p>\n<p>\/\/ \u65b9\u6cd51&#xff1a;Object.assign<br \/>\nconst shallow1 &#061; Object.assign({}, obj);<\/p>\n<p>\/\/ \u65b9\u6cd52&#xff1a;\u6269\u5c55\u8fd0\u7b97\u7b26<br \/>\nconst shallow2 &#061; { &#8230;obj };<\/p>\n<p>\/\/ \u65b9\u6cd53&#xff1a;\u6570\u7ec4\u6d45\u514b\u9686<br \/>\nconst arrShallow &#061; [&#8230;array];<br \/>\nconst arrShallow2 &#061; array.slice(); <\/p>\n<h6>\u6df1\u514b\u9686\u5b9e\u73b0&#xff1a;<\/h6>\n<p>javascript<\/p>\n<p>\/\/ \u65b9\u6cd51&#xff1a;JSON&#xff08;\u6709\u5c40\u9650\u6027&#xff09;<br \/>\nconst deep1 &#061; JSON.parse(JSON.stringify(obj));<br \/>\n\/\/ \u5c40\u9650\u6027&#xff1a;\u51fd\u6570\u3001undefined\u3001\u5faa\u73af\u5f15\u7528\u3001\u7279\u6b8a\u5bf9\u8c61&#xff08;Date\u3001RegExp\u7b49&#xff09;\u4f1a\u4e22\u5931<\/p>\n<p>\/\/ \u65b9\u6cd52&#xff1a;structuredClone&#xff08;\u73b0\u4ee3API&#xff09;<br \/>\nconst deep2 &#061; structuredClone(obj);<\/p>\n<p>\/\/ \u65b9\u6cd53&#xff1a;\u9012\u5f52\u51fd\u6570&#xff08;\u5b8c\u6574\u5b9e\u73b0&#xff09;<br \/>\nfunction deepClone(obj, hash &#061; new WeakMap()) {<br \/>\n  if (obj &#061;&#061;&#061; null || typeof obj !&#061;&#061; &#039;object&#039;) return obj;<br \/>\n  if (hash.has(obj)) return hash.get(obj);<\/p>\n<p>  const clone &#061; Array.isArray(obj) ? [] : {};<br \/>\n  hash.set(obj, clone);<\/p>\n<p>  for (let key in obj) {<br \/>\n    if (obj.hasOwnProperty(key)) {<br \/>\n      clone[key] &#061; deepClone(obj[key], hash);<br \/>\n    }<br \/>\n  }<\/p>\n<p>  return clone;<br \/>\n}<\/p>\n<p>\/\/ \u65b9\u6cd54&#xff1a;\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93<br \/>\n\/\/ Lodash: _.cloneDeep(obj) <\/p>\n<h5>6. \u7279\u6b8a\u60c5\u51b5\u5904\u7406<\/h5>\n<p>javascript<\/p>\n<p>const complexObj &#061; {<br \/>\n  date: new Date(),<br \/>\n  regex: \/pattern\/g,<br \/>\n  func: function() { return &#034;hello&#034;; },<br \/>\n  undef: undefined,<br \/>\n  infinity: Infinity,<br \/>\n  nested: {<br \/>\n    arr: [1, 2, 3],<br \/>\n    obj: { a: 1 }<br \/>\n  },<br \/>\n  \/\/ \u5faa\u73af\u5f15\u7528<br \/>\n  self: null<br \/>\n};<br \/>\ncomplexObj.self &#061; complexObj;<\/p>\n<p>\/\/ JSON\u65b9\u6cd5\u4f1a\u4e22\u5931\u4fe1\u606f<br \/>\nconst jsonClone &#061; JSON.parse(JSON.stringify(complexObj));<br \/>\n\/\/ date \u2192 \u5b57\u7b26\u4e32&#xff0c;func \u2192 \u4e22\u5931&#xff0c;undefined \u2192 \u4e22\u5931&#xff0c;\u5faa\u73af\u5f15\u7528 \u2192 \u9519\u8bef<\/p>\n<p>\/\/ \u81ea\u5b9a\u4e49\u6df1\u514b\u9686\u5904\u7406\u8fd9\u4e9b\u60c5\u51b5<br \/>\nfunction enhancedDeepClone(obj) {<br \/>\n  \/\/ \u5904\u7406\u57fa\u672c\u7c7b\u578b\u3001\u51fd\u6570\u7b49<br \/>\n  if (obj &#061;&#061;&#061; null || typeof obj !&#061;&#061; &#039;object&#039;) return obj;<\/p>\n<p>  \/\/ \u5904\u7406\u7279\u6b8a\u5bf9\u8c61<br \/>\n  if (obj instanceof Date) return new Date(obj);<br \/>\n  if (obj instanceof RegExp) return new RegExp(obj);<br \/>\n  \/\/ &#8230; \u5176\u4ed6\u7279\u6b8a\u7c7b\u578b\u5904\u7406<br \/>\n} <\/p>\n<h5>7. \u4f7f\u7528\u5efa\u8bae<\/h5>\n<p>\u4f7f\u7528\u6d45\u514b\u9686\u7684\u60c5\u51b5&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5bf9\u8c61\u7ed3\u6784\u7b80\u5355&#xff0c;\u6ca1\u6709\u5d4c\u5957\u5f15\u7528<\/p>\n<\/li>\n<li>\n<p>\u53ea\u9700\u8981\u590d\u5236\u7b2c\u4e00\u5c42\u6570\u636e<\/p>\n<\/li>\n<li>\n<p>\u6027\u80fd\u8981\u6c42\u9ad8<\/p>\n<\/li>\n<li>\n<p>\u660e\u786e\u77e5\u9053\u4fee\u6539\u4e0d\u4f1a\u5f71\u54cd\u539f\u5bf9\u8c61<\/p>\n<\/li>\n<\/ul>\n<p>\u4f7f\u7528\u6df1\u514b\u9686\u7684\u60c5\u51b5&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5bf9\u8c61\u6709\u590d\u6742\u7684\u5d4c\u5957\u7ed3\u6784<\/p>\n<\/li>\n<li>\n<p>\u9700\u8981\u5b8c\u5168\u72ec\u7acb\u7684\u526f\u672c<\/p>\n<\/li>\n<li>\n<p>\u9700\u8981\u4fee\u6539\u5d4c\u5957\u5bf9\u8c61\u800c\u4e0d\u5f71\u54cd\u539f\u5bf9\u8c61<\/p>\n<\/li>\n<li>\n<p>\u5904\u7406\u4e0d\u53ef\u53d8\u6570\u636e\u6a21\u5f0f<\/p>\n<\/li>\n<\/ul>\n<h5>8. \u6027\u80fd\u5bf9\u6bd4<\/h5>\n<p>javascript<\/p>\n<p>\/\/ \u6d45\u514b\u9686\u6027\u80fd\u901a\u5e38\u66f4\u597d<br \/>\nconsole.time(&#039;shallow&#039;);<br \/>\nfor (let i &#061; 0; i &lt; 10000; i&#043;&#043;) {<br \/>\n  const copy &#061; { &#8230;original };<br \/>\n}<br \/>\nconsole.timeEnd(&#039;shallow&#039;);<\/p>\n<p>console.time(&#039;deep&#039;);<br \/>\nfor (let i &#061; 0; i &lt; 10000; i&#043;&#043;) {<br \/>\n  const copy &#061; JSON.parse(JSON.stringify(original));<br \/>\n}<br \/>\nconsole.timeEnd(&#039;deep&#039;); <\/p>\n<h5>9. \u5e38\u89c1\u9677\u9631<\/h5>\n<p>javascript<\/p>\n<p>\/\/ \u9677\u96311&#xff1a;\u8bef\u4ee5\u4e3a\u6d45\u514b\u9686\u662f\u6df1\u514b\u9686<br \/>\nconst obj &#061; { a: { b: 1 } };<br \/>\nconst shallow &#061; { &#8230;obj };<br \/>\nshallow.a.b &#061; 2;  \/\/ obj.a.b \u4e5f\u53d8\u6210\u4e86 2&#xff01;<\/p>\n<p>\/\/ \u9677\u96312&#xff1a;JSON\u65b9\u6cd5\u4e22\u5931\u4fe1\u606f<br \/>\nconst withFunction &#061; { fn: () &#061;&gt; {} };<br \/>\nconst cloned &#061; JSON.parse(JSON.stringify(withFunction));<br \/>\n\/\/ cloned.fn \u4e0d\u5b58\u5728&#xff01;<\/p>\n<p>\/\/ \u9677\u96313&#xff1a;\u5faa\u73af\u5f15\u7528<br \/>\nconst a &#061; { name: &#039;a&#039; };<br \/>\nconst b &#061; { name: &#039;b&#039;, ref: a };<br \/>\na.ref &#061; b;  \/\/ \u5faa\u73af\u5f15\u7528<br \/>\n\/\/ JSON.stringify(a) \u4f1a\u62a5\u9519&#xff01; <\/p>\n<p>\u4e3b\u8981\u662fJAVA\u91cc\u9664\u4e868\u79cd\u57fa\u672c\u7c7b\u578b\u4f20\u53c2\u6570\u662f\u503c\u4f20\u9012&#xff0c;\u5176\u4ed6\u7684\u7c7b\u5bf9\u8c61\u4f20\u53c2\u6570\u90fd\u662f\u5f15\u7528&#xff0c;\u6211\u4eec\u6709\u65f6\u5019\u4e0d\u5e0c\u671b\u5728\u65b9\u6cd5\u91cc\u5c06\u53c2\u6570\u6539\u53d8&#xff0c;\u8fd9\u662f\u5c31\u9700\u8981\u5728\u7c7b\u4e2d\u590d\u5199clone\u65b9\u6cd5&#xff08;\u5b9e\u73b0\u6df1\u590d\u5236&#xff09;\u3002<\/p>\n<p>Clone\u662f\u5982\u4f55\u5b8c\u6210\u7684\u5462&#xff1f;Object\u5728\u5bf9\u67d0\u4e2a\u5bf9\u8c61\u5b9e\u65bdClone\u65f6\u5bf9\u5176\u662f\u4e00\u65e0\u6240\u77e5\u7684&#xff0c;\u5b83\u4ec5\u4ec5\u662f\u7b80\u5355\u5730\u6267\u884c\u57df\u5bf9\u57df\u7684copy&#xff0c;\u8fd9\u5c31\u662fShallow Clone\u3002\u8fd9\u6837&#xff0c;\u95ee\u9898\u5c31\u6765\u4e86\u54af\u3002<\/p>\n<p>\u4ee5Employee\u4e3a\u4f8b&#xff0c;\u5b83\u91cc\u9762\u6709\u4e00\u4e2a\u57dfhireDay\u4e0d\u662f\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u53d8\u91cf&#xff0c;\u800c\u662f\u4e00\u4e2areference\u53d8\u91cf&#xff0c;\u7ecf\u8fc7Clone\u4e4b\u540e\u5c31\u4f1a\u4ea7\u751f\u4e00\u4e2a\u65b0\u7684Date\u578b\u7684reference&#xff0c;<\/p>\n<p>\u5b83\u548c\u539f\u59cb\u5bf9\u8c61\u4e2d\u5bf9\u5e94\u7684\u57df\u6307\u5411\u540c\u4e00\u4e2aDate\u5bf9\u8c61&#xff0c;\u8fd9\u6837\u514b\u9686\u7c7b\u5c31\u548c\u539f\u59cb\u7c7b\u5171\u4eab\u4e86\u4e00\u90e8\u5206\u4fe1\u606f&#xff0c;\u800c\u8fd9\u6837\u663e\u7136\u662f\u4e0d\u5229\u7684&#xff0c;\u8fc7\u7a0b\u4e0b\u56fe\u6240\u793a&#xff1a;<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"398\" src=\"2026-01-14jsd40ssqqkf.png\" width=\"797\" \/><\/p>\n<p>\u8fd9\u4e2a\u65f6\u5019\u6211\u4eec\u5c31\u9700\u8981\u8fdb\u884cdeep Clone\u4e86&#xff0c;\u5bf9\u90a3\u4e9b\u975e\u57fa\u672c\u7c7b\u578b\u7684\u57df\u8fdb\u884c\u7279\u6b8a\u7684\u5904\u7406&#xff0c;\u4f8b\u5982\u672c\u4f8b\u4e2d\u7684 hireDay\u3002\u6211\u4eec\u53ef\u4ee5\u91cd\u65b0\u5b9a\u4e49Clone\u65b9\u6cd5&#xff0c;\u5bf9hireDay\u505a\u7279\u6b8a\u5904\u7406&#xff0c;\u5982\u4e0b\u4ee3\u7801\u6240\u793a&#xff1a;<\/p>\n<\/p>\n<p>class Employee implements Cloneable {<br \/>\n    public Object clone() throws CloneNotSupportedException {<br \/>\n        Employee cloned &#061; (Employee) super.clone();<br \/>\n        cloned.hireDay &#061; (Date) hireDay.clone()<br \/>\n        return cloned;<br \/>\n    }<br \/>\n} <\/p>\n<p>clone\u65b9\u6cd5\u7684\u4fdd\u62a4\u673a\u5236<\/p>\n<p>\u5728Object\u4e2dClone()\u662f\u88ab\u58f0\u660e\u4e3aprotected\u7684&#xff0c;\u8fd9\u6837\u505a\u662f\u6709\u4e00\u5b9a\u7684\u9053\u7406\u7684&#xff0c;\u4ee5Employee\u7c7b\u4e3a\u4f8b&#xff0c;\u901a\u8fc7\u58f0\u660e\u4e3aprotected&#xff0c;\u5c31\u53ef\u4ee5\u4fdd\u8bc1\u53ea\u6709Employee\u7c7b\u91cc\u9762\u624d\u80fd\u201c\u514b\u9686\u201dEmployee\u5bf9\u8c61\u3002<\/p>\n<p>clone\u65b9\u6cd5\u7684\u4f7f\u7528<\/p>\n<p>\u4ec0\u4e48\u65f6\u5019\u4f7f\u7528shallow Clone&#xff0c;\u4ec0\u4e48\u65f6\u5019\u4f7f\u7528deep Clone&#xff0c;\u8fd9\u4e2a\u4e3b\u8981\u770b\u5177\u4f53\u5bf9\u8c61\u7684\u57df\u662f\u4ec0\u4e48\u6027\u8d28\u7684&#xff0c;\u57fa\u672c\u578b\u522b\u8fd8\u662freference variable<\/p>\n<p>\u8c03\u7528Clone()\u65b9\u6cd5\u7684\u5bf9\u8c61\u6240\u5c5e\u7684\u7c7b(Class)\u5fc5\u987bimplements Clonable\u63a5\u53e3&#xff0c;\u5426\u5219\u5728\u8c03\u7528Clone\u65b9\u6cd5\u7684\u65f6\u5019 \u4f1a\u629b\u51faCloneNotSupportedException<\/p>\n<p>\u63a8\u8350&#xff1a;\u00a0\u6d45\u514b\u9686(ShallowClone)\u548c\u6df1\u514b\u9686(DeepClone)\u533a\u522b\u4ee5\u53ca\u5b9e\u73b0<\/p>\n<h4 id=\"_2-tostring-\u65b9\u6cd5\">2 toString()\u65b9\u6cd5<\/h4>\n<\/p>\n<p>public String toString() {<br \/>\nreturn getClass().getName() &#043; &#034;&#064;&#034; &#043; Integer.toHexString(hashCode());<br \/>\n} <\/p>\n<p>Object \u7c7b\u7684 toString \u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32&#xff0c;\u8be5\u5b57\u7b26\u4e32\u7531\u7c7b\u540d&#xff08;\u5bf9\u8c61\u662f\u8be5\u7c7b\u7684\u4e00\u4e2a\u5b9e\u4f8b&#xff09;\u3001at \u6807\u8bb0\u7b26\u201c&#064;\u201d \u548c\u6b64\u5bf9\u8c61\u54c8\u5e0c\u7801\u7684\u65e0\u7b26\u53f7\u5341\u516d\u8fdb\u5236\u8868\u793a\u7ec4\u6210\u3002<\/p>\n<p>\u8be5\u65b9\u6cd5\u7528\u5f97\u6bd4\u8f83\u591a&#xff0c;\u4e00\u822c\u5b50\u7c7b\u90fd\u6709\u8986\u76d6\u3002<\/p>\n<\/p>\n<p>public static void main(String[] args){<br \/>\n    Object o1 &#061; new Object();<br \/>\n    System.out.println(o1.toString());<br \/>\n} <\/p>\n<h4 id=\"_3-getclass-\u65b9\u6cd5\">3 getClass()\u65b9\u6cd5<\/h4>\n<\/p>\n<p>public final native Class&lt;?&gt; getClass(); <\/p>\n<p>\u8fd4\u56de\u6b21Object\u7684\u8fd0\u884c\u65f6\u7c7b\u7c7b\u578b\u3002<\/p>\n<p>\u4e0d\u53ef\u91cd\u5199&#xff0c;\u8981\u8c03\u7528\u7684\u8bdd&#xff0c;\u4e00\u822c\u548cgetName()\u8054\u5408\u4f7f\u7528&#xff0c;\u5982getClass().getName();<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    Object o &#061; new Object();<br \/>\n    System.out.println(o.getClass());<br \/>\n    \/\/class java.lang.Object<br \/>\n} <\/p>\n<h4 id=\"_4-finalize-\u65b9\u6cd5\">4 finalize()\u65b9\u6cd5<\/h4>\n<\/p>\n<p>protected void finalize() throws Throwable { } <\/p>\n<p>\u8be5\u65b9\u6cd5\u7528\u4e8e\u91ca\u653e\u8d44\u6e90\u3002\u56e0\u4e3a\u65e0\u6cd5\u786e\u5b9a\u8be5\u65b9\u6cd5\u4ec0\u4e48\u65f6\u5019\u88ab\u8c03\u7528&#xff0c;\u5f88\u5c11\u4f7f\u7528\u3002<\/p>\n<p>Java\u5141\u8bb8\u5728\u7c7b\u4e2d\u5b9a\u4e49\u4e00\u4e2a\u540d\u4e3afinalize()\u7684\u65b9\u6cd5\u3002\u5b83\u7684\u5de5\u4f5c\u539f\u7406\u662f&#xff1a;\u4e00\u65e6\u5783\u573e\u56de\u6536\u5668\u51c6\u5907\u597d\u91ca\u653e\u5bf9\u8c61\u5360\u7528\u7684\u5b58\u50a8\u7a7a\u95f4&#xff0c;\u5c06\u9996\u5148\u8c03\u7528\u5176finalize()\u65b9\u6cd5\u3002\u5e76\u4e14\u5728\u4e0b\u4e00\u6b21\u5783\u573e\u56de\u6536\u52a8\u4f5c\u53d1\u751f\u65f6&#xff0c;\u624d\u4f1a\u771f\u6b63\u56de\u6536\u5bf9\u8c61\u5360\u7528\u7684\u5185\u5b58\u3002<\/p>\n<p>\u5173\u4e8e\u5783\u573e\u56de\u6536&#xff0c;\u6709\u4e09\u70b9\u9700\u8981\u8bb0\u4f4f&#xff1a;<\/p>\n<p>1\u3001\u5bf9\u8c61\u53ef\u80fd\u4e0d\u88ab\u5783\u573e\u56de\u6536\u3002\u53ea\u8981\u7a0b\u5e8f\u6ca1\u6709\u6fd2\u4e34\u5b58\u50a8\u7a7a\u95f4\u7528\u5b8c\u7684\u90a3\u4e00\u523b&#xff0c;\u5bf9\u8c61\u5360\u7528\u7684\u7a7a\u95f4\u5c31\u603b\u4e5f\u5f97\u4e0d\u5230\u91ca\u653e\u3002<\/p>\n<p>2\u3001\u5783\u573e\u56de\u6536\u5e76\u4e0d\u7b49\u4e8e\u201c\u6790\u6784\u201d\u3002<\/p>\n<p>\u200b \u79d1\u666e&#xff1a;\u6790\u6784\u51fd\u6570(destructor) \u4e0e\u6784\u9020\u51fd\u6570\u76f8\u53cd&#xff0c;\u5f53\u5bf9\u8c61\u7ed3\u675f\u5176\u751f\u547d\u5468\u671f&#xff0c;\u5982\u5bf9\u8c61\u6240\u5728\u7684\u51fd\u6570\u5df2\u8c03\u7528\u5b8c\u6bd5\u65f6&#xff0c;\u7cfb\u7edf\u81ea\u52a8\u6267\u884c\u6790\u6784\u51fd\u6570\u3002\u6790\u6784\u51fd\u6570\u5f80\u5f80\u7528\u6765\u505a\u201c\u6e05\u7406\u5584\u540e\u201d \u7684\u5de5\u4f5c&#xff08;\u4f8b\u5982\u5728\u5efa\u7acb\u5bf9\u8c61\u65f6\u7528new\u5f00\u8f9f\u4e86\u4e00\u7247\u5185\u5b58\u7a7a\u95f4&#xff0c;delete\u4f1a\u81ea\u52a8\u8c03\u7528\u6790\u6784\u51fd\u6570\u540e\u91ca\u653e\u5185\u5b58&#xff09;\u3002<\/p>\n<p>3\u3001\u5783\u573e\u56de\u6536\u53ea\u4e0e\u5185\u5b58\u6709\u5173\u3002\u4f7f\u7528\u5783\u573e\u56de\u6536\u7684\u552f\u4e00\u539f\u56e0\u662f\u4e3a\u4e86\u56de\u6536\u7a0b\u5e8f\u4e0d\u518d\u4f7f\u7528\u7684\u5185\u5b58\u3002<\/p>\n<p>finalize()\u7684\u7528\u9014&#xff1a;<\/p>\n<p>\u65e0\u8bba\u5bf9\u8c61\u662f\u5982\u4f55\u521b\u5efa\u7684&#xff0c;\u5783\u573e\u56de\u6536\u5668\u90fd\u4f1a\u8d1f\u8d23\u91ca\u653e\u5bf9\u8c61\u5360\u636e\u7684\u6240\u6709\u5185\u5b58\u3002<\/p>\n<p>\u8fd9\u5c31\u5c06\u5bf9finalize()\u7684\u9700\u6c42\u9650\u5236\u5230\u4e00\u79cd\u7279\u6b8a\u60c5\u51b5&#xff0c;\u5373\u901a\u8fc7\u67d0\u79cd\u521b\u5efa\u5bf9\u8c61\u65b9\u5f0f\u4ee5\u5916\u7684\u65b9\u5f0f\u4e3a\u5bf9\u8c61\u5206\u914d\u4e86\u5b58\u50a8\u7a7a\u95f4\u3002\u4e0d\u8fc7\u8fd9\u79cd\u60c5\u51b5\u4e00\u822c\u53d1\u751f\u5728\u4f7f\u7528\u201c\u672c\u5730\u65b9\u6cd5\u201d\u7684\u60c5\u51b5\u4e0b&#xff0c;\u672c\u5730\u65b9\u6cd5\u662f\u4e00\u79cd\u5728Java\u4e2d\u8c03\u7528\u975eJava\u4ee3\u7801\u7684\u65b9\u5f0f\u3002<\/p>\n<h4 id=\"_5-equals-\u65b9\u6cd5\">5 equals()\u65b9\u6cd5<\/h4>\n<\/p>\n<p>public boolean equals(Object obj) {<br \/>\nreturn (this &#061;&#061; obj);<br \/>\n} <\/p>\n<p>Object\u4e2d\u7684equals\u65b9\u6cd5\u662f\u76f4\u63a5\u5224\u65adthis\u548cobj\u672c\u8eab\u7684\u503c\u662f\u5426\u76f8\u7b49&#xff0c;\u5373\u7528\u6765\u5224\u65ad\u8c03\u7528equals\u7684\u5bf9\u8c61\u548c\u5f62\u53c2 obj\u6240\u5f15\u7528\u7684\u5bf9\u8c61\u662f\u5426\u662f\u540c\u4e00\u5bf9\u8c61<\/p>\n<p>\u6240\u8c13\u540c\u4e00\u5bf9\u8c61\u5c31\u662f\u6307\u5185\u5b58\u4e2d\u540c\u4e00\u5757\u5b58\u50a8\u5355\u5143&#xff0c;\u5982\u679cthis\u548cobj\u6307\u5411\u7684\u662f\u540c\u4e00\u5757\u5185\u5b58\u5bf9\u8c61&#xff0c;\u5219\u8fd4\u56detrue&#xff0c;\u5982\u679cthis\u548cobj\u6307\u5411\u7684\u4e0d\u662f\u540c\u4e00\u5757\u5185\u5b58&#xff0c;\u5219\u8fd4\u56defalse\u3002<\/p>\n<p>\u6ce8\u610f&#xff1a;\u5373\u4fbf\u662f\u5185\u5bb9\u5b8c\u5168\u76f8\u7b49\u7684\u4e24\u5757\u4e0d\u540c\u7684\u5185\u5b58\u5bf9\u8c61&#xff0c;\u4e5f\u8fd4\u56defalse\u3002<\/p>\n<p>\u5982\u679c\u662f\u540c\u4e00\u5757\u5185\u5b58&#xff0c;\u5219object\u4e2d\u7684equals\u65b9\u6cd5\u8fd4\u56detrue&#xff0c;\u5982\u679c\u662f\u4e0d\u540c\u7684\u5185\u5b58&#xff0c;\u5219\u8fd4\u56defalse<\/p>\n<p>\u5982\u679c\u5e0c\u671b\u4e0d\u540c\u5185\u5b58\u4f46\u76f8\u540c\u5185\u5bb9\u7684\u4e24\u4e2a\u5bf9\u8c61equals\u65f6\u8fd4\u56detrue&#xff0c;\u5219\u6211\u4eec\u9700\u8981\u91cd\u5199\u7236\u7c7b\u7684equal\u65b9\u6cd5<\/p>\n<p>String\u7c7b\u5df2\u7ecf\u91cd\u5199\u4e86object\u4e2d\u7684equals\u65b9\u6cd5&#xff08;\u8fd9\u6837\u5c31\u662f\u6bd4\u8f83\u5185\u5bb9\u662f\u5426\u76f8\u7b49\u4e86&#xff09;<\/p>\n<p>\u67e5\u770bString\u7c7b\u6e90\u7801equals\u65b9\u6cd5<\/p>\n<\/p>\n<p>public boolean equals(Object anObject) {<br \/>\n    if (this &#061;&#061; anObject) {<br \/>\n        return true;<br \/>\n    }<br \/>\n    if (anObject instanceof String) {<br \/>\n        String anotherString &#061; (String)anObject;<br \/>\n        int n &#061; value.length;<br \/>\n        if (n &#061;&#061; anotherString.value.length) {<br \/>\n            char v1[] &#061; value;<br \/>\n            char v2[] &#061; anotherString.value;<br \/>\n            int i &#061; 0;<br \/>\n            while (n&#8211; !&#061; 0) {<br \/>\n                if (v1[i] !&#061; v2[i])<br \/>\n                    return false;<br \/>\n                i&#043;&#043;;<br \/>\n            }<br \/>\n            return true;<br \/>\n        }<br \/>\n    }<br \/>\n    return false;<br \/>\n} <\/p>\n<h4 id=\"_6-hashcode-\u65b9\u6cd5\">6 hashCode()\u65b9\u6cd5<\/h4>\n<\/p>\n<p>public native int hashCode(); <\/p>\n<p>\u8fd4\u56de\u8be5\u5bf9\u8c61\u7684\u54c8\u5e0c\u7801\u503c\u3002<\/p>\n<p>\u8be5\u65b9\u6cd5\u7528\u4e8e\u54c8\u5e0c\u67e5\u627e&#xff0c;\u53ef\u4ee5\u51cf\u5c11\u5728\u67e5\u627e\u4e2d\u4f7f\u7528equals\u7684\u6b21\u6570&#xff0c;\u91cd\u5199\u4e86equals\u65b9\u6cd5\u4e00\u822c\u90fd\u8981\u91cd\u5199 hashCode\u65b9\u6cd5\u3002\u8fd9\u4e2a\u65b9\u6cd5\u5728\u4e00\u4e9b\u5177\u6709\u54c8\u5e0c\u529f\u80fd\u7684Collection\u4e2d\u7528\u5230\u3002<\/p>\n<p>\u4e00\u822c\u5fc5\u987b\u6ee1\u8db3obj1.equals(obj2)&#061;&#061;true\u3002\u53ef\u4ee5\u63a8\u51faobj1.hashCode() &#061;&#061; obj2.hashCode()&#xff0c;\u4f46\u662f hashCode\u76f8\u7b49\u4e0d\u4e00\u5b9a\u5c31\u6ee1\u8db3equals\u3002\u4e0d\u8fc7\u4e3a\u4e86\u63d0\u9ad8\u6548\u7387&#xff0c;\u5e94\u8be5\u5c3d\u91cf\u4f7f\u4e0a\u9762\u4e24\u4e2a\u6761\u4ef6\u63a5\u8fd1\u7b49\u4ef7\u3002<\/p>\n<h4 id=\"_7-wait-\u65b9\u6cd5\">7 wait()\u65b9\u6cd5<\/h4>\n<\/p>\n<p>public final void wait(long timeoutMillis, int nanos) throws InterruptedException {<br \/>\n    if (timeoutMillis &lt; 0) {<br \/>\n        throw new IllegalArgumentException(&#034;timeoutMillis value is negative&#034;);<br \/>\n    }<\/p>\n<p>    if (nanos &lt; 0 || nanos &gt; 999999) {<br \/>\n        throw new IllegalArgumentException(<br \/>\n                            &#034;nanosecond timeout value out of range&#034;);<br \/>\n    }<\/p>\n<p>    if (nanos &gt; 0 &amp;&amp; timeoutMillis &lt; Long.MAX_VALUE) {<br \/>\n        timeoutMillis&#043;&#043;;<br \/>\n    }<\/p>\n<p>    wait(timeoutMillis);<br \/>\n} <\/p>\n<p>\u53ef\u4ee5\u770b\u5230\u6709\u4e09\u79cd\u91cd\u8f7d&#xff0c;wait\u4ec0\u4e48\u610f\u601d\u5462&#xff1f;<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"227\" src=\"2026-01-14tg3q511tuog.png\" width=\"1002\" \/><\/p>\n<p>\u65b9\u6cd5\u4e2d\u7684\u5f02\u5e38&#xff1a;<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"87\" src=\"2026-01-140dmfjx54sno.png\" width=\"921\" \/><\/p>\n<p>wait\u65b9\u6cd5\u5c31\u662f\u4f7f\u5f53\u524d\u7ebf\u7a0b\u7b49\u5f85\u8be5\u5bf9\u8c61\u7684\u9501&#xff0c;\u5f53\u524d\u7ebf\u7a0b\u5fc5\u987b\u662f\u8be5\u5bf9\u8c61\u7684\u62e5\u6709\u8005&#xff0c;\u4e5f\u5c31\u662f\u5177\u6709\u8be5\u5bf9\u8c61\u7684\u9501\u3002<\/p>\n<p>wait()\u65b9\u6cd5\u4e00\u76f4\u7b49\u5f85&#xff0c;\u76f4\u5230\u83b7\u5f97\u9501\u6216\u8005\u88ab\u4e2d\u65ad\u3002wait(long timeout)\u8bbe\u5b9a\u4e00\u4e2a\u8d85\u65f6\u95f4\u9694<\/p>\n<p>\u5982\u679c\u5728\u89c4\u5b9a\u65f6\u95f4\u5185\u6ca1\u6709\u83b7\u5f97\u9501\u5c31\u8fd4\u56de\u3002<\/p>\n<p>\u8c03\u7528\u8be5\u65b9\u6cd5\u540e\u5f53\u524d\u7ebf\u7a0b\u8fdb\u5165\u7761\u7720\u72b6\u6001&#xff0c;\u76f4\u5230\u4ee5\u4e0b\u4e8b\u4ef6\u53d1\u751f\u3002<\/p>\n<p>&#xff08;1&#xff09;\u5176\u4ed6\u7ebf\u7a0b\u8c03\u7528\u4e86\u8be5\u5bf9\u8c61\u7684notify\u65b9\u6cd5\u3002 &#xff08;2&#xff09;\u5176\u4ed6\u7ebf\u7a0b\u8c03\u7528\u4e86\u8be5\u5bf9\u8c61\u7684notifyAll\u65b9\u6cd5\u3002 &#xff08;3&#xff09;\u5176\u4ed6\u7ebf\u7a0b\u8c03\u7528\u4e86interrupt\u4e2d\u65ad\u8be5\u7ebf\u7a0b\u3002 &#xff08;4&#xff09;\u65f6\u95f4\u95f4\u9694\u5230\u4e86\u3002<\/p>\n<p>\u6b64\u65f6\u8be5\u7ebf\u7a0b\u5c31\u53ef\u4ee5\u88ab\u8c03\u5ea6\u4e86&#xff0c;\u5982\u679c\u662f\u88ab\u4e2d\u65ad\u7684\u8bdd\u5c31\u629b\u51fa\u4e00\u4e2aInterruptedException\u5f02\u5e38\u3002<\/p>\n<h4 id=\"_8-notify-\u65b9\u6cd5\">8 notify()\u65b9\u6cd5<\/h4>\n<\/p>\n<p>public final native void notify(); <\/p>\n<p>\u8be5\u65b9\u6cd5\u5524\u9192\u5728\u8be5\u5bf9\u8c61\u4e0a\u7b49\u5f85\u7684\u67d0\u4e2a\u7ebf\u7a0b\u3002<\/p>\n<\/p>\n<p>public final native void notifyAll(); <\/p>\n<p>\u8be5\u65b9\u6cd5\u5524\u9192\u5728\u8be5\u5bf9\u8c61\u4e0a\u7b49\u5f85\u7684\u6240\u6709\u7ebf\u7a0b\u3002<\/p>\n<h3 id=\"\u5305\u88c5\u7c7b\">\u5305\u88c5\u7c7b<\/h3>\n<h4 id=\"_1\u3001\u5305\u88c5\u7c7b\u4ecb\u7ecd\">1\u3001\u5305\u88c5\u7c7b\u4ecb\u7ecd<\/h4>\n<p>\u867d\u7136 Java \u8bed\u8a00\u662f\u5178\u578b\u7684\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u8bed\u8a00&#xff0c;\u4f46\u5176\u4e2d\u7684\u516b\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u5e76\u4e0d\u652f\u6301\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b&#xff0c;\u57fa\u672c\u7c7b\u578b\u7684\u6570\u636e\u4e0d\u5177\u5907\u201c\u5bf9\u8c61\u201d\u7684\u7279\u6027\u2014\u2014\u4e0d\u643a\u5e26\u5c5e\u6027\u3001\u6ca1\u6709\u65b9\u6cd5\u53ef\u8c03\u7528\u3002 \u6cbf\u7528\u5b83\u4eec\u53ea\u662f\u4e3a\u4e86\u8fce\u5408\u4eba\u7c7b\u6839\u6df1\u8482\u56fa\u7684\u4e60\u60ef&#xff0c;\u5e76\u7684\u786e\u80fd\u7b80\u5355\u3001\u6709\u6548\u5730\u8fdb\u884c\u5e38\u89c4\u6570\u636e\u5904\u7406\u3002<\/p>\n<p>\u8fd9\u79cd\u501f\u52a9\u4e8e\u975e\u9762\u5411\u5bf9\u8c61\u6280\u672f\u7684\u505a\u6cd5\u6709\u65f6\u4e5f\u4f1a\u5e26\u6765\u4e0d\u4fbf&#xff0c;\u6bd4\u5982\u5f15\u7528\u7c7b\u578b\u6570\u636e\u5747\u7ee7\u627f\u4e86 Object \u7c7b\u7684\u7279\u6027&#xff0c;\u8981\u8f6c\u6362\u4e3a String \u7c7b\u578b&#xff08;\u7ecf\u5e38\u6709\u8fd9\u79cd\u9700\u8981&#xff09;\u65f6\u53ea\u8981\u7b80\u5355\u8c03\u7528 Object \u7c7b\u4e2d\u5b9a\u4e49\u7684toString()\u5373\u53ef&#xff0c;\u800c\u57fa\u672c\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u4e3a String \u7c7b\u578b\u5219\u8981\u9ebb\u70e6\u5f97\u591a\u3002\u4e3a\u89e3\u51b3\u6b64\u7c7b\u95ee\u9898 &#xff0c;Java\u4e3a\u6bcf\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u5206\u522b\u8bbe\u8ba1\u4e86\u5bf9\u5e94\u7684\u7c7b&#xff0c;\u79f0\u4e4b\u4e3a\u5305\u88c5\u7c7b(Wrapper Classes)&#xff0c;\u4e5f\u6709\u6559\u6750\u79f0\u4e3a\u5916\u8986\u7c7b\u6216\u6570\u636e\u7c7b\u578b\u7c7b\u3002<\/p>\n<table>\n<tr>\u57fa\u672c\u6570\u636e\u7c7b\u578b\u5bf9\u5e94\u7684\u5305\u88c5\u7c7b<\/tr>\n<tbody>\n<tr>\n<td>byte<\/td>\n<td>Byte<\/td>\n<\/tr>\n<tr>\n<td>short<\/td>\n<td>Short<\/td>\n<\/tr>\n<tr>\n<td>int<\/td>\n<td>Integer<\/td>\n<\/tr>\n<tr>\n<td>long<\/td>\n<td>Long<\/td>\n<\/tr>\n<tr>\n<td>char<\/td>\n<td>Character<\/td>\n<\/tr>\n<tr>\n<td>float<\/td>\n<td>Float<\/td>\n<\/tr>\n<tr>\n<td>double<\/td>\n<td>Double<\/td>\n<\/tr>\n<tr>\n<td>boolean<\/td>\n<td>Boolean<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6bcf\u4e2a\u5305\u88c5\u7c7b\u7684\u5bf9\u8c61\u53ef\u4ee5\u5c01\u88c5\u4e00\u4e2a\u76f8\u5e94\u7684\u57fa\u672c\u7c7b\u578b\u7684\u6570\u636e&#xff0c;\u5e76\u63d0\u4f9b\u4e86\u5176\u5b83\u4e00\u4e9b\u6709\u7528\u7684\u65b9\u6cd5\u3002\u5305\u88c5\u7c7b\u5bf9\u8c61\u4e00 \u7ecf\u521b\u5efa&#xff0c;\u5176\u5185\u5bb9&#xff08;\u6240\u5c01\u88c5\u7684\u57fa\u672c\u7c7b\u578b\u6570\u636e\u503c&#xff09;\u4e0d\u53ef\u6539\u53d8\u3002<\/p>\n<p>\u57fa\u672c\u7c7b\u578b\u548c\u5bf9\u5e94\u7684\u5305\u88c5\u7c7b\u53ef\u4ee5\u76f8\u4e92\u88c5\u6362&#xff1a;<\/p>\n<ul>\n<li>\u7531\u57fa\u672c\u7c7b\u578b\u5411\u5bf9\u5e94\u7684\u5305\u88c5\u7c7b\u8f6c\u6362\u79f0\u4e3a\u88c5\u7bb1&#xff0c;\u4f8b\u5982\u628a int \u5305\u88c5\u6210 Integer \u7c7b\u7684\u5bf9\u8c61&#xff1b;<\/li>\n<li>\u5305\u88c5\u7c7b\u5411\u5bf9\u5e94\u7684\u57fa\u672c\u7c7b\u578b\u8f6c\u6362\u79f0\u4e3a\u62c6\u7bb1&#xff0c;\u4f8b\u5982\u628a Integer \u7c7b\u7684\u5bf9\u8c61\u91cd\u65b0\u7b80\u5316\u4e3a int\u3002<\/li>\n<\/ul>\n<h4 id=\"_2\u3001\u5305\u88c5\u7c7b\u7684\u5e94\u7528\">2\u3001\u5305\u88c5\u7c7b\u7684\u5e94\u7528<\/h4>\n<p>1\u3001 \u5b9e\u73b0 int \u548c Integer \u7684\u76f8\u4e92\u8f6c\u6362<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7 Integer \u7c7b\u7684\u6784\u9020\u65b9\u6cd5\u5c06 int \u88c5\u7bb1&#xff0c;\u901a\u8fc7 Integer \u7c7b\u7684 intValue \u65b9\u6cd5\u5c06 Integer \u62c6\u7bb1\u3002<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int m &#061; 500;<br \/>\n    Integer obj &#061; new Integer(m); \/\/ \u624b\u52a8\u88c5\u7bb1<br \/>\n    int n &#061; obj.intValue(); \/\/ \u624b\u52a8\u62c6\u7bb1<br \/>\n    System.out.println(&#034;n &#061; &#034; &#043; n);<\/p>\n<p>    Integer obj1 &#061; new Integer(500);<br \/>\n    System.out.println(&#034;obj \u7b49\u4ef7\u4e8e obj1&#xff1f;&#034; &#043; obj.equals(obj1));<br \/>\n} <\/p>\n<p>2\u3001 \u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6574\u6570<\/p>\n<p>Integer \u7c7b\u6709\u4e00\u4e2a\u9759\u6001\u7684 paseInt() \u65b9\u6cd5&#xff0c;\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6574\u6570&#xff0c;\u8bed\u6cd5\u4e3a&#xff1a;<\/p>\n<\/p>\n<p>parseInt(String s, int radix);<br \/>\n\/\/s \u4e3a\u8981\u8f6c\u6362\u7684\u5b57\u7b26\u4e32&#xff0c;radix \u4e3a\u8fdb\u5236&#xff0c;\u53ef\u9009&#xff0c;\u9ed8\u8ba4\u4e3a\u5341\u8fdb\u5236\u3002 <\/p>\n<p>\u4e0b\u9762\u7684\u4ee3\u7801\u5c06\u4f1a\u544a\u8bc9\u4f60\u4ec0\u4e48\u6837\u7684\u5b57\u7b26\u4e32\u53ef\u4ee5\u8f6c\u6362\u4e3a\u6574\u6570&#xff1a;<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    String[] strs &#061; {&#034;123&#034;, &#034;123abc&#034;, &#034;abc123&#034;, &#034;abcxyz&#034;};<br \/>\n    for (String str : strs) {<br \/>\n        try {<br \/>\n            int m &#061; Integer.parseInt(str, 10);<br \/>\n            System.out.println(str &#043; &#034; \u53ef\u4ee5\u8f6c\u6362\u4e3a\u6574\u6570 &#034; &#043; m);<br \/>\n        } catch (Exception e) {<br \/>\n            System.out.println(str &#043; &#034; \u65e0\u6cd5\u8f6c\u6362\u4e3a\u6574\u6570&#034;);<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<p>\u7ed3\u679c&#xff1a;<\/p>\n<p>123 \u53ef\u4ee5\u8f6c\u6362\u4e3a\u6574\u6570 123 123abc \u65e0\u6cd5\u8f6c\u6362\u4e3a\u6574\u6570 abc123 \u65e0\u6cd5\u8f6c\u6362\u4e3a\u6574\u6570 abcxyz \u65e0\u6cd5\u8f6c\u6362\u4e3a\u6574\u6570<\/p>\n<h4 id=\"_3\u3001\u5c06\u6574\u6570\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\">3\u3001\u5c06\u6574\u6570\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32<\/h4>\n<p>Integer \u7c7b\u6709\u4e00\u4e2a\u9759\u6001\u7684 toString() \u65b9\u6cd5&#xff0c;\u53ef\u4ee5\u5c06\u6574\u6570\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u3002\u6216\u8005\u76f4\u63a5\u5728\u6574\u6570\u540e\u9762\u52a0\u7a7a\u5b57\u7b26\u4e32&#xff01;<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int m &#061; 500;<br \/>\n    String s &#061; Integer.toString(m);<\/p>\n<p>    String s2 &#061; m &#043;&#034;&#034;;<br \/>\n    System.out.println(&#034;s &#061; &#034; &#043; s);<br \/>\n} <\/p>\n<h4 id=\"_3\u3001\u81ea\u52a8\u62c6\u7bb1\u548c\u88c5\u7bb1\">3\u3001\u81ea\u52a8\u62c6\u7bb1\u548c\u88c5\u7bb1<\/h4>\n<p>\u4e0a\u9762\u7684\u4f8b\u5b50\u90fd\u9700\u8981\u624b\u52a8\u5b9e\u4f8b\u5316\u4e00\u4e2a\u5305\u88c5\u7c7b&#xff0c;\u79f0\u4e3a\u624b\u52a8\u62c6\u7bb1\u88c5\u7bb1\u3002Java 1.5(5.0) \u4e4b\u524d\u5fc5\u987b\u624b\u52a8\u62c6\u7bb1\u88c5\u7bb1\u3002<\/p>\n<p>Java 1.5 \u4e4b\u540e\u53ef\u4ee5\u81ea\u52a8\u62c6\u7bb1\u88c5\u7bb1&#xff0c;\u4e5f\u5c31\u662f\u5728\u8fdb\u884c\u57fa\u672c\u6570\u636e\u7c7b\u578b\u548c\u5bf9\u5e94\u7684\u5305\u88c5\u7c7b\u8f6c\u6362\u65f6&#xff0c;\u7cfb\u7edf\u5c06\u81ea\u52a8\u8fdb\u884c&#xff0c;\u8fd9\u5c06\u5927\u5927\u65b9\u4fbf\u7a0b\u5e8f\u5458\u7684\u4ee3\u7801\u4e66\u5199\u3002<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    int m &#061; 500;<br \/>\n    Integer obj &#061; m; \/\/ \u81ea\u52a8\u88c5\u7bb1<br \/>\n    int n &#061; obj; \/\/ \u81ea\u52a8\u62c6\u7bb1<br \/>\n    System.out.println(&#034;n &#061; &#034; &#043; n);<br \/>\n    Integer obj1 &#061; 500;<br \/>\n    System.out.println(&#034;obj \u7b49\u4ef7\u4e8e obj1&#xff1f;&#034; &#043; obj.equals(obj1));<br \/>\n}<br \/>\n\/\/\u7ed3\u679c&#xff1a;<br \/>\n\/\/ n &#061; 500<br \/>\n\/\/ obj \u7b49\u4ef7\u4e8e obj1&#xff1f;true <\/p>\n<p>\u81ea\u52a8\u88c5\u7bb1\u4e0e\u62c6\u7bb1\u7684\u529f\u80fd\u4e8b\u5b9e\u4e0a\u662f\u7f16\u8bd1\u5668\u6765\u5e2e\u60a8\u7684\u5fd9&#xff0c;\u7f16\u8bd1\u5668\u5728\u7f16\u8bd1\u65f6\u671f\u4f9d\u60a8\u6240\u7f16\u5199\u7684\u8bed\u6cd5&#xff0c;\u51b3\u5b9a\u662f\u5426\u8fdb\u884c\u88c5\u7bb1\u6216\u62c6\u7bb1\u52a8\u4f5c\u3002\u4f8b\u5982&#xff1a;<\/p>\n<\/p>\n<p>Integer i &#061; 100;<br \/>\n\/\/\u76f8\u5f53\u4e8e\u7f16\u8bd1\u5668\u81ea\u52a8\u4e3a\u60a8\u4f5c\u4ee5\u4e0b\u7684\u8bed\u6cd5\u7f16\u8bd1&#xff1a;<br \/>\nInteger i &#061; new Integer(100); <\/p>\n<p>\u6240\u4ee5\u81ea\u52a8\u88c5\u7bb1\u4e0e\u62c6\u7bb1\u7684\u529f\u80fd\u662f\u6240\u8c13\u7684\u201c\u7f16\u8bd1\u5668\u871c\u7cd6\u201d(Compiler Sugar)&#xff0c;\u867d\u7136\u4f7f\u7528\u8fd9\u4e2a\u529f\u80fd\u5f88\u65b9\u4fbf&#xff0c;\u4f46\u5728\u7a0b\u5e8f\u8fd0\u884c\u9636\u6bb5\u4f60\u8981\u4e86\u89e3Java\u7684\u8bed\u4e49\u3002\u4f8b\u5982\u4e0b\u9762\u7684\u7a0b\u5e8f\u662f\u53ef\u4ee5\u901a\u8fc7\u7f16\u8bd1\u7684&#xff1a;<\/p>\n<\/p>\n<p>Integer i &#061; null;<br \/>\nint j &#061; i; <\/p>\n<p>\u8fd9\u6837\u7684\u8bed\u6cd5\u5728\u7f16\u8bd1\u65f6\u671f\u662f\u5408\u6cd5\u7684&#xff0c;\u4f46\u662f\u5728\u8fd0\u884c\u65f6\u671f\u4f1a\u6709\u9519\u8bef&#xff0c;\u56e0\u4e3a\u8fd9\u79cd\u5199\u6cd5\u76f8\u5f53\u4e8e&#xff1a;<\/p>\n<\/p>\n<p>Integer i &#061; null;<br \/>\nint j &#061; i.intValue(); <\/p>\n<p>null\u8868\u793ai \u6ca1\u6709\u53c2\u8003\u81f3\u4efb\u4f55\u7684\u5bf9\u8c61\u5b9e\u4f53&#xff0c;\u5b83\u53ef\u4ee5\u5408\u6cd5\u5730\u6307\u5b9a\u7ed9\u5bf9\u8c61\u53c2\u8003\u540d\u79f0\u3002\u7531\u4e8e\u5b9e\u9645\u4e0a i \u5e76\u6ca1\u6709\u53c2\u8003\u81f3\u4efb\u4f55\u7684\u5bf9\u8c61&#xff0c;\u6240\u4ee5\u4e5f\u5c31\u4e0d\u53ef\u80fd\u64cd\u4f5cintValue()\u65b9\u6cd5&#xff0c;\u8fd9\u6837\u4e0a\u9762\u7684\u5199\u6cd5\u5728\u8fd0\u884c\u65f6\u4f1a\u51fa\u73b0NullPointerException \u9519\u8bef\u3002<\/p>\n<p>\u81ea\u52a8\u62c6\u7bb1\u88c5\u7bb1\u662f\u5e38\u7528\u7684\u4e00\u4e2a\u529f\u80fd&#xff0c;\u9700\u8981\u91cd\u70b9\u638c\u63e1\u3002<\/p>\n<p>\u4e00\u822c\u5730&#xff0c;\u5f53\u9700\u8981\u4f7f\u7528\u6570\u5b57\u7684\u65f6\u5019&#xff0c;\u6211\u4eec\u901a\u5e38\u4f7f\u7528\u5185\u7f6e\u6570\u636e\u7c7b\u578b&#xff0c;\u5982&#xff1a;byte\u3001int\u3001long\u3001double \u7b49\u3002\u7136\u800c&#xff0c;\u5728\u5b9e\u9645\u5f00\u53d1\u8fc7\u7a0b\u4e2d&#xff0c;\u6211\u4eec\u7ecf\u5e38\u4f1a\u9047\u5230\u9700\u8981\u4f7f\u7528\u5bf9\u8c61&#xff0c;\u800c\u4e0d\u662f\u5185\u7f6e\u6570\u636e\u7c7b\u578b\u7684\u60c5\u5f62\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898&#xff0c;Java \u8bed\u8a00\u4e3a\u6bcf\u4e00\u4e2a\u5185\u7f6e\u6570\u636e\u7c7b\u578b\u63d0\u4f9b\u4e86\u5bf9\u5e94\u7684\u5305\u88c5\u7c7b\u3002<\/p>\n<p>\u6240\u6709\u7684\u5305\u88c5\u7c7b&#xff08;Integer\u3001Long\u3001Byte\u3001Double\u3001Float\u3001Short&#xff09;\u90fd\u662f\u62bd\u8c61\u7c7b Number \u7684\u5b50\u7c7b\u3002<\/p>\n<h3 id=\"math\u7c7b\">Math\u7c7b<\/h3>\n<p>Java \u7684 Math \u5305\u542b\u4e86\u7528\u4e8e\u6267\u884c\u57fa\u672c\u6570\u5b66\u8fd0\u7b97\u7684\u5c5e\u6027\u548c\u65b9\u6cd5&#xff0c;\u5982\u521d\u7b49\u6307\u6570\u3001\u5bf9\u6570\u3001\u5e73\u65b9\u6839\u548c\u4e09\u89d2\u51fd\u6570\u3002<\/p>\n<p>Math \u7684\u65b9\u6cd5\u90fd\u88ab\u5b9a\u4e49\u4e3a static \u5f62\u5f0f&#xff0c;\u901a\u8fc7 Math \u7c7b\u53ef\u4ee5\u5728\u4e3b\u51fd\u6570\u4e2d\u76f4\u63a5\u8c03\u7528<\/p>\n<p>\u3010\u6f14\u793a&#xff1a;\u67e5\u770bMath\u7c7b\u7684\u6e90\u7801\u3011<\/p>\n<\/p>\n<p>public final class Math{<br \/>\n\/\/\u6570\u5b66\u65b9\u6cd5<br \/>\n} <\/p>\n<p>\u3010\u5e38\u7528\u503c\u4e0e\u51fd\u6570\u3011<\/p>\n<p>Math.PI \u8bb0\u5f55\u7684\u5706\u5468\u7387 Math.E \u8bb0\u5f55e\u7684\u5e38\u91cf<\/p>\n<p>Math\u4e2d\u8fd8\u6709\u4e00\u4e9b\u7c7b\u4f3c\u7684\u5e38\u91cf&#xff0c;\u90fd\u662f\u4e00\u4e9b\u5de5\u7a0b\u6570\u5b66\u5e38\u7528\u91cf\u3002<\/p>\n<p>Math.abs \u6c42\u7edd\u5bf9\u503c Math.sin \u6b63\u5f26\u51fd\u6570 Math.asin \u53cd\u6b63\u5f26\u51fd\u6570 Math.cos \u4f59\u5f26\u51fd\u6570 Math.acos \u53cd\u4f59\u5f26\u51fd\u6570 Math.tan \u6b63\u5207\u51fd\u6570 Math.atan \u53cd\u6b63\u5207\u51fd\u6570 Math.atan2 \u5546\u7684\u53cd\u6b63\u5207\u51fd\u6570 Math.toDegrees \u5f27\u5ea6\u8f6c\u5316\u4e3a\u89d2\u5ea6 Math.toRadians \u89d2\u5ea6\u8f6c\u5316\u4e3a\u5f27\u5ea6 Math.ceil \u5f97\u5230\u4e0d\u5c0f\u4e8e\u67d0\u6570\u7684\u6700\u5927\u6574\u6570 Math.floor \u5f97\u5230\u4e0d\u5927\u4e8e\u67d0\u6570\u7684\u6700\u5927\u6574\u6570 Math.IEEEremainder \u6c42\u4f59 Math.max \u6c42\u4e24\u6570\u4e2d\u6700\u5927 Math.min \u6c42\u4e24\u6570\u4e2d\u6700\u5c0f Math.sqrt \u6c42\u5f00\u65b9 Math.pow \u6c42\u67d0\u6570\u7684\u4efb\u610f\u6b21\u65b9, \u629b\u51faArithmeticException\u5904\u7406\u6ea2\u51fa\u5f02\u5e38<\/p>\n<p>Math.exp \u6c42e\u7684\u4efb\u610f\u6b21\u65b9 Math.log10 \u4ee510\u4e3a\u5e95\u7684\u5bf9\u6570 Math.log \u81ea\u7136\u5bf9\u6570 Math.rint \u6c42\u8ddd\u79bb\u67d0\u6570\u6700\u8fd1\u7684\u6574\u6570&#xff08;\u53ef\u80fd\u6bd4\u67d0\u6570\u5927&#xff0c;\u4e5f\u53ef\u80fd\u6bd4\u5b83\u5c0f&#xff09; Math.round \u540c\u4e0a&#xff0c;\u8fd4\u56deint\u578b\u6216\u8005long\u578b&#xff08;\u4e0a\u4e00\u4e2a\u51fd\u6570\u8fd4\u56dedouble\u578b&#xff09; Math.random \u8fd4\u56de0&#xff0c;1\u4e4b\u95f4\u7684\u4e00\u4e2a\u968f\u673a\u6570<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    \/**<br \/>\n     *Math.sqrt()\/\/\u8ba1\u7b97\u5e73\u65b9\u6839<br \/>\n     *Math.cbrt()\/\/\u8ba1\u7b97\u7acb\u65b9\u6839<br \/>\n     *Math.pow(a, b)\/\/\u8ba1\u7b97a\u7684b\u6b21\u65b9<br \/>\n     *Math.max( , );\/\/\u8ba1\u7b97\u6700\u5927\u503c<br \/>\n     *Math.min( , );\/\/\u8ba1\u7b97\u6700\u5c0f\u503c<br \/>\n     *\/<br \/>\n    System.out.println(Math.sqrt(16)); \/\/4.0<br \/>\n    System.out.println(Math.cbrt(8)); \/\/2.0<br \/>\n    System.out.println(Math.pow(3, 2)); \/\/9.0<br \/>\n    System.out.println(Math.max(2.3, 4.5));\/\/4.5<br \/>\n    System.out.println(Math.min(2.3, 4.5));\/\/2.3<br \/>\n    \/**<br \/>\n     * abs\u6c42\u7edd\u5bf9\u503c<br \/>\n     *\/<br \/>\n    System.out.println(Math.abs(-10.4)); \/\/10.4<br \/>\n    System.out.println(Math.abs(10.1)); \/\/10.1<br \/>\n    \/**<br \/>\n     * ceil\u5929\u82b1\u677f\u7684\u610f\u601d&#xff0c;\u5c31\u662f\u8fd4\u56de\u5927\u7684\u503c<br \/>\n     *\/<br \/>\n    System.out.println(Math.ceil(-10.1)); \/\/-10.0<br \/>\n    System.out.println(Math.ceil(10.7)); \/\/11.0<br \/>\n    System.out.println(Math.ceil(-0.7)); \/\/-0.0<br \/>\n    System.out.println(Math.ceil(0.0)); \/\/0.0<br \/>\n    System.out.println(Math.ceil(-0.0)); \/\/-0.0<br \/>\n    System.out.println(Math.ceil(-1.7)); \/\/-1.0<br \/>\n    \/**<br \/>\n     * floor\u5730\u677f\u7684\u610f\u601d&#xff0c;\u5c31\u662f\u8fd4\u56de\u5c0f\u7684\u503c<br \/>\n     *\/<br \/>\n    System.out.println(Math.floor(-10.1)); \/\/-11.0<br \/>\n    System.out.println(Math.floor(10.7)); \/\/10.0<br \/>\n    System.out.println(Math.floor(-0.7)); \/\/-1.0<br \/>\n    System.out.println(Math.floor(0.0)); \/\/0.0<br \/>\n    System.out.println(Math.floor(-0.0)); \/\/-0.0<br \/>\n    \/**<br \/>\n     * random \u53d6\u5f97\u4e00\u4e2a\u5927\u4e8e\u6216\u8005\u7b49\u4e8e0.0\u5c0f\u4e8e\u4e0d\u7b49\u4e8e1.0\u7684\u968f\u673a\u6570 [0,1)<br \/>\n     *\/<br \/>\n    System.out.println(Math.random()); \/\/\u5c0f\u4e8e1\u5927\u4e8e0\u7684double\u7c7b\u578b\u7684\u6570<br \/>\n    System.out.println(Math.random() &#043; 1);\/\/\u5927\u4e8e1\u5c0f\u4e8e2\u7684double\u7c7b\u578b\u7684\u6570<br \/>\n    \/**<br \/>\n     * rint \u56db\u820d\u4e94\u5165&#xff0c;\u8fd4\u56dedouble\u503c<br \/>\n     * \u6ce8\u610f.5\u7684\u65f6\u5019\u4f1a\u53d6\u5076\u6570 \u5f02\u5e38\u7684\u5c34\u5c2c&#061;\u3002&#061;<br \/>\n     *\/<br \/>\n    System.out.println(Math.rint(10.1)); \/\/10.0<br \/>\n    System.out.println(Math.rint(10.7)); \/\/11.0<br \/>\n    System.out.println(Math.rint(11.5)); \/\/12.0<br \/>\n    System.out.println(Math.rint(10.5)); \/\/10.0<br \/>\n    System.out.println(Math.rint(10.51)); \/\/11.0<br \/>\n    System.out.println(Math.rint(-10.5)); \/\/-10.0<br \/>\n    System.out.println(Math.rint(-11.5)); \/\/-12.0<br \/>\n    System.out.println(Math.rint(-10.51)); \/\/-11.0<br \/>\n    System.out.println(Math.rint(-10.6)); \/\/-11.0<br \/>\n    System.out.println(Math.rint(-10.2)); \/\/-10.0<br \/>\n    \/**<br \/>\n     * round \u56db\u820d\u4e94\u5165&#xff0c;float\u65f6\u8fd4\u56deint\u503c&#xff0c;double\u65f6\u8fd4\u56delong\u503c<br \/>\n     *\/<br \/>\n    System.out.println(Math.round(10.1)); \/\/10<br \/>\n    System.out.println(Math.round(10.7)); \/\/11<br \/>\n    System.out.println(Math.round(10.5)); \/\/11<br \/>\n    System.out.println(Math.round(10.51)); \/\/11<br \/>\n    System.out.println(Math.round(-10.5)); \/\/-10<br \/>\n    System.out.println(Math.round(-10.51)); \/\/-11<br \/>\n    System.out.println(Math.round(-10.6)); \/\/-11<br \/>\n    System.out.println(Math.round(-10.2)); \/\/-10<br \/>\n} <\/p>\n<h3 id=\"random\u7c7b\">Random\u7c7b<\/h3>\n<p>Java\u4e2d\u5b58\u5728\u7740\u4e24\u79cdRandom\u51fd\u6570&#xff1a;<\/p>\n<p>1\u3001java.lang.Math.Random;<\/p>\n<p>\u8c03\u7528\u8fd9\u4e2aMath.Random()\u51fd\u6570\u80fd\u591f\u8fd4\u56de\u5e26\u6b63\u53f7\u7684double\u503c&#xff0c;\u8be5\u503c\u5927\u4e8e\u7b49\u4e8e0.0\u4e14\u5c0f\u4e8e1.0&#xff0c;\u5373\u53d6\u503c\u8303\u56f4\u662f [0.0,1.0)\u7684\u5de6\u95ed\u53f3\u5f00\u533a\u95f4&#xff0c;\u8fd4\u56de\u503c\u662f\u4e00\u4e2a\u4f2a\u968f\u673a\u9009\u62e9\u7684\u6570&#xff0c;\u5728\u8be5\u8303\u56f4\u5185&#xff08;\u8fd1\u4f3c&#xff09;\u5747\u5300\u5206\u5e03\u3002\u4f8b\u5b50\u5982\u4e0b&#xff1a;<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    \/\/ \u7ed3\u679c\u662f\u4e2adouble\u7c7b\u578b\u7684\u503c&#xff0c;\u533a\u95f4\u4e3a[0.0,1.0&#xff09;<br \/>\n    System.out.println(&#034;Math.random()&#061;&#034; &#043; Math.random());<br \/>\n    int num &#061; (int) (Math.random() * 3);<br \/>\n    \/\/ \u6ce8\u610f\u4e0d\u8981\u5199\u6210(int)Math.random()*3&#xff0c;\u8fd9\u4e2a\u7ed3\u679c\u4e3a0\u62161&#xff0c;\u56e0\u4e3a\u5148\u6267\u884c\u4e86\u5f3a\u5236\u8f6c\u6362<br \/>\n    System.out.println(&#034;num&#061;&#034; &#043; num);<br \/>\n} <\/p>\n<p>2\u3001java.util.Random<\/p>\n<p>\u4e0b\u9762\u662fRandom()\u7684\u4e24\u79cd\u6784\u9020\u65b9\u6cd5&#xff1a;<\/p>\n<p>Random()&#xff1a;\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u968f\u673a\u6570\u751f\u6210\u5668 Random(long seed)&#xff1a;\u4f7f\u7528\u5355\u4e2a long \u79cd\u5b50\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u968f\u673a\u6570\u751f\u6210\u5668\u3002<\/p>\n<p>\u4f60\u5728\u521b\u5efa\u4e00\u4e2aRandom\u5bf9\u8c61\u7684\u65f6\u5019\u53ef\u4ee5\u7ed9\u5b9a\u4efb\u610f\u4e00\u4e2a\u5408\u6cd5\u7684\u79cd\u5b50\u6570&#xff0c;\u79cd\u5b50\u6570\u53ea\u662f\u968f\u673a\u7b97\u6cd5\u7684\u8d77\u6e90\u6570\u5b57&#xff0c;\u548c\u751f\u6210\u7684\u968f\u673a\u6570\u7684\u533a\u95f4\u6ca1\u6709\u4efb\u4f55\u5173\u7cfb\u3002<\/p>\n<p>\u5982\u4e0b\u9762\u7684Java\u4ee3\u7801&#xff1a;<\/p>\n<p>\u3010\u6f14\u793a\u4e00\u3011<\/p>\n<p>\u5728\u6ca1\u5e26\u53c2\u6570\u6784\u9020\u51fd\u6570\u751f\u6210\u7684Random\u5bf9\u8c61\u7684\u79cd\u5b50\u662f\u5f53\u524d\u7cfb\u7edf\u65f6\u95f4\u7684\u6beb\u79d2\u6570\u3002<\/p>\n<p>rand.nextInt(100)\u4e2d\u7684100\u662f\u968f\u673a\u6570\u7684\u4e0a\u9650,\u4ea7\u751f\u7684\u968f\u673a\u6570\u4e3a0-100\u7684\u6574\u6570&#xff0c;\u4e0d\u5305\u62ec100\u3002<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    Random rand &#061; new Random();<br \/>\n    int i &#061; rand.nextInt(100);<br \/>\n    System.out.println(i);<br \/>\n} <\/p>\n<p>\u3010\u6f14\u793a\u4e8c\u3011<\/p>\n<p>\u5bf9\u4e8e\u79cd\u5b50\u76f8\u540c\u7684Random\u5bf9\u8c61&#xff0c;\u591a\u6b21\u6267\u884c\u540e\u751f\u6210\u7684\u968f\u673a\u6570\u5e8f\u5217\u662f\u4e00\u6837\u7684\u3002<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    Random ran1 &#061; new Random(25);<br \/>\n    System.out.println(&#034;\u4f7f\u7528\u79cd\u5b50\u4e3a25\u7684Random\u5bf9\u8c61\u751f\u6210[0,100)\u5185\u968f\u673a\u6574\u6570\u5e8f\u5217: &#034;);<br \/>\n    for (int i &#061; 0; i &lt; 10; i&#043;&#043;) {<br \/>\n        System.out.print(ran1.nextInt(100) &#043; &#034; &#034;);<br \/>\n    }<br \/>\n    System.out.println();<br \/>\n} <\/p>\n<p>\u3010\u65b9\u6cd5\u6458\u8981\u3011<\/p>\n<li>protected int next(int bits)&#xff1a;\u751f\u6210\u4e0b\u4e00\u4e2a\u4f2a\u968f\u673a\u6570\u3002<\/li>\n<li>boolean nextBoolean()&#xff1a;\u8fd4\u56de\u4e0b\u4e00\u4e2a\u4f2a\u968f\u673a\u6570&#xff0c;\u5b83\u662f\u53d6\u81ea\u6b64\u968f\u673a\u6570\u751f\u6210\u5668\u5e8f\u5217\u7684\u5747\u5300\u5206\u5e03\u7684 boolean\u503c\u3002<\/li>\n<li>void nextBytes(byte[] bytes)&#xff1a;\u751f\u6210\u968f\u673a\u5b57\u8282\u5e76\u5c06\u5176\u7f6e\u4e8e\u7528\u6237\u63d0\u4f9b\u7684 byte \u6570\u7ec4\u4e2d\u3002<\/li>\n<li>double nextDouble()&#xff1a;\u8fd4\u56de\u4e0b\u4e00\u4e2a\u4f2a\u968f\u673a\u6570&#xff0c;\u5b83\u662f\u53d6\u81ea\u6b64\u968f\u673a\u6570\u751f\u6210\u5668\u5e8f\u5217\u7684\u3001\u57280.0\u548c1.0\u4e4b\u95f4 \u5747\u5300\u5206\u5e03\u7684 double\u503c\u3002<\/li>\n<li>float nextFloat()&#xff1a;\u8fd4\u56de\u4e0b\u4e00\u4e2a\u4f2a\u968f\u673a\u6570&#xff0c;\u5b83\u662f\u53d6\u81ea\u6b64\u968f\u673a\u6570\u751f\u6210\u5668\u5e8f\u5217\u7684\u3001\u57280.0\u548c1.0\u4e4b\u95f4\u5747\u5300\u5206\u5e03float\u503c\u3002<\/li>\n<li>double nextGaussian()&#xff1a;\u8fd4\u56de\u4e0b\u4e00\u4e2a\u4f2a\u968f\u673a\u6570&#xff0c;\u5b83\u662f\u53d6\u81ea\u6b64\u968f\u673a\u6570\u751f\u6210\u5668\u5e8f\u5217\u7684\u3001\u5448\u9ad8\u65af&#xff08;\u201c\u6b63\u6001\u201d&#xff09;\u5206\u5e03\u7684double\u503c&#xff0c;\u5176\u5e73\u5747\u503c\u662f0.0\u6807\u51c6\u5dee\u662f1.0\u3002<\/li>\n<li>int nextInt()&#xff1a;\u8fd4\u56de\u4e0b\u4e00\u4e2a\u4f2a\u968f\u673a\u6570&#xff0c;\u5b83\u662f\u6b64\u968f\u673a\u6570\u751f\u6210\u5668\u7684\u5e8f\u5217\u4e2d\u5747\u5300\u5206\u5e03\u7684 int \u503c\u3002<\/li>\n<li>int nextInt(int n)&#xff1a;\u8fd4\u56de\u4e00\u4e2a\u4f2a\u968f\u673a\u6570&#xff0c;\u5b83\u662f\u53d6\u81ea\u6b64\u968f\u673a\u6570\u751f\u6210\u5668\u5e8f\u5217\u7684\u3001\u5728&#xff08;\u5305\u62ec\u548c\u6307\u5b9a\u503c&#xff08;\u4e0d\u5305\u62ec&#xff09;\u4e4b\u95f4\u5747\u5300\u5206\u5e03\u7684int\u503c\u3002<\/li>\n<li>long nextLong()&#xff1a;\u8fd4\u56de\u4e0b\u4e00\u4e2a\u4f2a\u968f\u673a\u6570&#xff0c;\u5b83\u662f\u53d6\u81ea\u6b64\u968f\u673a\u6570\u751f\u6210\u5668\u5e8f\u5217\u7684\u5747\u5300\u5206\u5e03\u7684 long \u503c\u3002<\/li>\n<li>void setSeed(long seed)&#xff1a;\u4f7f\u7528\u5355\u4e2a long \u79cd\u5b50\u8bbe\u7f6e\u6b64\u968f\u673a\u6570\u751f\u6210\u5668\u7684\u79cd\u5b50\u3002<\/li>\n<p>\u3010\u4f8b\u5b50\u3011<\/p>\n<li>\u751f\u6210[0,1.0)\u533a\u95f4\u7684\u5c0f\u6570&#xff1a;double d1 &#061; r.nextDouble();<\/li>\n<li>\u751f\u6210[0,5.0)\u533a\u95f4\u7684\u5c0f\u6570&#xff1a;double d2 &#061; r.nextDouble() * 5;<\/li>\n<li>\u751f\u6210[1,2.5)\u533a\u95f4\u7684\u5c0f\u6570&#xff1a;double d3 &#061; r.nextDouble() * 1.5 &#043; 1;<\/li>\n<li>\u751f\u6210[0,10)\u533a\u95f4\u7684\u6574\u6570&#xff1a;int n2 &#061; r.nextInt(10);<\/li>\n<h3 id=\"\u65e5\u671f\u65f6\u95f4\u7c7b\">\u65e5\u671f\u65f6\u95f4\u7c7b<\/h3>\n<h4 id=\"_1date\u7c7b\">1 Date\u7c7b<\/h4>\n<p>java.util \u5305\u63d0\u4f9b\u4e86 Date \u7c7b\u6765\u5c01\u88c5\u5f53\u524d\u7684\u65e5\u671f\u548c\u65f6\u95f4\u3002<\/p>\n<p>Date \u7c7b\u63d0\u4f9b\u4e24\u4e2a\u6784\u9020\u51fd\u6570\u6765\u5b9e\u4f8b\u5316 Date \u5bf9\u8c61\u3002<\/p>\n<p>\u7b2c\u4e00\u4e2a\u6784\u9020\u51fd\u6570\u4f7f\u7528\u5f53\u524d\u65e5\u671f\u548c\u65f6\u95f4\u6765\u521d\u59cb\u5316\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p>Date() <\/p>\n<p>\u7b2c\u4e8c\u4e2a\u6784\u9020\u51fd\u6570\u63a5\u6536\u4e00\u4e2a\u53c2\u6570&#xff0c;\u8be5\u53c2\u6570\u662f\u4ece1970\u5e741\u67081\u65e5\u8d77\u7684\u6beb\u79d2\u6570\u3002<\/p>\n<\/p>\n<p>Date(long millisec) <\/p>\n<p>Date\u5bf9\u8c61\u521b\u5efa\u4ee5\u540e&#xff0c;\u53ef\u4ee5\u8c03\u7528\u4e0b\u9762\u7684\u65b9\u6cd5\u3002<\/p>\n<table>\n<tr>\u5e8f\u53f7\u65b9\u6cd5\u548c\u63cf\u8ff0<\/tr>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>boolean after(Date date)\u00a0\u82e5\u5f53\u8c03\u7528\u6b64\u65b9\u6cd5\u7684Date\u5bf9\u8c61\u5728\u6307\u5b9a\u65e5\u671f\u4e4b\u540e\u8fd4\u56detrue,\u5426\u5219\u8fd4\u56defalse\u3002<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>boolean before(Date date)\u00a0\u82e5\u5f53\u8c03\u7528\u6b64\u65b9\u6cd5\u7684Date\u5bf9\u8c61\u5728\u6307\u5b9a\u65e5\u671f\u4e4b\u524d\u8fd4\u56detrue,\u5426\u5219\u8fd4\u56defalse\u3002<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Object clone( )\u00a0\u8fd4\u56de\u6b64\u5bf9\u8c61\u7684\u526f\u672c\u3002<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>int compareTo(Date date)\u00a0\u6bd4\u8f83\u5f53\u8c03\u7528\u6b64\u65b9\u6cd5\u7684Date\u5bf9\u8c61\u548c\u6307\u5b9a\u65e5\u671f\u3002\u4e24\u8005\u76f8\u7b49\u65f6\u5019\u8fd4\u56de0\u3002\u8c03\u7528\u5bf9\u8c61\u5728\u6307\u5b9a\u65e5\u671f\u4e4b\u524d\u5219\u8fd4\u56de\u8d1f\u6570\u3002\u8c03\u7528\u5bf9\u8c61\u5728\u6307\u5b9a\u65e5\u671f\u4e4b\u540e\u5219\u8fd4\u56de\u6b63\u6570\u3002<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>int compareTo(Object obj)\u00a0\u82e5obj\u662fDate\u7c7b\u578b\u5219\u64cd\u4f5c\u7b49\u540c\u4e8ecompareTo(Date) \u3002\u5426\u5219\u5b83\u629b\u51faClassCastException\u3002<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>boolean equals(Object date)\u00a0\u5f53\u8c03\u7528\u6b64\u65b9\u6cd5\u7684Date\u5bf9\u8c61\u548c\u6307\u5b9a\u65e5\u671f\u76f8\u7b49\u65f6\u5019\u8fd4\u56detrue,\u5426\u5219\u8fd4\u56defalse\u3002<\/td>\n<\/tr>\n<tr>\n<td>7<\/td>\n<td>long getTime( )\u00a0\u8fd4\u56de\u81ea 1970 \u5e74 1 \u6708 1 \u65e5 00:00:00 GMT \u4ee5\u6765\u6b64 Date \u5bf9\u8c61\u8868\u793a\u7684\u6beb\u79d2\u6570\u3002<\/td>\n<\/tr>\n<tr>\n<td>8<\/td>\n<td>int hashCode( )\u00a0\u8fd4\u56de\u6b64\u5bf9\u8c61\u7684\u54c8\u5e0c\u7801\u503c\u3002<\/td>\n<\/tr>\n<tr>\n<td>9<\/td>\n<td>void setTime(long time)\u00a0\u7528\u81ea1970\u5e741\u67081\u65e500:00:00 GMT\u4ee5\u540etime\u6beb\u79d2\u6570\u8bbe\u7f6e\u65f6\u95f4\u548c\u65e5\u671f\u3002<\/td>\n<\/tr>\n<tr>\n<td>10<\/td>\n<td>String toString( )\u00a0\u628a\u6b64 Date \u5bf9\u8c61\u8f6c\u6362\u4e3a\u4ee5\u4e0b\u5f62\u5f0f\u7684 String&#xff1a; dow mon dd hh:mm:ss zzz yyyy \u5176\u4e2d&#xff1a; dow \u662f\u4e00\u5468\u4e2d\u7684\u67d0\u4e00\u5929 (Sun, Mon, Tue, Wed, Thu, Fri, Sat)\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u3010\u6f14\u793a&#xff1a;\u83b7\u53d6\u5f53\u524d\u65e5\u671f\u65f6\u95f4\u3011<\/p>\n<p>Java\u4e2d\u83b7\u53d6\u5f53\u524d\u65e5\u671f\u548c\u65f6\u95f4\u5f88\u7b80\u5355&#xff0c;\u4f7f\u7528 Date \u5bf9\u8c61\u7684 toString() \u65b9\u6cd5\u6765\u6253\u5370\u5f53\u524d\u65e5\u671f\u548c\u65f6\u95f4<\/p>\n<\/p>\n<p>public static void main(String args[]) {<br \/>\n    \/\/ \u521d\u59cb\u5316 Date \u5bf9\u8c61<br \/>\n    Date date &#061; new Date();<\/p>\n<p>    \/\/ \u4f7f\u7528 toString() \u51fd\u6570\u663e\u793a\u65e5\u671f\u65f6\u95f4<br \/>\n    System.out.println(date.toString());<br \/>\n    \/\/Tue Mar 30 10:24:19 CST 2021<br \/>\n} <\/p>\n<p>\u3010\u6f14\u793a&#xff1a;\u65e5\u671f\u6bd4\u8f83\u3011<\/p>\n<p>\u4f7f\u7528 getTime() \u65b9\u6cd5\u83b7\u53d6\u4e24\u4e2a\u65e5\u671f&#xff08;\u81ea1970\u5e741\u67081\u65e5\u7ecf\u5386\u7684\u6beb\u79d2\u6570\u503c&#xff09;&#xff0c;\u7136\u540e\u6bd4\u8f83\u8fd9\u4e24\u4e2a\u503c\u3002<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    \/\/ \u521d\u59cb\u5316 Date \u5bf9\u8c61<br \/>\n    Date date &#061; new Date();<\/p>\n<p>    long time &#061; date.getTime();<br \/>\n    long time2 &#061; date.getTime();<br \/>\n    System.out.println(time&#061;&#061;time2);\/\/true<br \/>\n} <\/p>\n<p>\u4f7f\u7528\u65b9\u6cd5 before()&#xff0c;after() \u548c equals()\u3002\u4f8b\u5982&#xff0c;\u4e00\u4e2a\u6708\u768412\u53f7\u6bd418\u53f7\u65e9&#xff0c;\u5219 new Date(99, 2, 12).before(new Date (99, 2, 18)) \u8fd4\u56detrue\u3002<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    boolean before &#061; new Date(99, 01, 05).before(new Date(99, 11, 16));<br \/>\n    System.out.println(before);<br \/>\n} <\/p>\n<h4 id=\"_2\u3001simpledateformat\">2\u3001SimpleDateFormat<\/h4>\n<p>\u683c\u5f0f\u5316\u65e5\u671f<\/p>\n<p>SimpleDateFormat \u662f\u4e00\u4e2a\u4ee5\u8bed\u8a00\u73af\u5883\u654f\u611f\u7684\u65b9\u5f0f\u6765\u683c\u5f0f\u5316\u548c\u5206\u6790\u65e5\u671f\u7684\u7c7b\u3002SimpleDateFormat \u5141\u8bb8\u4f60\u9009\u62e9\u4efb\u4f55\u7528\u6237\u81ea\u5b9a\u4e49\u65e5\u671f\u65f6\u95f4\u683c\u5f0f\u6765\u8fd0\u884c\u3002\u4f8b\u5982&#xff1a;<\/p>\n<\/p>\n<p>public static void main(String args[]) {<br \/>\n    Date dNow &#061; new Date( );<br \/>\n    SimpleDateFormat ft &#061; new SimpleDateFormat (&#034;yyyy-MM-dd hh:mm:ss&#034;);<br \/>\n    System.out.println(&#034;\u5f53\u524d\u65f6\u95f4\u4e3a: &#034; &#043; ft.format(dNow));<br \/>\n} <\/p>\n<p>\u5176\u4e2d yyyy \u662f\u5b8c\u6574\u7684\u516c\u5143\u5e74&#xff0c;MM \u662f\u6708\u4efd&#xff0c;dd \u662f\u65e5\u671f&#xff0c;HH:mm:ss \u662f\u65f6\u3001\u5206\u3001\u79d2\u3002<\/p>\n<p>\u6ce8\u610f&#xff1a;\u6709\u7684\u683c\u5f0f\u5927\u5199&#xff0c;\u6709\u7684\u683c\u5f0f\u5c0f\u5199&#xff0c;\u4f8b\u5982 MM \u662f\u6708\u4efd&#xff0c;mm \u662f\u5206&#xff1b;HH \u662f 24 \u5c0f\u65f6\u5236&#xff0c;\u800c hh \u662f 12 \u5c0f\u65f6\u5236\u3002<\/p>\n<p>\u65f6\u95f4\u6a21\u5f0f\u5b57\u7b26\u4e32\u7528\u6765\u6307\u5b9a\u65f6\u95f4\u683c\u5f0f\u3002\u5728\u6b64\u6a21\u5f0f\u4e2d&#xff0c;\u6240\u6709\u7684 ASCII \u5b57\u6bcd\u88ab\u4fdd\u7559\u4e3a\u6a21\u5f0f\u5b57\u6bcd&#xff0c;\u5b9a\u4e49\u5982\u4e0b&#xff1a;<\/p>\n<table>\n<tr>\u5b57\u6bcd\u63cf\u8ff0\u793a\u4f8b<\/tr>\n<tbody>\n<tr>\n<td>G<\/td>\n<td>\u7eaa\u5143\u6807\u8bb0<\/td>\n<td>AD<\/td>\n<\/tr>\n<tr>\n<td>y<\/td>\n<td>\u56db\u4f4d\u5e74\u4efd<\/td>\n<td>2001<\/td>\n<\/tr>\n<tr>\n<td>M<\/td>\n<td>\u6708\u4efd<\/td>\n<td>July or 07<\/td>\n<\/tr>\n<tr>\n<td>d<\/td>\n<td>\u4e00\u4e2a\u6708\u7684\u65e5\u671f<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>h<\/td>\n<td>A.M.\/P.M. (1~12)\u683c\u5f0f\u5c0f\u65f6<\/td>\n<td>12<\/td>\n<\/tr>\n<tr>\n<td>H<\/td>\n<td>\u4e00\u5929\u4e2d\u7684\u5c0f\u65f6 (0~23)<\/td>\n<td>22<\/td>\n<\/tr>\n<tr>\n<td>m<\/td>\n<td>\u5206\u949f\u6570<\/td>\n<td>30<\/td>\n<\/tr>\n<tr>\n<td>s<\/td>\n<td>\u79d2\u6570<\/td>\n<td>55<\/td>\n<\/tr>\n<tr>\n<td>S<\/td>\n<td>\u6beb\u79d2\u6570<\/td>\n<td>234<\/td>\n<\/tr>\n<tr>\n<td>E<\/td>\n<td>\u661f\u671f\u51e0<\/td>\n<td>Tuesday<\/td>\n<\/tr>\n<tr>\n<td>D<\/td>\n<td>\u4e00\u5e74\u4e2d\u7684\u65e5\u5b50<\/td>\n<td>360<\/td>\n<\/tr>\n<tr>\n<td>F<\/td>\n<td>\u4e00\u4e2a\u6708\u4e2d\u7b2c\u51e0\u5468\u7684\u5468\u51e0<\/td>\n<td>2 (second Wed. in July)<\/td>\n<\/tr>\n<tr>\n<td>w<\/td>\n<td>\u4e00\u5e74\u4e2d\u7b2c\u51e0\u5468<\/td>\n<td>40<\/td>\n<\/tr>\n<tr>\n<td>W<\/td>\n<td>\u4e00\u4e2a\u6708\u4e2d\u7b2c\u51e0\u5468<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>a<\/td>\n<td>A.M.\/P.M. \u6807\u8bb0<\/td>\n<td>PM<\/td>\n<\/tr>\n<tr>\n<td>k<\/td>\n<td>\u4e00\u5929\u4e2d\u7684\u5c0f\u65f6(1~24)<\/td>\n<td>24<\/td>\n<\/tr>\n<tr>\n<td>K<\/td>\n<td>A.M.\/P.M. (0~11)\u683c\u5f0f\u5c0f\u65f6<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>z<\/td>\n<td>\u65f6\u533a<\/td>\n<td>Eastern Standard Time<\/td>\n<\/tr>\n<tr>\n<td>&#039;<\/td>\n<td>\u6587\u5b57\u5b9a\u754c\u7b26<\/td>\n<td>Delimiter<\/td>\n<\/tr>\n<tr>\n<td>&#034;<\/td>\n<td>\u5355\u5f15\u53f7<\/td>\n<td>&#096;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u3010\u6f14\u793a&#xff1a;\u4f7f\u7528printf\u683c\u5f0f\u5316\u65e5\u671f\u3011<\/p>\n<p>Java \u683c\u5f0f\u5316\u8f93\u51fa printf \u4f8b\u5b50&#xff1a;https:\/\/www.runoob.com\/w3cnote\/java-printf-formate-demo.html<\/p>\n<p>printf \u65b9\u6cd5\u53ef\u4ee5\u5f88\u8f7b\u677e\u5730\u683c\u5f0f\u5316\u65f6\u95f4\u548c\u65e5\u671f\u3002\u4f7f\u7528\u4e24\u4e2a\u5b57\u6bcd\u683c\u5f0f&#xff0c;\u5b83\u4ee5 %t \u5f00\u5934\u5e76\u4e14\u4ee5\u4e0b\u9762\u8868\u683c\u4e2d\u7684\u4e00\u4e2a\u5b57\u6bcd\u7ed3\u5c3e\u3002<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    \/\/ \u521d\u59cb\u5316 Date \u5bf9\u8c61<br \/>\n    Date date &#061; new Date();<br \/>\n    \/\/c\u7684\u4f7f\u7528<br \/>\n    System.out.printf(&#034;\u5168\u90e8\u65e5\u671f\u548c\u65f6\u95f4\u4fe1\u606f&#xff1a;%tc%n&#034;,date);<br \/>\n    \/\/f\u7684\u4f7f\u7528<br \/>\n    System.out.printf(&#034;\u5e74-\u6708-\u65e5\u683c\u5f0f&#xff1a;%tF%n&#034;,date);<br \/>\n    \/\/d\u7684\u4f7f\u7528<br \/>\n    System.out.printf(&#034;\u6708\/\u65e5\/\u5e74\u683c\u5f0f&#xff1a;%tD%n&#034;,date);<br \/>\n    \/\/r\u7684\u4f7f\u7528<br \/>\n    System.out.printf(&#034;HH:MM:SS PM\u683c\u5f0f&#xff08;12\u65f6\u5236&#xff09;&#xff1a;%tr%n&#034;,date);<br \/>\n    \/\/t\u7684\u4f7f\u7528<br \/>\n    System.out.printf(&#034;HH:MM:SS\u683c\u5f0f&#xff08;24\u65f6\u5236&#xff09;&#xff1a;%tT%n&#034;,date);<br \/>\n    \/\/R\u7684\u4f7f\u7528<br \/>\n    System.out.printf(&#034;HH:MM\u683c\u5f0f&#xff08;24\u65f6\u5236&#xff09;&#xff1a;%tR&#034;,date);<br \/>\n} <\/p>\n<p>\u7ed3\u679c&#xff1a;<\/p>\n<p>\u5168\u90e8\u65e5\u671f\u548c\u65f6\u95f4\u4fe1\u606f&#xff1a;\u5468\u4e8c 3\u6708 30 10:37:02 CST 2021 \u5e74-\u6708-\u65e5\u683c\u5f0f&#xff1a;2021-03-30 \u6708\/\u65e5\/\u5e74\u683c\u5f0f&#xff1a;03\/30\/21 HH:MM:SS PM\u683c\u5f0f&#xff08;12\u65f6\u5236&#xff09;&#xff1a;10:37:02 \u4e0a\u5348 HH:MM:SS\u683c\u5f0f&#xff08;24\u65f6\u5236&#xff09;&#xff1a;10:37:02 HH:MM\u683c\u5f0f&#xff08;24\u65f6\u5236&#xff09;&#xff1a;10:37<\/p>\n<p>\u3010\u65f6\u95f4\u4f11\u7720&#xff1a;\u4f11\u7720(sleep)\u3011<\/p>\n<p>sleep()\u4f7f\u5f53\u524d\u7ebf\u7a0b\u8fdb\u5165\u505c\u6ede\u72b6\u6001&#xff08;\u963b\u585e\u5f53\u524d\u7ebf\u7a0b&#xff09;&#xff0c;\u8ba9\u51faCPU\u7684\u4f7f\u7528\u3001\u76ee\u7684\u662f\u4e0d\u8ba9\u5f53\u524d\u7ebf\u7a0b\u72ec\u81ea\u9738\u5360\u8be5\u8fdb\u7a0b\u6240\u83b7\u7684CPU\u8d44\u6e90&#xff0c;\u4ee5\u7559\u4e00\u5b9a\u65f6\u95f4\u7ed9\u5176\u4ed6\u7ebf\u7a0b\u6267\u884c\u7684\u673a\u4f1a\u3002<\/p>\n<p>\u4f60\u53ef\u4ee5\u8ba9\u7a0b\u5e8f\u4f11\u7720\u4e00\u6beb\u79d2\u7684\u65f6\u95f4\u6216\u8005\u5230\u60a8\u7684\u8ba1\u7b97\u673a\u7684\u5bff\u547d\u957f\u7684\u4efb\u610f\u6bb5\u65f6\u95f4\u3002\u4f8b\u5982&#xff0c;\u4e0b\u9762\u7684\u7a0b\u5e8f\u4f1a\u4f11\u77203\u79d2&#xff1a;<\/p>\n<\/p>\n<p>public static void main(String args[]) {<br \/>\n    try {<br \/>\n        System.out.println(new Date( ) &#043; &#034;\\\\n&#034;);<br \/>\n        Thread.sleep(1000*3); \/\/ \u4f11\u77203\u79d2<br \/>\n        System.out.println(new Date( ) &#043; &#034;\\\\n&#034;);<br \/>\n    } catch (Exception e) {<br \/>\n        System.out.println(&#034;Got an exception!&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<h4 id=\"_3\u3001calendar\u7c7b\">3\u3001Calendar\u7c7b<\/h4>\n<p>\u6211\u4eec\u73b0\u5728\u5df2\u7ecf\u80fd\u591f\u683c\u5f0f\u5316\u5e76\u521b\u5efa\u4e00\u4e2a\u65e5\u671f\u5bf9\u8c61\u4e86&#xff0c;\u4f46\u662f\u6211\u4eec\u5982\u4f55\u624d\u80fd\u8bbe\u7f6e\u548c\u83b7\u53d6\u65e5\u671f\u6570\u636e\u7684\u7279\u5b9a\u90e8\u5206\u5462&#xff0c;\u6bd4\u5982\u8bf4\u5c0f\u65f6&#xff0c;\u65e5&#xff0c;\u6216\u8005\u5206\u949f? \u6211\u4eec\u53c8\u5982\u4f55\u5728\u65e5\u671f\u7684\u8fd9\u4e9b\u90e8\u5206\u52a0\u4e0a\u6216\u8005\u51cf\u53bb\u503c\u5462? \u7b54\u6848\u662f\u4f7f\u7528Calendar\u7c7b\u3002Date\u4e2d\u6709\u5f88\u591a\u65b9\u6cd5\u90fd\u5df2\u7ecf\u5e9f\u5f03\u4e86&#xff01;<\/p>\n<p>Calendar\u7c7b\u7684\u529f\u80fd\u8981\u6bd4Date\u7c7b\u5f3a\u5927\u5f88\u591a&#xff0c;\u800c\u4e14\u5728\u5b9e\u73b0\u65b9\u5f0f\u4e0a\u4e5f\u6bd4Date\u7c7b\u8981\u590d\u6742\u4e00\u4e9b\u3002<\/p>\n<p>Calendar\u7c7b\u662f\u4e00\u4e2a\u62bd\u8c61\u7c7b&#xff0c;\u5728\u5b9e\u9645\u4f7f\u7528\u65f6\u5b9e\u73b0\u7279\u5b9a\u7684\u5b50\u7c7b\u7684\u5bf9\u8c61&#xff0c;\u521b\u5efa\u5bf9\u8c61\u7684\u8fc7\u7a0b\u5bf9\u7a0b\u5e8f\u5458\u6765\u8bf4\u662f\u900f\u660e\u7684&#xff0c;\u53ea\u9700\u8981\u4f7f\u7528getInstance\u65b9\u6cd5\u521b\u5efa\u5373\u53ef\u3002<\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u4ee3\u8868\u7cfb\u7edf\u5f53\u524d\u65e5\u671f\u7684Calendar\u5bf9\u8c61<\/p>\n<\/p>\n<p>public static void main(String args[]) {<br \/>\n    Calendar c &#061; Calendar.getInstance();\/\/\u9ed8\u8ba4\u662f\u5f53\u524d\u65e5\u671f<br \/>\n    System.out.println(c);<br \/>\n} <\/p>\n<p>\u8f93\u51fa&#xff1a;<\/p>\n<p>java.util.GregorianCalendar[time&#061;1617072097924,areFieldsSet&#061;true,areAllFieldsSet&#061;true,lenient&#061;true,zone&#061;sun.util.calendar.ZoneInfo[id&#061;&#034;Asia\/Shanghai&#034;,offset&#061;28800000,dstSavings&#061;0,useDaylight&#061;false,transitions&#061;31,lastRule&#061;null],firstDayOfWeek&#061;1,minimalDaysInFirstWeek&#061;1,ERA&#061;1,YEAR&#061;2021,MONTH&#061;2,WEEK_OF_YEAR&#061;14,WEEK_OF_MONTH&#061;5,DAY_OF_MONTH&#061;30,DAY_OF_YEAR&#061;89,DAY_OF_WEEK&#061;3,DAY_OF_WEEK_IN_MONTH&#061;5,AM_PM&#061;0,HOUR&#061;10,HOUR_OF_DAY&#061;10,MINUTE&#061;41,SECOND&#061;37,MILLISECOND&#061;924,ZONE_OFFSET&#061;28800000,DST_OFFSET&#061;0]<\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u6307\u5b9a\u65e5\u671f\u7684Calendar\u5bf9\u8c61<\/p>\n<p>\u4f7f\u7528Calendar\u7c7b\u4ee3\u8868\u7279\u5b9a\u7684\u65f6\u95f4&#xff0c;\u9700\u8981\u9996\u5148\u521b\u5efa\u4e00\u4e2aCalendar\u7684\u5bf9\u8c61&#xff0c;\u7136\u540e\u518d\u8bbe\u5b9a\u8be5\u5bf9\u8c61\u4e2d\u7684\u5e74\u6708\u65e5\u53c2\u6570\u6765\u5b8c\u6210\u3002<\/p>\n<\/p>\n<p>\/\/\u521b\u5efa\u4e00\u4e2a\u4ee3\u88682019\u5e744\u670827\u65e5\u7684Calendar\u5bf9\u8c61<br \/>\nCalendar c1 &#061; Calendar.getInstance();<br \/>\nc1.set(2019, 4 &#8211; 1, 27); <\/p>\n<p>Calendar\u7c7b\u5bf9\u8c61\u5b57\u6bb5\u7c7b\u578b<\/p>\n<p>Calendar\u7c7b\u4e2d\u7528\u4ee5\u4e0b\u8fd9\u4e9b\u5e38\u91cf\u8868\u793a\u4e0d\u540c\u7684\u610f\u4e49&#xff0c;jdk\u5185\u7684\u5f88\u591a\u7c7b\u5176\u5b9e\u90fd\u662f\u91c7\u7528\u7684\u8fd9\u79cd\u601d\u60f3<\/p>\n<table>\n<tr>\u5e38\u91cf\u63cf\u8ff0<\/tr>\n<tbody>\n<tr>\n<td>Calendar.YEAR<\/td>\n<td>\u5e74\u4efd<\/td>\n<\/tr>\n<tr>\n<td>Calendar.MONTH<\/td>\n<td>\u6708\u4efd<\/td>\n<\/tr>\n<tr>\n<td>Calendar.DATE<\/td>\n<td>\u65e5\u671f<\/td>\n<\/tr>\n<tr>\n<td>Calendar.DAY_OF_MONTH<\/td>\n<td>\u65e5\u671f&#xff0c;\u548c\u4e0a\u9762\u7684\u5b57\u6bb5\u610f\u4e49\u5b8c\u5168\u76f8\u540c<\/td>\n<\/tr>\n<tr>\n<td>Calendar.HOUR<\/td>\n<td>12\u5c0f\u65f6\u5236\u7684\u5c0f\u65f6<\/td>\n<\/tr>\n<tr>\n<td>Calendar.HOUR_OF_DAY<\/td>\n<td>24\u5c0f\u65f6\u5236\u7684\u5c0f\u65f6<\/td>\n<\/tr>\n<tr>\n<td>Calendar.MINUTE<\/td>\n<td>\u5206\u949f<\/td>\n<\/tr>\n<tr>\n<td>Calendar.SECOND<\/td>\n<td>\u79d2<\/td>\n<\/tr>\n<tr>\n<td>Calendar.DAY_OF_WEEK<\/td>\n<td>\u661f\u671f\u51e0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\/\/ \u83b7\u5f97\u5e74\u4efd<br \/>\nint year &#061; c1.get(Calendar.YEAR);<br \/>\n\/\/ \u83b7\u5f97\u6708\u4efd<br \/>\nint month &#061; c1.get(Calendar.MONTH) &#043; 1;<br \/>\n\/\/ \u83b7\u5f97\u65e5\u671f<br \/>\nint date &#061; c1.get(Calendar.DATE);<br \/>\n\/\/ \u83b7\u5f97\u5c0f\u65f6<br \/>\nint hour &#061; c1.get(Calendar.HOUR_OF_DAY);<br \/>\n\/\/ \u83b7\u5f97\u5206\u949f<br \/>\nint minute &#061; c1.get(Calendar.MINUTE);<br \/>\n\/\/ \u83b7\u5f97\u79d2<br \/>\nint second &#061; c1.get(Calendar.SECOND);<br \/>\n\/\/ \u83b7\u5f97\u661f\u671f\u51e0&#xff08;\u6ce8\u610f&#xff08;\u8fd9\u4e2a\u4e0eDate\u7c7b\u662f\u4e0d\u540c\u7684&#xff09;&#xff1a;1\u4ee3\u8868\u661f\u671f\u65e5\u30012\u4ee3\u8868\u661f\u671f1\u30013\u4ee3\u8868\u661f\u671f\u4e8c&#xff0c;\u4ee5\u6b64\u7c7b\u63a8&#xff09;<br \/>\nint day &#061; c1.get(Calendar.DAY_OF_WEEK); <\/p>\n<p>\u8bbe\u7f6e\u5b8c\u6574\u65e5\u671f<\/p>\n<\/p>\n<p>Calendar c1 &#061; Calendar.getInstance();<br \/>\nc1.set(2009, 6 &#8211; 1, 12);\/\/\u628aCalendar\u5bf9\u8c61c1\u7684\u5e74\u6708\u65e5\u5206\u522b\u8bbe\u8fd9\u4e3a&#xff1a;2009\u30016\u300112 <\/p>\n<p>\u8bbe\u7f6e\u67d0\u4e2a\u5b57\u6bb5<\/p>\n<\/p>\n<p>c1.set(Calendar.DATE,10);<br \/>\nc1.set(Calendar.YEAR,2008);<br \/>\n\/\/\u5176\u4ed6\u5b57\u6bb5\u5c5e\u6027set\u7684\u610f\u4e49\u4ee5\u6b64\u7c7b\u63a8 <\/p>\n<p>add\u8bbe\u7f6e<\/p>\n<\/p>\n<p>\/\/\u628ac1\u5bf9\u8c61\u7684\u65e5\u671f\u52a0\u4e0a10&#xff0c;\u4e5f\u5c31\u662fc1\u4e5f\u5c31\u8868\u793a\u4e3a10\u5929\u540e\u7684\u65e5\u671f&#xff0c;\u5176\u5b83\u6240\u6709\u7684\u6570\u503c\u4f1a\u88ab\u91cd\u65b0\u8ba1\u7b97<br \/>\nc1.add(Calendar.DATE, 10);<br \/>\n\/\/\u628ac1\u5bf9\u8c61\u7684\u65e5\u671f\u51cf\u53bb10&#xff0c;\u4e5f\u5c31\u662fc1\u4e5f\u5c31\u8868\u793a\u4e3a10\u5929\u524d\u7684\u65e5\u671f&#xff0c;\u5176\u5b83\u6240\u6709\u7684\u6570\u503c\u4f1a\u88ab\u91cd\u65b0\u8ba1\u7b97<br \/>\nc1.add(Calendar.DATE, -10); <\/p>\n<p>\u3010\u6f14\u793a&#xff1a;GregorianCalendar\u3011<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    String months[] &#061; {<br \/>\n            &#034;Jan&#034;, &#034;Feb&#034;, &#034;Mar&#034;, &#034;Apr&#034;,<br \/>\n            &#034;May&#034;, &#034;Jun&#034;, &#034;Jul&#034;, &#034;Aug&#034;,<br \/>\n            &#034;Sep&#034;, &#034;Oct&#034;, &#034;Nov&#034;, &#034;Dec&#034;};<\/p>\n<p>    int year;<br \/>\n    \/\/ \u521d\u59cb\u5316 Gregorian \u65e5\u5386<br \/>\n    \/\/ \u4f7f\u7528\u5f53\u524d\u65f6\u95f4\u548c\u65e5\u671f<br \/>\n    \/\/ \u9ed8\u8ba4\u4e3a\u672c\u5730\u65f6\u95f4\u548c\u65f6\u533a<br \/>\n    GregorianCalendar gcalendar &#061; new GregorianCalendar();<br \/>\n    \/\/ \u663e\u793a\u5f53\u524d\u65f6\u95f4\u548c\u65e5\u671f\u7684\u4fe1\u606f<br \/>\n    System.out.print(&#034;Date: &#034;);<br \/>\n    System.out.print(months[gcalendar.get(Calendar.MONTH)]);<br \/>\n    System.out.print(&#034; &#034; &#043; gcalendar.get(Calendar.DATE) &#043; &#034; &#034;);<br \/>\n    System.out.println(year &#061; gcalendar.get(Calendar.YEAR));<br \/>\n    System.out.print(&#034;Time: &#034;);<br \/>\n    System.out.print(gcalendar.get(Calendar.HOUR) &#043; &#034;:&#034;);<br \/>\n    System.out.print(gcalendar.get(Calendar.MINUTE) &#043; &#034;:&#034;);<br \/>\n    System.out.println(gcalendar.get(Calendar.SECOND));<\/p>\n<p>    \/\/ \u6d4b\u8bd5\u5f53\u524d\u5e74\u4efd\u662f\u5426\u4e3a\u95f0\u5e74<br \/>\n    if (gcalendar.isLeapYear(year)) {<br \/>\n        System.out.println(&#034;\u5f53\u524d\u5e74\u4efd\u662f\u95f0\u5e74&#034;);<br \/>\n    } else {<br \/>\n        System.out.println(&#034;\u5f53\u524d\u5e74\u4efd\u4e0d\u662f\u95f0\u5e74&#034;);<br \/>\n    }<\/p>\n<p>} <\/p>\n<p>\u8f93\u51fa&#xff1a;<\/p>\n<p>Date: Mar 30 2021 Time: 10:49:35 \u5f53\u524d\u5e74\u4efd\u4e0d\u662f\u95f0\u5e74<\/p>\n<p>\u6ce8\u610f&#xff1a;Calender\u7684\u6708\u4efd\u662f\u4ece0\u5f00\u59cb\u7684&#xff0c;\u4f46\u65e5\u671f\u548c\u5e74\u4efd\u662f\u4ece1\u5f00\u59cb\u7684<\/p>\n<p>\u3010\u6f14\u793a\u3011<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    Calendar c1 &#061; Calendar.getInstance();<br \/>\n    c1.set(2017, 1, 1);<br \/>\n    System.out.println(c1.get(Calendar.YEAR)<br \/>\n            &#043; &#034;-&#034; &#043; c1.get(Calendar.MONTH)<br \/>\n            &#043; &#034;-&#034; &#043; c1.get(Calendar.DATE));<br \/>\n    c1.set(2017, 1, 0);<br \/>\n    System.out.println(c1.get(Calendar.YEAR)<br \/>\n            &#043; &#034;-&#034; &#043; c1.get(Calendar.MONTH)<br \/>\n            &#043; &#034;-&#034; &#043; c1.get(Calendar.DATE));<br \/>\n}<br \/>\n\/*<br \/>\n\u8f93\u51fa<br \/>\n2017-1-1<br \/>\n2017-0-31<br \/>\n    \/* <\/p>\n<p>\u53ef\u89c1&#xff0c;\u5c06\u65e5\u671f\u8bbe\u4e3a0\u4ee5\u540e&#xff0c;\u6708\u4efd\u53d8\u6210\u4e86\u4e0a\u4e2a\u6708&#xff0c;\u4f46\u6708\u4efd\u53ef\u4ee5\u4e3a0&#xff0c;\u628a\u6708\u4efd\u6539\u4e3a2\u8bd5\u8bd5&#xff1a;<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    Calendar c1 &#061; Calendar.getInstance();<br \/>\n    c1.set(2017, 2, 1);<br \/>\n    System.out.println(c1.get(Calendar.YEAR)<br \/>\n            &#043; &#034;-&#034; &#043; c1.get(Calendar.MONTH)<br \/>\n            &#043; &#034;-&#034; &#043; c1.get(Calendar.DATE));<br \/>\n    c1.set(2017, 2, 0);<br \/>\n    System.out.println(c1.get(Calendar.YEAR)<br \/>\n            &#043; &#034;-&#034; &#043; c1.get(Calendar.MONTH)<br \/>\n            &#043; &#034;-&#034; &#043; c1.get(Calendar.DATE));<br \/>\n}<br \/>\n\/*<br \/>\n\u8f93\u51fa<br \/>\n2017-2-1<br \/>\n2017-1-28<br \/>\n*\/ <\/p>\n<p>\u53ef\u4ee5\u770b\u5230\u4e0a\u4e2a\u6708\u7684\u6700\u540e\u4e00\u5929\u662f28\u53f7&#xff0c;\u6240\u4ee5Calendar.MONTH\u4e3a1\u7684\u65f6\u5019\u662f2\u6708 \u3002<\/p>\n<h3 id=\"string\u7c7b\">String\u7c7b<\/h3>\n<h4 id=\"_1\u3001string\u6982\u8ff0\">1\u3001String\u6982\u8ff0<\/h4>\n<p>\u5728API\u4e2d\u662f\u8fd9\u6837\u63cf\u8ff0&#xff1a;<\/p>\n<p>String \u7c7b\u4ee3\u8868\u5b57\u7b26\u4e32\u3002Java \u7a0b\u5e8f\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u4e32\u5b57\u9762\u503c&#xff08;\u5982 &#034;abc&#034; &#xff09;\u90fd\u4f5c\u4e3a\u6b64\u7c7b\u7684\u5b9e\u4f8b\u5b9e\u73b0\u3002 \u5b57\u7b26\u4e32\u662f\u5e38\u91cf&#xff1b;\u5b83\u4eec\u7684\u503c\u5728\u521b\u5efa\u4e4b\u540e\u4e0d\u80fd\u66f4\u6539\u3002\u5b57\u7b26\u4e32\u7f13\u51b2\u533a\u652f\u6301\u53ef\u53d8\u7684\u5b57\u7b26\u4e32\u3002\u56e0\u4e3a String \u5bf9\u8c61\u662f\u4e0d\u53ef\u53d8\u7684&#xff0c; \u6240\u4ee5\u53ef\u4ee5\u5171\u4eab\u3002<\/p>\n<p>\u3010\u6f14\u793a&#xff1a;\u67e5\u770bString\u6e90\u7801\u3011<\/p>\n<\/p>\n<p>public final class String<br \/>\nimplements java.io.Serializable, Comparable&lt;String&gt;, CharSequence {<\/p>\n<p>} <\/p>\n<p>\u3010String\u7684\u6210\u5458\u53d8\u91cf\u3011<\/p>\n<\/p>\n<p>\/\/String\u7684\u5c5e\u6027\u503c<br \/>\nprivate final char value[];<\/p>\n<p>\/\/\u6570\u7ec4\u88ab\u4f7f\u7528\u7684\u5f00\u59cb\u4f4d\u7f6e<br \/>\nprivate final int offset;<\/p>\n<p>\/\/String\u4e2d\u5143\u7d20\u7684\u4e2a\u6570<br \/>\nprivate final int count;<\/p>\n<p>\/\/String\u7c7b\u578b\u7684hash\u503c<br \/>\nprivate int hash; \/\/ Default to 0<\/p>\n<p>private static final long serialVersionUID &#061; -6849794470754667710L;<br \/>\nprivate static final ObjectStreamField[] serialPersistentFields &#061;<br \/>\nnew ObjectStreamField[0]; <\/p>\n<p>\u4ece\u6e90\u7801\u770b\u51faString\u5e95\u5c42\u4f7f\u7528\u4e00\u4e2a\u5b57\u7b26\u6570\u7ec4\u6765\u7ef4\u62a4\u7684\u3002<\/p>\n<p>\u6210\u5458\u53d8\u91cf\u53ef\u4ee5\u77e5\u9053String\u7c7b\u7684\u503c\u662ffinal\u7c7b\u578b\u7684&#xff0c;\u4e0d\u80fd\u88ab\u6539\u53d8\u7684&#xff0c;\u6240\u4ee5\u53ea\u8981\u4e00\u4e2a\u503c\u6539\u53d8\u5c31\u4f1a\u751f\u6210\u4e00\u4e2a\u65b0\u7684 String\u7c7b\u578b\u5bf9\u8c61&#xff0c;\u5b58\u50a8String\u6570\u636e\u4e5f\u4e0d\u4e00\u5b9a\u4ece\u6570\u7ec4\u7684\u7b2c0\u4e2a\u5143\u7d20\u5f00\u59cb\u7684&#xff0c;\u800c\u662f\u4eceoffset\u6240\u6307\u7684\u5143\u7d20\u5f00\u59cb\u3002<\/p>\n<p>\u3010String\u7684\u6784\u9020\u65b9\u6cd5\u3011<\/p>\n<\/p>\n<p>String()<br \/>\n\/\/\u521d\u59cb\u5316\u4e00\u4e2a\u65b0\u521b\u5efa\u7684 String \u5bf9\u8c61&#xff0c;\u4f7f\u5176\u8868\u793a\u4e00\u4e2a\u7a7a\u5b57\u7b26\u5e8f\u5217\u3002<\/p>\n<p>String(byte[] bytes)<br \/>\n\/\/\u901a\u8fc7\u4f7f\u7528\u5e73\u53f0\u7684\u9ed8\u8ba4\u5b57\u7b26\u96c6\u89e3\u7801\u6307\u5b9a\u7684 byte \u6570\u7ec4&#xff0c;\u6784\u9020\u4e00\u4e2a\u65b0\u7684 String\u3002<\/p>\n<p>String(byte[] bytes, Charset charset)<br \/>\n\/\/\u901a\u8fc7\u4f7f\u7528\u6307\u5b9a\u7684 charset \u89e3\u7801\u6307\u5b9a\u7684 byte \u6570\u7ec4&#xff0c;\u6784\u9020\u4e00\u4e2a\u65b0\u7684 String\u3002<\/p>\n<p>String(byte[] bytes, int offset, int length)<br \/>\n\/\/\u901a\u8fc7\u4f7f\u7528\u5e73\u53f0\u7684\u9ed8\u8ba4\u5b57\u7b26\u96c6\u89e3\u7801\u6307\u5b9a\u7684 byte \u5b50\u6570\u7ec4&#xff0c;\u6784\u9020\u4e00\u4e2a\u65b0\u7684 String\u3002<\/p>\n<p>String(byte[] bytes, int offset, int length, Charset charset)<br \/>\n\/\/\u901a\u8fc7\u4f7f\u7528\u6307\u5b9a\u7684 charset \u89e3\u7801\u6307\u5b9a\u7684 byte \u5b50\u6570\u7ec4&#xff0c;\u6784\u9020\u4e00\u4e2a\u65b0\u7684 String\u3002<\/p>\n<p>String(byte[] bytes, int offset, int length, String charsetName)<br \/>\n\/\/\u901a\u8fc7\u4f7f\u7528\u6307\u5b9a\u7684\u5b57\u7b26\u96c6\u89e3\u7801\u6307\u5b9a\u7684 byte \u5b50\u6570\u7ec4&#xff0c;\u6784\u9020\u4e00\u4e2a\u65b0\u7684 String\u3002<\/p>\n<p>String(byte[] bytes, String charsetName)<br \/>\n\/\/\u901a\u8fc7\u4f7f\u7528\u6307\u5b9a\u7684 charset \u89e3\u7801\u6307\u5b9a\u7684 byte \u6570\u7ec4&#xff0c;\u6784\u9020\u4e00\u4e2a\u65b0\u7684 String\u3002<\/p>\n<p>String(char[] value)<br \/>\n\/\/\u5206\u914d\u4e00\u4e2a\u65b0\u7684 String&#xff0c;\u4f7f\u5176\u8868\u793a\u5b57\u7b26\u6570\u7ec4\u53c2\u6570\u4e2d\u5f53\u524d\u5305\u542b\u7684\u5b57\u7b26\u5e8f\u5217\u3002<\/p>\n<p>String(char[] value, int offset, int count)<br \/>\n\/\/\u5206\u914d\u4e00\u4e2a\u65b0\u7684 String&#xff0c;\u5b83\u5305\u542b\u53d6\u81ea\u5b57\u7b26\u6570\u7ec4\u53c2\u6570\u4e00\u4e2a\u5b50\u6570\u7ec4\u7684\u5b57\u7b26\u3002<\/p>\n<p>String(int[] codePoints, int offset, int count)<br \/>\n\/\/\u5206\u914d\u4e00\u4e2a\u65b0\u7684 String&#xff0c;\u5b83\u5305\u542b Unicode \u4ee3\u7801\u70b9\u6570\u7ec4\u53c2\u6570\u4e00\u4e2a\u5b50\u6570\u7ec4\u7684\u5b57\u7b26\u3002<\/p>\n<p>String(String original)<br \/>\n\/\/\u521d\u59cb\u5316\u4e00\u4e2a\u65b0\u521b\u5efa\u7684 String \u5bf9\u8c61&#xff0c;\u4f7f\u5176\u8868\u793a\u4e00\u4e2a\u4e0e\u53c2\u6570\u76f8\u540c\u7684\u5b57\u7b26\u5e8f\u5217&#xff1b;\u6362\u53e5\u8bdd\u8bf4&#xff0c;\u65b0\u521b\u5efa\u7684\u5b57\u7b26\u4e32\u662f\u8be5\u53c2\u6570\u5b57\u7b26\u4e32\u7684\u526f\u672c\u3002<\/p>\n<p>String(StringBuffer buffer)<br \/>\n\/\/\u5206\u914d\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32&#xff0c;\u5b83\u5305\u542b\u5b57\u7b26\u4e32\u7f13\u51b2\u533a\u53c2\u6570\u4e2d\u5f53\u524d\u5305\u542b\u7684\u5b57\u7b26\u5e8f\u5217\u3002<\/p>\n<p>String(StringBuilder builder)<br \/>\n\/\/\u5206\u914d\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32&#xff0c;\u5b83\u5305\u542b\u5b57\u7b26\u4e32\u751f\u6210\u5668\u53c2\u6570\u4e2d\u5f53\u524d\u5305\u542b\u7684\u5b57\u7b26\u5e8f\u5217\u3002 <\/p>\n<h4 id=\"_2\u3001\u521b\u5efa\u5b57\u7b26\u4e32\u5bf9\u8c61\u65b9\u5f0f\">2\u3001\u521b\u5efa\u5b57\u7b26\u4e32\u5bf9\u8c61\u65b9\u5f0f<\/h4>\n<p>\u76f4\u63a5\u8d4b\u503c\u65b9\u5f0f\u521b\u5efa\u5bf9\u8c61\u662f\u5728\u65b9\u6cd5\u533a\u7684\u5e38\u91cf\u6c60<\/p>\n<\/p>\n<p>String str&#061;&#034;hello&#034;;\/\/\u76f4\u63a5\u8d4b\u503c\u7684\u65b9\u5f0f <\/p>\n<p>\u901a\u8fc7\u6784\u9020\u65b9\u6cd5\u521b\u5efa\u5b57\u7b26\u4e32\u5bf9\u8c61\u662f\u5728\u5806\u5185\u5b58<\/p>\n<\/p>\n<p>String str&#061;new String(&#034;hello&#034;);\/\/\u5b9e\u4f8b\u5316\u7684\u65b9\u5f0f <\/p>\n<p>\u3010\u4e24\u79cd\u5b9e\u4f8b\u5316\u65b9\u5f0f\u7684\u6bd4\u8f83\u3011<\/p>\n<p>\u7f16\u5199\u4ee3\u7801\u6bd4\u8f83<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    String str1 &#061; &#034;Lance&#034;;<br \/>\n    String str2 &#061; new String(&#034;Lance&#034;);<br \/>\n    String str3 &#061; str2; \/\/\u5f15\u7528\u4f20\u9012&#xff0c;str3\u76f4\u63a5\u6307\u5411st2\u7684\u5806\u5185\u5b58\u5730\u5740<br \/>\n    String str4 &#061; &#034;Lance&#034;;<br \/>\n    \/**<br \/>\n     * &#061;&#061;:<br \/>\n     * \u57fa\u672c\u6570\u636e\u7c7b\u578b&#xff1a;\u6bd4\u8f83\u7684\u662f\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u503c\u662f\u5426\u76f8\u540c<br \/>\n     * \u5f15\u7528\u6570\u636e\u7c7b\u578b&#xff1a;\u6bd4\u8f83\u7684\u662f\u5f15\u7528\u6570\u636e\u7c7b\u578b\u7684\u5730\u5740\u503c\u662f\u5426\u76f8\u540c<br \/>\n     * \u6240\u4ee5\u5728\u8fd9\u91cc\u7684\u8bdd&#xff1a;String\u7c7b\u5bf9\u8c61&#061;&#061;\u6bd4\u8f83&#xff0c;\u6bd4\u8f83\u7684\u662f\u5730\u5740&#xff0c;\u800c\u4e0d\u662f\u5185\u5bb9<br \/>\n     *\/<br \/>\n    System.out.println(str1 &#061;&#061; str2);\/\/false<br \/>\n    System.out.println(str1 &#061;&#061; str3);\/\/false<br \/>\n    System.out.println(str3 &#061;&#061; str2);\/\/true<br \/>\n    System.out.println(str1 &#061;&#061; str4);\/\/true<br \/>\n} <\/p>\n<p>\u5185\u5b58\u56fe\u5206\u6790<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"328\" src=\"2026-01-14fexb5miiqwj.png\" width=\"705\" \/><\/p>\n<p>\u53ef\u80fd\u8fd9\u91cc\u8fd8\u662f\u4e0d\u591f\u660e\u663e&#xff0c;\u6784\u9020\u65b9\u6cd5\u5b9e\u4f8b\u5316\u65b9\u5f0f\u7684\u5185\u5b58\u56fe&#xff1a;String str &#061; new String(&#034;Hello&#034;);<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"261\" src=\"2026-01-14qhhasyahby0.png\" width=\"496\" \/><\/p>\n<p>\u5f53\u6211\u4eec\u518d\u4e00\u6b21\u7684new\u4e00\u4e2aString\u5bf9\u8c61\u65f6&#xff1a;<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"251\" src=\"2026-01-14a0h5xs0d5jd.png\" width=\"544\" \/><\/p>\n<p>\u3010\u5b57\u7b26\u4e32\u5e38\u91cf\u6c60\u3011<\/p>\n<p>\u5728\u5b57\u7b26\u4e32\u4e2d&#xff0c;\u5982\u679c\u91c7\u7528\u76f4\u63a5\u8d4b\u503c\u7684\u65b9\u5f0f&#xff08;String str&#061;&#034;Lance&#034;&#xff09;\u8fdb\u884c\u5bf9\u8c61\u7684\u5b9e\u4f8b\u5316&#xff0c;\u5219\u4f1a\u5c06\u533f\u540d\u5bf9\u8c61 \u201cLance\u201d\u653e\u5165\u5bf9\u8c61\u6c60&#xff0c;\u6bcf\u5f53\u4e0b\u4e00\u6b21\u5bf9\u4e0d\u540c\u7684\u5bf9\u8c61\u8fdb\u884c\u76f4\u63a5\u8d4b\u503c\u7684\u65f6\u5019\u4f1a\u76f4\u63a5\u5229\u7528\u6c60\u4e2d\u539f\u6709\u7684\u533f\u540d\u5bf9\u8c61&#xff0c;\u6211\u4eec\u53ef\u4ee5\u7528\u5bf9\u8c61\u624b\u5de5\u5165\u6c60&#xff1b;<\/p>\n<\/p>\n<p>public static void main(String args[]){<br \/>\n    String str &#061; new String(&#034;Lance&#034;).intern();\/\/\u5bf9\u533f\u540d\u5bf9\u8c61\u8fdb\u884c\u624b\u5de5\u5165\u6c60\u64cd\u4f5c<br \/>\n    String str1 &#061; &#034;Lance&#034;;<br \/>\n    System.out.println(str&#061;&#061;str1);\/\/true<br \/>\n} <\/p>\n<p>\u3010\u4e24\u79cd\u5b9e\u4f8b\u5316\u65b9\u5f0f\u7684\u533a\u522b\u3011<\/p>\n<li>\n<p>\u76f4\u63a5\u8d4b\u503c&#xff08;String str &#061; &#034;hello&#034;&#xff09;<\/p>\n<p>\u53ea\u5f00\u8f9f\u4e00\u5757\u5806\u5185\u5b58\u7a7a\u95f4&#xff0c;\u5e76\u4e14\u4f1a\u81ea\u52a8\u5165\u6c60&#xff0c;\u4e0d\u4f1a\u4ea7\u751f\u5783\u573e\u3002<\/p>\n<\/li>\n<li>\n<p>\u6784\u9020\u65b9\u6cd5&#xff08;String str&#061; new String(&#034;hello&#034;);&#xff09;<\/p>\n<p>\u4f1a\u5f00\u8f9f\u4e24\u5757\u5806\u5185\u5b58\u7a7a\u95f4&#xff0c;\u5176\u4e2d\u4e00\u5757\u5806\u5185\u5b58\u4f1a\u53d8\u6210\u5783\u573e\u88ab\u7cfb\u7edf\u56de\u6536&#xff0c;\u800c\u4e14\u4e0d\u80fd\u591f\u81ea\u52a8\u5165\u6c60&#xff0c;\u9700\u8981\u901a\u8fc7public String intern();\u65b9\u6cd5\u8fdb\u884c\u624b\u5de5\u5165\u6c60\u3002<\/p>\n<\/li>\n<li>\n<p>\u5728\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\u4e0d\u4f1a\u91c7\u7528\u6784\u9020\u65b9\u6cd5\u8fdb\u884c\u5b57\u7b26\u4e32\u7684\u5b9e\u4f8b\u5316\u3002<\/p>\n<\/li>\n<p>\u3010\u907f\u514d\u7a7a\u6307\u5411\u3011<\/p>\n<p>\u9996\u5148\u4e86\u89e3&#xff1a; &#061;&#061; \u548cpublic boolean equals()\u6bd4\u8f83\u5b57\u7b26\u4e32\u7684\u533a\u522b<\/p>\n<p>&#061;&#061;\u5728\u5bf9\u5b57\u7b26\u4e32\u6bd4\u8f83\u7684\u65f6\u5019&#xff0c;\u5bf9\u6bd4\u7684\u662f\u5185\u5b58\u5730\u5740&#xff0c;\u800cequals\u6bd4\u8f83\u7684\u662f\u5b57\u7b26\u4e32\u5185\u5bb9&#xff0c;\u5728\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d&#xff0c; equals()\u901a\u8fc7\u63a5\u53d7\u53c2\u6570&#xff0c;\u53ef\u4ee5\u907f\u514d\u7a7a\u6307\u5411\u3002<\/p>\n<\/p>\n<p>String str &#061; null;<br \/>\nif(str.equals(&#034;hello&#034;)){\/\/\u6b64\u65f6\u4f1a\u51fa\u73b0\u7a7a\u6307\u5411\u5f02\u5e38<\/p>\n<p>}<\/p>\n<p>if(&#034;hello&#034;.equals(str)){\/\/\u6b64\u65f6equals\u4f1a\u5904\u7406null\u503c&#xff0c;\u53ef\u4ee5\u907f\u514d\u7a7a\u6307\u5411\u5f02\u5e38<\/p>\n<p>} <\/p>\n<p>String\u7c7b\u5bf9\u8c61\u4e00\u65e6\u58f0\u660e\u5219\u4e0d\u53ef\u4ee5\u6539\u53d8&#xff1b;\u800c\u6539\u53d8\u7684\u53ea\u662f\u5730\u5740&#xff0c;\u539f\u6765\u7684\u5b57\u7b26\u4e32\u8fd8\u662f\u5b58\u5728\u7684&#xff0c;\u5e76\u4e14\u4ea7\u751f\u5783\u573e<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"258\" src=\"2026-01-142lh2cuwvbu3.png\" width=\"785\" \/><\/p>\n<h4 id=\"_3\u3001string\u5e38\u7528\u7684\u65b9\u6cd5\">3\u3001String\u5e38\u7528\u7684\u65b9\u6cd5<\/h4>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"699\" src=\"2026-01-14bobwumwlh0z.png\" width=\"1021\" \/><\/p>\n<h5 id=\"string\u7684\u5224\u65ad\">String\u7684\u5224\u65ad<\/h5>\n<p>boolean equals(Object obj)&#xff1a;\u6bd4\u8f83\u5b57\u7b26\u4e32\u7684\u5185\u5bb9\u662f\u5426\u76f8\u540c boolean equalsIgnoreCase(String str)&#xff1a; \u6bd4\u8f83\u5b57\u7b26\u4e32\u7684\u5185\u5bb9\u662f\u5426\u76f8\u540c,\u5ffd\u7565\u5927\u5c0f\u5199 boolean startsWith(String str)&#xff1a; \u5224\u65ad\u5b57\u7b26\u4e32\u5bf9\u8c61\u662f\u5426\u4ee5\u6307\u5b9a\u7684str\u5f00\u5934 boolean endsWith(String str)&#xff1a; \u5224\u65ad\u5b57\u7b26\u4e32\u5bf9\u8c61\u662f\u5426\u4ee5\u6307\u5b9a\u7684str\u7ed3\u5c3e<\/p>\n<p>\u6f14\u793a&#xff1a;<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    \/\/ \u521b\u5efa\u5b57\u7b26\u4e32\u5bf9\u8c61<br \/>\n    String s1 &#061; &#034;hello&#034;;<br \/>\n    String s2 &#061; &#034;hello&#034;;<br \/>\n    String s3 &#061; &#034;Hello&#034;;<\/p>\n<p>    \/\/ boolean equals(Object obj):\u6bd4\u8f83\u5b57\u7b26\u4e32\u7684\u5185\u5bb9\u662f\u5426\u76f8\u540c<br \/>\n    System.out.println(s1.equals(s2)); \/\/true<br \/>\n    System.out.println(s1.equals(s3)); \/\/false<br \/>\n    System.out.println(&#034;&#8212;&#8212;&#8212;&#8211;&#034;);<\/p>\n<p>    \/\/ boolean equalsIgnoreCase(String str):\u6bd4\u8f83\u5b57\u7b26\u4e32\u7684\u5185\u5bb9\u662f\u5426\u76f8\u540c,\u5ffd\u7565\u5927\u5c0f\u5199<br \/>\n    System.out.println(s1.equalsIgnoreCase(s2)); \/\/true<br \/>\n    System.out.println(s1.equalsIgnoreCase(s3)); \/\/true<br \/>\n    System.out.println(&#034;&#8212;&#8212;&#8212;&#8211;&#034;);<\/p>\n<p>    \/\/ boolean startsWith(String str):\u5224\u65ad\u5b57\u7b26\u4e32\u5bf9\u8c61\u662f\u5426\u4ee5\u6307\u5b9a\u7684str\u5f00\u5934<br \/>\n    System.out.println(s1.startsWith(&#034;he&#034;)); \/\/true<br \/>\n    System.out.println(s1.startsWith(&#034;ll&#034;)); \/\/false<br \/>\n} <\/p>\n<h5 id=\"string\u7684\u622a\u53d6\">String\u7684\u622a\u53d6<\/h5>\n<p>int length():\u83b7\u53d6\u5b57\u7b26\u4e32\u7684\u957f\u5ea6&#xff0c;\u5176\u5b9e\u4e5f\u5c31\u662f\u5b57\u7b26\u4e2a\u6570 char charAt(int index):\u83b7\u53d6\u6307\u5b9a\u7d22\u5f15\u5904\u7684\u5b57\u7b26 int indexOf(String str):\u83b7\u53d6str\u5728\u5b57\u7b26\u4e32\u5bf9\u8c61\u4e2d\u7b2c\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15 String substring(int start):\u4ecestart\u5f00\u59cb\u622a\u53d6\u5b57\u7b26\u4e32 String substring(int start,int end):\u4ecestart\u5f00\u59cb&#xff0c;\u5230end\u7ed3\u675f\u622a\u53d6\u5b57\u7b26\u4e32\u3002\u5305\u62ecstart&#xff0c;\u4e0d\u5305\u62ecend<\/p>\n<p>\u6f14\u793a<\/p>\n<\/p>\n<p>public static void main(String args[]) {<br \/>\n    \/\/ \u521b\u5efa\u5b57\u7b26\u4e32\u5bf9\u8c61<br \/>\n    String s &#061; &#034;helloworld&#034;;<br \/>\n    \/\/ int length():\u83b7\u53d6\u5b57\u7b26\u4e32\u7684\u957f\u5ea6&#xff0c;\u5176\u5b9e\u4e5f\u5c31\u662f\u5b57\u7b26\u4e2a\u6570<br \/>\n    System.out.println(s.length()); \/\/10<br \/>\n    System.out.println(&#034;&#8212;&#8212;&#8211;&#034;);<br \/>\n    \/\/ char charAt(int index):\u83b7\u53d6\u6307\u5b9a\u7d22\u5f15\u5904\u7684\u5b57\u7b26<br \/>\n    System.out.println(s.charAt(0)); \/\/h<br \/>\n    System.out.println(s.charAt(1)); \/\/e<br \/>\n    System.out.println(&#034;&#8212;&#8212;&#8211;&#034;);<br \/>\n    \/\/ int indexOf(String str):\u83b7\u53d6str\u5728\u5b57\u7b26\u4e32\u5bf9\u8c61\u4e2d\u7b2c\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15<br \/>\n    System.out.println(s.indexOf(&#034;l&#034;)); \/\/2<br \/>\n    System.out.println(s.indexOf(&#034;owo&#034;)); \/\/4<br \/>\n    System.out.println(s.indexOf(&#034;ak&#034;)); \/\/-1<br \/>\n    System.out.println(&#034;&#8212;&#8212;&#8211;&#034;);<br \/>\n    \/\/ String substring(int start):\u4ecestart\u5f00\u59cb\u622a\u53d6\u5b57\u7b26\u4e32<br \/>\n    System.out.println(s.substring(0)); \/\/helloworld<br \/>\n    System.out.println(s.substring(5)); \/\/world<br \/>\n    System.out.println(&#034;&#8212;&#8212;&#8211;&#034;);<br \/>\n    \/\/ String substring(int start,int end):\u4ecestart\u5f00\u59cb&#xff0c;\u5230end\u7ed3\u675f\u622a\u53d6\u5b57\u7b26\u4e32<br \/>\n    System.out.println(s.substring(0, s.length())); \/\/helloworld<br \/>\n    System.out.println(s.substring(3, 8)); \/\/lowor<br \/>\n} <\/p>\n<h5 id=\"string\u7684\u8f6c\u6362\">String\u7684\u8f6c\u6362<\/h5>\n<p>char[] toCharArray()&#xff1a;\u628a\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4 String toLowerCase()&#xff1a;\u628a\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5c0f\u5199\u5b57\u7b26\u4e32 String toUpperCase()&#xff1a;\u628a\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5927\u5199\u5b57\u7b26\u4e32<\/p>\n<p>\u6f14\u793a<\/p>\n<\/p>\n<p>public static void main(String args[]) {<br \/>\n\/\/ \u521b\u5efa\u5b57\u7b26\u4e32\u5bf9\u8c61<br \/>\n    String s &#061; &#034;abcde&#034;;<\/p>\n<p>    \/\/ char[] toCharArray():\u628a\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4<br \/>\n    char[] chs &#061; s.toCharArray();<br \/>\n    for (int x &#061; 0; x &lt; chs.length; x&#043;&#043;) {<br \/>\n        System.out.println(chs[x]);<br \/>\n    }<\/p>\n<p>    System.out.println(&#034;&#8212;&#8212;&#8212;&#8211;&#034;);<\/p>\n<p>    \/\/ String toLowerCase():\u628a\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5c0f\u5199\u5b57\u7b26\u4e32<br \/>\n    System.out.println(&#034;HelloWorld&#034;.toLowerCase());<br \/>\n    \/\/ String toUpperCase():\u628a\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5927\u5199\u5b57\u7b26\u4e32<br \/>\n    System.out.println(&#034;HelloWorld&#034;.toUpperCase());<br \/>\n} <\/p>\n<h5 id=\"\u5176\u4ed6\u65b9\u6cd5\">\u5176\u4ed6\u65b9\u6cd5<\/h5>\n<p>\u53bb\u9664\u5b57\u7b26\u4e32\u4e24\u7aef\u7a7a\u683c&#xff1a;String trim()<\/p>\n<p>\u6309\u7167\u6307\u5b9a\u7b26\u53f7\u5206\u5272\u5b57\u7b26\u4e32&#xff1a;String[] split(String str)<\/p>\n<\/p>\n<p>public static void main(String args[]) {<br \/>\n    \/\/ \u521b\u5efa\u5b57\u7b26\u4e32\u5bf9\u8c61<br \/>\n    String s1 &#061; &#034;helloworld&#034;;<br \/>\n    String s2 &#061; &#034; helloworld &#034;;<br \/>\n    String s3 &#061; &#034; hello world &#034;;<br \/>\n    System.out.println(&#034;&#8212;&#034; &#043; s1 &#043; &#034;&#8212;&#034;);<br \/>\n    System.out.println(&#034;&#8212;&#034; &#043; s1.trim() &#043; &#034;&#8212;&#034;);<br \/>\n    System.out.println(&#034;&#8212;&#034; &#043; s2 &#043; &#034;&#8212;&#034;);<br \/>\n    System.out.println(&#034;&#8212;&#034; &#043; s2.trim() &#043; &#034;&#8212;&#034;);<br \/>\n    System.out.println(&#034;&#8212;&#034; &#043; s3 &#043; &#034;&#8212;&#034;);<br \/>\n    System.out.println(&#034;&#8212;&#034; &#043; s3.trim() &#043; &#034;&#8212;&#034;);<br \/>\n    System.out.println(&#034;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#034;);<\/p>\n<p>    \/\/ String[] split(String str)<br \/>\n    \/\/ \u521b\u5efa\u5b57\u7b26\u4e32\u5bf9\u8c61<br \/>\n    String s4 &#061; &#034;aa,bb,cc&#034;;<br \/>\n    String[] strArray &#061; s4.split(&#034;,&#034;);<br \/>\n    for (int x &#061; 0; x &lt; strArray.length; x&#043;&#043;) {<br \/>\n        System.out.println(strArray[x]);<br \/>\n    }<br \/>\n} <\/p>\n<h4 id=\"_4\u3001string\u7684\u4e0d\u53ef\u53d8\u6027\">4\u3001String\u7684\u4e0d\u53ef\u53d8\u6027<\/h4>\n<p>\u5f53\u6211\u4eec\u53bb\u9605\u8bfb\u6e90\u4ee3\u7801\u7684\u65f6\u5019&#xff0c;\u4f1a\u53d1\u73b0\u6709\u8fd9\u6837\u7684\u4e00\u53e5\u8bdd&#xff1a;<\/p>\n<p>Strings are constant; their values cannot be changed after they are created.<\/p>\n<p>\u610f\u601d\u5c31\u662f\u8bf4&#xff1a;String\u662f\u4e2a\u5e38\u91cf&#xff0c;\u4ece\u4e00\u51fa\u751f\u5c31\u6ce8\u5b9a\u4e0d\u53ef\u53d8<\/p>\n<p>\u6211\u60f3\u5927\u5bb6\u5e94\u8be5\u5c31\u77e5\u9053\u4e3a\u4ec0\u4e48String\u4e0d\u53ef\u53d8\u4e86&#xff0c;String\u7c7b\u88abfinal\u4fee\u9970&#xff0c;\u5b98\u65b9\u6ce8\u91ca\u8bf4\u660e\u521b\u5efa\u540e\u4e0d\u80fd\u88ab\u6539\u53d8&#xff0c;\u4f46 \u662f\u4e3a\u4ec0\u4e48String\u8981\u4f7f\u7528final\u4fee\u9970\u5462&#xff1f;<\/p>\n<p>\u4e86\u89e3\u4e00\u4e2a\u7ecf\u5178\u7684\u9762\u8bd5\u9898<\/p>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    String a &#061; &#034;abc&#034;;<br \/>\n    String b &#061; &#034;abc&#034;;<br \/>\n    String c &#061; new String(&#034;abc&#034;);<br \/>\n    System.out.println(a&#061;&#061;b); \/\/true<br \/>\n    System.out.println(a.equals(b)); \/\/true<br \/>\n    System.out.println(a&#061;&#061;c); \/\/false<br \/>\n    System.out.println(a.equals(c)); \/\/true<br \/>\n} <\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"336\" src=\"2026-01-14gd5odqyoagu.png\" width=\"619\" \/><\/p>\n<p>\u56e0\u4e3aString\u592a\u8fc7\u5e38\u7528&#xff0c;JAVA\u7c7b\u5e93\u7684\u8bbe\u8ba1\u8005\u5728\u5b9e\u73b0\u65f6\u505a\u4e86\u4e2a\u5c0f\u5c0f\u7684\u53d8\u5316&#xff0c;\u5373\u91c7\u7528\u4e86\u4eab\u5143\u6a21\u5f0f&#xff0c;\u6bcf\u5f53\u751f\u6210\u4e00\u4e2a\u65b0\u5185\u5bb9\u7684\u5b57\u7b26\u4e32\u65f6&#xff0c;\u4ed6\u4eec\u90fd\u88ab\u6dfb\u52a0\u5230\u4e00\u4e2a\u5171\u4eab\u6c60\u4e2d&#xff0c;\u5f53\u7b2c\u4e8c\u6b21\u518d\u6b21\u751f\u6210\u540c\u6837\u5185\u5bb9\u7684\u5b57\u7b26\u4e32\u5b9e\u4f8b\u65f6&#xff0c;\u5c31\u5171\u4eab\u6b64\u5bf9\u8c61&#xff0c;\u800c\u4e0d\u662f\u521b\u5efa\u4e00\u4e2a\u65b0\u5bf9\u8c61&#xff0c;\u4f46\u662f\u8fd9\u6837\u7684\u505a\u6cd5\u4ec5\u4ec5\u9002\u5408\u4e8e\u901a\u8fc7&#061;\u7b26\u53f7\u8fdb\u884c\u7684\u521d\u59cb\u5316\u3002<\/p>\n<p>\u9700\u8981\u8bf4\u660e\u4e00\u70b9\u7684\u662f&#xff0c;\u5728object\u4e2d&#xff0c;equals()\u662f\u7528\u6765\u6bd4\u8f83\u5185\u5b58\u5730\u5740\u7684&#xff0c;\u4f46\u662fString\u91cd\u5199\u4e86equals()\u65b9 \u6cd5&#xff0c;\u7528\u6765\u6bd4\u8f83\u5185\u5bb9\u7684&#xff0c;\u5373\u4f7f\u662f\u4e0d\u540c\u5730\u5740&#xff0c;\u53ea\u8981\u5185\u5bb9\u4e00\u81f4&#xff0c;\u4e5f\u4f1a\u8fd4\u56detrue&#xff0c;\u8fd9\u4e5f\u5c31\u662f\u4e3a\u4ec0\u4e48a.equals(c)\u8fd4\u56detrue\u7684\u539f\u56e0\u4e86\u3002<\/p>\n<p>String\u4e0d\u53ef\u53d8\u7684\u597d\u5904<\/p>\n<ul>\n<li>\u53ef\u4ee5\u5b9e\u73b0\u591a\u4e2a\u53d8\u91cf\u5f15\u7528\u5806\u5185\u5b58\u4e2d\u7684\u540c\u4e00\u4e2a\u5b57\u7b26\u4e32\u5b9e\u4f8b&#xff0c;\u907f\u514d\u521b\u5efa\u7684\u5f00\u9500\u3002<\/li>\n<li>\u6211\u4eec\u7684\u7a0b\u5e8f\u4e2d\u5927\u91cf\u4f7f\u7528\u4e86String\u5b57\u7b26\u4e32&#xff0c;\u6709\u53ef\u80fd\u662f\u51fa\u4e8e\u5b89\u5168\u6027\u8003\u8651\u3002<\/li>\n<li>\u5927\u5bb6\u90fd\u77e5\u9053HashMap\u4e2dkey\u4e3aString\u7c7b\u578b&#xff0c;\u5982\u679c\u53ef\u53d8\u5c06\u53d8\u7684\u591a\u4e48\u53ef\u6015\u3002<\/li>\n<li>\u5f53\u6211\u4eec\u5728\u4f20\u53c2\u7684\u65f6\u5019&#xff0c;\u4f7f\u7528\u4e0d\u53ef\u53d8\u7c7b\u4e0d\u9700\u8981\u53bb\u8003\u8651\u8c01\u53ef\u80fd\u4f1a\u4fee\u6539\u5176\u5185\u90e8\u7684\u503c&#xff0c;\u5982\u679c\u4f7f\u7528\u53ef\u53d8\u7c7b\u7684\u8bdd&#xff0c;\u53ef\u80fd\u9700\u8981\u6bcf\u6b21\u8bb0\u5f97\u91cd\u65b0\u62f7\u8d1d\u51fa\u91cc\u9762\u7684\u503c&#xff0c;\u6027\u80fd\u4f1a\u6709\u4e00\u5b9a\u7684\u635f\u5931\u3002<\/li>\n<\/ul>\n<h4 id=\"_5\u3001\u5b57\u7b26\u4e32\u5e38\u91cf\u6c60\">5\u3001\u5b57\u7b26\u4e32\u5e38\u91cf\u6c60<\/h4>\n<p>\u5b57\u7b26\u4e32\u5e38\u91cf\u6c60\u6982\u8ff0&#xff1a;<\/p>\n<p>1\u3001\u5e38\u91cf\u6c60\u8868&#xff08;Constant_Pool table&#xff09;<\/p>\n<p>Class\u6587\u4ef6\u4e2d\u5b58\u50a8\u6240\u6709\u5e38\u91cf&#xff08;\u5305\u62ec\u5b57\u7b26\u4e32&#xff09;\u7684table\u3002\u8fd9\u662fClass\u6587\u4ef6\u4e2d\u7684\u5185\u5bb9&#xff0c;\u8fd8\u4e0d\u662f\u8fd0\u884c\u65f6\u7684\u5185\u5bb9&#xff0c;\u4e0d\u8981\u7406\u89e3\u5b83\u662f\u4e2a\u6c60\u5b50&#xff0c;\u5176\u5b9e\u5c31\u662fClass\u6587\u4ef6\u4e2d\u7684\u5b57\u8282\u7801\u6307\u4ee4\u3002<\/p>\n<p>2\u3001\u8fd0\u884c\u65f6\u5e38\u91cf\u6c60&#xff08;Runtime Constant Pool&#xff09;<\/p>\n<p>JVM\u5185\u5b58\u4e2d\u65b9\u6cd5\u533a\u7684\u4e00\u90e8\u5206&#xff0c;\u8fd9\u662f\u8fd0\u884c\u65f6\u7684\u5185\u5bb9\u3002\u8fd9\u90e8\u5206\u5185\u5bb9&#xff08;\u7edd\u5927\u90e8\u5206&#xff09;\u662f\u968f\u7740JVM\u8fd0\u884c\u65f6\u5019&#xff0c;\u4ece\u5e38\u91cf\u6c60\u8f6c\u5316\u800c\u6765&#xff0c;\u6bcf\u4e2aClass\u5bf9\u5e94\u4e00\u4e2a\u8fd0\u884c\u65f6\u5e38\u91cf\u6c60\u3002\u4e0a\u4e00\u53e5\u4e2d\u8bf4\u7edd\u5927\u90e8\u5206\u662f\u56e0\u4e3a&#xff1a;\u9664\u4e86 Class\u4e2d\u5e38\u91cf\u6c60\u5185 \u5bb9&#xff0c;\u8fd8\u53ef\u80fd\u5305\u62ec\u52a8\u6001\u751f\u6210\u5e76\u52a0\u5165\u8fd9\u91cc\u7684\u5185\u5bb9\u3002<\/p>\n<p>3\u3001\u5b57\u7b26\u4e32\u5e38\u91cf\u6c60&#xff08;String Pool&#xff09;<\/p>\n<p>\u8fd9\u90e8\u5206\u4e5f\u5728\u65b9\u6cd5\u533a\u4e2d&#xff0c;\u4f46\u4e0eRuntime Constant Pool\u4e0d\u662f\u4e00\u4e2a\u6982\u5ff5&#xff0c;String Pool\u662fJVM\u5b9e\u4f8b\u5168\u5c40\u5171\u4eab\u7684&#xff0c;\u5168\u5c40\u53ea\u6709\u4e00\u4e2a\u3002JVM\u89c4\u8303\u8981\u6c42\u8fdb\u5165\u8fd9\u91cc\u7684String\u5b9e\u4f8b\u53eb\u201c\u88ab\u9a7b\u7559\u7684interned string\u201d&#xff0c;\u5404\u4e2aJVM\u53ef\u4ee5\u6709\u4e0d\u540c\u7684\u5b9e\u73b0&#xff0c;HotSpot\u662f\u8bbe\u7f6e\u4e86\u4e00\u4e2a\u54c8\u5e0c\u8868StringTable\u6765\u5f15\u7528\u5806\u4e2d\u7684\u5b57\u7b26\u4e32\u5b9e\u4f8b&#xff0c;\u88ab\u5f15\u7528\u5c31\u662f\u88ab\u9a7b\u7559\u3002<\/p>\n<p>\u3010\u4ea8\u5143\u6a21\u5f0f\u3011<\/p>\n<p>\u5176\u5b9e\u5b57\u7b26\u4e32\u5e38\u91cf\u6c60\u8fd9\u4e2a\u95ee\u9898\u6d89\u53ca\u5230\u4e00\u4e2a\u8bbe\u8ba1\u6a21\u5f0f&#xff0c;\u53eb\u201c\u4eab\u5143\u6a21\u5f0f\u201d&#xff0c;\u987e\u540d\u601d\u4e49 &#8211; &#8211; &#8211; &gt; \u5171\u4eab\u5143\u7d20\u6a21\u5f0f \u4e5f\u5c31\u662f\u8bf4&#xff1a;\u4e00\u4e2a\u7cfb\u7edf\u4e2d\u5982\u679c\u6709\u591a\u5904\u7528\u5230\u4e86\u76f8\u540c\u7684\u4e00\u4e2a\u5143\u7d20&#xff0c;\u90a3\u4e48\u6211\u4eec\u5e94\u8be5\u53ea\u5b58\u50a8\u4e00\u4efd\u6b64\u5143\u7d20&#xff0c;\u800c\u8ba9\u6240\u6709\u5730\u65b9\u90fd\u5f15\u7528\u8fd9\u4e00\u4e2a\u5143\u7d20<\/p>\n<p>Java\u4e2dString\u90e8\u5206\u5c31\u662f\u6839\u636e\u4eab\u5143\u6a21\u5f0f\u8bbe\u8ba1\u7684&#xff0c;\u800c\u90a3\u4e2a\u5b58\u50a8\u5143\u7d20\u7684\u5730\u65b9\u5c31\u53eb\u505a\u201c\u5b57\u7b26\u4e32\u5e38\u91cf\u6c60 &#8211; String Pool\u201d<\/p>\n<p>\u3010\u8be6\u7ec6\u5206\u6790\u3011<\/p>\n<\/p>\n<p>int x &#061; 10;<br \/>\nString y &#061; &#034;hello&#034;; <\/p>\n<p>\u2460\u00a0\u9996\u5148&#xff0c;\u00a010\u00a0\u548c\u00a0&#034;hello&#034;\u00a0\u4f1a\u5728\u7ecf\u8fc7javac&#xff08;\u6216\u8005\u5176\u4ed6\u7f16\u8bd1\u5668&#xff09;\u7f16\u8bd1\u8fc7\u540e\u53d8\u4e3aClass\u6587\u4ef6\u4e2d\u00a0constant_pool table\u00a0\u7684\u5185\u5bb9<\/p>\n<p>\u2461\u00a0\u5f53\u6211\u4eec\u7684\u7a0b\u5e8f\u8fd0\u884c\u65f6&#xff0c;\u4e5f\u5c31\u662f\u8bf4JVM\u8fd0\u884c\u65f6&#xff0c;\u6bcf\u4e2aClass constant_pool table \u4e2d\u7684\u5185\u5bb9\u4f1a\u88ab\u52a0\u8f7d\u5230JVM\u5185\u5b58\u4e2d\u7684\u65b9\u6cd5\u533a\u4e2d\u5404\u81eaClass\u7684 Runtime Constant Pool\u3002<\/p>\n<p>\u2462\u00a0\u4e00\u4e2a\u6ca1\u6709\u88abString Pool\u5305\u542b\u7684Runtime Constant Pool\u4e2d\u7684\u5b57\u7b26\u4e32&#xff08;\u8fd9\u91cc\u662f&#034;hello&#034;&#xff09;\u4f1a\u88ab\u52a0\u5165\u5230 String Pool\u4e2d&#xff08;HosSpot\u4f7f\u7528hashtable\u5f15\u7528\u65b9\u5f0f&#xff09;&#xff0c;\u6b65\u9aa4\u5982\u4e0b&#xff1a;<\/p>\n<li>\n<p>\u5728Java Heap&#xff08;\u5806&#xff09;\u4e2d\u6839\u636e&#034;hello&#034;\u5b57\u9762\u91cfcreate\u4e00\u4e2a\u5b57\u7b26\u4e32\u5bf9\u8c61<\/p>\n<\/li>\n<li>\n<p>\u5c06\u5b57\u9762\u91cf&#034;hello&#034;\u4e0e\u5b57\u7b26\u4e32\u5bf9\u8c61\u7684\u5f15\u7528\u5728hashtable\u4e2d\u5173\u8054\u8d77\u6765\u952e &#8211; \u503c<\/p>\n<p>\u5f62\u5f0f\u662f&#xff1a;&#034;hello&#034; &#061; \u5bf9\u8c61\u7684\u5f15\u7528\u5730\u5740\u3002<\/p>\n<\/li>\n<p>\u53e6\u5916\u6765\u8bf4&#xff0c;\u5f53\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32\u51fa\u73b0\u5728Runtime Constant Pool\u4e2d\u65f6\u600e\u4e48\u5224\u65ad\u9700\u4e0d\u9700\u8981\u5728Java Heap\u4e2d\u521b\u5efa \u65b0\u5bf9\u8c61\u5462&#xff1f;<\/p>\n<p>\u7b56\u7565\u662f\u8fd9\u6837&#xff1a;\u4f1a\u5148\u53bb\u6839\u636eequals\u6765\u6bd4\u8f83Runtime Constant Pool\u4e2d\u7684\u8fd9\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u548cString Pool\u4e2d\u67d0\u4e00\u4e2a\u662f\u76f8\u7b49\u7684&#xff08;\u4e5f\u5c31\u662f\u627e\u662f\u5426\u5df2\u7ecf\u5b58\u5728&#xff09;&#xff0c;\u5982\u679c\u6709\u90a3\u4e48\u5c31\u4e0d\u521b\u5efa&#xff0c;\u76f4\u63a5\u4f7f\u7528\u5176\u5f15\u7528&#xff1b;\u53cd\u4e4b&#xff0c;\u5c31\u5982\u540c\u4e0a\u9762\u7684\u7b2c\u4e09\u6b65\u3002<\/p>\n<p>\u5982\u6b64&#xff0c;\u5c31\u5b9e\u73b0\u4e86\u4eab\u5143\u6a21\u5f0f&#xff0c;\u63d0\u9ad8\u7684\u5185\u5b58\u5229\u7528\u6548\u7387\u3002<\/p>\n<p>\u4e3e\u4f8b&#xff1a;<\/p>\n<p>\u4f7f\u7528String s &#061; new String(&#034;hello&#034;);\u4f1a\u521b\u5efa\u51e0\u4e2a\u5bf9\u8c61 \u7b54&#xff1a;\u4f1a\u521b\u5efa2\u4e2a\u5bf9\u8c61<\/p>\n<p>\u9996\u5148&#xff0c;\u51fa\u73b0\u4e86\u5b57\u9762\u91cf&#034;hello&#034;&#xff0c;\u90a3\u4e48\u53bbString Pool\u4e2d\u67e5\u627e\u662f\u5426\u6709\u76f8\u540c\u5b57\u7b26\u4e32\u5b58\u5728&#xff0c;\u56e0\u4e3a\u7a0b\u5e8f\u5c31\u8fd9\u4e00\u884c\u4ee3\u7801\u6240\u4ee5\u80af\u5b9a\u6ca1\u6709&#xff0c;\u90a3\u4e48\u5c31\u5728Java Heap\u4e2d\u7528\u5b57\u9762\u91cf&#034;hello&#034;\u9996\u5148\u521b\u5efa1\u4e2aString\u5bf9\u8c61\u3002<\/p>\n<p>\u63a5\u7740&#xff0c;new String(&#034;hello&#034;)&#xff0c;\u5173\u952e\u5b57new\u53c8\u5728Java Heap\u4e2d\u521b\u5efa\u4e861\u4e2a\u5bf9\u8c61&#xff0c;\u7136\u540e\u8c03\u7528\u63a5\u6536String \u53c2\u6570\u7684\u6784\u9020\u5668\u8fdb\u884c\u4e86\u521d\u59cb\u5316\u3002\u6700\u7ec8s\u7684\u5f15\u7528\u662f\u8fd9\u4e2aString\u5bf9\u8c61.<\/p>\n<h3 id=\"stringbuilder\u548cstringbuffer\">StringBuilder\u548cStringBuffer<\/h3>\n<h4 id=\"_1\u3001\u6982\u8ff0\">1\u3001\u6982\u8ff0<\/h4>\n<p>\u3010\u6f14\u793a&#xff1a;\u67e5\u770b\u6e90\u7801\u53caAPI\u6587\u6863\u3011<\/p>\n<\/p>\n<p>public final class StringBuilder<br \/>\n    extends AbstractStringBuilder<br \/>\n    implements java.io.Serializable, CharSequence{<\/p>\n<p>} <\/p>\n<p>StringBuilder \u662f\u4e00\u4e2a\u53ef\u53d8\u7684\u5b57\u7b26\u5e8f\u5217\u3002\u5b83\u7ee7\u627f\u4e8eAbstractStringBuilder&#xff0c;\u5b9e\u73b0\u4e86CharSequence\u63a5\u53e3\u3002 StringBuffer \u4e5f\u662f\u7ee7\u627f\u4e8eAbstractStringBuilder\u7684\u5b50\u7c7b&#xff1b; \u4f46\u662f&#xff0c;StringBuilder\u548cStringBuffer\u4e0d\u540c&#xff0c;\u524d\u8005\u662f\u975e\u7ebf\u7a0b\u5b89\u5168\u7684&#xff0c;\u540e\u8005\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\u3002<\/p>\n<p>StringBuilder \u548c CharSequence\u4e4b\u95f4\u7684\u5173\u7cfb\u56fe\u5982\u4e0b&#xff1a;<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"385\" src=\"2026-01-14im2fls5t3to.png\" width=\"563\" \/><\/p>\n<p>\u3010\u6e90\u7801\u6982\u89c8\u3011<\/p>\n<\/p>\n<p>package java.lang;<br \/>\npublic final class StringBuilder<br \/>\n    extends AbstractStringBuilder<br \/>\n    implements java.io.Serializable, CharSequence {<\/p>\n<p>    static final long serialVersionUID &#061; 4383685877147921099L;<br \/>\n    \/\/ \u6784\u9020\u51fd\u6570\u3002\u9ed8\u8ba4\u7684\u5b57\u7b26\u6570\u7ec4\u5927\u5c0f\u662f16\u3002<br \/>\n    public StringBuilder() {<br \/>\n        super(16);<br \/>\n    }<\/p>\n<p>    \/\/ \u6784\u9020\u51fd\u6570\u3002\u6307\u5b9aStringBuilder\u7684\u5b57\u7b26\u6570\u7ec4\u5927\u5c0f\u662fcapacity\u3002<br \/>\n        public StringBuilder(int capacity) {<br \/>\n        super(capacity);<br \/>\n    }<\/p>\n<p>    \/\/ \u6784\u9020\u51fd\u6570\u3002\u6307\u5b9a\u5b57\u7b26\u6570\u7ec4\u5927\u5c0f&#061;str\u957f\u5ea6&#043;15&#xff0c;\u4e14\u5c06str\u7684\u503c\u8d4b\u503c\u5230\u5f53\u524d\u5b57\u7b26\u6570\u7ec4\u4e2d\u3002<br \/>\n    public StringBuilder(String str) {<br \/>\n        super(str.length() &#043; 16);<br \/>\n        append(str);<br \/>\n    }<\/p>\n<p>    \/\/ \u6784\u9020\u51fd\u6570\u3002\u6307\u5b9a\u5b57\u7b26\u6570\u7ec4\u5927\u5c0f&#061;seq\u957f\u5ea6&#043;15&#xff0c;\u4e14\u5c06seq\u7684\u503c\u8d4b\u503c\u5230\u5f53\u524d\u5b57\u7b26\u6570\u7ec4\u4e2d\u3002<br \/>\n    public StringBuilder(CharSequence seq) {<br \/>\n        this(seq.length() &#043; 16);<br \/>\n        append(seq);<br \/>\n    }<\/p>\n<p>    \/\/ \u8ffd\u52a0\u201c\u5bf9\u8c61obj\u5bf9\u5e94\u7684\u5b57\u7b26\u4e32\u201d\u3002String.valueOf(obj)\u5b9e\u9645\u4e0a\u662f\u8c03\u7528obj.toString()<br \/>\n    public StringBuilder append(Object obj) {<br \/>\n        return append(String.valueOf(obj));<br \/>\n    }<\/p>\n<p>    \/\/ \u8ffd\u52a0\u201cstr\u201d\u3002<br \/>\n    public StringBuilder append(String str) {<br \/>\n        super.append(str);<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>      \/\/ \u8ffd\u52a0\u201csb\u7684\u5185\u5bb9\u201d\u3002<br \/>\n    private StringBuilder append(StringBuilder sb) {<br \/>\n        if (sb &#061;&#061; null)<br \/>\n        return append(&#034;null&#034;);<br \/>\n        int len &#061; sb.length();<br \/>\n        int newcount &#061; count &#043; len;<br \/>\n        if (newcount &gt; value.length)<br \/>\n        expandCapacity(newcount);<br \/>\n        sb.getChars(0, len, value, count);<br \/>\n        count &#061; newcount;<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>    \/\/ \u8ffd\u52a0\u201csb\u7684\u5185\u5bb9\u201d\u3002<br \/>\n    public StringBuilder append(StringBuffer sb) {<br \/>\n        super.append(sb);<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>    \/\/ \u8ffd\u52a0\u201cs\u7684\u5185\u5bb9\u201d\u3002<br \/>\n    public StringBuilder append(CharSequence s) {<br \/>\n        if (s &#061;&#061; null)<br \/>\n            s &#061; &#034;null&#034;;<br \/>\n        if (s instanceof String)<br \/>\n            return this.append((String)s);<br \/>\n        if (s instanceof StringBuffer)<br \/>\n            return this.append((StringBuffer)s);<br \/>\n        if (s instanceof StringBuilder)<br \/>\n            return this.append((StringBuilder)s);<br \/>\n        return this.append(s, 0, s.length());<br \/>\n    }<\/p>\n<p>    \/\/ \u8ffd\u52a0\u201cs\u4ecestart(\u5305\u62ec)\u5230end(\u4e0d\u5305\u62ec)\u7684\u5185\u5bb9\u201d\u3002<br \/>\n    public StringBuilder append(CharSequence s, int start, int end) {<br \/>\n        super.append(s, start, end);<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>    \/\/ \u8ffd\u52a0\u201cstr\u5b57\u7b26\u6570\u7ec4\u5bf9\u5e94\u7684\u5b57\u7b26\u4e32\u201d<br \/>\n    public StringBuilder append(char[] str) {<br \/>\n        super.append(str);<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>    \/\/ \u8ffd\u52a0\u201cstr\u4eceoffset\u5f00\u59cb\u7684\u5185\u5bb9&#xff0c;\u5185\u5bb9\u957f\u5ea6\u662flen\u201d<br \/>\n    public StringBuilder append(char[] str, int offset, int len) {<br \/>\n        super.append(str, offset, len);<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>    \/\/ \u8ffd\u52a0\u201cb\u5bf9\u5e94\u7684\u5b57\u7b26\u4e32\u201d<br \/>\n    public StringBuilder append(boolean b) {<br \/>\n        super.append(b);<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>    \/\/ \u8ffd\u52a0\u201cc\u201d<br \/>\n    public StringBuilder append(char c) {<br \/>\n        super.append(c);<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>    \/\/ \u8ffd\u52a0\u201ci\u201d<br \/>\n    public StringBuilder append(int i) {<br \/>\n        super.append(i);<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>    \/\/ \u8ffd\u52a0\u201clng\u201d<br \/>\n    public StringBuilder append(long lng) {<br \/>\n        super.append(lng);<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>    \/\/ \u8ffd\u52a0\u201cf\u201d<br \/>\n    public StringBuilder append(float f) {<br \/>\n        super.append(f);<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>    \/\/ \u8ffd\u52a0\u201cd\u201d<br \/>\n    public StringBuilder append(double d) {<br \/>\n        super.append(d);<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>    \/\/ \u8ffd\u52a0\u201ccodePoint\u201d<br \/>\n    public StringBuilder appendCodePoint(int codePoint) {<br \/>\n        super.appendCodePoint(codePoint);<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>    \/\/ \u5220\u9664\u201c\u4ecestart(\u5305\u62ec)\u5230end\u7684\u5185\u5bb9\u201d<br \/>\n    public StringBuilder delete(int start, int end) {<br \/>\n        super.delete(start, end);<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>    \/\/ \u5220\u9664\u201c\u4f4d\u7f6eindex\u7684\u5185\u5bb9\u201d<br \/>\n    public StringBuilder deleteCharAt(int index) {<br \/>\n        super.deleteCharAt(index);<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>    \/\/ \u201c\u7528str\u66ff\u6362StringBuilder\u4e2d\u4ecestart(\u5305\u62ec)\u5230end(\u4e0d\u5305\u62ec)\u7684\u5185\u5bb9\u201d<br \/>\n    public StringBuilder replace(int start, int end, String str) {<br \/>\n        super.replace(start, end, str);<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>    \/\/ \u201c\u5728StringBuilder\u7684\u4f4d\u7f6eindex\u5904\u63d2\u5165\u2018str\u4e2d\u4eceoffset\u5f00\u59cb\u7684\u5185\u5bb9\u2019&#xff0c;\u63d2\u5165\u5185\u5bb9\u957f\u5ea6\u662flen\u201d<br \/>\n    public StringBuilder insert(int index, char[] str, int offset,<br \/>\n    int len)<br \/>\n    {<br \/>\n        super.insert(index, str, offset, len);<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>    \/\/ \u201c\u5728StringBuilder\u7684\u4f4d\u7f6eoffset\u5904\u63d2\u5165obj\u5bf9\u5e94\u7684\u5b57\u7b26\u4e32\u201d<br \/>\n    public StringBuilder insert(int offset, Object obj) {<br \/>\n    return insert(offset, String.valueOf(obj));<br \/>\n    }<\/p>\n<p>    \/\/ \u201c\u5728StringBuilder\u7684\u4f4d\u7f6eoffset\u5904\u63d2\u5165str\u201d<br \/>\n    public StringBuilder insert(int offset, String str) {<br \/>\n        super.insert(offset, str);<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>    \/\/ \u201c\u5728StringBuilder\u7684\u4f4d\u7f6eoffset\u5904\u63d2\u5165str\u201d<br \/>\n    public StringBuilder insert(int offset, char[] str) {<br \/>\n        super.insert(offset, str);<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>    \/\/ \u201c\u5728StringBuilder\u7684\u4f4d\u7f6edstOffset\u5904\u63d2\u5165s\u201d<br \/>\n    public StringBuilder insert(int dstOffset, CharSequence s) {<br \/>\n        if (s &#061;&#061; null)<br \/>\n        s &#061; &#034;null&#034;;<br \/>\n        if (s instanceof String)<br \/>\n        return this.insert(dstOffset, (String)s);<br \/>\n        return this.insert(dstOffset, s, 0, s.length());<br \/>\n    }<\/p>\n<p>    \/\/ \u201c\u5728StringBuilder\u7684\u4f4d\u7f6edstOffset\u5904\u63d2\u5165&#039;s\u4e2d\u4ecestart\u5230end\u7684\u5185\u5bb9&#039;\u201d<br \/>\n    public StringBuilder insert(int dstOffset, CharSequence s,<br \/>\n    int start, int end)<br \/>\n    {<br \/>\n        super.insert(dstOffset, s, start, end);<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>    \/\/ \u201c\u5728StringBuilder\u7684\u4f4d\u7f6eOffset\u5904\u63d2\u5165b\u201d<br \/>\n    public StringBuilder insert(int offset, boolean b) {<br \/>\n        super.insert(offset, b);<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>    \/\/ \u201c\u5728StringBuilder\u7684\u4f4d\u7f6eOffset\u5904\u63d2\u5165c\u201d<br \/>\n    public StringBuilder insert(int offset, char c) {<br \/>\n        super.insert(offset, c);<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>    \/\/ \u201c\u5728StringBuilder\u7684\u4f4d\u7f6eOffset\u5904\u63d2\u5165i\u201d<br \/>\n    public StringBuilder insert(int offset, int i) {<br \/>\n    return insert(offset, String.valueOf(i));<br \/>\n    }<\/p>\n<p>    \/\/ \u201c\u5728StringBuilder\u7684\u4f4d\u7f6eOffset\u5904\u63d2\u5165l\u201d<br \/>\n    public StringBuilder insert(int offset, long l) {<br \/>\n    return insert(offset, String.valueOf(l));<br \/>\n    }<\/p>\n<p>    \/\/ \u201c\u5728StringBuilder\u7684\u4f4d\u7f6eOffset\u5904\u63d2\u5165f\u201d<br \/>\n    public StringBuilder insert(int offset, float f) {<br \/>\n    return insert(offset, String.valueOf(f));<br \/>\n    }<\/p>\n<p>    \/\/ \u201c\u5728StringBuilder\u7684\u4f4d\u7f6eOffset\u5904\u63d2\u5165d\u201d<br \/>\n    public StringBuilder insert(int offset, double d) {<br \/>\n    return insert(offset, String.valueOf(d));<br \/>\n    }<\/p>\n<p>    \/\/ \u8fd4\u56de\u201cstr\u201d\u5728StringBuilder\u7684\u4f4d\u7f6e<br \/>\n    public int indexOf(String str) {<br \/>\n    return indexOf(str, 0);<br \/>\n    }<\/p>\n<p>    \/\/ \u4ecefromIndex\u5f00\u59cb\u67e5\u627e&#xff0c;\u8fd4\u56de\u201cstr\u201d\u5728StringBuilder\u7684\u4f4d\u7f6e<br \/>\n    public int indexOf(String str, int fromIndex) {<br \/>\n        return String.indexOf(value, 0, count,<br \/>\n        str.toCharArray(), 0, str.length(),fromIndex);<br \/>\n    }<\/p>\n<p>    \/\/ \u4ece\u540e\u5411\u524d\u67e5\u627e&#xff0c;\u8fd4\u56de\u201cstr\u201d\u5728StringBuilder\u7684\u4f4d\u7f6e<br \/>\n    public int lastIndexOf(String str) {<br \/>\n    return lastIndexOf(str, count);<br \/>\n    }<\/p>\n<p>    \/\/ \u4ecefromIndex\u5f00\u59cb&#xff0c;\u4ece\u540e\u5411\u524d\u67e5\u627e&#xff0c;\u8fd4\u56de\u201cstr\u201d\u5728StringBuilder\u7684\u4f4d\u7f6e<br \/>\n    public int lastIndexOf(String str, int fromIndex) {<br \/>\n    return String.lastIndexOf(value, 0, count,<br \/>\n    str.toCharArray(), 0, str.length(),fromIndex);<br \/>\n    }<\/p>\n<p>    \/\/ \u53cd\u8f6cStringBuilder<br \/>\n    public StringBuilder reverse() {<br \/>\n        super.reverse();<br \/>\n        return this;<br \/>\n    }<\/p>\n<p>    public String toString() {<br \/>\n    \/\/ Create a copy, don&#039;t share the array<br \/>\n    return new String(value, 0, count);<br \/>\n    }<\/p>\n<p>    \/\/ \u5e8f\u5217\u5316\u5bf9\u5e94\u7684\u5199\u5165\u51fd\u6570<br \/>\n    private void writeObject(java.io.ObjectOutputStream s)<br \/>\n        throws java.io.IOException {<br \/>\n            s.defaultWriteObject();<br \/>\n            s.writeInt(count);<br \/>\n            s.writeObject(value);<br \/>\n    }<\/p>\n<p>        \/\/ \u5e8f\u5217\u5316\u5bf9\u5e94\u7684\u8bfb\u53d6\u51fd\u6570<br \/>\n    private void readObject(java.io.ObjectInputStream s)<br \/>\n        throws java.io.IOException, ClassNotFoundException {<br \/>\n            s.defaultReadObject();<br \/>\n            count &#061; s.readInt();<br \/>\n            value &#061; (char[]) s.readObject();<br \/>\n    } <\/p>\n<h4 id=\"_2\u3001\u5e38\u7528\u65b9\u6cd5\">2\u3001\u5e38\u7528\u65b9\u6cd5<\/h4>\n<h5 id=\"insert\">insert<\/h5>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    StringBuilder sbuilder &#061; new StringBuilder();<br \/>\n    \/\/ \u5728\u4f4d\u7f6e0\u5904\u63d2\u5165\u5b57\u7b26\u6570\u7ec4<br \/>\n    sbuilder.insert(0, new char[]{&#039;a&#039;, &#039;b&#039;, &#039;c&#039;, &#039;d&#039;, &#039;e&#039;});<br \/>\n    \/\/ \u5728\u4f4d\u7f6e0\u5904\u63d2\u5165\u5b57\u7b26\u6570\u7ec4\u30020\u8868\u793a\u5b57\u7b26\u6570\u7ec4\u8d77\u59cb\u4f4d\u7f6e&#xff0c;3\u8868\u793a\u957f\u5ea6<br \/>\n    sbuilder.insert(0, new char[]{&#039;A&#039;, &#039;B&#039;, &#039;C&#039;, &#039;D&#039;, &#039;E&#039;}, 0, 3);<br \/>\n    \/\/ \u5728\u4f4d\u7f6e0\u5904\u63d2\u5165float<br \/>\n    sbuilder.insert(0, 1.414f);<br \/>\n    \/\/ \u5728\u4f4d\u7f6e0\u5904\u63d2\u5165double<br \/>\n    sbuilder.insert(0, 3.14159d);<br \/>\n    \/\/ \u5728\u4f4d\u7f6e0\u5904\u63d2\u5165boolean<br \/>\n    sbuilder.insert(0, true);<br \/>\n    \/\/ \u5728\u4f4d\u7f6e0\u5904\u63d2\u5165char<br \/>\n    sbuilder.insert(0, &#039;\\\\n&#039;);<br \/>\n    \/\/ \u5728\u4f4d\u7f6e0\u5904\u63d2\u5165int<br \/>\n    sbuilder.insert(0, 100);<br \/>\n    \/\/ \u5728\u4f4d\u7f6e0\u5904\u63d2\u5165long<br \/>\n    sbuilder.insert(0, 12345L);<br \/>\n    \/\/ \u5728\u4f4d\u7f6e0\u5904\u63d2\u5165StringBuilder\u5bf9\u8c61<br \/>\n    sbuilder.insert(0, new StringBuilder(&#034;StringBuilder&#034;));<br \/>\n    \/\/ \u5728\u4f4d\u7f6e0\u5904\u63d2\u5165StringBuilder\u5bf9\u8c61\u30026\u8868\u793a\u88ab\u5728\u4f4d\u7f6e0\u5904\u63d2\u5165\u5bf9\u8c61\u7684\u8d77\u59cb\u4f4d\u7f6e(\u5305\u62ec)&#xff0c;13\u662f\u7ed3\u675f\u4f4d\u7f6e(\u4e0d\u5305\u62ec)<br \/>\n    sbuilder.insert(0, new StringBuilder(&#034;STRINGBUILDER&#034;), 6, 13);<br \/>\n    \/\/ \u5728\u4f4d\u7f6e0\u5904\u63d2\u5165StringBuffer\u5bf9\u8c61\u3002<br \/>\n    sbuilder.insert(0, new StringBuffer(&#034;StringBuffer&#034;));<br \/>\n    \/\/ \u5728\u4f4d\u7f6e0\u5904\u63d2\u5165StringBuffer\u5bf9\u8c61\u30026\u8868\u793a\u88ab\u5728\u4f4d\u7f6e0\u5904\u63d2\u5165\u5bf9\u8c61\u7684\u8d77\u59cb\u4f4d\u7f6e(\u5305\u62ec)&#xff0c;12\u662f\u7ed3\u675f\u4f4d\u7f6e(\u4e0d\u5305\u62ec)<br \/>\n    sbuilder.insert(0, new StringBuffer(&#034;STRINGBUFFER&#034;), 6, 12);<br \/>\n    \/\/ \u5728\u4f4d\u7f6e0\u5904\u63d2\u5165String\u5bf9\u8c61\u3002<br \/>\n    sbuilder.insert(0, &#034;String&#034;);<br \/>\n    \/\/ \u5728\u4f4d\u7f6e0\u5904\u63d2\u5165String\u5bf9\u8c61\u30021\u8868\u793a\u88ab\u5728\u4f4d\u7f6e0\u5904\u63d2\u5165\u5bf9\u8c61\u7684\u8d77\u59cb\u4f4d\u7f6e(\u5305\u62ec)&#xff0c;6\u662f\u7ed3\u675f\u4f4d\u7f6e(\u4e0d\u5305\u62ec)<br \/>\n    sbuilder.insert(0, &#034;0123456789&#034;, 1, 6);<br \/>\n    sbuilder.insert(0, &#039;\\\\n&#039;);<\/p>\n<p>    \/\/ \u5728\u4f4d\u7f6e0\u5904\u63d2\u5165Object\u5bf9\u8c61\u3002\u6b64\u5904\u4ee5HashMap\u4e3a\u4f8b<br \/>\n    HashMap map &#061; new HashMap();<br \/>\n    map.put(&#034;1&#034;, &#034;one&#034;);<br \/>\n    map.put(&#034;2&#034;, &#034;two&#034;);<br \/>\n    map.put(&#034;3&#034;, &#034;three&#034;);<\/p>\n<p>    sbuilder.insert(0, map);<\/p>\n<p>    System.out.printf(&#034;%s\\\\n\\\\n&#034;, sbuilder);<br \/>\n} <\/p>\n<h5 id=\"append\">append<\/h5>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    StringBuilder sbuilder &#061; new StringBuilder();<br \/>\n    \/\/ \u8ffd\u52a0\u5b57\u7b26\u6570\u7ec4<br \/>\n    sbuilder.append(new char[]{&#039;a&#039;, &#039;b&#039;, &#039;c&#039;, &#039;d&#039;, &#039;e&#039;});<br \/>\n    \/\/ \u8ffd\u52a0\u5b57\u7b26\u6570\u7ec4\u30020\u8868\u793a\u5b57\u7b26\u6570\u7ec4\u8d77\u59cb\u4f4d\u7f6e&#xff0c;3\u8868\u793a\u957f\u5ea6<br \/>\n    sbuilder.append(new char[]{&#039;A&#039;, &#039;B&#039;, &#039;C&#039;, &#039;D&#039;, &#039;E&#039;}, 0, 3);<br \/>\n    \/\/ \u8ffd\u52a0float<br \/>\n    sbuilder.append(1.414f);<br \/>\n    \/\/ \u8ffd\u52a0double<br \/>\n    sbuilder.append(3.14159d);<br \/>\n    \/\/ \u8ffd\u52a0boolean<br \/>\n    sbuilder.append(true);<br \/>\n    \/\/ \u8ffd\u52a0char<br \/>\n    sbuilder.append(&#039;\\\\n&#039;);<br \/>\n    \/\/ \u8ffd\u52a0int<br \/>\n    sbuilder.append(100);<br \/>\n    \/\/ \u8ffd\u52a0long<br \/>\n    sbuilder.append(12345L);<br \/>\n    \/\/ \u8ffd\u52a0StringBuilder\u5bf9\u8c61<br \/>\n    sbuilder.append(new StringBuilder(&#034;StringBuilder&#034;));<br \/>\n    \/\/ \u8ffd\u52a0StringBuilder\u5bf9\u8c61\u30026\u8868\u793a\u88ab\u8ffd\u52a0\u5bf9\u8c61\u7684\u8d77\u59cb\u4f4d\u7f6e(\u5305\u62ec)&#xff0c;13\u662f\u7ed3\u675f\u4f4d\u7f6e(\u4e0d\u5305\u62ec)<br \/>\n    sbuilder.append(new StringBuilder(&#034;STRINGBUILDER&#034;), 6, 13);<br \/>\n    \/\/ \u8ffd\u52a0StringBuffer\u5bf9\u8c61\u3002<br \/>\n    sbuilder.append(new StringBuffer(&#034;StringBuffer&#034;));<br \/>\n    \/\/ \u8ffd\u52a0StringBuffer\u5bf9\u8c61\u30026\u8868\u793a\u88ab\u8ffd\u52a0\u5bf9\u8c61\u7684\u8d77\u59cb\u4f4d\u7f6e(\u5305\u62ec)&#xff0c;12\u662f\u7ed3\u675f\u4f4d\u7f6e(\u4e0d\u5305\u62ec)<br \/>\n    sbuilder.append(new StringBuffer(&#034;STRINGBUFFER&#034;), 6, 12);<br \/>\n    \/\/ \u8ffd\u52a0String\u5bf9\u8c61\u3002<br \/>\n    sbuilder.append(&#034;String&#034;);<br \/>\n    \/\/ \u8ffd\u52a0String\u5bf9\u8c61\u30021\u8868\u793a\u88ab\u8ffd\u52a0\u5bf9\u8c61\u7684\u8d77\u59cb\u4f4d\u7f6e(\u5305\u62ec)&#xff0c;6\u662f\u7ed3\u675f\u4f4d\u7f6e(\u4e0d\u5305\u62ec)<br \/>\n    sbuilder.append(&#034;0123456789&#034;, 1, 6);<\/p>\n<p>    sbuilder.append(&#039;\\\\n&#039;);<\/p>\n<p>    \/\/ \u8ffd\u52a0Object\u5bf9\u8c61\u3002\u6b64\u5904\u4ee5HashMap\u4e3a\u4f8b<br \/>\n    HashMap map &#061; new HashMap();<br \/>\n    map.put(&#034;1&#034;, &#034;one&#034;);<br \/>\n    map.put(&#034;2&#034;, &#034;two&#034;);<br \/>\n    map.put(&#034;3&#034;, &#034;three&#034;);<br \/>\n    sbuilder.append(map);<br \/>\n    sbuilder.append(&#039;\\\\n&#039;);<\/p>\n<p>    \/\/ \u8ffd\u52a0unicode\u7f16\u7801<br \/>\n    sbuilder.appendCodePoint(0x5b57); \/\/ 0x5b57\u662f\u201c\u5b57\u201d\u7684unicode\u7f16\u7801<br \/>\n    sbuilder.appendCodePoint(0x7b26); \/\/ 0x7b26\u662f\u201c\u7b26\u201d\u7684unicode\u7f16\u7801<br \/>\n    sbuilder.appendCodePoint(0x7f16); \/\/ 0x7f16\u662f\u201c\u7f16\u201d\u7684unicode\u7f16\u7801<br \/>\n    sbuilder.appendCodePoint(0x7801); \/\/ 0x7801\u662f\u201c\u7801\u201d\u7684unicode\u7f16\u7801<\/p>\n<p>    System.out.printf(&#034;%s\\\\n\\\\n&#034;, sbuilder);<br \/>\n} <\/p>\n<h5 id=\"replace\">replace<\/h5>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    StringBuilder sbuilder;<\/p>\n<p>    sbuilder &#061; new StringBuilder(&#034;0123456789&#034;);<br \/>\n    sbuilder.replace(0, 3, &#034;ABCDE&#034;);<br \/>\n    System.out.printf(&#034;sbuilder&#061;%s\\\\n&#034;, sbuilder);<\/p>\n<p>    sbuilder &#061; new StringBuilder(&#034;0123456789&#034;);<br \/>\n    sbuilder.reverse();<br \/>\n    System.out.printf(&#034;sbuilder&#061;%s\\\\n&#034;, sbuilder);<\/p>\n<p>    sbuilder &#061; new StringBuilder(&#034;0123456789&#034;);<br \/>\n    sbuilder.setCharAt(0, &#039;M&#039;);<br \/>\n    System.out.printf(&#034;sbuilder&#061;%s\\\\n&#034;, sbuilder);<br \/>\n    System.out.println();<br \/>\n    \/*<br \/>\n    sbuilder&#061;ABCDE3456789<br \/>\n    sbuilder&#061;9876543210<br \/>\n    sbuilder&#061;M123456789<br \/>\n*\/<br \/>\n} <\/p>\n<h5 id=\"delete\">delete<\/h5>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    StringBuilder sbuilder &#061; new StringBuilder(&#034;0123456789&#034;);<\/p>\n<p>    \/\/ \u5220\u9664\u4f4d\u7f6e0\u7684\u5b57\u7b26&#xff0c;\u5269\u4f59\u5b57\u7b26\u662f\u201c123456789\u201d\u3002<br \/>\n    sbuilder.deleteCharAt(0);<br \/>\n    \/\/ \u5220\u9664\u4f4d\u7f6e3(\u5305\u62ec)\u5230\u4f4d\u7f6e6(\u4e0d\u5305\u62ec)\u4e4b\u95f4\u7684\u5b57\u7b26&#xff0c;\u5269\u4f59\u5b57\u7b26\u662f\u201c123789\u201d\u3002<br \/>\n    sbuilder.delete(3, 6);<\/p>\n<p>    \/\/ \u83b7\u53d6sb\u4e2d\u4ece\u4f4d\u7f6e1\u5f00\u59cb\u7684\u5b57\u7b26\u4e32<br \/>\n    String str1 &#061; sbuilder.substring(1);<br \/>\n    \/\/ \u83b7\u53d6sb\u4e2d\u4ece\u4f4d\u7f6e3(\u5305\u62ec)\u5230\u4f4d\u7f6e5(\u4e0d\u5305\u62ec)\u4e4b\u95f4\u7684\u5b57\u7b26\u4e32<br \/>\n    String str2 &#061; sbuilder.substring(3, 5);<br \/>\n    \/\/ \u83b7\u53d6sb\u4e2d\u4ece\u4f4d\u7f6e3(\u5305\u62ec)\u5230\u4f4d\u7f6e5(\u4e0d\u5305\u62ec)\u4e4b\u95f4\u7684\u5b57\u7b26\u4e32&#xff0c;\u83b7\u53d6\u7684\u5bf9\u8c61\u662fCharSequence\u5bf9\u8c61&#xff0c;\u6b64\u5904\u8f6c\u578b\u4e3aString<br \/>\n    String str3 &#061; (String) sbuilder.subSequence(3, 5);<\/p>\n<p>    System.out.printf(&#034;sbuilder&#061;%s\\\\nstr1&#061;%s\\\\nstr2&#061;%s\\\\nstr3&#061;%s\\\\n&#034;,<br \/>\n            sbuilder, str1, str2, str3);<\/p>\n<p>} <\/p>\n<h5 id=\"index\">index<\/h5>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    StringBuilder sbuilder &#061; new StringBuilder(&#034;abcAbcABCabCaBcAbCaBCabc&#034;);<\/p>\n<p>    System.out.printf(&#034;sbuilder&#061;%s\\\\n&#034;, sbuilder);<\/p>\n<p>    \/\/ 1. \u4ece\u524d\u5f80\u540e&#xff0c;\u627e\u51fa&#034;bc&#034;\u7b2c\u4e00\u6b21\u51fa\u73b0\u7684\u4f4d\u7f6e<br \/>\n    System.out.printf(&#034;%-30s &#061; %d\\\\n&#034;, &#034;sbuilder.indexOf(\\\\&#034;bc\\\\&#034;)&#034;, sbuilder.indexOf(&#034;bc&#034;));<\/p>\n<p>    \/\/ 2. \u4ece\u4f4d\u7f6e5\u5f00\u59cb&#xff0c;\u4ece\u524d\u5f80\u540e&#xff0c;\u627e\u51fa&#034;bc&#034;\u7b2c\u4e00\u6b21\u51fa\u73b0\u7684\u4f4d\u7f6e<br \/>\n    System.out.printf(&#034;%-30s &#061; %d\\\\n&#034;, &#034;sbuilder.indexOf(\\\\&#034;bc\\\\&#034;, 5)&#034;, sbuilder.indexOf(&#034;bc&#034;, 5));<\/p>\n<p>    \/\/ 3. \u4ece\u540e\u5f80\u524d&#xff0c;\u627e\u51fa&#034;bc&#034;\u7b2c\u4e00\u6b21\u51fa\u73b0\u7684\u4f4d\u7f6e<br \/>\n    System.out.printf(&#034;%-30s &#061; %d\\\\n&#034;, &#034;sbuilder.lastIndexOf(\\\\&#034;bc\\\\&#034;)&#034;, sbuilder.lastIndexOf(&#034;bc&#034;));<\/p>\n<p>    \/\/ 4. \u4ece\u4f4d\u7f6e4\u5f00\u59cb&#xff0c;\u4ece\u540e\u5f80\u524d&#xff0c;\u627e\u51fa&#034;bc&#034;\u7b2c\u4e00\u6b21\u51fa\u73b0\u7684\u4f4d\u7f6e<br \/>\n    System.out.printf(&#034;%-30s &#061; %d\\\\n&#034;, &#034;sbuilder.lastIndexOf(\\\\&#034;bc\\\\&#034;, 4)&#034;, sbuilder.lastIndexOf(&#034;bc&#034;, 4));<br \/>\n} <\/p>\n<h5 id=\"\u5176\u4ed6api\">\u5176\u4ed6API<\/h5>\n<\/p>\n<p>public static void main(String[] args) {<br \/>\n    StringBuilder sbuilder &#061; new StringBuilder(&#034;0123456789&#034;);<\/p>\n<p>    int cap &#061; sbuilder.capacity();<br \/>\n    System.out.printf(&#034;cap&#061;%d\\\\n&#034;, cap);<\/p>\n<p>    \/*<br \/>\n    capacity()\u8fd4\u56de\u7684\u662f\u5b57\u7b26\u4e32\u7f13\u51b2\u533a\u7684\u5bb9\u91cf<br \/>\n    StringBuffer( ); \u5206\u914d16\u4e2a\u5b57\u7b26\u7684\u7f13\u51b2\u533a<br \/>\n    StringBuffer( int len ); \u5206\u914dlen\u4e2a\u5b57\u7b26\u7684\u7f13\u51b2\u533a<br \/>\n    StringBuffer( String s ); \u9664\u4e86\u6309\u7167s\u7684\u5927\u5c0f\u5206\u914d\u7a7a\u95f4\u5916,\u518d\u5206\u914d16\u4e2a \u5b57\u7b26\u7684\u7f13\u51b2\u533a<br \/>\n    \u4f60\u7684StringBuffer\u662f\u7528\u5b57\u7b26\u6784\u9020\u7684&#xff0c;&#034;0123456789&#034;\u7684\u957f\u5ea6\u662f10\u53e6\u5916\u518d\u5206\u914d16\u4e2a\u5b57\u7b26&#xff0c;\u6240\u4ee5\u4e00\u5171\u662f26\u3002<br \/>\n    *\/<\/p>\n<p>    char c &#061; sbuilder.charAt(6);<br \/>\n    System.out.printf(&#034;c&#061;%c\\\\n&#034;, c);<\/p>\n<p>    char[] carr &#061; new char[4];<br \/>\n    sbuilder.getChars(3, 7, carr, 0);<br \/>\n    for (int i &#061; 0; i &lt; carr.length; i&#043;&#043;) {<br \/>\n        System.out.printf(&#034;carr[%d]&#061;%c &#034;, i, carr[i]);<br \/>\n    }<br \/>\n    System.out.println();<\/p>\n<p>} <\/p>\n<h4 id=\"_3\u3001stringbuffer\">3\u3001StringBuffer<\/h4>\n<p>\u548cStringBulider\u7528\u6cd5\u5dee\u4e0d\u591a&#xff0c;\u4e0d\u8fc7\u591a\u4ecb\u7ecd&#xff0c;\u4e3b\u8981\u770b\u4e00\u4e0b\u4e09\u8005\u7684\u533a\u522b<\/p>\n<p>StringBuffer\u662f\u7ebf\u7a0b\u5b89\u5168\u7684&#xff0c;\u63a8\u8350\u5728\u591a\u7ebf\u7a0b\u91cc\u4f7f\u7528\u3002<\/p>\n<h4 id=\"_4\u3001\u5c0f\u7ed3\">4\u3001\u5c0f\u7ed3<\/h4>\n<p>String\u3001StringBuffer\u3001StringBuilder\u4e4b\u95f4\u7684\u533a\u522b<\/p>\n<p>\u9996\u5148\u9700\u8981\u8bf4\u660e\u7684\u662f&#xff1a;<\/p>\n<ul>\n<li>String \u5b57\u7b26\u4e32\u5e38\u91cf<\/li>\n<li>StringBuffer \u5b57\u7b26\u4e32\u53d8\u91cf&#xff08;\u7ebf\u7a0b\u5b89\u5168&#xff09;<\/li>\n<li>StringBuilder \u5b57\u7b26\u4e32\u53d8\u91cf&#xff08;\u975e\u7ebf\u7a0b\u5b89\u5168&#xff09;<\/li>\n<\/ul>\n<p>\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u4e09\u8005\u5728\u6267\u884c\u901f\u5ea6\u65b9\u9762\u7684\u6bd4\u8f83&#xff1a;StringBuilder &gt; StringBuffer &gt; String<\/p>\n<p>\u89e3\u91ca&#xff1a;<\/p>\n<p>String \u7c7b\u578b\u548c StringBuffer \u7c7b\u578b\u7684\u4e3b\u8981\u6027\u80fd\u533a\u522b\u5176\u5b9e\u5728\u4e8e String \u662f\u4e0d\u53ef\u53d8\u7684\u5bf9\u8c61&#xff0c;\u56e0\u6b64\u5728\u6bcf\u6b21\u5bf9 String \u7c7b\u578b\u8fdb\u884c\u6539\u53d8\u7684\u65f6\u5019\u5176\u5b9e\u90fd\u7b49\u540c\u4e8e\u751f\u6210\u4e86\u4e00\u4e2a\u65b0\u7684 String \u5bf9\u8c61&#xff0c;\u7136\u540e\u5c06\u6307\u9488\u6307\u5411\u65b0\u7684 String \u5bf9\u8c61&#xff0c;\u6240\u4ee5\u7ecf\u5e38\u6539\u53d8\u5185\u5bb9\u7684\u5b57\u7b26\u4e32\u6700\u597d\u4e0d\u8981\u7528 String &#xff0c;\u56e0\u4e3a\u6bcf\u6b21\u751f\u6210\u5bf9\u8c61\u90fd\u4f1a\u5bf9\u7cfb\u7edf\u6027\u80fd\u4ea7\u751f\u5f71\u54cd&#xff0c;\u7279\u522b\u5f53\u5185\u5b58\u4e2d\u65e0\u5f15\u7528\u5bf9\u8c61\u591a\u4e86\u4ee5\u540e&#xff0c; JVM \u7684 GC \u5c31\u4f1a\u5f00\u59cb\u5de5\u4f5c&#xff0c;\u90a3\u901f\u5ea6\u662f\u4e00\u5b9a\u4f1a\u76f8\u5f53\u6162\u7684\u3002<\/p>\n<p>\u800c\u5982\u679c\u662f\u4f7f\u7528 StringBuffer \u7c7b\u5219\u7ed3\u679c\u5c31\u4e0d\u4e00\u6837\u4e86&#xff0c;\u6bcf\u6b21\u7ed3\u679c\u90fd\u4f1a\u5bf9 StringBuffer \u5bf9\u8c61\u672c\u8eab\u8fdb\u884c\u64cd\u4f5c&#xff0c;\u800c\u4e0d\u662f\u751f\u6210\u65b0\u7684\u5bf9\u8c61&#xff0c;\u518d\u6539\u53d8\u5bf9\u8c61\u5f15\u7528\u3002\u6240\u4ee5\u5728\u4e00\u822c\u60c5\u51b5\u4e0b\u6211\u4eec\u63a8\u8350\u4f7f\u7528 StringBuffer &#xff0c;\u7279\u522b\u662f\u5b57\u7b26\u4e32\u5bf9\u8c61\u7ecf\u5e38\u6539\u53d8\u7684\u60c5\u51b5\u4e0b\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48\u662f\u5927\u591a\u6570\u60c5\u51b5\u5462&#xff1f;<\/p>\n<p>\u5728\u67d0\u4e9b\u7279\u522b\u60c5\u51b5\u4e0b&#xff0c; String \u5bf9\u8c61\u7684\u5b57\u7b26\u4e32\u62fc\u63a5\u5176\u5b9e\u662f\u88ab JVM \u89e3\u91ca\u6210\u4e86 StringBuffer \u5bf9\u8c61\u7684\u62fc\u63a5&#xff0c; \u6240\u4ee5\u8fd9\u4e9b\u65f6\u5019 String \u5bf9\u8c61\u7684\u901f\u5ea6\u5e76\u4e0d\u4f1a\u6bd4 StringBuffer \u5bf9\u8c61\u6162&#xff0c;\u800c\u7279\u522b\u662f\u4ee5\u4e0b\u7684\u5b57\u7b26\u4e32\u5bf9\u8c61\u751f\u6210\u4e2d&#xff0c; String \u6548\u7387\u662f\u8fdc\u8981\u6bd4 StringBuffer \u5feb\u7684&#xff1a;<\/p>\n<\/p>\n<p>String S1 &#061; \u201cThis is only a\u201d &#043; \u201c simple\u201d &#043; \u201c test\u201d;<br \/>\nStringBuffer Sb &#061; new StringBuilder(\u201cThis is only a\u201d).append(\u201csimple\u201d).append(\u201c test\u201d); <\/p>\n<p>\u4f60\u4f1a\u5f88\u60ca\u8bb6\u7684\u53d1\u73b0&#xff0c;\u751f\u6210 String S1 \u5bf9\u8c61\u7684\u901f\u5ea6\u7b80\u76f4\u592a\u5feb\u4e86&#xff0c;\u800c\u8fd9\u4e2a\u65f6\u5019 StringBuffer \u5c45\u7136\u901f\u5ea6\u4e0a\u6839\u672c \u4e00\u70b9\u90fd\u4e0d\u5360\u4f18\u52bf\u3002\u5176\u5b9e\u8fd9\u662f JVM \u7684\u4e00\u4e2a\u628a\u620f&#xff0c;\u5728 JVM \u773c\u91cc&#xff0c;\u8fd9\u4e2a<\/p>\n<p>String S1 &#061; \u201cThis is only a\u201d &#043; \u201c simple\u201d &#043; \u201ctest\u201d;<\/p>\n<p>\u5176\u5b9e\u5c31\u662f&#xff1a;String S1 &#061; \u201cThis is only a simple test\u201d;<\/p>\n<p>\u6240\u4ee5\u5f53\u7136\u4e0d\u9700\u8981\u592a\u591a\u7684\u65f6\u95f4\u4e86\u3002\u4f46\u5927\u5bb6\u8fd9\u91cc\u8981\u6ce8\u610f\u7684\u662f&#xff0c;\u5982\u679c\u4f60\u7684\u5b57\u7b26\u4e32\u662f\u6765\u81ea\u53e6\u5916\u7684 String \u5bf9\u8c61 \u7684\u8bdd&#xff0c;\u901f\u5ea6\u5c31\u6ca1\u90a3\u4e48\u5feb\u4e86&#xff0c;\u8b6c\u5982&#xff1a;<\/p>\n<p>String S2 &#061; \u201cThis is only a\u201d; String S3 &#061; \u201c simple\u201d; String S4 &#061; \u201c test\u201d;<\/p>\n<p>\u5927\u90e8\u5206\u60c5\u51b5\u4e0bStringBuilder\u7684\u901f\u5ea6\u8981\u5927\u4e8eStringBuffer&#xff1a;<\/p>\n<p>java.lang.StringBuilder\u4e00\u4e2a\u53ef\u53d8\u7684\u5b57\u7b26\u5e8f\u5217\u662f5.0\u65b0\u589e\u7684\u3002&#xff08;\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u5c31\u662f\u6211\u4eec\u662f\u5728\u5355\u7ebf\u7a0b\u4e0b\u8fdb\u884c\u7684\u64cd\u4f5c&#xff0c;\u6240\u4ee5\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u662f\u5efa\u8bae\u7528StringBuilder\u800c\u4e0d\u7528StringBuffer\u7684&#xff09;\u6b64\u7c7b\u63d0\u4f9b\u4e00\u4e2a\u4e0e StringBuffer \u517c\u5bb9\u7684 API&#xff0c;\u4f46\u4e0d\u4fdd\u8bc1\u540c\u6b65\u3002\u8be5\u7c7b\u88ab\u8bbe\u8ba1\u7528\u4f5c StringBuffer \u7684\u4e00\u4e2a\u7b80\u6613\u66ff\u6362&#xff0c;\u7528\u5728\u5b57\u7b26\u4e32\u7f13\u51b2\u533a\u88ab\u5355\u4e2a \u7ebf\u7a0b\u4f7f\u7528\u7684\u65f6\u5019&#xff08;\u8fd9\u79cd\u60c5\u51b5\u5f88\u666e\u904d&#xff09;\u3002\u5982\u679c\u53ef\u80fd&#xff0c;\u5efa\u8bae\u4f18\u5148\u91c7\u7528\u8be5\u7c7b&#xff0c;\u56e0\u4e3a\u5728\u5927\u591a\u6570\u5b9e\u73b0\u4e2d&#xff0c;\u5b83\u6bd4 StringBuffer \u8981\u5feb\u3002\u4e24\u8005\u7684\u65b9\u6cd5\u57fa\u672c\u76f8\u540c\u3002<\/p>\n<p>\u5bf9\u4e8e\u4e09\u8005\u4f7f\u7528\u7684\u603b\u7ed3&#xff1a;<\/p>\n<ul>\n<li>\u5982\u679c\u8981\u64cd\u4f5c\u5c11\u91cf\u7684\u6570\u636e\u7528 &#xff1a;String<\/li>\n<li>\u5355\u7ebf\u7a0b\u64cd\u4f5c\u5b57\u7b26\u4e32\u7f13\u51b2\u533a \u4e0b\u64cd\u4f5c\u5927\u91cf\u6570\u636e &#xff1a;StringBuilder<\/li>\n<li>\u591a\u7ebf\u7a0b\u64cd\u4f5c\u5b57\u7b26\u4e32\u7f13\u51b2\u533a \u4e0b\u64cd\u4f5c\u5927\u91cf\u6570\u636e &#xff1a; StringBuffer<\/li>\n<\/ul>\n<h4 id=\"_5\u3001\u9762\u8bd5\u9898\u7684\u56de\u7b54\">5\u3001\u9762\u8bd5\u9898\u7684\u56de\u7b54<\/h4>\n<p>StringBuilder \u4e0eStringBuffer\u7684\u533a\u522b&#xff0c;StringBuilder\u4e0eString\u7684\u533a\u522b\u3002<\/p>\n<p>1&#xff09;StringBuilder\u6548\u7387\u9ad8&#xff0c;\u7ebf\u7a0b\u4e0d\u5b89\u5168&#xff0c;StringBuffer\u5bf9\u6bd4\u4e4b\u4e0b\u6ca1\u5b83\u9ad8&#xff0c;\u7ebf\u7a0b\u5b89\u5168\u3002<\/p>\n<p>2&#xff09;String\u662f\u4e0d\u53ef\u53d8\u5b57\u7b26\u4e32&#xff0c;StringBuilder\u662f\u53ef\u53d8\u5b57\u7b26\u4e32\u3002\u4e3a\u4ec0\u4e48\u6709\u8fd9\u6837\u7684\u5dee\u5f02&#xff0c;\u53ef\u4ee5\u6df1\u5165\u6e90\u7801\u53bb\u89e3\u6790&#xff0c; \u6bd4\u5982String\u7c7b\u5185\u7684 priver final char value[] \u7b49\u65b9\u6cd5\u7684\u539f\u56e0\u3002<\/p>\n<p>3&#xff09;\u5982\u679c\u662f\u7b80\u5355\u7684\u58f0\u660e\u4e00\u4e2a\u5b57\u7b26\u4e32\u6ca1\u6709\u540e\u7eed\u8fc7\u591a\u7684\u64cd\u4f5c&#xff0c;\u4f7f\u7528String,StringBuilder\u5747\u53ef&#xff0c;\u82e5\u540e\u7eed\u5bf9\u5b57\u7b26\u7a7f\u505a\u9891\u7e41\u7684\u6dfb\u52a0&#xff0c;\u5220\u9664\u64cd\u4f5c,\u6216\u8005\u662f\u5728\u5faa\u73af\u5f53\u4e2d\u52a8\u6001\u7684\u6539\u53d8\u5b57\u7b26\u7a7f\u7684\u957f\u5ea6\u5e94\u8be5\u7528StringBuilder\u3002\u4f7f\u7528String \u4f1a\u4ea7\u751f\u591a\u4f59\u7684\u5b57\u7b26\u4e32&#xff0c;\u5360\u7528\u5185\u5b58\u7a7a\u95f4\u3002<\/p>\n<h3 id=\"file\u7c7b\">File\u7c7b<\/h3>\n<h4 id=\"_1\u3001file\u7c7b\u7684\u57fa\u672c\u7528\u6cd5\">1\u3001File\u7c7b\u7684\u57fa\u672c\u7528\u6cd5<\/h4>\n<p>java.io.File\u7c7b&#xff1a;\u6587\u4ef6\u548c\u76ee\u5f55\u8def\u5f84\u540d\u7684\u62bd\u8c61\u8868\u793a\u5f62\u5f0f\u3002<\/p>\n<p>File\u7c7b\u7684\u5e38\u89c1\u6784\u9020\u65b9\u6cd5&#xff1a;<\/p>\n<\/p>\n<p>public File(String pathname) <\/p>\n<p>\u4ee5pathname\u4e3a\u8def\u5f84\u521b\u5efaFile\u5bf9\u8c61&#xff0c;\u5982\u679cpathname\u662f\u76f8\u5bf9\u8def\u5f84&#xff0c;\u5219\u9ed8\u8ba4\u7684\u5f53\u524d\u8def\u5f84\u5728\u7cfb\u7edf\u5c5e\u6027user.dir \u4e2d\u5b58\u50a8\u3002<\/p>\n<p>File\u7684\u9759\u6001\u5c5e\u6027String separator\u5b58\u50a8\u4e86\u5f53\u524d\u7cfb\u7edf\u7684\u8def\u5f84\u5206\u9694\u7b26\u3002<\/p>\n<p>\u901a\u8fc7File\u5bf9\u8c61\u53ef\u4ee5\u8bbf\u95ee\u6587\u4ef6\u7684\u5c5e\u6027\u3002<\/p>\n<\/p>\n<p>public boolean canRead()<br \/>\npublic boolean exists()<br \/>\npublic boolean isFile()<br \/>\npublic long lastModified()<br \/>\npublic String getName()<br \/>\npublic boolean canWrite()<br \/>\npublic boolean isDirectory()<br \/>\npublic boolean isHidden()<br \/>\npublic long length()<br \/>\npublic String getPath() <\/p>\n<p>\u901a\u8fc7File\u5bf9\u8c61\u521b\u5efa\u7a7a\u6587\u4ef6\u6216\u76ee\u5f55&#xff08;\u5728\u8be5\u5bf9\u8c61\u6240\u6307\u7684\u6587\u4ef6\u6216\u76ee\u5f55\u4e0d\u5b58\u5728\u7684\u60c5\u51b5\u4e0b&#xff09;\u3002<\/p>\n<\/p>\n<p>public boolean createNewFile()throws IOException<br \/>\npublic boolean delete()<br \/>\npublic boolean mkdir()&#xff0c; mkdirs() <\/p>\n<p>\u5e38\u89c1\u6784\u9020\u5668&#xff0c;\u65b9\u6cd5<\/p>\n<\/p>\n<p>import java.io.File;<br \/>\nimport java.io.IOException;<br \/>\npublic class TestFile {<br \/>\n    \/**<br \/>\n    * File\u6587\u4ef6\u7c7b 1.\u4ee3\u8868\u6587\u4ef6 2.\u4ee3\u8868\u76ee\u5f55<br \/>\n    *\/<br \/>\n    public static void main(String[] args) {<br \/>\n        File f &#061; new File(&#034;d:\/src3\/TestObject.java&#034;);<br \/>\n        File f2 &#061; new File(&#034;d:\/src3&#034;);<br \/>\n        File f3 &#061; new File(f2, &#034;TestFile.java&#034;);<br \/>\n        File f4 &#061; new File(f2, &#034;TestFile666.java&#034;);<br \/>\n        File f5 &#061; new File(&#034;d:\/src3\/aa\/bb\/cc\/dd&#034;);<br \/>\n        \/\/f5.mkdirs();<br \/>\n        f5.delete();<\/p>\n<p>        try {<br \/>\n            f4.createNewFile();<br \/>\n            System.out.println(&#034;\u6587\u4ef6\u521b\u5efa\u6210\u529f&#xff01;&#034;);<br \/>\n        } catch (IOException e) {<br \/>\n            e.printStackTrace();<br \/>\n        }<br \/>\n        if (f.isFile()) {<br \/>\n            System.out.println(&#034;\u662f\u4e00\u4e2a\u6587\u4ef6&#xff01;&#034;);<br \/>\n        }<br \/>\n        if (f2.isDirectory()) {<br \/>\n            System.out.println(&#034;\u662f\u4e00\u4e2a\u76ee\u5f55&#xff01;&#034;);<br \/>\n        }<br \/>\n        if (f3.isFile()) {<br \/>\n            System.out.println(&#034;\u662f\u4e00\u4e2a\u6587\u4ef6\u5965&#034;);<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u521d\u8bc6java \u00a0<br \/>\nJava : \u4e00\u4e2a\u5e1d\u56fd\u7684\u8bde\u751f<br \/>\n1\u3001C\u8bed\u8a00\u5e1d\u56fd\u7684\u7edf\u6cbb<br \/>\n\u73b0\u5728\u662f\u516c\u51431995\u5e74&#xff0c; C\u8bed\u8a00\u5e1d\u56fd\u5df2\u7ecf\u7edf\u6cbb\u4e86\u6211\u4eec20\u591a\u5e74&#xff0c; \u5b9e\u5728\u662f\u592a\u4e45\u4e86\u3002<br \/>\n1972\u5e74&#xff0c; \u968f\u7740C\u8bed\u8a00\u7684\u8bde\u751f\u548cUnix\u7684\u95ee\u4e16&#xff0c; \u5e1d\u56fd\u8fc5\u901f\u5efa\u7acb\u7edf\u6cbb&#xff0c; \u4ece\u5317\u7f8e\u5230\u6b27\u6d32&#xff0c; \u4ece\u6b27\u6d32\u5230\u4e9a\u6d32&#xff0c; \u65e0\u6570\u7a0b\u5e8f\u5458\u81e3\u670d\u5728\u4ed6\u7684\u811a\u4e0b\u3002<br \/>\n\u5e1d\u56fd\u7ed9\u6211\u4eec\u63d0\u4f9b\u4e86\u6781\u597d\u7684\u798f\u5229&#xff1a;\u8d34\u8fd1\u786c\u4ef6&#xff0c; \u8fd0\u884c\u6781\u5feb&#xff0c;<\/p>\n","protected":false},"author":2,"featured_media":59738,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,426,190],"topic":[],"class_list":["post-59758","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-java","tag-jvm","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>java\u4ece\u5165\u95e8\u5230\u7cbe\u901a\u2014\u2014\u57fa\u7840\u7bc7\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/59758.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"java\u4ece\u5165\u95e8\u5230\u7cbe\u901a\u2014\u2014\u57fa\u7840\u7bc7\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e00\u3001\u521d\u8bc6java \u00a0 Java : \u4e00\u4e2a\u5e1d\u56fd\u7684\u8bde\u751f 1\u3001C\u8bed\u8a00\u5e1d\u56fd\u7684\u7edf\u6cbb \u73b0\u5728\u662f\u516c\u51431995\u5e74&#xff0c; C\u8bed\u8a00\u5e1d\u56fd\u5df2\u7ecf\u7edf\u6cbb\u4e86\u6211\u4eec20\u591a\u5e74&#xff0c; \u5b9e\u5728\u662f\u592a\u4e45\u4e86\u3002 1972\u5e74&#xff0c; \u968f\u7740C\u8bed\u8a00\u7684\u8bde\u751f\u548cUnix\u7684\u95ee\u4e16&#xff0c; \u5e1d\u56fd\u8fc5\u901f\u5efa\u7acb\u7edf\u6cbb&#xff0c; \u4ece\u5317\u7f8e\u5230\u6b27\u6d32&#xff0c; \u4ece\u6b27\u6d32\u5230\u4e9a\u6d32&#xff0c; \u65e0\u6570\u7a0b\u5e8f\u5458\u81e3\u670d\u5728\u4ed6\u7684\u811a\u4e0b\u3002 \u5e1d\u56fd\u7ed9\u6211\u4eec\u63d0\u4f9b\u4e86\u6781\u597d\u7684\u798f\u5229&#xff1a;\u8d34\u8fd1\u786c\u4ef6&#xff0c; \u8fd0\u884c\u6781\u5feb&#xff0c;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/59758.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-14T04:50:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114045015-69672087b2de2.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"110 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/59758.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/59758.html\",\"name\":\"java\u4ece\u5165\u95e8\u5230\u7cbe\u901a\u2014\u2014\u57fa\u7840\u7bc7\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-14T04:50:18+00:00\",\"dateModified\":\"2026-01-14T04:50:18+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/59758.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/59758.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/59758.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"java\u4ece\u5165\u95e8\u5230\u7cbe\u901a\u2014\u2014\u57fa\u7840\u7bc7\uff08\u4e00\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"java\u4ece\u5165\u95e8\u5230\u7cbe\u901a\u2014\u2014\u57fa\u7840\u7bc7\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/59758.html","og_locale":"zh_CN","og_type":"article","og_title":"java\u4ece\u5165\u95e8\u5230\u7cbe\u901a\u2014\u2014\u57fa\u7840\u7bc7\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e00\u3001\u521d\u8bc6java \u00a0 Java : \u4e00\u4e2a\u5e1d\u56fd\u7684\u8bde\u751f 1\u3001C\u8bed\u8a00\u5e1d\u56fd\u7684\u7edf\u6cbb \u73b0\u5728\u662f\u516c\u51431995\u5e74&#xff0c; C\u8bed\u8a00\u5e1d\u56fd\u5df2\u7ecf\u7edf\u6cbb\u4e86\u6211\u4eec20\u591a\u5e74&#xff0c; \u5b9e\u5728\u662f\u592a\u4e45\u4e86\u3002 1972\u5e74&#xff0c; \u968f\u7740C\u8bed\u8a00\u7684\u8bde\u751f\u548cUnix\u7684\u95ee\u4e16&#xff0c; \u5e1d\u56fd\u8fc5\u901f\u5efa\u7acb\u7edf\u6cbb&#xff0c; \u4ece\u5317\u7f8e\u5230\u6b27\u6d32&#xff0c; \u4ece\u6b27\u6d32\u5230\u4e9a\u6d32&#xff0c; \u65e0\u6570\u7a0b\u5e8f\u5458\u81e3\u670d\u5728\u4ed6\u7684\u811a\u4e0b\u3002 \u5e1d\u56fd\u7ed9\u6211\u4eec\u63d0\u4f9b\u4e86\u6781\u597d\u7684\u798f\u5229&#xff1a;\u8d34\u8fd1\u786c\u4ef6&#xff0c; \u8fd0\u884c\u6781\u5feb&#xff0c;","og_url":"https:\/\/www.wsisp.com\/helps\/59758.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-14T04:50:18+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114045015-69672087b2de2.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"110 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/59758.html","url":"https:\/\/www.wsisp.com\/helps\/59758.html","name":"java\u4ece\u5165\u95e8\u5230\u7cbe\u901a\u2014\u2014\u57fa\u7840\u7bc7\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-14T04:50:18+00:00","dateModified":"2026-01-14T04:50:18+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/59758.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/59758.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/59758.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"java\u4ece\u5165\u95e8\u5230\u7cbe\u901a\u2014\u2014\u57fa\u7840\u7bc7\uff08\u4e00\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/59758","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=59758"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/59758\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/59738"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=59758"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=59758"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=59758"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=59758"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}