{"id":279,"date":"2020-04-14T23:43:46","date_gmt":"2020-04-15T02:43:46","guid":{"rendered":"http:\/\/desarrollo-agil.ml\/blog\/?p=279"},"modified":"2020-04-14T23:44:39","modified_gmt":"2020-04-15T02:44:39","slug":"migrating-from-java-to-kotlin","status":"publish","type":"post","link":"http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/","title":{"rendered":"Migrating from Java to Kotlin"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">What is Kotlin?<\/h3>\n\n\n\n<p>It&#8217;s a programming language that runs over Java VM. Originally used to develop Android apps, but lately it&#8217;s been gaining ground in back-end development<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Isn&#8217;t Java enough for you?<\/h3>\n\n\n\n<p>Java is an excellent programming language. But it was born in mid 90&#8217;s and it&#8217;s been a long while since that. Software development evolved, and although Java accompanied this evolution, it was left behind comparing to several new languages, who have more advanced features in a more natural way, as they where already conceived with those features from scratch. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Kotlin main features<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Data Class<\/h4>\n\n\n\n<p>It&#8217;s Java&#8217;s main absence. When we just need classes to acummulate info, transfer between layers without logic, data classes are our allies. They provide us with copy and equals methods, and automatic implementation of setters and getters. You are going to save a lot of code just by using data classes.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Null safety<\/h4>\n\n\n\n<p>Kotlin data types don&#8217;t allow null values, unless we say the contrary. Does it mean that I don&#8217;t have to nullcheck everything? Exactly. So, how do I get nullable value types when I need them? I have to indicate that to kotlin when I declare variable types. This has 2 advantages: The first one is that for non nullable values, I don&#8217;t have to perform nullchecks. The second one, is in case I have nullable values, I MUST perform nullcheck, otherwise, compiler will scream at me, so I won&#8217;t forget to do it. And when I do it, I can use \u00ablet\u00bb and \u00abrun\u00bb instead of \u00abif (value != null)\u00bb, which are more readable in the end.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">High Order Functions <\/h4>\n\n\n\n<p>Several times I wanted to send functions as parameters to a method to get a simpler design, but in Java you have to involve functional interfaces and that&#8217;s not the friendliest way to do it. In kotlin this concept of functional programming is provided easily to enhance our code.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Interaction with Java code<\/h4>\n\n\n\n<p>Kotlin was born to be used in conjunction with Java. I can have a Kotlin class in a project nearly entirely made with Java, I can invoke it from and to Java classes, and everything keeps working as a charm. Being so easy to integrate with existing Java code enables us to try it and easily rollback in case we don&#8217;t like it (which is highly unlikely)<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Low learning curve<\/h4>\n\n\n\n<p>Kotlin was born for Java developers who wanted to have some extra features and a more friendly code. It&#8217;s not a start from scratch. Any Java developer can benefit from Kotlin in a few hours.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Collections API<\/h4>\n\n\n\n<p>Map, filter, forEach, first, last and others are factory included. You don&#8217;t have to write \u00abmyList.stream().map(&#8230;).filter(&#8230;).collect(Collectors.toList())\u00bb In Kotlin is as simple as myList.map(&#8230;).filter(&#8230;)<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Extension functions<\/h4>\n\n\n\n<p>Have you ever thought \u00abIt would be nice if this class had this method\u00bband you couldn&#8217;t add it because it was from a library, or wasn&#8217;t under your scope? With Kotlin we can declare extension functions to a type, and we can invoke it everywhere.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How to try Kotlin?<\/h3>\n\n\n\n<p>If you use Maven for your builds, it&#8217;s as simple as copy pasting a plugin in your pom. I&#8217;m not going to expand over this, just read official docs from Kotlin itself:\u00a0<a href=\"https:\/\/kotlinlang.org\/docs\/reference\/using-maven.html\">https:\/\/kotlinlang.org\/docs\/reference\/using-maven.html<\/a><\/p>\n\n\n\n<p>A very important thing to keep in mind is to have an IDE with good language Integration. As kotlin  was developed by Intellij, language support in this ide is excellent,  Kotlin also has eclipse plugins, but I haven&#8217;t tried it yet.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Final thoughts<\/h3>\n\n\n\n<p>If you are coding with Java, and you have a couple of spare hours, give yourself the chance to try Kotlin. If you ever tried Scala, you wil find most of it&#8217;s main features, at a much lower price.<\/p>\n\n\n\n<p>Satis-function guaranteed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is Kotlin? It&#8217;s a programming language that runs over Java VM. Originally used to develop Android apps, but lately it&#8217;s been gaining ground in back-end development Isn&#8217;t Java enough for you? Java is an excellent programming language. But it was born in mid 90&#8217;s and it&#8217;s been a long while since that. Software development\u2026 <span class=\"read-more\"><a href=\"http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/\">Leer m\u00e1s &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[86],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v17.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Migrating from Java to Kotlin - Desarrollo \u00c1gil<\/title>\n<meta name=\"description\" content=\"Reasons to try kotlin\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/\" \/>\n<meta property=\"og:locale\" content=\"es_ES\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Migrating from Java to Kotlin - Desarrollo \u00c1gil\" \/>\n<meta property=\"og:description\" content=\"Reasons to try kotlin\" \/>\n<meta property=\"og:url\" content=\"http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/\" \/>\n<meta property=\"og:site_name\" content=\"Desarrollo \u00c1gil\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-15T02:43:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-04-15T02:44:39+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@emilianotebes\" \/>\n<meta name=\"twitter:site\" content=\"@emilianotebes\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"Emiliano\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tiempo de lectura\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"http:\/\/desarrollo-agil.com\/blog\/#website\",\"url\":\"http:\/\/desarrollo-agil.com\/blog\/\",\"name\":\"Desarrollo \\u00c1gil\",\"description\":\"Sofware por y para humanos\",\"publisher\":{\"@id\":\"http:\/\/desarrollo-agil.com\/blog\/#\/schema\/person\/d3f309d88ee70165de93b55560c9f851\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/desarrollo-agil.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"es\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/#webpage\",\"url\":\"http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/\",\"name\":\"Migrating from Java to Kotlin - Desarrollo \\u00c1gil\",\"isPartOf\":{\"@id\":\"http:\/\/desarrollo-agil.com\/blog\/#website\"},\"datePublished\":\"2020-04-15T02:43:46+00:00\",\"dateModified\":\"2020-04-15T02:44:39+00:00\",\"description\":\"Reasons to try kotlin\",\"breadcrumb\":{\"@id\":\"http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/#breadcrumb\"},\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Portada\",\"item\":\"http:\/\/desarrollo-agil.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Migrating from Java to Kotlin\"}]},{\"@type\":\"Article\",\"@id\":\"http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/#article\",\"isPartOf\":{\"@id\":\"http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/#webpage\"},\"author\":{\"@id\":\"http:\/\/desarrollo-agil.com\/blog\/#\/schema\/person\/d3f309d88ee70165de93b55560c9f851\"},\"headline\":\"Migrating from Java to Kotlin\",\"datePublished\":\"2020-04-15T02:43:46+00:00\",\"dateModified\":\"2020-04-15T02:44:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/#webpage\"},\"wordCount\":638,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/desarrollo-agil.com\/blog\/#\/schema\/person\/d3f309d88ee70165de93b55560c9f851\"},\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/#respond\"]}]},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/desarrollo-agil.com\/blog\/#\/schema\/person\/d3f309d88ee70165de93b55560c9f851\",\"name\":\"Emiliano\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"http:\/\/desarrollo-agil.com\/blog\/#personlogo\",\"inLanguage\":\"es\",\"url\":\"http:\/\/2.gravatar.com\/avatar\/e2997f02fe4216c2cce9e5a88e3e3726?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/2.gravatar.com\/avatar\/e2997f02fe4216c2cce9e5a88e3e3726?s=96&d=mm&r=g\",\"caption\":\"Emiliano\"},\"logo\":{\"@id\":\"http:\/\/desarrollo-agil.com\/blog\/#personlogo\"},\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/emilianotebes\/\",\"https:\/\/twitter.com\/emilianotebes\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Migrating from Java to Kotlin - Desarrollo \u00c1gil","description":"Reasons to try kotlin","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":"http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/","og_locale":"es_ES","og_type":"article","og_title":"Migrating from Java to Kotlin - Desarrollo \u00c1gil","og_description":"Reasons to try kotlin","og_url":"http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/","og_site_name":"Desarrollo \u00c1gil","article_published_time":"2020-04-15T02:43:46+00:00","article_modified_time":"2020-04-15T02:44:39+00:00","twitter_card":"summary_large_image","twitter_creator":"@emilianotebes","twitter_site":"@emilianotebes","twitter_misc":{"Escrito por":"Emiliano","Tiempo de lectura":"3 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"http:\/\/desarrollo-agil.com\/blog\/#website","url":"http:\/\/desarrollo-agil.com\/blog\/","name":"Desarrollo \u00c1gil","description":"Sofware por y para humanos","publisher":{"@id":"http:\/\/desarrollo-agil.com\/blog\/#\/schema\/person\/d3f309d88ee70165de93b55560c9f851"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/desarrollo-agil.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"es"},{"@type":"WebPage","@id":"http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/#webpage","url":"http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/","name":"Migrating from Java to Kotlin - Desarrollo \u00c1gil","isPartOf":{"@id":"http:\/\/desarrollo-agil.com\/blog\/#website"},"datePublished":"2020-04-15T02:43:46+00:00","dateModified":"2020-04-15T02:44:39+00:00","description":"Reasons to try kotlin","breadcrumb":{"@id":"http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/#breadcrumb"},"inLanguage":"es","potentialAction":[{"@type":"ReadAction","target":["http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Portada","item":"http:\/\/desarrollo-agil.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Migrating from Java to Kotlin"}]},{"@type":"Article","@id":"http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/#article","isPartOf":{"@id":"http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/#webpage"},"author":{"@id":"http:\/\/desarrollo-agil.com\/blog\/#\/schema\/person\/d3f309d88ee70165de93b55560c9f851"},"headline":"Migrating from Java to Kotlin","datePublished":"2020-04-15T02:43:46+00:00","dateModified":"2020-04-15T02:44:39+00:00","mainEntityOfPage":{"@id":"http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/#webpage"},"wordCount":638,"commentCount":0,"publisher":{"@id":"http:\/\/desarrollo-agil.com\/blog\/#\/schema\/person\/d3f309d88ee70165de93b55560c9f851"},"inLanguage":"es","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/desarrollo-agil.com\/blog\/en\/sin-categoria-en\/migrating-from-java-to-kotlin\/#respond"]}]},{"@type":["Person","Organization"],"@id":"http:\/\/desarrollo-agil.com\/blog\/#\/schema\/person\/d3f309d88ee70165de93b55560c9f851","name":"Emiliano","image":{"@type":"ImageObject","@id":"http:\/\/desarrollo-agil.com\/blog\/#personlogo","inLanguage":"es","url":"http:\/\/2.gravatar.com\/avatar\/e2997f02fe4216c2cce9e5a88e3e3726?s=96&d=mm&r=g","contentUrl":"http:\/\/2.gravatar.com\/avatar\/e2997f02fe4216c2cce9e5a88e3e3726?s=96&d=mm&r=g","caption":"Emiliano"},"logo":{"@id":"http:\/\/desarrollo-agil.com\/blog\/#personlogo"},"sameAs":["https:\/\/www.linkedin.com\/in\/emilianotebes\/","https:\/\/twitter.com\/emilianotebes"]}]}},"_links":{"self":[{"href":"http:\/\/desarrollo-agil.com\/blog\/wp-json\/wp\/v2\/posts\/279"}],"collection":[{"href":"http:\/\/desarrollo-agil.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/desarrollo-agil.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/desarrollo-agil.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/desarrollo-agil.com\/blog\/wp-json\/wp\/v2\/comments?post=279"}],"version-history":[{"count":8,"href":"http:\/\/desarrollo-agil.com\/blog\/wp-json\/wp\/v2\/posts\/279\/revisions"}],"predecessor-version":[{"id":291,"href":"http:\/\/desarrollo-agil.com\/blog\/wp-json\/wp\/v2\/posts\/279\/revisions\/291"}],"wp:attachment":[{"href":"http:\/\/desarrollo-agil.com\/blog\/wp-json\/wp\/v2\/media?parent=279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/desarrollo-agil.com\/blog\/wp-json\/wp\/v2\/categories?post=279"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/desarrollo-agil.com\/blog\/wp-json\/wp\/v2\/tags?post=279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}