{"id":68,"date":"2019-12-24T19:56:00","date_gmt":"2019-12-24T19:56:00","guid":{"rendered":"http:\/\/appstudio.ca\/blog\/?p=68"},"modified":"2023-04-10T10:29:59","modified_gmt":"2023-04-10T10:29:59","slug":"java-vs-kotlin","status":"publish","type":"post","link":"https:\/\/www.appstudio.ca\/blog\/java-vs-kotlin\/","title":{"rendered":"JAVA vs KOTLIN"},"content":{"rendered":"\n<div class=\"wp-block-group is-layout-flow wp-block-group-is-layout-flow\">\n<div class=\"wp-block-group is-layout-flow wp-block-group-is-layout-flow\">\n<p class=\"wp-block-paragraph\">You can write Android apps in any language that can compile and run on the <strong>Java Virtual Machine (JVM)<\/strong>, and your end users will be none the wiser. Java is one of the world\u2019s\u00a0most widely used <strong>programming languages<\/strong>. \u00a0If you want to consider a different language then switch to one of the many modern programming languages that are designed to run on the JVM. While there\u2019s no shortage of languages that compile to Java bytecode, there are a few factors that make <strong>Kotlin <\/strong>stand out from the crowd.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One of Kotlin\u2019s greatest strengths as a potential alternative to <strong><a href=\"https:\/\/www.appstudio.ca\/java-development.html\" target=\"_blank\" rel=\"noreferrer noopener\">Java<\/a> <\/strong>is the sheer level of interoperability between Java and Kotlin. You can even have Java and Kotlin code existing side by side in the same project, and everything will still compile perfectly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-kotlin-fixes-a-series-of-issues-that-java-suffers-from\"><strong>Kotlin fixes a series of issues that Java suffers from<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Null references are\u00a0controlled by the type system<\/strong>.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">One of the most common pitfalls in many programming languages, including Java, is that of accessing a member of a null reference, resulting in a null reference exception. In Java, this would be the equivalent of a&nbsp;NullPointerException or NPE for short.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In Kotlin, the type system distinguishes between references that can hold&nbsp;<em>null<\/em> and those that can not.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Arrays in Kotlin are&nbsp;invariant<\/strong><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Unlike Java, arrays in Kotlin are invariant. This means that Kotlin does not let us assign an&nbsp;Array&lt;String&gt;to an Array&lt;Any&gt; which prevents a possible runtime failure.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Kotlin has proper\u00a0<strong>function types,<\/strong> as opposed to Java&#8217;s SAM conversions<\/li><li>Kotlin does not have checked\u00a0<strong>exceptions<\/strong><\/li><\/ul>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>You can write Android apps in any language that can compile and run on the Java Virtual Machine (JVM), and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3241,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[127],"tags":[],"class_list":["post-68","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java-development"],"_links":{"self":[{"href":"https:\/\/www.appstudio.ca\/blog\/wp-json\/wp\/v2\/posts\/68","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appstudio.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appstudio.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appstudio.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appstudio.ca\/blog\/wp-json\/wp\/v2\/comments?post=68"}],"version-history":[{"count":2,"href":"https:\/\/www.appstudio.ca\/blog\/wp-json\/wp\/v2\/posts\/68\/revisions"}],"predecessor-version":[{"id":16128,"href":"https:\/\/www.appstudio.ca\/blog\/wp-json\/wp\/v2\/posts\/68\/revisions\/16128"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.appstudio.ca\/blog\/wp-json\/wp\/v2\/media\/3241"}],"wp:attachment":[{"href":"https:\/\/www.appstudio.ca\/blog\/wp-json\/wp\/v2\/media?parent=68"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appstudio.ca\/blog\/wp-json\/wp\/v2\/categories?post=68"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appstudio.ca\/blog\/wp-json\/wp\/v2\/tags?post=68"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}