{"id":685,"date":"2025-09-15T12:00:06","date_gmt":"2025-09-15T04:00:06","guid":{"rendered":"https:\/\/hueil.top\/?p=685"},"modified":"2026-01-18T23:03:17","modified_gmt":"2026-01-18T15:03:17","slug":"java%e5%9f%ba%e7%a1%80%e8%af%ad%e6%b3%95","status":"publish","type":"post","link":"https:\/\/hueil.top\/?p=685","title":{"rendered":"JAVA\u57fa\u7840\u8bed\u6cd5"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u4e00,\u57fa\u7840\u7ed3\u6784<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\npublic class Dinosaur {\n   public static void main(String&#91;] args) {\n    System.out.println(\"Hello Dinosaur\");\n   }   \n}\n<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-left wp-block-paragraph\"><strong>\u8be5\u4ee3\u7801\u521b\u5efa\u4e86\u4e00\u4e2a Dinosaur \u7c7b\uff0c\u5728\u8fd9\u4e2a\u7c7b\u4e2d\u58f0\u660e\u4e86\u4e00\u4e2a main \u65b9\u6cd5\uff08main \u65b9\u6cd5\u662f\u7279\u6b8a\u7684\u9759\u6001\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u662f Java \u865a\u62df\u673a\u6267\u884c\u7a0b\u5e8f\u7684\u8d77\u70b9\uff09\uff0c\u5728\u8fd9\u4e2a main \u65b9\u6cd5\u4e2d\uff0c\u901a\u8fc7\u4f7f\u7528System.out.println() \u8f93\u51fa\u5e76\u6362\u884c\uff0c\u5373\u8f93\u51fa\u5706\u62ec\u53f7\u4e2d\u7684\u5185\u5bb9\u540e\u6dfb\u52a0\u4e00\u4e2a\u6362\u884c\u7b26\uff0c\u4f7f\u5f97\u4e0b\u6b21\u8f93\u51fa\u4ece\u65b0\u7684\u4e00\u884c\u5f00\u59cb\u3002<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c,\u57fa\u7840\u8bed\u6cd5<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1.\u6ce8\u91ca<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>public class HelloWorld {\n   \/* \u8fd9\u662f\u7b2c\u4e00\u4e2aJava\u7a0b\u5e8f\n    * \u5b83\u5c06\u8f93\u51fa Hello World\n    * \u8fd9\u662f\u4e00\u4e2a\u591a\u884c\u6ce8\u91ca\u7684\u793a\u4f8b\n    *\/\n    public static void main(String&#91;] args){\n       \/\/ \u8fd9\u662f\u5355\u884c\u6ce8\u91ca\u7684\u793a\u4f8b\n       \/* \u8fd9\u4e2a\u4e5f\u662f\u5355\u884c\u6ce8\u91ca\u7684\u793a\u4f8b *\/\n       System.out.println(\"Hello World\"); \n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Java\u4e2d\u6709\u4e09\u79cd\u6ce8\u91ca\uff0c\u5206\u4e3a\u5355\u884c\u6ce8\u91ca\uff0c\u591a\u884c\u6ce8\u91ca\uff0c\u6587\u6863\u6ce8\u91ca\u3002\u5728\u5199\u4ee3\u7801\u65f6\u52a0\u5165\u6ce8\u91ca\u53ef\u4ee5\u66f4\u65b9\u4fbf\u7684\u9605\u8bfb\u4ee3\u7801,\u5e76\u4e14\u5728\u51fa\u9519\u65f6\u4e5f\u80fd\u5e2e\u52a9\u5feb\u901f\u5b9a\u4f4d\u9519\u8bef\u533a\u57df\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.\u6570\u636e\u7c7b\u578b<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Java\u8bed\u8a00\u63d0\u4f9b\u4e86\u516b\u79cd\u57fa\u672c\u7c7b\u578b,\u4f9d\u6b21\u4e3a<strong>byte<\/strong>,<strong>short<\/strong>,<strong>int<\/strong>,<strong>long,float<\/strong>,<strong>double<\/strong>,<strong>boolean<\/strong>,<strong>char\u3002<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>final double PI = 3.1415927;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u6570\u636e\u7c7b\u578b_\u53d8\u91cf\u540d\u6765\u58f0\u660e\uff0cfinal\u5173\u952e\u5b57\u7528\u4e8e\u58f0\u660e\u5e38\u91cf\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1.\u7c7b\u578b\u8f6c\u6362<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>public class ZiDongLeiZhuan{\n        public static void main(String&#91;] args){\n            char c1='a';\/\/\u5b9a\u4e49\u4e00\u4e2achar\u7c7b\u578b\n            int i1 = c1;\/\/char\u81ea\u52a8\u7c7b\u578b\u8f6c\u6362\u4e3aint\n            System.out.println(\"char\u81ea\u52a8\u7c7b\u578b\u8f6c\u6362\u4e3aint\u540e\u7684\u503c\u7b49\u4e8e\"+i1);\n            char c2 = 'A';\/\/\u5b9a\u4e49\u4e00\u4e2achar\u7c7b\u578b\n            int i2 = c2+1;\/\/char \u7c7b\u578b\u548c int \u7c7b\u578b\u8ba1\u7b97\n            System.out.println(\"char\u7c7b\u578b\u548cint\u8ba1\u7b97\u540e\u7684\u503c\u7b49\u4e8e\"+i2);\n        }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">char\u7c7b\u578b\u662f\u5b57\u7b26\uff0c\u5f53\u88ab\u8f6c\u6362\u6210\u6570\u503c\u7c7b\u578b\u65f6\uff0c\u4f1a\u8fd4\u56de\u8be5\u5b57\u7b26\u7684Ascii\u7f16\u7801\u3002\u5982\u2018a\u2019\u8f6c\u6362\u4e3a\u6570\u503c\u5c31\u8fd4\u56de97\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9700\u8981\u6ce8\u610f\u7684\u662fchar\u7c7b\u578b\u662f\u5355\u4e2a\u5b57\u7b26\uff0c\u7528\u4e24\u4e2a\u5355\u5f15\u53f7\u8868\u793a\u3002\u5982\u679c\u8981\u58f0\u660e\u5b57\u7b26\u4e32\u7c7b\u578b\u7684\u591a\u4e2a\u5b57\u7b26\uff0c\u9700\u8981\u4f7f\u7528String\u5173\u952e\u5b57\u58f0\u660e\uff0c\u5e76\u7528\u53cc\u5f15\u53f7\u8868\u793a\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2.\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>public class ForceTransform {\n    public static void main(String&#91;] args){\n        int i1 = 123;\n        byte b = (byte)i1;\/\/\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u4e3abyte\n        System.out.println(\"int\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u4e3abyte\u540e\u7684\u503c\u7b49\u4e8e\"+b);\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u9700\u8981\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u65f6\uff0c\u7528&#8221;\uff08\u6570\u636e\u7c7b\u578b\uff09\u53d8\u91cf&#8221;\u6765\u8fdb\u884c\u5f3a\u5236\u8f6c\u6362\u3002\u9700\u8981\u6ce8\u610f\u5f3a\u5236\u8f6c\u6362\u53ef\u80fd\u5bfc\u81f4\u6ea2\u51fa\u6216\u635f\u5931\u7cbe\u5ea6\uff0c\u6bd4\u5982\u5bb9\u91cf\u8f83\u5927\u7684\u6570\u636e\u8f6c\u6362\u4e3a\u8f83\u5c0f\u7684\u6570\u636e\u4f1a\u51fa\u73b0\u4e0b\u9762\u60c5\u51b5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\npublic class Dinosaur {\n   public static void main(String&#91;] args) {\n    int a = 327;\n    byte b = (byte)a;\n    System.out.println(b);\n   }   \n    \n}\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u7684\u8f93\u51fa\u7ed3\u679c\u662f71\uff0c\u8fd9\u662f\u56e0\u4e3a\u53d8\u91cfa\u7684\u957f\u5ea6\u8d85\u8fc7\u4e86byte\u7684\u5bb9\u91cf\u957f\u5ea6.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.\u8fd0\u7b97\u7b26\u7684\u4f18\u5148\u7ea7<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><div class='fancybox-wrapper' data-fancybox='post-images' href='https:\/\/hueil.top\/wp-content\/uploads\/2025\/09\/\u56fe\u7247-3-1024x767.png'><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"767\" src=\"https:\/\/hueil.top\/wp-content\/uploads\/2025\/09\/\u56fe\u7247-3-1024x767.png\" alt=\"\" class=\"wp-image-1028\" srcset=\"https:\/\/hueil.top\/wp-content\/uploads\/2025\/09\/\u56fe\u7247-3-1024x767.png 1024w, https:\/\/hueil.top\/wp-content\/uploads\/2025\/09\/\u56fe\u7247-3-300x225.png 300w, https:\/\/hueil.top\/wp-content\/uploads\/2025\/09\/\u56fe\u7247-3-768x575.png 768w, https:\/\/hueil.top\/wp-content\/uploads\/2025\/09\/\u56fe\u7247-3.png 1089w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/div><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">4.\u6570\u7ec4<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u58f0\u660e\u4e00\u7ef4\u6570\u7ec4\u7684\u65b9\u6cd5\u6709\u4e24\u79cd\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u7b2c\u4e00\u79cd\nint&#91;] array;\n\/\/\u7b2c\u4e8c\u79cd\nint array&#91;];<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09,\u7c7b\u5bf9\u8c61<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b9e\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Dinosaur {\n   public void pupAge(){\n      int age = 0;\n      age = age + 7;\n      System.out.println(\"\u5c0f\u72d7\u7684\u5e74\u9f84\u662f: \" + age);\n   }\n   public static void main(String&#91;] args) {\n      Dinosaur test = new Dinosaur();\n      test.pupAge();\n   }   \n    \n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u8fd9\u4e2a\u5b9e\u4f8b\u53ef\u4ee5\u65b9\u4fbf\u4e86\u89e3\u5bf9\u8c61\u7684\u521b\u5efa\u548c\u65b9\u6cd5\u7684\u8c03\u7528,\u5728\u8fd9\u4e2a\u5b9e\u4f8b\u4e2d\u521b\u5efa\u4e86\u4e2aDinosaur\u7c7b,\u5728\u4e3b\u51fd\u6570\u4e2d\u7528\u7c7b\u540d\u52a0\u5bf9\u8c61\u540d\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3atest\u7684\u5bf9\u8c61\uff0c\u5e76\u4e14\u901a\u8fc7\u5bf9\u8c61\u540d.\u65b9\u6cd5\u8c03\u7528\u4e86pupAge\u65b9\u6cd5\uff0c\u8f93\u51fa&#8221;\u5c0f\u72d7\u7684\u5e74\u9f84\u662f\uff1a7&#8243;\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00,\u57fa\u7840\u7ed3\u6784 \u8be5\u4ee3\u7801\u521b\u5efa\u4e86\u4e00\u4e2a Dinosaur \u7c7b\uff0c\u5728\u8fd9\u4e2a\u7c7b\u4e2d\u58f0\u660e\u4e86\u4e00\u4e2a main \u65b9\u6cd5\uff08main \u65b9\u6cd5\u662f\u7279 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":850,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"class_list":["post-685","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/hueil.top\/index.php?rest_route=\/wp\/v2\/posts\/685","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hueil.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hueil.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hueil.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hueil.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=685"}],"version-history":[{"count":31,"href":"https:\/\/hueil.top\/index.php?rest_route=\/wp\/v2\/posts\/685\/revisions"}],"predecessor-version":[{"id":1746,"href":"https:\/\/hueil.top\/index.php?rest_route=\/wp\/v2\/posts\/685\/revisions\/1746"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hueil.top\/index.php?rest_route=\/wp\/v2\/media\/850"}],"wp:attachment":[{"href":"https:\/\/hueil.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hueil.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hueil.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}