{"id":16436,"date":"2020-05-12T19:50:05","date_gmt":"2020-05-12T12:50:05","guid":{"rendered":"https:\/\/acaltc.com\/?p=16436"},"modified":"2020-05-12T19:50:05","modified_gmt":"2020-05-12T12:50:05","slug":"su-khac-biet-giua-java-va-javascript","status":"publish","type":"post","link":"https:\/\/acaltc.com\/en\/su-khac-biet-giua-java-va-javascript\/","title":{"rendered":"S\u1ef1 kh\u00e1c bi\u1ec7t gi\u1eefa Java v\u00e0 JavaScript"},"content":{"rendered":"

Nhi\u1ec1u ng\u01b0\u1eddi c\u00f3 suy ngh\u0129 r\u1eb1ng Java v\u00e0 JavaScript c\u00f3 t\u00ean g\u1ea7n nh\u01b0 nhau, c\u00f3 th\u1ec3 c\u00f3 nhi\u1ec1u \u0111i\u1ec3m t\u01b0\u01a1ng \u0111\u1ed3ng ho\u1eb7c JavaScript l\u00e0 m\u1ed9t th\u01b0 vi\u1ec7n c\u1ee7a Java. Tuy nhi\u00ean, trong th\u1ef1c t\u1ebf, Java v\u00e0 JavaScript l\u00e0 c\u00e1c ng\u00f4n ng\u1eef l\u1eadp tr\u00ecnh ch\u1ee7 y\u1ebfu \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng cho c\u00e1c m\u1ee5c \u0111\u00edch kh\u00e1c nhau v\u00e0 \u00a0c\u00f3 m\u1ed9t s\u1ef1 kh\u00e1c bi\u1ec7t l\u1edbn gi\u1eefa Java v\u00e0 JavaScript. .. B\u00e0i vi\u1ebft sau \u0111\u00e2y s\u1ebd chia s\u1ebb s\u1ef1 kh\u00e1c bi\u1ec7t gi\u1eefa java v\u00e0 java script<\/em><\/p>\n

Java l\u00e0 g\u00ec ?<\/strong><\/span><\/h2>\n

Java<\/strong>\u00a0l\u00e0 ng\u00f4n ng\u1eef l\u1eadp tr\u00ecnh h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng c\u00f3 m\u1ee5c \u0111\u00edch chung \u0111\u01b0\u1ee3c thi\u1ebft k\u1ebf v\u1edbi m\u1ee5c \u0111\u00edch t\u1ea1o ra m\u1ed9t m\u00e3 trong \u0111\u00f3 c\u00f9ng m\u1ed9t m\u00e3 c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u1edf b\u1ea5t c\u1ee9 \u0111\u00e2u.\u00a0James Gosling<\/strong>\u00a0c\u1ee7a\u00a0Sun microsystems \u0111\u00e3<\/strong>\u00a0h\u01b0\u1edbng d\u1eabn s\u1ef1 ph\u00e1t tri\u1ec3n c\u1ee7a Java v\u00e0o cu\u1ed1i nh\u1eefng n\u0103m 1990. Ng\u00f4n ng\u1eef l\u1eadp tr\u00ecnh n\u00e0y l\u00e0 d\u1ef1a tr\u00ean l\u1edbp, h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng v\u00e0 con ng\u01b0\u1eddi c\u00f3 th\u1ec3 \u0111\u1ecdc \u0111\u01b0\u1ee3c. Java \u0111\u01b0\u1ee3c bi\u00ean d\u1ecbch c\u0169ng nh\u01b0 di\u1ec5n gi\u1ea3i. Tr\u00ecnh bi\u00ean d\u1ecbch Java chuy\u1ec3n \u0111\u1ed5i m\u00e3 ngu\u1ed3n th\u00e0nh m\u00e3 byte, sau \u0111\u00f3 tr\u00ecnh th\u00f4ng d\u1ecbch java t\u1ea1o m\u00e3 m\u00e1y \u0111\u01b0\u1ee3c th\u1ef1c thi th\u1eb3ng b\u1edfi m\u00e1y \u0111ang ch\u1ea1y ch\u01b0\u01a1ng tr\u00ecnh java. N\u00f3 l\u00e0 \u0111\u00e1ng tin c\u1eady, ph\u00e2n ph\u1ed1i, di \u0111\u1ed9ng. N\u00f3 c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 ph\u00e1t tri\u1ec3n c\u00e1c \u1ee9ng d\u1ee5ng \u0111\u1ed9c l\u1eadp ho\u1eb7c \u1ee9ng d\u1ee5ng d\u1ef1a tr\u00ean web.<\/p>\n

JavaScript l\u00e0 g\u00ec?<\/span><\/h2>\n

JavaScript l\u00e0 ng\u00f4n ng\u1eef v\u0103n b\u1ea3n nh\u1eb9 nh\u00e0ng, d\u1ec5 h\u1ecdc m\u00e0 c\u00e1c nh\u00e0 ph\u00e1t tri\u1ec3n c\u00f3 th\u1ec3 ch\u00e8n v\u00e0o c\u00e1c trang HTML v\u00e0 CSS \u0111\u1ec3 th\u00eam t\u00ednh t\u01b0\u01a1ng t\u00e1c, h\u00ecnh \u0111\u1ed9ng v\u00e0 x\u00e1c th\u1ef1c m\u1eabu cho c\u00e1c trang web. Khi Flash ng\u1eebng ho\u1ea1t \u0111\u1ed9ng, JavaScript \u0111\u00e3 chi\u1ebfm l\u0129nh v\u00ec n\u00f3 m\u1ea1nh m\u1ebd, linh ho\u1ea1t v\u00e0 c\u00f3 th\u1ec3 t\u00e1i s\u1eed d\u1ee5ng. JavaScript ch\u1ee7 y\u1ebfu l\u00e0 m\u1ed9t \u1ee9ng d\u1ee5ng ph\u00eda m\u00e1y kh\u00e1ch, ngh\u0129a l\u00e0 n\u00f3 ch\u1ea1y ngay trong tr\u00ecnh duy\u1ec7t web m\u00e0 kh\u00f4ng ph\u1ea3i l\u1ea5y b\u1ea5t k\u1ef3 m\u00e3 n\u00e0o t\u1eeb m\u00e1y ch\u1ee7 t\u1eeb xa. Tuy nhi\u00ean, vi\u1ec7c ph\u00e1t minh ra Node.js \u0111\u00e3 m\u1edf ra c\u00e1c t\u00f9y ch\u1ecdn cho c\u00e1c \u1ee9ng d\u1ee5ng ph\u00eda m\u00e1y ch\u1ee7. C\u00e1c nh\u00e0 ph\u00e1t tri\u1ec3n JavaScript chia s\u1ebb c\u00e1c \u0111o\u1ea1n m\u00e3, th\u01b0 vi\u1ec7n, l\u1edbp v\u00e0 khung t\u00f9y ch\u1ec9nh \u0111\u1ec3 cho ph\u00e9p b\u1ea1n m\u00e3 h\u00f3a c\u00e1c \u1ee9ng d\u1ee5ng ph\u1ee9c t\u1ea1p m\u1ed9t c\u00e1ch nhanh ch\u00f3ng.<\/p>\n

S\u1ef1 kh\u00e1c bi\u1ec7t ch\u00ednh gi\u1eefa Java v\u00e0 JavaScript<\/span><\/h2>\n
    \n
  • V\u1ec1 c\u01a1 ch\u1ebf<\/strong>: Java run b\u1edfi c\u01a1 ch\u1ebf bi\u00ean d\u1ecbch (compile), JavaScript (JS) run b\u1edfi c\u01a1 ch\u1ebf th\u00f4ng d\u1ecbch (interpreted). C\u1ee5 th\u1ec3 l\u00e0 \u0111\u1ec3 run m\u1ed9t ch\u01b0\u01a1ng tr\u00ecnh Java, ta ph\u1ea3i build c\u00e1c file java th\u00e0nh file class (byte code), khi method c\u00f3 thay \u0111\u1ed5i, ta c\u1ea7n build l\u1ea1i file. \u0110\u1ed1i v\u1edbi JS, vi\u1ebft r\u1ed3i run th\u00f4i ch\u1ee9 kh\u00f4ng c\u1ea7n ph\u1ea3i build.<\/li>\n
  • Thi\u1ebft k\u1ebf<\/strong>: Java l\u00e0 OOP (ng\u00f4n ng\u1eef h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng), m\u1ecdi th\u1ee9 \u0111\u1ec1u l\u00e0 \u0111\u1ed1i t\u01b0\u1ee3ng (object), \u0111\u1ec3 s\u1eed d\u1ee5ng m\u1ed9t variable ho\u1eb7c method c\u1ee7a Java, tr\u01b0\u1edbc h\u1ebft ph\u1ea3i t\u1ea1o class, sau \u0111\u00f3 truy c\u1eadp variable, method \u0111\u00f3 th\u00f4ng qua object \u0111\u01b0\u1ee3c t\u1ea1o t\u1eeb class \u0111\u00f3.<\/li>\n
  • C\u00f2n \u0111\u1ed1i v\u1edbi JS, ch\u1ee7 y\u1ebfu l\u00e0 support functional programming language (t\u1ea1m d\u1ecbch l\u00e0 ng\u00f4n ng\u1eef l\u1eadp tr\u00ecnh ch\u1ee9c n\u0103ng \u2013 m\u00e0 th\u1ea5y n\u00f3 chu\u1ed1i chu\u1ed1i th\u1ebf n\u00e0o \u1ea5y -.-) ta ch\u1ec9 vi\u1ec7c define variable, mehthod v\u00e0 g\u1ecdi. L\u01b0u \u00fd l\u00e0 \u0111\u1ebfn phi\u00ean b\u1ea3n Java 8, Java \u0111\u00e3 support functional programming<\/li>\n<\/ul>\n

    \"\"<\/p>\n

      \n
    • Run v\u00e0 debug<\/strong>: \u0110\u1ec3 execute Java ta c\u1ea7n Java compiler v\u00e0 ta ph\u1ea3i c\u1ea7n IDE nh\u01b0 Eclipse, Netbeans, Intelij\u2026 \u0111\u1ec3 debug Java code. Trong HTML, JS \u0111\u01b0\u1ee3c execute b\u1edfi web browser, ta c\u00f3 th\u1ec3 debug JS tr\u1ef1c ti\u1ebfp tr\u00ean browser b\u1eb1ng c\u00e1ch m\u1edf ch\u1ebf \u0111\u1ed9 deverloper tool, xem log JS tr\u00ean browser \u1edf ch\u1ebf \u0111\u1ed9 console c\u1ee7a browser.<\/li>\n
    • Variable<\/strong>: d\u1eef li\u1ec7u Java l\u00e0 static type, JS l\u00e0 dynamic type.\u00a0C\u1ee5 th\u1ec3 l\u00e0 trong Java, \u0111\u1ec3 \u0111\u1ecbnh ngh\u0129a m\u1ed9t variable, ta ph\u1ea3i \u0111\u1ecbnh ngh\u0129a c\u1ee5 th\u1ec3 ki\u1ec3u d\u1eef li\u1ec7u cho variable \u0111\u00f3:\n
        \n
      • V\u00ed d\u1ee5: int a = 50;\u00a0boolean a = true;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n

        \u00a0 \u00a0 \u00a0 \u00a0 \u0110\u1ed1i v\u1edbi JS th\u00ec ta c\u00f3 th\u1ec3 d\u00f9ng ki\u1ec3u var \u0111\u1ec3 \u0111\u1ecbnh ngh\u0129a chung cho t\u1ea5t c\u1ea3 c\u00e1c ki\u1ec3u d\u1eef li\u1ec7u. Khi ta g\u00e1n gi\u00e1 tr\u1ecb cho variable th\u00ec m\u1eb7c \u0111\u1ecbnh ch\u01b0\u01a1ng tr\u00ecnh s\u1ebd g\u00e1n ki\u1ec3u d\u1eef li\u1ec7u cho variable \u0111\u00f3.<\/p>\n

          \n
        • \n
            \n
          • V\u00ed d\u1ee5: var a = 50; \/\/ s\u1eed d\u1ee5ng a nh\u01b0 int;\u00a0 \u00a0 \u00a0var a = true; \/\/s\u1eed d\u1ee5ng a boolean\u2026<\/li>\n<\/ul>\n<\/li>\n
          • Method<\/strong>\n
              \n
            • \u0110\u1ecbnh ngh\u0129a method trong Java: access modifier\u00a0returntype\u00a0<\/em><\/strong>methodname(params)<\/li>\n
            • \u0110\u1ecbnh ngh\u0129a method trong JS:\u00a0function<\/em>\u00a0<\/strong>methodname(params)<\/li>\n<\/ul>\n<\/li>\n
            • Object<\/strong>\n
                \n
              • T\u1ea1o object trong Java ta c\u1ea7n class v\u00e0 contructor<\/li>\n
              • T\u1ea1o object trong JS ta c\u00f3 th\u1ec3 t\u1ea1o tr\u1ef1c ti\u1ebfp m\u00e0 kh\u00f4ng c\u1ea7n \u0111\u1ecbnh ngh\u0129a c\u1ee5 th\u1ec3 ki\u1ec3u d\u1eef li\u1ec7u cho t\u1eebng thu\u1ed9c t\u00ednh nh\u01b0 sau:\n
                  \n
                • var\u00a0person = {firstName:\u201cDung\u201d, lastName:\u201cChau\u201d}<\/em><\/li>\n<\/ul>\n<\/li>\n
                • Trong Java ta truy c\u1eadp property c\u1ee7a object th\u00f4ng qua ph\u01b0\u01a1ng th\u1ee9c get(), set()\u2026 \u0110\u1ed1i v\u1edbi JS th\u00ec m\u1eb7c \u0111\u1ecbnh c\u00e1c property l\u00e0 public v\u00e0 ta c\u00f3 th\u1ec3 truy c\u1eadp tr\u1ef1c ti\u1ebfp b\u1eb1ng c\u00fa ph\u00e1p person.firstName ho\u1eb7c person[\u201cfirstName\u201d].<\/li>\n<\/ul>\n<\/li>\n
                • Compare<\/strong>: trong Java ta s\u1eed d\u1ee5ng = = \u0111\u1ec3 so s\u00e1nh d\u1eef li\u1ec7u theo value, v\u00e0 ph\u01b0\u01a1ng th\u1ee9c equal() \u0111\u1ec3 so s\u00e1nh d\u1eef li\u1ec7u theo reference. Trong JS, = = d\u00f9ng \u0111\u1ec3 so s\u00e1nh d\u1eef li\u1ec7u theo value data type.<\/li>\n<\/ul>\n

                  N\u00ean <\/span>s\u1eed d\u1ee5ng\u00a0<\/span>ng\u00f4n ng\u1eef n\u00e0o ?<\/span><\/h2>\n

                  S\u1eed d\u1ee5ng Java ho\u1eb7c JavaScript ph\u1ee5 thu\u1ed9c v\u00e0o m\u1ed9t s\u1ed1 y\u1ebfu t\u1ed1 v\u00e0 n\u00f3 c\u00f3 th\u1ec3 t\u00f9y thu\u1ed9c v\u00e0o s\u1edf th\u00edch c\u00e1 nh\u00e2n. N\u1ebfu \u1ee9ng d\u1ee5ng c\u1ee7a b\u1ea1n s\u1ebd ch\u1ea1y tr\u00ean m\u00e1y t\u00ednh \u0111\u1ec3 b\u00e0n ho\u1eb7c thi\u1ebft b\u1ecb di \u0111\u1ed9ng ho\u1eb7c d\u1ef1a tr\u00ean web, th\u00ec Java c\u00f3 \u00fd ngh\u0129a nh\u1ea5t. N\u1ebfu b\u1ea1n \u0111ang t\u00ecm c\u00e1ch th\u00eam t\u01b0\u01a1ng t\u00e1c \u0111\u1ed9ng v\u00e0o m\u1ed9t trang web b\u1eb1ng jQuery \u0111\u1ec3 c\u00f3 k\u1ebft qu\u1ea3 t\u00ecm ki\u1ebfm ngay l\u1eadp t\u1ee9c, th\u00ec JavaScript l\u00e0 m\u1ed9t l\u1ef1a ch\u1ecdn t\u1ed1t h\u01a1n.<\/p>\n

                  Ngu\u1ed3n s\u01b0u t\u1ea7m<\/em><\/p>\n

                   <\/p>\n\n

                  \n\n\t\t\n
                    \n\t\t\t <\/ul>\n <\/div>","protected":false},"excerpt":{"rendered":"

                    Nhi\u1ec1u ng\u01b0\u1eddi c\u00f3 suy ngh\u0129 r\u1eb1ng Java v\u00e0 JavaScript c\u00f3 t\u00ean g\u1ea7n nh\u01b0 nhau, c\u00f3 th\u1ec3 c\u00f3 nhi\u1ec1u \u0111i\u1ec3m t\u01b0\u01a1ng \u0111\u1ed3ng ho\u1eb7c JavaScript l\u00e0 m\u1ed9t th\u01b0 vi\u1ec7n c\u1ee7a Java. Tuy nhi\u00ean, trong th\u1ef1c t\u1ebf, Java v\u00e0 JavaScript l\u00e0 c\u00e1c ng\u00f4n ng\u1eef l\u1eadp tr\u00ecnh ch\u1ee7 y\u1ebfu \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng cho c\u00e1c m\u1ee5c \u0111\u00edch kh\u00e1c nhau v\u00e0 […]<\/p>","protected":false},"author":25,"featured_media":16439,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48,64],"tags":[432,693],"class_list":["post-16436","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dao-tao","category-sinh-vien","tag-java-va-javascript","tag-su-khac-biet-java-va-javascript"],"_links":{"self":[{"href":"https:\/\/acaltc.com\/en\/wp-json\/wp\/v2\/posts\/16436"}],"collection":[{"href":"https:\/\/acaltc.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/acaltc.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/acaltc.com\/en\/wp-json\/wp\/v2\/users\/25"}],"replies":[{"embeddable":true,"href":"https:\/\/acaltc.com\/en\/wp-json\/wp\/v2\/comments?post=16436"}],"version-history":[{"count":0,"href":"https:\/\/acaltc.com\/en\/wp-json\/wp\/v2\/posts\/16436\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/acaltc.com\/en\/wp-json\/wp\/v2\/media\/16439"}],"wp:attachment":[{"href":"https:\/\/acaltc.com\/en\/wp-json\/wp\/v2\/media?parent=16436"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/acaltc.com\/en\/wp-json\/wp\/v2\/categories?post=16436"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/acaltc.com\/en\/wp-json\/wp\/v2\/tags?post=16436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}