{"id":2177,"date":"2025-03-01T18:10:34","date_gmt":"2025-03-01T10:10:34","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=2177"},"modified":"2025-03-01T18:10:34","modified_gmt":"2025-03-01T10:10:34","slug":"java-%e5%9f%ba%e7%a1%80%e8%af%ad%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/03\/01\/java-%e5%9f%ba%e7%a1%80%e8%af%ad%e6%b3%95\/","title":{"rendered":"Java \u57fa\u7840\u8bed\u6cd5"},"content":{"rendered":"\n<p>Java \u57fa\u7840\u8bed\u6cd5\u662f\u5b66\u4e60 Java \u7f16\u7a0b\u7684\u7b2c\u4e00\u6b65\uff0c\u4e86\u89e3\u8fd9\u4e9b\u57fa\u672c\u8bed\u6cd5\u89c4\u5219\u6709\u52a9\u4e8e\u4f60\u7f16\u5199\u6709\u6548\u7684 Java \u7a0b\u5e8f\u3002\u4e0b\u9762\u662f\u4e00\u4e9b Java \u57fa\u7840\u8bed\u6cd5\u7684\u6838\u5fc3\u6982\u5ff5\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>Java \u7a0b\u5e8f\u7ed3\u6784<\/strong><\/h3>\n\n\n\n<p>\u4e00\u4e2a Java \u7a0b\u5e8f\u7531\u7c7b\uff08Class\uff09\u548c\u65b9\u6cd5\uff08Method\uff09\u7ec4\u6210\u3002\u6bcf\u4e2a Java \u7a0b\u5e8f\u5fc5\u987b\u5305\u542b\u4e00\u4e2a <code>main()<\/code> \u65b9\u6cd5\uff0c\u8fd9\u662f\u7a0b\u5e8f\u7684\u5165\u53e3\u70b9\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>   public class HelloWorld {\n       public static void main(String&#91;] args) {\n           System.out.println(\"Hello, World!\");\n       }\n   }<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>public class HelloWorld<\/code><\/strong>\uff1a\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a <code>HelloWorld<\/code> \u7684\u7c7b\uff0c<code>public<\/code> \u662f\u8bbf\u95ee\u4fee\u9970\u7b26\uff0c\u8868\u793a\u7c7b\u662f\u516c\u5171\u7684\u3002<\/li>\n\n\n\n<li><strong><code>public static void main(String[] args)<\/code><\/strong>\uff1a\u5b9a\u4e49 <code>main<\/code> \u65b9\u6cd5\uff0c<code>String[] args<\/code> \u662f\u547d\u4ee4\u884c\u53c2\u6570\uff0c<code>void<\/code> \u8868\u793a\u8be5\u65b9\u6cd5\u4e0d\u8fd4\u56de\u4efb\u4f55\u503c\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>\u53d8\u91cf\u4e0e\u6570\u636e\u7c7b\u578b<\/strong><\/h3>\n\n\n\n<p>Java \u662f\u5f3a\u7c7b\u578b\u8bed\u8a00\uff0c\u9700\u8981\u663e\u5f0f\u58f0\u660e\u53d8\u91cf\u7684\u7c7b\u578b\u3002\u5e38\u89c1\u7684\u6570\u636e\u7c7b\u578b\u6709\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u57fa\u672c\u6570\u636e\u7c7b\u578b\uff08Primitive Data Types\uff09<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li><code>int<\/code>\uff1a\u6574\u6570\u7c7b\u578b\uff0c32 \u4f4d<\/li>\n\n\n\n<li><code>double<\/code>\uff1a\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u6570\uff0c64 \u4f4d<\/li>\n\n\n\n<li><code>char<\/code>\uff1a\u5b57\u7b26\u7c7b\u578b\uff0c16 \u4f4d<\/li>\n\n\n\n<li><code>boolean<\/code>\uff1a\u5e03\u5c14\u7c7b\u578b\uff0c\u8868\u793a <code>true<\/code> \u6216 <code>false<\/code><\/li>\n\n\n\n<li><code>long<\/code>\uff1a\u957f\u6574\u6570\uff0c64 \u4f4d<\/li>\n\n\n\n<li><code>float<\/code>\uff1a\u5355\u7cbe\u5ea6\u6d6e\u70b9\u6570\uff0c32 \u4f4d<\/li>\n\n\n\n<li><code>byte<\/code>\uff1a\u5b57\u8282\uff0c8 \u4f4d<\/li>\n\n\n\n<li><code>short<\/code>\uff1a\u77ed\u6574\u6570\uff0c16 \u4f4d<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u5f15\u7528\u6570\u636e\u7c7b\u578b\uff08Reference Data Types\uff09<\/strong>\uff1a<ul><li><code>String<\/code>\uff1a\u5b57\u7b26\u4e32\u7c7b\u578b\uff0c\u7528\u4e8e\u8868\u793a\u6587\u672c\u3002<\/li><li>\u6570\u7ec4\u3001\u7c7b\u3001\u63a5\u53e3\u7b49\u3002<\/li><\/ul><strong>\u793a\u4f8b\uff1a<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>   int age = 25;        \/\/ \u6574\u578b\u53d8\u91cf\n   double price = 19.99; \/\/ \u6d6e\u70b9\u578b\u53d8\u91cf\n   char grade = 'A';     \/\/ \u5b57\u7b26\u53d8\u91cf\n   boolean isStudent = true; \/\/ \u5e03\u5c14\u53d8\u91cf\n   String name = \"John\"; \/\/ \u5b57\u7b26\u4e32\u53d8\u91cf<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>\u8fd0\u7b97\u7b26<\/strong><\/h3>\n\n\n\n<p>Java \u63d0\u4f9b\u4e86\u5404\u79cd\u8fd0\u7b97\u7b26\uff0c\u7528\u4e8e\u64cd\u4f5c\u53d8\u91cf\u548c\u5e38\u91cf\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7b97\u672f\u8fd0\u7b97\u7b26<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li><code>+<\/code> \u52a0\u6cd5<\/li>\n\n\n\n<li><code>-<\/code> \u51cf\u6cd5<\/li>\n\n\n\n<li><code>*<\/code> \u4e58\u6cd5<\/li>\n\n\n\n<li><code>\/<\/code> \u9664\u6cd5<\/li>\n\n\n\n<li><code>%<\/code> \u53d6\u4f59<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u5173\u7cfb\u8fd0\u7b97\u7b26<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li><code>==<\/code> \u7b49\u4e8e<\/li>\n\n\n\n<li><code>!=<\/code> \u4e0d\u7b49\u4e8e<\/li>\n\n\n\n<li><code>><\/code> \u5927\u4e8e<\/li>\n\n\n\n<li><code>&lt;<\/code> \u5c0f\u4e8e<\/li>\n\n\n\n<li><code>>=<\/code> \u5927\u4e8e\u7b49\u4e8e<\/li>\n\n\n\n<li><code>&lt;=<\/code> \u5c0f\u4e8e\u7b49\u4e8e<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u903b\u8f91\u8fd0\u7b97\u7b26<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li><code>&amp;&amp;<\/code> \u903b\u8f91\u4e0e<\/li>\n\n\n\n<li><code>||<\/code> \u903b\u8f91\u6216<\/li>\n\n\n\n<li><code>!<\/code> \u903b\u8f91\u975e<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u8d4b\u503c\u8fd0\u7b97\u7b26<\/strong>\uff1a<ul><li><code>=<\/code> \u8d4b\u503c<\/li><li><code>+=<\/code> \u52a0\u6cd5\u8d4b\u503c<\/li><li><code>-=<\/code> \u51cf\u6cd5\u8d4b\u503c<\/li><li><code>*=<\/code> \u4e58\u6cd5\u8d4b\u503c<\/li><li><code>\/=<\/code> \u9664\u6cd5\u8d4b\u503c<\/li><li><code>%=<\/code> \u53d6\u4f59\u8d4b\u503c<\/li><\/ul><strong>\u793a\u4f8b\uff1a<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>   int a = 10, b = 5;\n   int sum = a + b;  \/\/ \u52a0\u6cd5\n   boolean result = (a &gt; b) &amp;&amp; (b != 0); \/\/ \u903b\u8f91\u8fd0\u7b97\u7b26<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>\u63a7\u5236\u7ed3\u6784<\/strong><\/h3>\n\n\n\n<p>Java \u63d0\u4f9b\u4e86\u591a\u79cd\u63a7\u5236\u7ed3\u6784\u6765\u5b9e\u73b0\u6761\u4ef6\u5224\u65ad\u548c\u5faa\u73af\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6761\u4ef6\u8bed\u53e5\uff1a<\/strong><ul><li><code>if<\/code>\uff1a\u5982\u679c\u6761\u4ef6\u4e3a\u771f\uff0c\u5219\u6267\u884c\u4ee3\u7801\u5757\u3002<\/li><li><code>else<\/code>\uff1a\u5982\u679c\u6761\u4ef6\u4e3a\u5047\uff0c\u5219\u6267\u884c\u53e6\u4e00\u4e2a\u4ee3\u7801\u5757\u3002<\/li><li><code>else if<\/code>\uff1a\u7528\u4e8e\u591a\u4e2a\u6761\u4ef6\u5224\u65ad\u3002<\/li><li><code>switch<\/code>\uff1a\u57fa\u4e8e\u53d8\u91cf\u7684\u503c\u6267\u884c\u4e0d\u540c\u7684\u4ee3\u7801\u5757\u3002<\/li><\/ul><strong>\u793a\u4f8b\uff1a<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>   int number = 10;\n   if (number &gt; 0) {\n       System.out.println(\"Positive\");\n   } else {\n       System.out.println(\"Negative or Zero\");\n   }<\/code><\/pre>\n\n\n\n<p><strong>switch \u8bed\u53e5\u793a\u4f8b\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>   int day = 3;\n   switch (day) {\n       case 1:\n           System.out.println(\"Monday\");\n           break;\n       case 2:\n           System.out.println(\"Tuesday\");\n           break;\n       case 3:\n           System.out.println(\"Wednesday\");\n           break;\n       default:\n           System.out.println(\"Invalid day\");\n   }<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5faa\u73af\u8bed\u53e5\uff1a<\/strong><ul><li><code>for<\/code>\uff1a\u7528\u4e8e\u6307\u5b9a\u6b21\u6570\u7684\u5faa\u73af\u3002<\/li><li><code>while<\/code>\uff1a\u53ea\u8981\u6761\u4ef6\u4e3a\u771f\uff0c\u5c31\u6301\u7eed\u5faa\u73af\u3002<\/li><li><code>do-while<\/code>\uff1a\u5148\u6267\u884c\u5faa\u73af\uff0c\u518d\u68c0\u67e5\u6761\u4ef6\u3002<\/li><\/ul><strong>\u793a\u4f8b\uff1a<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>   \/\/ for \u5faa\u73af\n   for (int i = 0; i &lt; 5; i++) {\n       System.out.println(i);\n   }\n\n   \/\/ while \u5faa\u73af\n   int i = 0;\n   while (i &lt; 5) {\n       System.out.println(i);\n       i++;\n   }<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. <strong>\u6570\u7ec4<\/strong><\/h3>\n\n\n\n<p>\u6570\u7ec4\u662f\u4e00\u79cd\u5bb9\u5668\uff0c\u53ef\u4ee5\u5b58\u50a8\u591a\u4e2a\u76f8\u540c\u7c7b\u578b\u7684\u5143\u7d20\u3002\u6570\u7ec4\u7684\u7d22\u5f15\u4ece <code>0<\/code> \u5f00\u59cb\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>   int&#91;] numbers = {1, 2, 3, 4, 5};\n   System.out.println(numbers&#91;0]); \/\/ \u8f93\u51fa 1<\/code><\/pre>\n\n\n\n<p>\u4f60\u4e5f\u53ef\u4ee5\u901a\u8fc7 <code>new<\/code> \u5173\u952e\u5b57\u521b\u5efa\u6570\u7ec4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>   int&#91;] scores = new int&#91;5];\n   scores&#91;0] = 100;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6. <strong>\u65b9\u6cd5\uff08\u51fd\u6570\uff09<\/strong><\/h3>\n\n\n\n<p>\u65b9\u6cd5\u662f Java \u7a0b\u5e8f\u4e2d\u7684\u57fa\u672c\u5355\u5143\uff0c\u53ef\u4ee5\u6267\u884c\u67d0\u4e2a\u4efb\u52a1\u3002\u65b9\u6cd5\u6709\u4e00\u4e2a\u8fd4\u56de\u7c7b\u578b\u3001\u540d\u79f0\u3001\u53c2\u6570\u5217\u8868\u548c\u65b9\u6cd5\u4f53\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>   public class Main {\n       public static void main(String&#91;] args) {\n           greet(\"John\");\n       }\n\n       \/\/ \u5b9a\u4e49\u4e00\u4e2a\u65b9\u6cd5\n       public static void greet(String name) {\n           System.out.println(\"Hello, \" + name);\n       }\n   }<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8fd4\u56de\u7c7b\u578b<\/strong>\uff1a\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u7c7b\u578b\uff0c\u4f8b\u5982 <code>int<\/code>\u3001<code>void<\/code> \u7b49\u3002<\/li>\n\n\n\n<li><strong>\u65b9\u6cd5\u540d\u79f0<\/strong>\uff1a\u7528\u6765\u8c03\u7528\u65b9\u6cd5\u7684\u540d\u79f0\u3002<\/li>\n\n\n\n<li><strong>\u53c2\u6570<\/strong>\uff1a\u53ef\u4ee5\u4f20\u9012\u7ed9\u65b9\u6cd5\u7684\u503c\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">7. <strong>\u7c7b\u548c\u5bf9\u8c61<\/strong><\/h3>\n\n\n\n<p>Java \u662f\u9762\u5411\u5bf9\u8c61\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u7c7b\u662f\u5bf9\u8c61\u7684\u6a21\u677f\uff0c\u7c7b\u4e2d\u7684\u65b9\u6cd5\u5b9a\u4e49\u4e86\u5bf9\u8c61\u7684\u884c\u4e3a\uff0c\u5b57\u6bb5\u5b9a\u4e49\u4e86\u5bf9\u8c61\u7684\u72b6\u6001\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>   \/\/ \u5b9a\u4e49\u4e00\u4e2a\u7c7b\n   public class Car {\n       String model;\n       int year;\n\n       \/\/ \u6784\u9020\u51fd\u6570\n       public Car(String model, int year) {\n           this.model = model;\n           this.year = year;\n       }\n\n       \/\/ \u65b9\u6cd5\n       public void displayInfo() {\n           System.out.println(\"Model: \" + model + \", Year: \" + year);\n       }\n\n       public static void main(String&#91;] args) {\n           Car myCar = new Car(\"Toyota\", 2021);\n           myCar.displayInfo();\n       }\n   }<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">8. <strong>\u9762\u5411\u5bf9\u8c61\u7279\u6027<\/strong><\/h3>\n\n\n\n<p>Java \u5177\u6709\u4ee5\u4e0b\u9762\u5411\u5bf9\u8c61\u7684\u7279\u6027\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5c01\u88c5\uff08Encapsulation\uff09<\/strong>\uff1a\u9690\u85cf\u5bf9\u8c61\u7684\u5185\u90e8\u6570\u636e\uff0c\u53ea\u66b4\u9732\u5fc5\u8981\u7684\u63a5\u53e3\u3002<\/li>\n\n\n\n<li><strong>\u7ee7\u627f\uff08Inheritance\uff09<\/strong>\uff1a\u5b50\u7c7b\u7ee7\u627f\u7236\u7c7b\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002<\/li>\n\n\n\n<li><strong>\u591a\u6001\uff08Polymorphism\uff09<\/strong>\uff1a\u5b50\u7c7b\u53ef\u4ee5\u91cd\u65b0\u5b9a\u4e49\u7236\u7c7b\u7684\u65b9\u6cd5\u3002<\/li>\n\n\n\n<li><strong>\u62bd\u8c61\uff08Abstraction\uff09<\/strong>\uff1a\u5b9a\u4e49\u63a5\u53e3\u6216\u62bd\u8c61\u7c7b\u6765\u5b9e\u73b0\u4e0d\u5b8c\u5168\u7684\u62bd\u8c61\u884c\u4e3a\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u603b\u7ed3<\/h3>\n\n\n\n<p>\u8fd9\u4e9b\u662f Java \u57fa\u7840\u8bed\u6cd5\u7684\u4e00\u4e9b\u6838\u5fc3\u6982\u5ff5\uff0c\u638c\u63e1\u5b83\u4eec\u4e4b\u540e\uff0c\u4f60\u5c31\u53ef\u4ee5\u5f00\u59cb\u7f16\u5199\u548c\u8c03\u8bd5\u7b80\u5355\u7684 Java \u7a0b\u5e8f\u4e86\u3002\u968f\u7740\u5b66\u4e60\u7684\u6df1\u5165\uff0c\u4f60\u5c06\u4f1a\u4e86\u89e3\u66f4\u591a\u5173\u4e8e Java \u7684\u9ad8\u7ea7\u7279\u6027\u548c\u7f16\u7a0b\u6280\u5de7\u3002<\/p>\n\n\n\n<p>\u66f4\u591a\u8be6\u7ec6\u5185\u5bb9\u8bf7\u5173\u6ce8\u5176\u4ed6\u76f8\u5173\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java \u57fa\u7840\u8bed\u6cd5\u662f\u5b66\u4e60 Java \u7f16\u7a0b\u7684\u7b2c\u4e00\u6b65\uff0c\u4e86\u89e3\u8fd9\u4e9b\u57fa\u672c\u8bed\u6cd5\u89c4\u5219\u6709\u52a9\u4e8e\u4f60\u7f16\u5199\u6709\u6548\u7684 Java \u7a0b\u5e8f\u3002\u4e0b\u9762 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[68],"tags":[],"class_list":["post-2177","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/2177","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=2177"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/2177\/revisions"}],"predecessor-version":[{"id":2178,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/2177\/revisions\/2178"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=2177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=2177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=2177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}