{"id":83660,"date":"2024-12-31T21:52:16","date_gmt":"2024-12-31T14:52:16","guid":{"rendered":"https:\/\/itviec.com\/blog\/?p=83660"},"modified":"2025-09-28T23:17:34","modified_gmt":"2025-09-28T16:17:34","slug":"cac-cau-lenh-trong-java","status":"publish","type":"post","link":"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/","title":{"rendered":"C\u00e1c c\u00e2u l\u1ec7nh trong Java: Chi ti\u1ebft t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">N\u1ed9i dung b\u00e0i vi\u1ebft<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/#Phan_loai_co_ban_cac_cau_lenh_trong_Java\" >Ph\u00e2n lo\u1ea1i c\u01a1 b\u1ea3n c\u00e1c c\u00e2u l\u1ec7nh trong Java<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/#Cau_lenh_khai_bao_bien_Declaration_Statement\" >C\u00e2u l\u1ec7nh khai b\u00e1o bi\u1ebfn (Declaration Statement)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/#Cau_lenh_gan_gia_tri_Assignment_Statement\" >C\u00e2u l\u1ec7nh g\u00e1n gi\u00e1 tr\u1ecb (Assignment Statement)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/#Cau_lenh_in_ra_man_hinh_Print_Statement\" >C\u00e2u l\u1ec7nh in ra m\u00e0n h\u00ecnh (Print Statement)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/#Cau_lenh_nhap_lieu_tu_ban_phim_Input_Statement\" >C\u00e2u l\u1ec7nh nh\u1eadp li\u1ec7u t\u1eeb b\u00e0n ph\u00edm (Input Statement)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/#Cac_cau_lenh_trong_Java_dung_de_dieu_khien_luong\" >C\u00e1c c\u00e2u l\u1ec7nh trong Java d\u00f9ng \u0111\u1ec3 \u0111i\u1ec1u khi\u1ec3n lu\u1ed3ng<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/#Cac_cau_lenh_trong_Java_dung_de_xu_ly_loi\" >C\u00e1c c\u00e2u l\u1ec7nh trong Java d\u00f9ng \u0111\u1ec3 x\u1eed l\u00fd l\u1ed7i&nbsp;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/#Cac_cau_lenh_trong_Java_dac_biet\" >C\u00e1c c\u00e2u l\u1ec7nh trong Java \u0111\u1eb7c bi\u1ec7t&nbsp;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/#Tong_ket_cac_cau_lenh_trong_Java\" >T\u1ed5ng k\u1ebft c\u00e1c c\u00e2u l\u1ec7nh trong Java<\/a><\/li><\/ul><\/nav><\/div>\n\n<p><em><strong>Khi h\u1ecdc Java, vi\u1ec7c n\u1eafm v\u1eefng c\u00e1c c\u00e2u l\u1ec7nh trong Java l\u00e0 b\u01b0\u1edbc \u0111\u1ea7u ti\u00ean v\u00e0 quan tr\u1ecdng \u0111\u1ec3 l\u00e0m ch\u1ee7 v\u00e0 ph\u00e1t tri\u1ec3n c\u00e1c \u1ee9ng d\u1ee5ng t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao. B\u00e0i vi\u1ebft n\u00e0y s\u1ebd gi\u1edbi thi\u1ec7u t\u1ed5ng quan v\u1ec1 c\u00e1c c\u00e1c c\u00e2u l\u1ec7nh trong Java, g\u1ed3m c\u00e1c c\u00e2u l\u1ec7nh \u0111i\u1ec1u khi\u1ec3n, c\u00e2u l\u1ec7nh v\u00f2ng l\u1eb7p, c\u00e2u l\u1ec7nh r\u1ebd nh\u00e1nh v\u00e0 c\u00e1c c\u00e2u l\u1ec7nh kh\u00e1c nh\u1eefng th\u1ef1c gi\u00fap l\u1eadp tr\u00ecnh vi\u00ean vi\u1ebft m\u00e3 hi\u1ec7u qu\u1ea3 h\u01a1n.<\/strong><\/em><\/p>\n\n\n\n<p>\u0110\u1ecdc b\u00e0i vi\u1ebft n\u00e0y \u0111\u1ec3 bi\u1ebft th\u00eam chi ti\u1ebft:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400;\">C\u00e1c c\u00e2u l\u1ec7nh trong Java c\u01a1 b\u1ea3n<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">C\u00e1c l\u1ec7nh \u0111i\u1ec1u khi\u1ec3n lu\u1ed3ng<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh x\u1eed l\u00fd l\u1ed7i\u00a0<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">C\u00e1c c\u00e2u l\u1ec7nh trong Java \u0111\u1eb7c bi\u1ec7t<\/span><\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><em>Tham kh\u1ea3o <strong><a href=\"https:\/\/itviec.com\/it-jobs\/java?utm_medium=anchor_text_high&amp;utm_source=blog&amp;utm_campaign=viec_lam_java&amp;utm_content=cac_cau_lenh_trong_java\" target=\"_blank\" rel=\"noreferrer noopener\">vi\u1ec7c l\u00e0m Java<\/a><\/strong> m\u1edbi nh\u1ea5t tr\u00ean to\u00e0n qu\u1ed1c<\/em><\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-phan-lo\u1ea1i-c\u01a1-b\u1ea3n-cac-cau-l\u1ec7nh-trong-java\"><span class=\"ez-toc-section\" id=\"Phan_loai_co_ban_cac_cau_lenh_trong_Java\"><\/span><strong>Ph\u00e2n lo\u1ea1i c\u01a1 b\u1ea3n c\u00e1c c\u00e2u l\u1ec7nh trong Java<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">C\u00e1c c\u00e2u l\u1ec7nh trong Java bao g\u1ed3m:<\/span><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>C\u00e2u l\u1ec7nh khai b\u00e1o bi\u1ebfn (Declaration Statement)<\/li>\n\n\n\n<li>C\u00e2u l\u1ec7nh g\u00e1n gi\u00e1 tr\u1ecb (Assignment Statement)<\/li>\n\n\n\n<li>C\u00e2u l\u1ec7nh in ra m\u00e0n h\u00ecnh (Print Statement)<\/li>\n\n\n\n<li>C\u00e2u l\u1ec7nh nh\u1eadp li\u1ec7u t\u1eeb b\u00e0n ph\u00edm (Input Statement)<\/li>\n<\/ul>\n\n\n\n<p><span style=\"font-weight: 400;\">Nh\u1eefng c\u00e2u l\u1ec7nh n\u00e0y \u0111\u00f3ng vai tr\u00f2 quan tr\u1ecdng trong vi\u1ec7c t\u1ed5 ch\u1ee9c, qu\u1ea3n l\u00fd v\u00e0 x\u1eed l\u00fd d\u1eef li\u1ec7u trong ch\u01b0\u01a1ng tr\u00ecnh Java. Ch\u00fang gi\u00fap l\u1eadp tr\u00ecnh vi\u00ean x\u00e2y d\u1ef1ng c\u00e1c \u1ee9ng d\u1ee5ng \u0111\u01a1n gi\u1ea3n \u0111\u1ebfn ph\u1ee9c t\u1ea1p m\u1ed9t c\u00e1ch c\u00f3 h\u1ec7 th\u1ed1ng.<\/span><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><em>\u0110\u1ecdc th\u00eam: <a href=\"https:\/\/itviec.com\/blog\/java-la-gi\/\" target=\"_blank\" rel=\"noopener\"><strong>Java l\u00e0 g\u00ec? T\u1ea5t c\u1ea3 nh\u1eefng \u0111i\u1ec1u b\u1ea1n c\u1ea7n bi\u1ebft v\u1ec1 ng\u00f4n ng\u1eef Java<\/strong><\/a><\/em><\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-cau-l\u1ec7nh-khai-bao-bi\u1ebfn-declaration-statement\"><span class=\"ez-toc-section\" id=\"Cau_lenh_khai_bao_bien_Declaration_Statement\"><\/span><b>C\u00e2u l\u1ec7nh khai b\u00e1o bi\u1ebfn (Declaration Statement)<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh khai b\u00e1o d\u00f9ng \u0111\u1ec3 khai b\u00e1o c\u00e1c bi\u1ebfn trong Java. Bi\u1ebfn l\u00e0 v\u00f9ng nh\u1edb trong b\u1ed9 nh\u1edb m\u00e1y t\u00ednh \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 l\u01b0u tr\u1eef d\u1eef li\u1ec7u t\u1ea1m th\u1eddi trong qu\u00e1 tr\u00ecnh ch\u1ea1y ch\u01b0\u01a1ng tr\u00ecnh.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">C\u00fa ph\u00e1p:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">&lt;kieu_du_lieu&gt; &lt;ten_bien&gt;;<\/span><\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">int age;<\/span><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">float salary;<\/span><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">String name;<\/span><\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3:<\/span><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400;\">int<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">float<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">String<\/span><span style=\"font-weight: 400;\"> l\u00e0 ki\u1ec3u d\u1eef li\u1ec7u \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 x\u00e1c \u0111\u1ecbnh lo\u1ea1i gi\u00e1 tr\u1ecb m\u00e0 bi\u1ebfn c\u00f3 th\u1ec3 l\u01b0u tr\u1eef.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">age<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">salary<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">name<\/span><span style=\"font-weight: 400;\"> l\u00e0 c\u00e1c t\u00ean bi\u1ebfn \u0111\u01b0\u1ee3c khai b\u00e1o.<\/span><\/li>\n<\/ul>\n\n\n\n<p><b>Gi\u1ea3i th\u00edch:<\/b><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400;\">int<\/span><span style=\"font-weight: 400;\">: d\u00f9ng \u0111\u1ec3 l\u01b0u tr\u1eef s\u1ed1 nguy\u00ean.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">float<\/span><span style=\"font-weight: 400;\">: l\u01b0u tr\u1eef s\u1ed1 th\u1ef1c v\u1edbi d\u1ea5u ch\u1ea5m \u0111\u1ed9ng.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">String<\/span><span style=\"font-weight: 400;\">: d\u00f9ng \u0111\u1ec3 l\u01b0u tr\u1eef chu\u1ed7i k\u00fd t\u1ef1.<\/span><\/li>\n<\/ul>\n\n\n\n<p><span style=\"font-weight: 400;\">Khai b\u00e1o bi\u1ebfn l\u00e0 b\u01b0\u1edbc \u0111\u1ea7u ti\u00ean trong qu\u00e1 tr\u00ecnh l\u00e0m vi\u1ec7c v\u1edbi d\u1eef li\u1ec7u trong Java.<\/span><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-cau-l\u1ec7nh-gan-gia-tr\u1ecb-assignment-statement\"><span class=\"ez-toc-section\" id=\"Cau_lenh_gan_gia_tri_Assignment_Statement\"><\/span><b>C\u00e2u l\u1ec7nh g\u00e1n gi\u00e1 tr\u1ecb (Assignment Statement)<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh g\u00e1n gi\u00e1 tr\u1ecb d\u00f9ng \u0111\u1ec3 g\u00e1n m\u1ed9t gi\u00e1 tr\u1ecb c\u1ee5 th\u1ec3 cho bi\u1ebfn \u0111\u00e3 \u0111\u01b0\u1ee3c khai b\u00e1o tr\u01b0\u1edbc \u0111\u00f3. Vi\u1ec7c g\u00e1n gi\u00e1 tr\u1ecb gi\u00fap bi\u1ebfn c\u00f3 d\u1eef li\u1ec7u \u0111\u1ec3 s\u1eed d\u1ee5ng trong c\u00e1c thao t\u00e1c t\u00ednh to\u00e1n ho\u1eb7c hi\u1ec3n th\u1ecb.<\/span><\/p>\n\n\n\n<p><b>C\u00fa ph\u00e1p:<\/b><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">&lt;ten_bien&gt; = &lt;gia_tri&gt;;<\/span><\/code><\/pre>\n\n\n\n<p><b>V\u00ed d\u1ee5:<\/b><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">age = 25;<\/span><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">salary = 1500.50f;<\/span><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">name = \"Nguyen Van A\";<\/span><\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3:<\/span><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400;\">age<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">salary<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">name<\/span><span style=\"font-weight: 400;\"> l\u00e0 c\u00e1c bi\u1ebfn \u0111\u00e3 khai b\u00e1o tr\u01b0\u1edbc.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">25<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">1500.50f<\/span><span style=\"font-weight: 400;\">, v\u00e0 <\/span><span style=\"font-weight: 400;\">&#8220;Nguyen Van A&#8221;<\/span><span style=\"font-weight: 400;\"> l\u00e0 c\u00e1c gi\u00e1 tr\u1ecb \u0111\u01b0\u1ee3c g\u00e1n cho bi\u1ebfn t\u01b0\u01a1ng \u1ee9ng.<\/span><\/li>\n<\/ul>\n\n\n\n<p><span style=\"font-weight: 400;\">L\u01b0u \u00fd:<\/span><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400;\">Bi\u1ebfn ph\u1ea3i \u0111\u01b0\u1ee3c khai b\u00e1o tr\u01b0\u1edbc khi g\u00e1n gi\u00e1 tr\u1ecb.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb \u0111\u01b0\u1ee3c g\u00e1n ph\u1ea3i t\u01b0\u01a1ng th\u00edch v\u1edbi ki\u1ec3u d\u1eef li\u1ec7u c\u1ee7a bi\u1ebfn.<\/span><\/li>\n<\/ul>\n\n\n\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 ho\u00e0n ch\u1ec9nh:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">int age;<\/span>\n\n<span style=\"font-weight: 400;\">age = 30;<\/span>\n\n<span style=\"font-weight: 400;\">System.out.println(\"Tu\u1ed5i c\u1ee7a b\u1ea1n l\u00e0: \" + age);<\/span><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-cau-l\u1ec7nh-in-ra-man-hinh-print-statement\"><span class=\"ez-toc-section\" id=\"Cau_lenh_in_ra_man_hinh_Print_Statement\"><\/span><b>C\u00e2u l\u1ec7nh in ra m\u00e0n h\u00ecnh (Print Statement)<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh in d\u00f9ng \u0111\u1ec3 hi\u1ec3n th\u1ecb th\u00f4ng tin ho\u1eb7c d\u1eef li\u1ec7u ra m\u00e0n h\u00ecnh. Trong Java, ch\u00fang ta th\u01b0\u1eddng s\u1eed d\u1ee5ng <\/span><span style=\"font-weight: 400;\">System.out.println<\/span><span style=\"font-weight: 400;\"> ho\u1eb7c <\/span><span style=\"font-weight: 400;\">System.out.print<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 th\u1ef1c hi\u1ec7n vi\u1ec7c n\u00e0y.<\/span><\/p>\n\n\n\n<p>C\u00fa ph\u00e1p<span style=\"font-weight: 400;\">:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>System.out.println(&lt;noi_dung&gt;);\nSystem.out.print(&lt;noi_dung&gt;);<\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>System.out.println(\"Xin ch\u00e0o! H\u1ecd v\u00e0 t\u00ean: \" + name);\nSystem.out.println(\"Tu\u1ed5i: \" + age);<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400;\">System.out.println<\/span><span style=\"font-weight: 400;\">: in n\u1ed9i dung ra m\u00e0n h\u00ecnh v\u00e0 t\u1ef1 \u0111\u1ed9ng xu\u1ed1ng d\u00f2ng m\u1edbi.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">System.out.print<\/span><span style=\"font-weight: 400;\">: in n\u1ed9i dung ra m\u00e0n h\u00ecnh nh\u01b0ng kh\u00f4ng xu\u1ed1ng d\u00f2ng m\u1edbi.<\/span><\/li>\n<\/ul>\n\n\n\n<p><b>Gi\u1ea3i th\u00edch th\u00eam:<\/b><span style=\"font-weight: 400;\"> C\u00e2u l\u1ec7nh n\u00e0y th\u01b0\u1eddng \u0111\u01b0\u1ee3c d\u00f9ng \u0111\u1ec3 hi\u1ec3n th\u1ecb k\u1ebft qu\u1ea3 t\u00ednh to\u00e1n, th\u00f4ng b\u00e1o, ho\u1eb7c d\u1eef li\u1ec7u nh\u1eadp t\u1eeb ng\u01b0\u1eddi d\u00f9ng. Vi\u1ec7c s\u1eed d\u1ee5ng d\u1ea5u <\/span><span style=\"font-weight: 400;\">+<\/span><span style=\"font-weight: 400;\"> gi\u00fap n\u1ed1i chu\u1ed7i v\u1edbi bi\u1ebfn ho\u1eb7c c\u00e1c d\u1eef li\u1ec7u kh\u00e1c.<\/span><\/p>\n\n\n\n<p>V\u00ed d\u1ee5 m\u1edf r\u1ed9ng:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int a = 10, b = 20;\nSystem.out.println(\"T\u1ed5ng c\u1ee7a a v\u00e0 b l\u00e0: \" + (a + b));<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-cau-l\u1ec7nh-nh\u1eadp-li\u1ec7u-t\u1eeb-ban-phim-input-statement\"><span class=\"ez-toc-section\" id=\"Cau_lenh_nhap_lieu_tu_ban_phim_Input_Statement\"><\/span><b>C\u00e2u l\u1ec7nh nh\u1eadp li\u1ec7u t\u1eeb b\u00e0n ph\u00edm (Input Statement)<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh nh\u1eadp li\u1ec7u cho ph\u00e9p ch\u01b0\u01a1ng tr\u00ecnh \u0111\u1ecdc d\u1eef li\u1ec7u do ng\u01b0\u1eddi d\u00f9ng nh\u1eadp v\u00e0o t\u1eeb b\u00e0n ph\u00edm. Trong Java, ch\u00fang ta th\u01b0\u1eddng s\u1eed d\u1ee5ng l\u1edbp Scanner \u0111\u1ec3 th\u1ef1c hi\u1ec7n nh\u1eadp li\u1ec7u.<\/span><\/p>\n\n\n\n<p><b>B\u01b0\u1edbc 1: <\/b><b>Import l\u1edbp Scanner<\/b><\/p>\n\n\n\n<p>Tr\u01b0\u1edbc khi s\u1eed d\u1ee5ng Scanner, c\u1ea7n import l\u1edbp n\u00e0y t\u1eeb th\u01b0 vi\u1ec7n java.util:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">import java.util.Scanner;<\/span><\/code><\/pre>\n\n\n\n<p><b>B\u01b0\u1edbc 2: Khai b\u00e1o \u0111\u1ed1i t\u01b0\u1ee3ng Scanner<\/b><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Khai b\u00e1o \u0111\u1ed1i t\u01b0\u1ee3ng Scanner \u0111\u1ec3 \u0111\u1ecdc d\u1eef li\u1ec7u t\u1eeb b\u00e0n ph\u00edm:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">Scanner scanner = new Scanner(System.in);<\/span><\/code><\/pre>\n\n\n\n<p><b>B\u01b0\u1edbc 3: S\u1eed d\u1ee5ng Scanner \u0111\u1ec3 nh\u1eadp d\u1eef li\u1ec7u<\/b><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">int age = scanner.nextInt();&nbsp; \/\/ Nh\u1eadp s\u1ed1 nguy\u00ean<\/span>\n<span style=\"font-weight: 400;\">String name = scanner.nextLine();&nbsp; \/\/ Nh\u1eadp chu\u1ed7i<\/span>\n<span style=\"font-weight: 400;\">float salary = scanner.nextFloat(); \/\/ Nh\u1eadp s\u1ed1 th\u1ef1c<\/span><\/code><\/pre>\n\n\n\n<p><b>V\u00ed d\u1ee5 ho\u00e0n ch\u1ec9nh:<\/b><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;\n\npublic class InputExample {\n  public static void main(String&#91;] args) {\n    Scanner scanner = new Scanner(System.in);\n\n    System.out.print(\"Nh\u1eadp t\u00ean c\u1ee7a b\u1ea1n: \");\n    String name = scanner.nextLine();\n\n    System.out.print(\"Nh\u1eadp tu\u1ed5i c\u1ee7a b\u1ea1n: \");\n    int age = scanner.nextInt();\n\n    System.out.print(\"Nh\u1eadp l\u01b0\u01a1ng c\u1ee7a b\u1ea1n: \");\n    float salary = scanner.nextFloat();\n\n    System.out.println(\"Th\u00f4ng tin b\u1ea1n v\u1eeba nh\u1eadp:\");\n    System.out.println(\"H\u1ecd t\u00ean: \" + name);\n    System.out.println(\"Tu\u1ed5i: \" + age);\n    System.out.println(\"L\u01b0\u01a1ng: \" + salary);\n  }\n}<\/code><\/pre>\n\n\n\n<p><b>Gi\u1ea3i th\u00edch:<\/b><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400;\">nextInt():<\/span><span style=\"font-weight: 400;\"> \u0111\u1ecdc s\u1ed1 nguy\u00ean.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">nextFloat():<\/span><span style=\"font-weight: 400;\"> \u0111\u1ecdc s\u1ed1 th\u1ef1c.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">nextLine():<\/span><span style=\"font-weight: 400;\"> \u0111\u1ecdc chu\u1ed7i k\u00fd t\u1ef1.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">Ng\u01b0\u1eddi d\u00f9ng nh\u1eadp d\u1eef li\u1ec7u v\u00e0 nh\u1ea5n <\/span><span style=\"font-weight: 400;\">Enter<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 ch\u01b0\u01a1ng tr\u00ecnh ti\u1ebfp t\u1ee5c ch\u1ea1y.<\/span><\/li>\n<\/ul>\n\n\n\n<p><b>L\u01b0u \u00fd:<\/b><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400;\">Scanner c\u1ea7n \u0111\u01b0\u1ee3c \u0111\u00f3ng l\u1ea1i sau khi s\u1eed d\u1ee5ng b\u1eb1ng <\/span><span style=\"font-weight: 400;\">scanner.close(<\/span><span style=\"font-weight: 400;\">) \u0111\u1ec3 tr\u00e1nh r\u00f2 r\u1ec9 b\u1ed9 nh\u1edb.<\/span><\/li>\n<\/ul>\n\n\n\n<p><span style=\"font-weight: 400;\">Tr\u00ean \u0111\u00e2y l\u00e0 c\u00e1c lo\u1ea1i c\u00e2u l\u1ec7nh c\u01a1 b\u1ea3n trong Java, bao g\u1ed3m khai b\u00e1o bi\u1ebfn, g\u00e1n gi\u00e1 tr\u1ecb, in d\u1eef li\u1ec7u ra m\u00e0n h\u00ecnh v\u00e0 nh\u1eadp li\u1ec7u t\u1eeb b\u00e0n ph\u00edm.<\/span><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><em>Tham kh\u1ea3o <strong><a href=\"https:\/\/itviec.com\/it-jobs\/java?utm_medium=anchor_text_mid&amp;utm_source=blog&amp;utm_campaign=viec_lam_java&amp;utm_content=cac_cau_lenh_trong_java\" target=\"_blank\" rel=\"noreferrer noopener\">vi\u1ec7c l\u00e0m Java<\/a><\/strong> m\u1edbi nh\u1ea5t tr\u00ean to\u00e0n qu\u1ed1c<\/em><\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-cac-cau-l\u1ec7nh-trong-java-dung-d\u1ec3-di\u1ec1u-khi\u1ec3n-lu\u1ed3ng\"><span class=\"ez-toc-section\" id=\"Cac_cau_lenh_trong_Java_dung_de_dieu_khien_luong\"><\/span><strong>C\u00e1c c\u00e2u l\u1ec7nh trong Java d\u00f9ng \u0111\u1ec3 \u0111i\u1ec1u khi\u1ec3n lu\u1ed3ng<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">Trong l\u1eadp tr\u00ecnh Java, c\u00e1c c\u00e2u l\u1ec7nh \u0111i\u1ec1u khi\u1ec3n lu\u1ed3ng \u0111\u00f3ng vai tr\u00f2 quan tr\u1ecdng trong vi\u1ec7c x\u00e1c \u0111\u1ecbnh lu\u1ed3ng th\u1ef1c thi c\u1ee7a ch\u01b0\u01a1ng tr\u00ecnh.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">D\u01b0\u1edbi \u0111\u00e2y l\u00e0 c\u00e1c lo\u1ea1i c\u00e2u l\u1ec7nh \u0111i\u1ec1u khi\u1ec3n lu\u1ed3ng ph\u1ed5 bi\u1ebfn:<\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-cau-l\u1ec7nh-if-di\u1ec1u-ki\u1ec7n-d\u01a1n\"><b>C\u00e2u l\u1ec7nh if (\u0110i\u1ec1u ki\u1ec7n \u0111\u01a1n)<\/b><\/h3>\n\n\n\n<p><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh if \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 ki\u1ec3m tra m\u1ed9t \u0111i\u1ec1u ki\u1ec7n c\u1ee5 th\u1ec3 v\u00e0 th\u1ef1c thi kh\u1ed1i l\u1ec7nh n\u1ebfu \u0111i\u1ec1u ki\u1ec7n \u0111\u00f3 \u0111\u00fang (true).<\/span><\/p>\n\n\n\n<p><b>C\u00fa ph\u00e1p:<\/b><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">if (\u0111i\u1ec1u ki\u1ec7n) {<\/span>\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\/\/ Kh\u1ed1i l\u1ec7nh s\u1ebd th\u1ef1c thi n\u1ebfu \u0111i\u1ec1u ki\u1ec7n \u0111\u00fang<\/span>\n<span style=\"font-weight: 400;\">}<\/span><\/code><\/pre>\n\n\n\n<p>V<span style=\"font-weight: 400;\">\u00ed d\u1ee5:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">int age = 18;<\/span>\n<span style=\"font-weight: 400;\">if (age &gt;= 18) {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;System.out.println(\"B\u1ea1n \u0111\u1ee7 tu\u1ed5i \u0111\u1ec3 tham gia.\");<\/span>\n<span style=\"font-weight: 400;\">}<\/span><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-cau-l\u1ec7nh-if-else-di\u1ec1u-ki\u1ec7n-kep\"><b>C\u00e2u l\u1ec7nh if-else (\u0110i\u1ec1u ki\u1ec7n k\u00e9p)<\/b><\/h3>\n\n\n\n<p><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh if-else cho ph\u00e9p ch\u01b0\u01a1ng tr\u00ecnh th\u1ef1c thi m\u1ed9t kh\u1ed1i l\u1ec7nh khi \u0111i\u1ec1u ki\u1ec7n \u0111\u00fang v\u00e0 m\u1ed9t kh\u1ed1i l\u1ec7nh kh\u00e1c khi \u0111i\u1ec1u ki\u1ec7n sai.<\/span><\/p>\n\n\n\n<p><b>C\u00fa ph\u00e1p:<\/b><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">if (\u0111i\u1ec1u ki\u1ec7n) {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;\/\/ Kh\u1ed1i l\u1ec7nh th\u1ef1c thi khi \u0111i\u1ec1u ki\u1ec7n \u0111\u00fang<\/span>\n<span style=\"font-weight: 400;\">} else {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;\/\/ Kh\u1ed1i l\u1ec7nh th\u1ef1c thi khi \u0111i\u1ec1u ki\u1ec7n sai<\/span>\n<span style=\"font-weight: 400;\">}<\/span><\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">int score = 75;<\/span>\n<span style=\"font-weight: 400;\">if (score &gt;= 50) {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;System.out.println(\"B\u1ea1n \u0111\u00e3 \u0111\u1eadu.\");<\/span>\n<span style=\"font-weight: 400;\">} else {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;System.out.println(\"B\u1ea1n \u0111\u00e3 tr\u01b0\u1ee3t.\");<\/span>\n<span style=\"font-weight: 400;\">}<\/span><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-cau-l\u1ec7nh-switch-case-di\u1ec1u-ki\u1ec7n-nhi\u1ec1u-l\u1ef1a-ch\u1ecdn\"><b>C\u00e2u l\u1ec7nh switch-case (\u0110i\u1ec1u ki\u1ec7n nhi\u1ec1u l\u1ef1a ch\u1ecdn)<\/b><\/h3>\n\n\n\n<p><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh switch-case \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng khi b\u1ea1n c\u1ea7n ki\u1ec3m tra m\u1ed9t gi\u00e1 tr\u1ecb v\u1edbi nhi\u1ec1u tr\u01b0\u1eddng h\u1ee3p (case) kh\u00e1c nhau.<\/span><\/p>\n\n\n\n<p><b>C\u00fa ph\u00e1p:<\/b><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>switch (bi\u1ec3u th\u1ee9c) {\n  case gi\u00e1_tr\u1ecb_1:\n    \/\/ Kh\u1ed1i l\u1ec7nh khi bi\u1ec3u th\u1ee9c bang gi\u00e1_tr\u1ecb_1\n    break;\n  case gi\u00e1_tr\u1ecb_2:\n    \/\/ Kh\u1ed1i l\u1ec7nh khi bi\u1ec3u th\u1ee9c bang gi\u00e1 tr\u1ecb_2\n    break;\n  default:\n    \/\/ Kh\u1ed1i l\u1ec7nh khi kh\u00f4ng c\u00f3 case n\u00e0o kh\u1edbp\n}<\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int day = 3;\nswitch (day) {\n  case 1:\n    System.out.println(\"Th\u1ee9 Hai\");\n    break;\n  case 2:\n    System.out.println(\"Th\u1ee9 Ba\");\n    break;\n  case 3:\n    System.out.println(\"Th\u1ee9 T\u01b0\");\n    break;\n  default:\n    System.out.println(\"Ng\u00e0y kh\u00f4ng h\u1ee3p l\u1ec7\");\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-cau-l\u1ec7nh-vong-l\u1eb7p-for-while-do-while\"><b>C\u00e2u l\u1ec7nh v\u00f2ng l\u1eb7p (for, while, do-while)<\/b><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-vong-l\u1eb7p-for\"><b>V\u00f2ng l\u1eb7p for<\/b><\/h4>\n\n\n\n<p><span style=\"font-weight: 400;\">D\u00f9ng khi b\u1ea1n bi\u1ebft tr\u01b0\u1edbc s\u1ed1 l\u1ea7n l\u1eb7p.<\/span><\/p>\n\n\n\n<p><b>C\u00fa ph\u00e1p:<\/b><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">for (kh\u1edfi_t\u1ea1o; \u0111i\u1ec1u_ki\u1ec7n; b\u01b0\u1edbc_nh\u1ea3y) {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;\/\/ Kh\u1ed1i l\u1ec7nh l\u1eb7p l\u1ea1i<\/span>\n<span style=\"font-weight: 400;\">}<\/span><\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">for (int i = 1; i &lt;= 5; i++) {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;System.out.println(\"L\u1ea7n l\u1eb7p: \" + i);<\/span>\n<span style=\"font-weight: 400;\">}<\/span><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-vong-l\u1eb7p-while\"><b>V\u00f2ng l\u1eb7p while<\/b><\/h4>\n\n\n\n<p><span style=\"font-weight: 400;\">D\u00f9ng khi b\u1ea1n ch\u01b0a bi\u1ebft tr\u01b0\u1edbc s\u1ed1 l\u1ea7n l\u1eb7p nh\u01b0ng c\u00f3 \u0111i\u1ec1u ki\u1ec7n d\u1eebng.<\/span><\/p>\n\n\n\n<p><b>C\u00fa ph\u00e1p:<\/b><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">while (\u0111i\u1ec1u_ki\u1ec7n) {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;\/\/ Kh\u1ed1i l\u1ec7nh l\u1eb7p l\u1ea1i<\/span>\n<span style=\"font-weight: 400;\">}<\/span><\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">int i = 1;<\/span>\n<span style=\"font-weight: 400;\">while (i &lt;= 5) {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;System.out.println(\"L\u1ea7n l\u1eb7p: \" + i);<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;i++;<\/span>\n<span style=\"font-weight: 400;\">}<\/span><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-vong-l\u1eb7p-do-while\"><b>V\u00f2ng l\u1eb7p do-while<\/b><\/h4>\n\n\n\n<p><span style=\"font-weight: 400;\">D\u00f9ng khi b\u1ea1n mu\u1ed1n kh\u1ed1i l\u1ec7nh \u0111\u01b0\u1ee3c th\u1ef1c thi \u00edt nh\u1ea5t m\u1ed9t l\u1ea7n, d\u00f9 \u0111i\u1ec1u ki\u1ec7n sai.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">C\u00fa ph\u00e1p:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">do {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;\/\/ Kh\u1ed1i l\u1ec7nh l\u1eb7p l\u1ea1i<\/span>\n<span style=\"font-weight: 400;\">} while (\u0111i\u1ec1u_ki\u1ec7n);<\/span><\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">int i = 1;<\/span>\n<span style=\"font-weight: 400;\">do {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;System.out.println(\"L\u1ea7n l\u1eb7p: \" + i);<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;i++;<\/span>\n<span style=\"font-weight: 400;\">} while (i &lt;= 5);<\/span><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-cau-l\u1ec7nh-break\"><b>C\u00e2u l\u1ec7nh break<\/b><\/h3>\n\n\n\n<p><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh break \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 tho\u00e1t kh\u1ecfi v\u00f2ng l\u1eb7p ho\u1eb7c c\u00e2u l\u1ec7nh switch.<\/span><\/p>\n\n\n\n<p><b>V\u00ed d\u1ee5:<\/b><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">for (int i = 1; i &lt;= 5; i++) {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;if (i == 3) {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break; \/\/ Tho\u00e1t kh\u1ecfi v\u00f2ng l\u1eb7p khi i = 3<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;}<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;System.out.println(\"i = \" + i);<\/span>\n<span style=\"font-weight: 400;\">}<\/span><\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">K\u1ebft qu\u1ea3:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">i = 1<\/span>\n\n<span style=\"font-weight: 400;\">i = 2<\/span><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-cau-l\u1ec7nh-continue\"><b>C\u00e2u l\u1ec7nh continue<\/b><\/h3>\n\n\n\n<p><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh continue \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 b\u1ecf qua ph\u1ea7n c\u00f2n l\u1ea1i c\u1ee7a v\u00f2ng l\u1eb7p hi\u1ec7n t\u1ea1i v\u00e0 chuy\u1ec3n sang v\u00f2ng l\u1eb7p ti\u1ebfp theo.<\/span><\/p>\n\n\n\n<p><b>V\u00ed d\u1ee5:<\/b><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">for (int i = 1; i &lt;= 5; i++) {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;if (i == 3) {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue; \/\/ B\u1ecf qua v\u00f2ng l\u1eb7p khi i = 3<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;}<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;System.out.println(\"i = \" + i);<\/span>\n<span style=\"font-weight: 400;\">}<\/span><\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">K\u1ebft qu\u1ea3:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">i = 1<\/span>\n\n<span style=\"font-weight: 400;\">i = 2<\/span>\n\n<span style=\"font-weight: 400;\">i = 4<\/span>\n\n<span style=\"font-weight: 400;\">i = 5<\/span><\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">C\u00e1c c\u00e2u l\u1ec7nh \u0111i\u1ec1u khi\u1ec3n lu\u1ed3ng trong Java nh\u01b0 <\/span><span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">if-else<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">switch-case<\/span><span style=\"font-weight: 400;\">, v\u00e0 c\u00e1c v\u00f2ng l\u1eb7p <\/span><span style=\"font-weight: 400;\">for<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">while<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">do-while<\/span><span style=\"font-weight: 400;\"> gi\u00fap l\u1eadp tr\u00ecnh vi\u00ean \u0111i\u1ec1u khi\u1ec3n lu\u1ed3ng th\u1ef1c thi ch\u01b0\u01a1ng tr\u00ecnh m\u1ed9t c\u00e1ch linh ho\u1ea1t.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh <\/span><span style=\"font-weight: 400;\">break<\/span><span style=\"font-weight: 400;\"> v\u00e0 <\/span><span style=\"font-weight: 400;\">continue<\/span><span style=\"font-weight: 400;\"> \u0111\u00f3ng vai tr\u00f2 quan tr\u1ecdng trong vi\u1ec7c ki\u1ec3m so\u00e1t qu\u00e1 tr\u00ecnh l\u1eb7p, gi\u00fap ch\u01b0\u01a1ng tr\u00ecnh ho\u1ea1t \u0111\u1ed9ng hi\u1ec7u qu\u1ea3 h\u01a1n.<\/span><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-cac-cau-l\u1ec7nh-trong-java-dung-d\u1ec3-x\u1eed-ly-l\u1ed7i-nbsp\"><span class=\"ez-toc-section\" id=\"Cac_cau_lenh_trong_Java_dung_de_xu_ly_loi\"><\/span><span style=\"font-weight: 400;\"><strong>C\u00e1c c\u00e2u l\u1ec7nh trong Java d\u00f9ng \u0111\u1ec3 x\u1eed l\u00fd l\u1ed7i<\/strong>&nbsp;<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">Trong Java, vi\u1ec7c x\u1eed l\u00fd l\u1ed7i v\u00e0 ngo\u1ea1i l\u1ec7 l\u00e0 m\u1ed9t ph\u1ea7n quan tr\u1ecdng gi\u00fap \u0111\u1ea3m b\u1ea3o ch\u01b0\u01a1ng tr\u00ecnh ch\u1ea1y \u1ed5n \u0111\u1ecbnh, tr\u00e1nh t\u00ecnh tr\u1ea1ng gi\u00e1n \u0111o\u1ea1n do c\u00e1c l\u1ed7i ph\u00e1t sinh. C\u00e1c c\u00e2u l\u1ec7nh x\u1eed l\u00fd l\u1ed7i gi\u00fap ki\u1ec3m so\u00e1t v\u00e0 qu\u1ea3n l\u00fd c\u00e1c t\u00ecnh hu\u1ed1ng kh\u00f4ng mong \u0111\u1ee3i nh\u01b0 l\u1ed7i logic, l\u1ed7i nh\u1eadp li\u1ec7u ho\u1eb7c c\u00e1c v\u1ea5n \u0111\u1ec1 trong qu\u00e1 tr\u00ecnh th\u1ef1c thi ch\u01b0\u01a1ng tr\u00ecnh.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Java cung c\u1ea5p c\u00e1c kh\u1ed1i l\u1ec7nh <\/span><b>try<\/b><span style=\"font-weight: 400;\">, <\/span><b>catch<\/b><span style=\"font-weight: 400;\">, <\/span><b>finally<\/b><span style=\"font-weight: 400;\">, v\u00e0 t\u1eeb kh\u00f3a <\/span><b>throw<\/b><span style=\"font-weight: 400;\"> \u0111\u1ec3 x\u1eed l\u00fd ngo\u1ea1i l\u1ec7. C\u00f9ng t\u00ecm hi\u1ec3u chi ti\u1ebft t\u1eebng c\u00e2u l\u1ec7nh sau \u0111\u00e2y:<\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-cau-l\u1ec7nh-try-catch-x\u1eed-ly-ngo\u1ea1i-l\u1ec7\"><b>C\u00e2u l\u1ec7nh try-catch (X\u1eed l\u00fd ngo\u1ea1i l\u1ec7)<\/b><\/h3>\n\n\n\n<p><b>M\u1ee5c \u0111\u00edch:<\/b><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400;\">try-catch \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 b\u1eaft v\u00e0 x\u1eed l\u00fd c\u00e1c ngo\u1ea1i l\u1ec7 x\u1ea3y ra trong ch\u01b0\u01a1ng tr\u00ecnh, \u0111\u1ea3m b\u1ea3o ch\u01b0\u01a1ng tr\u00ecnh kh\u00f4ng b\u1ecb d\u1eebng \u0111\u1ed9t ng\u1ed9t.<\/span><\/li>\n<\/ul>\n\n\n\n<p><b>C\u00e1ch ho\u1ea1t \u0111\u1ed9ng:<\/b><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400;\">Kh\u1ed1i try ch\u1ee9a \u0111o\u1ea1n m\u00e3 c\u00f3 th\u1ec3 g\u00e2y ra ngo\u1ea1i l\u1ec7.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">Kh\u1ed1i catch s\u1ebd x\u1eed l\u00fd ngo\u1ea1i l\u1ec7 n\u1ebfu c\u00f3 x\u1ea3y ra trong kh\u1ed1i try.<\/span><\/li>\n<\/ul>\n\n\n\n<p><b>C\u00fa ph\u00e1p:<\/b><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">try {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;\/\/ Code c\u00f3 th\u1ec3 g\u00e2y ra ngo\u1ea1i l\u1ec7<\/span>\n<span style=\"font-weight: 400;\">} catch (LoaiNgoaiLe e) {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;\/\/ X\u1eed l\u00fd ngo\u1ea1i l\u1ec7<\/span>\n<span style=\"font-weight: 400;\">}<\/span><\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">public class TryCatchExample {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;public static void main(String&#91;] args) {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int result = 10 \/ 0; \/\/ L\u1ed7i chia cho 0<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} catch (ArithmeticException e) {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(\"C\u00f3 l\u1ed7i x\u1ea3y ra: \" + e.getMessage());<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(\"Ch\u01b0\u01a1ng tr\u00ecnh ti\u1ebfp t\u1ee5c ch\u1ea1y...\");<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;}<\/span>\n<span style=\"font-weight: 400;\">}<\/span><\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">Output:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>C\u00f3 l\u1ed7i x\u1ea3y ra: \/ by zero\nCh\u01b0\u01a1ng tr\u00ecnh ti\u1ebfp t\u1ee5c ch\u1ea1y...<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-cau-l\u1ec7nh-throw-nem-ngo\u1ea1i-l\u1ec7\"><b>C\u00e2u l\u1ec7nh throw (N\u00e9m ngo\u1ea1i l\u1ec7)<\/b><\/h3>\n\n\n\n<p><b>M\u1ee5c \u0111\u00edch:<\/b><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">T\u1eeb kh\u00f3a throw \u0111\u01b0\u1ee3c d\u00f9ng \u0111\u1ec3 n\u00e9m m\u1ed9t ngo\u1ea1i l\u1ec7 c\u1ee5 th\u1ec3. N\u00f3 th\u01b0\u1eddng \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng trong c\u00e1c t\u00ecnh hu\u1ed1ng b\u1ea1n mu\u1ed1n ki\u1ec3m so\u00e1t ngo\u1ea1i l\u1ec7 theo logic ri\u00eang c\u1ee7a ch\u01b0\u01a1ng tr\u00ecnh.<\/span><\/p>\n\n\n\n<p><b>C\u00e1ch ho\u1ea1t \u0111\u1ed9ng:<\/b><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Sau t\u1eeb kh\u00f3a throw, b\u1ea1n ph\u1ea3i ch\u1ec9 \u0111\u1ecbnh m\u1ed9t \u0111\u1ed1i t\u01b0\u1ee3ng ngo\u1ea1i l\u1ec7 (instance c\u1ee7a Throwable ho\u1eb7c c\u00e1c l\u1edbp con).<\/span><\/p>\n\n\n\n<p><b>C\u00fa ph\u00e1p:<\/b><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">throw new LoaiNgoaiLe(\"Th\u00f4ng b\u00e1o l\u1ed7i\");<\/span><\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class ThrowExample {\n  static void validateAge(int age) {\n    if (age&lt;18) {\n      throw new IllegalArgumentException(\"Tu\u1ed5i kh\u00f4ng \u0111\u1ee7 \u0111i\u1ec1u ki\u1ec7n!\");\n    } else {\n      System.out.println(\"Tu\u1ed5i h\u1ee3p l\u1ec7.\");\n    }\n  }\n\n  public static void main(String&#91;] args) {\n    try {\n      validateAge(16); \/\/ N\u00e9m ngo\u1ea1i l\u1ec7\n    } catch (IllegalArgumentException e) {\n      System.out.println(\"L\u1ed7i: \" + e.getMessage());\n    }\n    System.out.println(\"Ch\u01b0\u01a1ng tr\u00ecnh ti\u1ebfp t\u1ee5c ch\u1ea1y...\");\n  }\n}<\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">Output:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>L\u1ed7i: Tu\u1ed5i kh\u00f4ng \u0111\u1ee7 \u0111i\u1ec1u ki\u1ec7n!\nCh\u01b0\u01a1ng tr\u00ecnh ti\u1ebfp t\u1ee5c ch\u1ea1y...<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-cau-l\u1ec7nh-finally-kh\u1ed1i-ma-luon-th\u1ef1c-thi\"><b>C\u00e2u l\u1ec7nh finally (Kh\u1ed1i m\u00e3 lu\u00f4n th\u1ef1c thi)<\/b><\/h3>\n\n\n\n<p><b>M\u1ee5c \u0111\u00edch:<\/b><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400;\">finally l\u00e0 kh\u1ed1i m\u00e3 lu\u00f4n \u0111\u01b0\u1ee3c th\u1ef1c thi sau khi k\u1ebft th\u00fac try-catch, cho d\u00f9 c\u00f3 x\u1ea3y ra ngo\u1ea1i l\u1ec7 hay kh\u00f4ng.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">Th\u01b0\u1eddng \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 \u0111\u00f3ng t\u00e0i nguy\u00ean (file, k\u1ebft n\u1ed1i database, v.v.) nh\u1eb1m \u0111\u1ea3m b\u1ea3o h\u1ec7 th\u1ed1ng kh\u00f4ng b\u1ecb r\u00f2 r\u1ec9 t\u00e0i nguy\u00ean.<\/span><\/li>\n<\/ul>\n\n\n\n<p><b>C\u00fa ph\u00e1p:<\/b><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">try {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;\/\/ Code c\u00f3 th\u1ec3 g\u00e2y ra ngo\u1ea1i l\u1ec7<\/span>\n<span style=\"font-weight: 400;\">} catch (LoaiNgoaiLe e) {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;\/\/ X\u1eed l\u00fd ngo\u1ea1i l\u1ec7<\/span>\n<span style=\"font-weight: 400;\">} finally {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;\/\/ Kh\u1ed1i m\u00e3 lu\u00f4n th\u1ef1c thi<\/span>\n<span style=\"font-weight: 400;\">}<\/span><\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class FinallyExample {\n  public static void main(String&#91;] args) {\n    try {\n      int result = 10 \/ 0; \/\/ L\u1ed7i chia cho 0\n    } catch (ArithmeticException e) {\n      System.out.println(\"C\u00f3 l\u1ed7i x\u1ea3y ra: \" + e.getMessage());\n    } finally {\n      System.out.println(\"Kh\u1ed1i finally lu\u00f4n \u0111\u01b0\u1ee3c th\u1ef1c thi.\");\n    }\n    System.out.println(\"Ch\u01b0\u01a1ng tr\u00ecnh ti\u1ebfp t\u1ee5c ch\u1ea1y...\");\n  }\n}<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>C\u00f3 l\u1ed7i x\u1ea3y ra: \/ by zero\nKh\u1ed1i finally lu\u00f4n \u0111\u01b0\u1ee3c th\u1ef1c thi.\nCh\u01b0\u01a1ng tr\u00ecnh ti\u1ebfp t\u1ee5c ch\u1ea1y...<\/code><\/pre>\n\n\n\n<p><b>T\u00f3m l\u1ea1i<\/b><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Trong Java, c\u00e1c c\u00e2u l\u1ec7nh x\u1eed l\u00fd l\u1ed7i nh\u01b0 try-catch, throw, v\u00e0 finally gi\u00fap l\u1eadp tr\u00ecnh vi\u00ean ki\u1ec3m so\u00e1t \u0111\u01b0\u1ee3c c\u00e1c t\u00ecnh hu\u1ed1ng b\u1ea5t th\u01b0\u1eddng trong qu\u00e1 tr\u00ecnh th\u1ef1c thi ch\u01b0\u01a1ng tr\u00ecnh.<\/span><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400;\">try-catch: B\u1eaft v\u00e0 x\u1eed l\u00fd ngo\u1ea1i l\u1ec7.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">throw: N\u00e9m ngo\u1ea1i l\u1ec7 theo \u00fd \u0111\u1ecbnh c\u1ee7a l\u1eadp tr\u00ecnh vi\u00ean.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">finally: \u0110\u1ea3m b\u1ea3o th\u1ef1c thi \u0111o\u1ea1n m\u00e3 quan tr\u1ecdng b\u1ea5t k\u1ec3 c\u00f3 x\u1ea3y ra ngo\u1ea1i l\u1ec7 hay kh\u00f4ng.<\/span><\/li>\n<\/ul>\n\n\n\n<p><span style=\"font-weight: 400;\">Hi\u1ec3u v\u00e0 s\u1eed d\u1ee5ng linh ho\u1ea1t c\u00e1c c\u00e2u l\u1ec7nh n\u00e0y s\u1ebd gi\u00fap ch\u01b0\u01a1ng tr\u00ecnh Java tr\u1edf n\u00ean an to\u00e0n, \u1ed5n \u0111\u1ecbnh v\u00e0 d\u1ec5 b\u1ea3o tr\u00ec h\u01a1n.<\/span><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-cac-cau-l\u1ec7nh-trong-java-d\u1eb7c-bi\u1ec7t-nbsp\"><span class=\"ez-toc-section\" id=\"Cac_cau_lenh_trong_Java_dac_biet\"><\/span><span style=\"font-weight: 400;\"><strong>C\u00e1c c\u00e2u l\u1ec7nh trong Java \u0111\u1eb7c bi\u1ec7t<\/strong>&nbsp;<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">Java cung c\u1ea5p nhi\u1ec1u c\u00e2u l\u1ec7nh kh\u00e1c nhau \u0111\u1ec3 l\u1eadp tr\u00ecnh vi\u00ean x\u00e2y d\u1ef1ng v\u00e0 ki\u1ec3m so\u00e1t lu\u1ed3ng ch\u01b0\u01a1ng tr\u00ecnh. Trong b\u00e0i vi\u1ebft n\u00e0y, ch\u00fang ta s\u1ebd t\u1eadp trung v\u00e0o <\/span><b>c\u00e1c c\u00e2u l\u1ec7nh \u0111\u1eb7c bi\u1ec7t<\/b><span style=\"font-weight: 400;\"> g\u1ed3m: <\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">assert<\/span><span style=\"font-weight: 400;\">, v\u00e0 <\/span><span style=\"font-weight: 400;\">synchronized<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-cau-l\u1ec7nh-return-tr\u1ea3-gia-tr\u1ecb-v\u1ec1\"><b>C\u00e2u l\u1ec7nh <\/b><b>return<\/b><b> (Tr\u1ea3 gi\u00e1 tr\u1ecb v\u1ec1)<\/b><\/h3>\n\n\n\n<p><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh <\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\"> \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 k\u1ebft th\u00fac m\u1ed9t ph\u01b0\u01a1ng th\u1ee9c v\u00e0 tr\u1ea3 v\u1ec1 m\u1ed9t gi\u00e1 tr\u1ecb cho n\u01a1i g\u1ecdi ph\u01b0\u01a1ng th\u1ee9c (n\u1ebfu c\u00f3). \u0110\u00e2y l\u00e0 c\u00e2u l\u1ec7nh ph\u1ed5 bi\u1ebfn trong Java, \u0111\u1eb7c bi\u1ec7t trong c\u00e1c h\u00e0m c\u00f3 gi\u00e1 tr\u1ecb tr\u1ea3 v\u1ec1.<\/span><\/p>\n\n\n\n<p><b>C\u00fa ph\u00e1p<\/b><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">return &#91;gi\u00e1 tr\u1ecb];<\/span><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400;\">N\u1ebfu ph\u01b0\u01a1ng th\u1ee9c c\u00f3 ki\u1ec3u tr\u1ea3 v\u1ec1 (v\u00ed d\u1ee5: <\/span><span style=\"font-weight: 400;\">int<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">String<\/span><span style=\"font-weight: 400;\">), <\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\"> s\u1ebd tr\u1ea3 v\u1ec1 m\u1ed9t gi\u00e1 tr\u1ecb t\u01b0\u01a1ng \u1ee9ng.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">N\u1ebfu ph\u01b0\u01a1ng th\u1ee9c c\u00f3 ki\u1ec3u <\/span><span style=\"font-weight: 400;\">void<\/span><span style=\"font-weight: 400;\">, c\u00e2u l\u1ec7nh <\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\"> s\u1ebd kh\u00f4ng c\u1ea7n gi\u00e1 tr\u1ecb \u0111i k\u00e8m.<\/span><\/li>\n<\/ul>\n\n\n\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public int add(int a, int b) {\n  return a + b; \/\/ Tr\u1ea3 v\u1ec1 t\u1ed5ng c\u1ee7a a v\u00e0 b\n}\n\npublic void displayMessage() {\n  System.out.println(\"Hello, World!\");\n  return; \/\/ K\u1ebft th\u00fac ph\u01b0\u01a1ng th\u1ee9c, c\u00f3 th\u1ec3 b\u1ecf qua return \u1edf ki\u1ec3u void\n}<\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">L\u01b0u \u00fd:<\/span><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400;\">Khi g\u1eb7p <\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\">, ch\u01b0\u01a1ng tr\u00ecnh s\u1ebd k\u1ebft th\u00fac ngay t\u1ea1i c\u00e2u l\u1ec7nh \u0111\u00f3 v\u00e0 kh\u00f4ng th\u1ef1c thi c\u00e1c l\u1ec7nh sau trong ph\u01b0\u01a1ng th\u1ee9c.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">Trong c\u00e1c v\u00f2ng l\u1eb7p, n\u1ebfu d\u00f9ng <\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\">, v\u00f2ng l\u1eb7p s\u1ebd k\u1ebft th\u00fac c\u00f9ng v\u1edbi ph\u01b0\u01a1ng th\u1ee9c.<\/span><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-cau-l\u1ec7nh-assert-ki\u1ec3m-tra-gi\u1ea3-d\u1ecbnh-nbsp\"><b>C\u00e2u l\u1ec7nh <\/b><b>assert<\/b><b> (Ki\u1ec3m tra gi\u1ea3 \u0111\u1ecbnh)&nbsp;<\/b><\/h3>\n\n\n\n<p><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh <\/span><span style=\"font-weight: 400;\">assert<\/span><span style=\"font-weight: 400;\"> \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 ki\u1ec3m tra c\u00e1c \u0111i\u1ec1u ki\u1ec7n m\u00e0 l\u1eadp tr\u00ecnh vi\u00ean gi\u1ea3 \u0111\u1ecbnh l\u00e0 \u0111\u00fang. N\u1ebfu \u0111i\u1ec1u ki\u1ec7n sai, ch\u01b0\u01a1ng tr\u00ecnh s\u1ebd n\u00e9m ra ngo\u1ea1i l\u1ec7 <\/span><span style=\"font-weight: 400;\">AssertionError<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh n\u00e0y ch\u1ee7 y\u1ebfu \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 ph\u00e1t hi\u1ec7n l\u1ed7i trong qu\u00e1 tr\u00ecnh ph\u00e1t tri\u1ec3n v\u00e0 debug ch\u01b0\u01a1ng tr\u00ecnh.<\/span><\/p>\n\n\n\n<p><b>C\u00fa ph\u00e1p<\/b><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400;\"><strong>assert bi\u1ec3u_th\u1ee9c_logic<\/strong>: bi\u1ec3u_th\u1ee9c_gi\u1ea3i_th\u00edch;<\/span><\/li>\n\n\n\n<li><b>bi\u1ec3u_th\u1ee9c_logic<\/b><span style=\"font-weight: 400;\">: \u0110i\u1ec1u ki\u1ec7n c\u1ea7n ki\u1ec3m tra.<\/span><\/li>\n\n\n\n<li><b>bi\u1ec3u_th\u1ee9c_gi\u1ea3i_th\u00edch<\/b><span style=\"font-weight: 400;\"> (t\u00f9y ch\u1ecdn): Th\u00f4ng b\u00e1o ho\u1eb7c gi\u00e1 tr\u1ecb k\u00e8m theo khi \u0111i\u1ec1u ki\u1ec7n kh\u00f4ng \u0111\u00fang.<\/span><\/li>\n<\/ul>\n\n\n\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static void main(String&#91;] args) {\n  int number = -1;\n  assert number &gt;= 0 : \"S\u1ed1 ph\u1ea3i kh\u00f4ng \u00e2m\";\n  System.out.println(\"Gi\u00e1 tr\u1ecb c\u1ee7a s\u1ed1: \" + number);\n}<\/code><\/pre>\n\n\n\n<p>K\u1ebft qu\u1ea3:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400;\">N\u1ebfu number >= 0, ch\u01b0\u01a1ng tr\u00ecnh ti\u1ebfp t\u1ee5c ch\u1ea1y b\u00ecnh th\u01b0\u1eddng.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">N\u1ebfu number &lt; 0, ch\u01b0\u01a1ng tr\u00ecnh s\u1ebd n\u00e9m ra AssertionError v\u1edbi th\u00f4ng b\u00e1o: &#8220;S\u1ed1 ph\u1ea3i kh\u00f4ng \u00e2m&#8221;.<\/span><\/li>\n<\/ul>\n\n\n\n<p><b>L\u01b0u \u00fd<\/b><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh assert b\u1ecb v\u00f4 hi\u1ec7u h\u00f3a m\u1eb7c \u0111\u1ecbnh khi ch\u1ea1y ch\u01b0\u01a1ng tr\u00ecnh. \u0110\u1ec3 k\u00edch ho\u1ea1t, c\u1ea7n d\u00f9ng t\u00f9y ch\u1ecdn -ea (enable assertions) khi ch\u1ea1y Java.<\/span><span style=\"font-weight: 400;\"><br><\/span><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: java -ea MyProgram<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">Kh\u00f4ng n\u00ean d\u00f9ng assert \u0111\u1ec3 x\u1eed l\u00fd l\u1ed7i logic quan tr\u1ecdng trong m\u00f4i tr\u01b0\u1eddng production.<\/span><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-cau-l\u1ec7nh-synchronized-d\u1ed3ng-b\u1ed9-hoa\"><b>C\u00e2u l\u1ec7nh <\/b><b>synchronized<\/b><b> (\u0110\u1ed3ng b\u1ed9 h\u00f3a)<\/b><\/h3>\n\n\n\n<p><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh synchronized \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o t\u00ednh to\u00e0n v\u1eb9n d\u1eef li\u1ec7u trong l\u1eadp tr\u00ecnh \u0111a lu\u1ed3ng (multithreading). N\u00f3 cho ph\u00e9p ch\u1ec9 m\u1ed9t lu\u1ed3ng \u0111\u01b0\u1ee3c truy c\u1eadp v\u00e0o m\u1ed9t \u0111o\u1ea1n m\u00e3 ho\u1eb7c t\u00e0i nguy\u00ean c\u1ee5 th\u1ec3 trong c\u00f9ng m\u1ed9t th\u1eddi \u0111i\u1ec3m.<\/span><\/p>\n\n\n\n<p><b>M\u1ee5c \u0111\u00edch<\/b><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Tr\u00e1nh xung \u0111\u1ed9t d\u1eef li\u1ec7u v\u00e0 \u0111\u1ea3m b\u1ea3o an to\u00e0n khi nhi\u1ec1u lu\u1ed3ng c\u00f9ng truy c\u1eadp v\u00e0 ch\u1ec9nh s\u1eeda d\u1eef li\u1ec7u.<\/span><\/p>\n\n\n\n<p><b>C\u00fa ph\u00e1p<\/b><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng synchronized tr\u00ean m\u1ed9t ph\u01b0\u01a1ng th\u1ee9c:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">public synchronized void method() {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;\/\/ \u0110o\u1ea1n m\u00e3 ch\u1ec9 \u0111\u01b0\u1ee3c truy c\u1eadp b\u1edfi m\u1ed9t lu\u1ed3ng t\u1ea1i m\u1ed9t th\u1eddi \u0111i\u1ec3m<\/span>\n<span style=\"font-weight: 400;\">}<\/span><\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng <\/span><span style=\"font-weight: 400;\">synchronized<\/span><span style=\"font-weight: 400;\"> tr\u00ean m\u1ed9t kh\u1ed1i m\u00e3:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">synchronized (object) {<\/span>\n\n<span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;\/\/ \u0110o\u1ea1n m\u00e3 \u0111\u1ed3ng b\u1ed9 h\u00f3a d\u1ef1a tr\u00ean object<\/span>\n\n<span style=\"font-weight: 400;\">}<\/span><\/code><\/pre>\n\n\n\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"font-weight: 400;\">class Counter {<\/span>\n<span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;private int count = 0;<\/span>\n\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;public synchronized void increment() {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count++;<\/span>\n<span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;}<\/span>\n\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;public int getCount() {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return count;<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;}<\/span>\n<span style=\"font-weight: 400;\">}<\/span>\n\n<span style=\"font-weight: 400;\">public class SynchronizedExample {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;public static void main(String&#91;] args) {<\/span>\n<span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Counter counter = new Counter();<\/span>\n\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ T\u1ea1o v\u00e0 ch\u1ea1y nhi\u1ec1u lu\u1ed3ng<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread t1 = new Thread(() -&gt; {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 0; i &lt; 1000; i++) {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;counter.increment();<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<\/span>\n<span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});<\/span>\n\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread t2 = new Thread(() -&gt; {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 0; i &lt; 1000; i++) {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;counter.increment();<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<\/span>\n<span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});<\/span>\n\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t1.start();<\/span>\n<span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t2.start();<\/span>\n\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t1.join();<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t2.join();<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} catch (InterruptedException e) {<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<\/span>\n<span style=\"font-weight: 400;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<\/span>\n\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(\"Gi\u00e1 tr\u1ecb cu\u1ed1i c\u00f9ng c\u1ee7a count: \" + counter.getCount());<\/span>\n<span style=\"font-weight: 400;\"> &nbsp;&nbsp;&nbsp;}<\/span>\n<span style=\"font-weight: 400;\">}<\/span><\/code><\/pre>\n\n\n\n<p>K\u1ebft qu\u1ea3:<\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Do s\u1eed d\u1ee5ng <\/span><span style=\"font-weight: 400;\">synchronized<\/span><span style=\"font-weight: 400;\">, c\u00e1c lu\u1ed3ng s\u1ebd truy c\u1eadp v\u00e0o ph\u01b0\u01a1ng th\u1ee9c <\/span><span style=\"font-weight: 400;\">increment()<\/span><span style=\"font-weight: 400;\"> m\u1ed9t c\u00e1ch tu\u1ea7n t\u1ef1. K\u1ebft qu\u1ea3 \u0111\u1ea3m b\u1ea3o ch\u00ednh x\u00e1c, kh\u00f4ng b\u1ecb m\u1ea5t d\u1eef li\u1ec7u khi t\u0103ng gi\u00e1 tr\u1ecb <\/span><span style=\"font-weight: 400;\">count<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><b>L\u01b0u \u00fd<\/b>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400;\">Tr\u00e1nh l\u1ea1m d\u1ee5ng <\/span><span style=\"font-weight: 400;\">synchronized<\/span><span style=\"font-weight: 400;\"> v\u00ec c\u00f3 th\u1ec3 l\u00e0m gi\u1ea3m hi\u1ec7u su\u1ea5t ch\u01b0\u01a1ng tr\u00ecnh.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">Trong c\u00e1c tr\u01b0\u1eddng h\u1ee3p ph\u1ee9c t\u1ea1p, b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng c\u00e1c c\u00f4ng c\u1ee5 nh\u01b0 <\/span><span style=\"font-weight: 400;\">ReentrantLock<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 qu\u1ea3n l\u00fd \u0111\u1ed3ng b\u1ed9 h\u00f3a thay cho <\/span><span style=\"font-weight: 400;\">synchronized<\/span><span style=\"font-weight: 400;\">.<\/span><\/li>\n<\/ul>\n\n\n\n<p><span style=\"font-weight: 400;\">Trong Java, c\u00e1c c\u00e2u l\u1ec7nh \u0111\u1eb7c bi\u1ec7t nh\u01b0 <\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">assert<\/span><span style=\"font-weight: 400;\">, v\u00e0 <\/span><span style=\"font-weight: 400;\">synchronized<\/span><span style=\"font-weight: 400;\"> \u0111\u00f3ng vai tr\u00f2 quan tr\u1ecdng trong vi\u1ec7c ki\u1ec3m so\u00e1t lu\u1ed3ng ch\u01b0\u01a1ng tr\u00ecnh, ki\u1ec3m tra gi\u1ea3 \u0111\u1ecbnh, v\u00e0 x\u1eed l\u00fd l\u1eadp tr\u00ecnh \u0111a lu\u1ed3ng. Vi\u1ec7c hi\u1ec3u v\u00e0 s\u1eed d\u1ee5ng \u0111\u00fang c\u00e1c c\u00e2u l\u1ec7nh n\u00e0y s\u1ebd gi\u00fap b\u1ea1n vi\u1ebft m\u00e3 hi\u1ec7u qu\u1ea3, b\u1ea3o tr\u00ec d\u1ec5 d\u00e0ng v\u00e0 \u0111\u1ea3m b\u1ea3o t\u00ednh to\u00e0n v\u1eb9n d\u1eef li\u1ec7u trong \u1ee9ng d\u1ee5ng.<\/span><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><em>\u0110\u1ecdc th\u00eam: <a href=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-java\/\" target=\"_blank\" rel=\"noopener\"><strong>Top 40+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Java nh\u1ea5t \u0111\u1ecbnh c\u00f3 trong bu\u1ed5i ph\u1ecfng v\u1ea5n<\/strong><\/a><\/em><\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-t\u1ed5ng-k\u1ebft-cac-cau-l\u1ec7nh-trong-java\"><span class=\"ez-toc-section\" id=\"Tong_ket_cac_cau_lenh_trong_Java\"><\/span><strong>T\u1ed5ng k\u1ebft c\u00e1c c\u00e2u l\u1ec7nh trong Java<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">N\u1eafm v\u1eefng <\/span>c\u00e1c c\u00e2u l\u1ec7nh trong Java<span style=\"font-weight: 400;\"> l\u00e0 n\u1ec1n t\u1ea3ng quan tr\u1ecdng \u0111\u1ec3 ph\u00e1t tri\u1ec3n c\u00e1c \u1ee9ng d\u1ee5ng Java t\u1eeb \u0111\u01a1n gi\u1ea3n \u0111\u1ebfn ph\u1ee9c t\u1ea1p. T\u1eeb nh\u1eefng c\u00e2u l\u1ec7nh c\u01a1 b\u1ea3n nh\u01b0 khai b\u00e1o bi\u1ebfn, \u0111i\u1ec1u ki\u1ec7n, v\u00f2ng l\u1eb7p cho \u0111\u1ebfn c\u00e1c c\u00e2u l\u1ec7nh \u0111i\u1ec1u khi\u1ec3n lu\u1ed3ng ch\u01b0\u01a1ng tr\u00ecnh nh\u01b0 <\/span><span style=\"font-weight: 400;\">break<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">continue<\/span><span style=\"font-weight: 400;\">, v\u00e0 <\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\">, m\u1ed7i c\u00e2u l\u1ec7nh \u0111\u1ec1u \u0111\u00f3ng m\u1ed9t vai tr\u00f2 thi\u1ebft y\u1ebfu trong vi\u1ec7c x\u00e2y d\u1ef1ng logic v\u00e0 t\u1ed1i \u01b0u h\u00f3a m\u00e3 ngu\u1ed3n.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Vi\u1ec7c hi\u1ec3u r\u00f5 v\u00e0 \u00e1p d\u1ee5ng th\u00e0nh th\u1ea1o c\u00e1c c\u00e2u l\u1ec7nh n\u00e0y kh\u00f4ng ch\u1ec9 gi\u00fap b\u1ea1n vi\u1ebft m\u00e3 hi\u1ec7u qu\u1ea3 h\u01a1n m\u00e0 c\u00f2n n\u00e2ng cao kh\u1ea3 n\u0103ng gi\u1ea3i quy\u1ebft v\u1ea5n \u0111\u1ec1 v\u00e0 t\u01b0 duy l\u1eadp tr\u00ecnh. H\u00e3y th\u01b0\u1eddng xuy\u00ean th\u1ef1c h\u00e0nh v\u00e0 th\u1eed nghi\u1ec7m \u0111\u1ec3 l\u00e0m ch\u1ee7 c\u00e1c kh\u00e1i ni\u1ec7m n\u00e0y, t\u1eeb \u0111\u00f3 ti\u1ebfn xa h\u01a1n trong h\u00e0nh tr\u00ecnh tr\u1edf th\u00e0nh m\u1ed9t l\u1eadp tr\u00ecnh vi\u00ean Java chuy\u00ean nghi\u1ec7p.<\/span><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><em>Tham kh\u1ea3o <strong><a href=\"https:\/\/itviec.com\/it-jobs\/java?utm_medium=anchor_text_low&amp;utm_source=blog&amp;utm_campaign=viec_lam_java&amp;utm_content=cac_cau_lenh_trong_java\" target=\"_blank\" rel=\"noreferrer noopener\">vi\u1ec7c l\u00e0m Java<\/a><\/strong> m\u1edbi nh\u1ea5t tr\u00ean to\u00e0n qu\u1ed1c<\/em><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Khi h\u1ecdc Java, vi\u1ec7c n\u1eafm v\u1eefng c\u00e1c c\u00e2u l\u1ec7nh trong Java l\u00e0 b\u01b0\u1edbc \u0111\u1ea7u ti\u00ean v\u00e0 quan tr\u1ecdng \u0111\u1ec3 l\u00e0m ch\u1ee7 v\u00e0 ph\u00e1t tri\u1ec3n c\u00e1c \u1ee9ng d\u1ee5ng t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao. B\u00e0i vi\u1ebft n\u00e0y s\u1ebd gi\u1edbi thi\u1ec7u t\u1ed5ng quan v\u1ec1 c\u00e1c c\u00e1c c\u00e2u l\u1ec7nh trong Java, g\u1ed3m c\u00e1c c\u00e2u l\u1ec7nh \u0111i\u1ec1u khi\u1ec3n, c\u00e2u [&hellip;]<\/p>\n","protected":false},"author":203,"featured_media":83663,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_gspb_post_css":"","footnotes":""},"categories":[109],"tags":[],"class_list":["post-83660","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chuyen-mon-it"],"blocksy_meta":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.8 (Yoast SEO v27.8) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>C\u00e1c c\u00e2u l\u1ec7nh trong Java: Chi ti\u1ebft t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao - ITviec Blog<\/title>\n<meta name=\"description\" content=\"L\u01b0u ngay b\u00e0i gi\u1ea3i th\u00edch chi ti\u1ebft c\u00e1c c\u00e2u l\u1ec7nh trong Java t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn \u0111\u1eb7c bi\u1ec7t, g\u1ed3m c\u00fa ph\u00e1p, v\u00ed d\u1ee5 c\u1ee5 th\u1ec3 v\u00e0 m\u1ee5c \u0111\u00edch s\u1eed d\u1ee5ng c\u1ee7a t\u1eebng lo\u1ea1i.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/\" \/>\n<meta property=\"og:locale\" content=\"vi_VN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C\u00e1c c\u00e2u l\u1ec7nh trong Java: Chi ti\u1ebft t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao\" \/>\n<meta property=\"og:description\" content=\"Khi h\u1ecdc Java, vi\u1ec7c n\u1eafm v\u1eefng c\u00e1c c\u00e2u l\u1ec7nh trong Java l\u00e0 b\u01b0\u1edbc \u0111\u1ea7u ti\u00ean v\u00e0 quan tr\u1ecdng \u0111\u1ec3 l\u00e0m ch\u1ee7 v\u00e0 ph\u00e1t tri\u1ec3n c\u00e1c \u1ee9ng d\u1ee5ng t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao. B\u00e0i vi\u1ebft\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/\" \/>\n<meta property=\"og:site_name\" content=\"ITviec Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ITviec\" \/>\n<meta property=\"article:published_time\" content=\"2024-12-31T14:52:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-09-28T16:17:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/12\/cac-cau-lenh-trong-Java-vippro.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1500\" \/>\n\t<meta property=\"og:image:height\" content=\"790\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Tien Tran\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ITviec\" \/>\n<meta name=\"twitter:site\" content=\"@ITviec\" \/>\n<meta name=\"twitter:label1\" content=\"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tien Tran\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 ph\u00fat\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"C\u00e1c c\u00e2u l\u1ec7nh trong Java: Chi ti\u1ebft t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao - ITviec Blog","description":"L\u01b0u ngay b\u00e0i gi\u1ea3i th\u00edch chi ti\u1ebft c\u00e1c c\u00e2u l\u1ec7nh trong Java t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn \u0111\u1eb7c bi\u1ec7t, g\u1ed3m c\u00fa ph\u00e1p, v\u00ed d\u1ee5 c\u1ee5 th\u1ec3 v\u00e0 m\u1ee5c \u0111\u00edch s\u1eed d\u1ee5ng c\u1ee7a t\u1eebng lo\u1ea1i.","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:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/","og_locale":"vi_VN","og_type":"article","og_title":"C\u00e1c c\u00e2u l\u1ec7nh trong Java: Chi ti\u1ebft t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao","og_description":"Khi h\u1ecdc Java, vi\u1ec7c n\u1eafm v\u1eefng c\u00e1c c\u00e2u l\u1ec7nh trong Java l\u00e0 b\u01b0\u1edbc \u0111\u1ea7u ti\u00ean v\u00e0 quan tr\u1ecdng \u0111\u1ec3 l\u00e0m ch\u1ee7 v\u00e0 ph\u00e1t tri\u1ec3n c\u00e1c \u1ee9ng d\u1ee5ng t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao. B\u00e0i vi\u1ebft","og_url":"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/","og_site_name":"ITviec Blog","article_publisher":"https:\/\/www.facebook.com\/ITviec","article_published_time":"2024-12-31T14:52:16+00:00","article_modified_time":"2025-09-28T16:17:34+00:00","og_image":[{"width":1500,"height":790,"url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/12\/cac-cau-lenh-trong-Java-vippro.jpg","type":"image\/jpeg"}],"author":"Tien Tran","twitter_card":"summary_large_image","twitter_creator":"@ITviec","twitter_site":"@ITviec","twitter_misc":{"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi":"Tien Tran","\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc":"12 ph\u00fat"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/#article","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/"},"author":{"name":"Tien Tran","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/1595d671c49cfa2a48cd3c0a047a1298"},"headline":"C\u00e1c c\u00e2u l\u1ec7nh trong Java: Chi ti\u1ebft t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao","datePublished":"2024-12-31T14:52:16+00:00","dateModified":"2025-09-28T16:17:34+00:00","mainEntityOfPage":{"@id":"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/"},"wordCount":3471,"publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"image":{"@id":"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/12\/cac-cau-lenh-trong-Java-vippro.jpg","articleSection":["Chuy\u00ean m\u00f4n IT"],"inLanguage":"vi"},{"@type":"WebPage","@id":"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/","url":"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/","name":"C\u00e1c c\u00e2u l\u1ec7nh trong Java: Chi ti\u1ebft t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao - ITviec Blog","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/#primaryimage"},"image":{"@id":"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/12\/cac-cau-lenh-trong-Java-vippro.jpg","datePublished":"2024-12-31T14:52:16+00:00","dateModified":"2025-09-28T16:17:34+00:00","description":"L\u01b0u ngay b\u00e0i gi\u1ea3i th\u00edch chi ti\u1ebft c\u00e1c c\u00e2u l\u1ec7nh trong Java t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn \u0111\u1eb7c bi\u1ec7t, g\u1ed3m c\u00fa ph\u00e1p, v\u00ed d\u1ee5 c\u1ee5 th\u1ec3 v\u00e0 m\u1ee5c \u0111\u00edch s\u1eed d\u1ee5ng c\u1ee7a t\u1eebng lo\u1ea1i.","breadcrumb":{"@id":"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/#breadcrumb"},"inLanguage":"vi","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/"]}]},{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/#primaryimage","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/12\/cac-cau-lenh-trong-Java-vippro.jpg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/12\/cac-cau-lenh-trong-Java-vippro.jpg","width":1500,"height":790,"caption":"ca\u0301c ca\u0302u le\u0323\u0302nh trong Java - itviec blog"},{"@type":"BreadcrumbList","@id":"https:\/\/itviec.com\/blog\/cac-cau-lenh-trong-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Chuy\u00ean m\u00f4n IT","item":"https:\/\/itviec.com\/blog\/chuyen-mon-it\/"},{"@type":"ListItem","position":2,"name":"C\u00e1c c\u00e2u l\u1ec7nh trong Java: Chi ti\u1ebft t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao"}]},{"@type":"WebSite","@id":"https:\/\/itviec.com\/blog\/#website","url":"https:\/\/itviec.com\/blog\/","name":"ITviec Blog","description":"IT Jobs &amp; People in Vietnam","publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/itviec.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"vi"},{"@type":"Organization","@id":"https:\/\/itviec.com\/blog\/#organization","name":"ITviec","url":"https:\/\/itviec.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","width":1800,"height":1800,"caption":"ITviec"},"image":{"@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ITviec","https:\/\/x.com\/ITviec","https:\/\/www.linkedin.com\/company\/itviec","https:\/\/www.youtube.com\/channel\/UCYthAQ3bcGr57M_ag5gHDvQ"]},{"@type":"Person","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/1595d671c49cfa2a48cd3c0a047a1298","name":"Tien Tran","image":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/05\/tien-tran-author-e1715658627643-100x100.jpg","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/05\/tien-tran-author-e1715658627643-100x100.jpg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/05\/tien-tran-author-e1715658627643-100x100.jpg","caption":"Tien Tran"},"url":"https:\/\/itviec.com\/blog\/author\/tien-tran\/"}]}},"_links":{"self":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/83660","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/users\/203"}],"replies":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/comments?post=83660"}],"version-history":[{"count":1,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/83660\/revisions"}],"predecessor-version":[{"id":91810,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/83660\/revisions\/91810"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media\/83663"}],"wp:attachment":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media?parent=83660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/categories?post=83660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/tags?post=83660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}