{"id":1060,"date":"2019-02-01T12:28:50","date_gmt":"2019-02-01T06:58:50","guid":{"rendered":"http:\/\/blog.openwebsolutions.in\/?p=1060"},"modified":"2019-02-01T12:28:50","modified_gmt":"2019-02-01T06:58:50","slug":"why-kotlin-is-used-what-is-singleton-in-kotlin","status":"publish","type":"post","link":"https:\/\/openwebsolutions.in\/blog\/why-kotlin-is-used-what-is-singleton-in-kotlin\/","title":{"rendered":"Why Kotlin is used and what is SINGLETON in Kotlin?"},"content":{"rendered":"<p>Kotlin is a statically typed language. It is also known as JVM language because Kotlin needs Java Virtual Machine (JVM) to execute its bytecode.<\/p>\n<h5><strong>Some exceptional features making it different than others<\/strong><\/h5>\n<p>i) Since it is JVM language so it&#8217;s fully interoperable on Java language. Since it is new in the market so it&#8217;s developed with lots of features that new developers for real-world crave for.<\/p>\n<p>ii) It supports to avoid NullPointerException which is a big headache for developers if they get this exception.<\/p>\n<p>iii) It supports Immutability that is you can declare a value inside Kotlin either in values or variables. If they are variables they can change but if they are values then their values are fixed at initialization just like constants.<\/p>\n<p>iv) It is Object Oriented Language just like Java or C++.<\/p>\n<p>v) In Kotlin, you can pass a function as a parameter to another function likely pass of the variable. Even a function can return another function likely return of any values.<\/p>\n<p>vi) It follows less ceremony. It means you use less number of codes to get more results compared to any other languages. Therefore by your code looks much cleaner.<\/p>\n<p>In the case of Singleton, we have just ONE INSTANCE of a class in the whole application. In Kotlin, suppose you have a class named Student which is declared as singleton then we cannot create objects for this class that is there exists only one object for this class by default which is created by Kotlin internally. In simple word, you can say we cannot create objects like student1,student2, etc. In kotlin, you cannot declare &#8216;static&#8217; variables and methods. When you declare something as object, the koltin internally create a singleton object when the program is running. Example-<\/p>\n<p>object Customer {<\/p>\n<p>var id:Int = -1 \/\/Behaving as Static Variable<\/p>\n<p>fun registerCustomer() { \/\/Behaving as Static Method<\/p>\n<p>\/\/Your code&#8230;<\/p>\n<p>}<br \/>\n}<\/p>\n<p>Customer.id=27 \/\/Calling without creating instance<\/p>\n<p>Customer.registerCustomer()<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Kotlin is a statically typed language. It is also known as JVM language because Kotlin needs Java Virtual Machine (JVM) to execute its bytecode. Some exceptional features making it different than others i) Since it is JVM language so it&#8217;s fully interoperable on Java language. Since it is new in the market so it&#8217;s developed [&hellip;]<\/p>\n","protected":false},"author":35,"featured_media":1112,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[12,18],"tags":[41,43,86,87],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v14.8.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Why Kotlin is used and what is SINGLETON in Kotlin?<\/title>\n<meta name=\"robots\" content=\"index, follow\" \/>\n<meta name=\"googlebot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta name=\"bingbot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/openwebsolutions.in\/blog\/why-kotlin-is-used-what-is-singleton-in-kotlin\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Why Kotlin is used and what is SINGLETON in Kotlin?\" \/>\n<meta property=\"og:description\" content=\"Kotlin is a statically typed language. It is also known as JVM language because Kotlin needs Java Virtual Machine (JVM) to execute its bytecode. Some exceptional features making it different than others i) Since it is JVM language so it&#8217;s fully interoperable on Java language. Since it is new in the market so it&#8217;s developed [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/openwebsolutions.in\/blog\/why-kotlin-is-used-what-is-singleton-in-kotlin\/\" \/>\n<meta property=\"og:site_name\" content=\"Openweb Solutions Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-02-01T06:58:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/openwebsolutions.in\/blog\/wp-content\/uploads\/2019\/02\/kotlin_800x320.png\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"320\" \/>\n<meta name=\"twitter:card\" content=\"summary\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#website\",\"url\":\"https:\/\/openwebsolutions.in\/blog\/\",\"name\":\"Openweb Solutions Blog\",\"description\":\"Transforming ideas into reality\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/openwebsolutions.in\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/why-kotlin-is-used-what-is-singleton-in-kotlin\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/openwebsolutions.in\/blog\/wp-content\/uploads\/2019\/02\/kotlin_800x320.png\",\"width\":800,\"height\":320,\"caption\":\"kotlin\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/why-kotlin-is-used-what-is-singleton-in-kotlin\/#webpage\",\"url\":\"https:\/\/openwebsolutions.in\/blog\/why-kotlin-is-used-what-is-singleton-in-kotlin\/\",\"name\":\"Why Kotlin is used and what is SINGLETON in Kotlin?\",\"isPartOf\":{\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/openwebsolutions.in\/blog\/why-kotlin-is-used-what-is-singleton-in-kotlin\/#primaryimage\"},\"datePublished\":\"2019-02-01T06:58:50+00:00\",\"dateModified\":\"2019-02-01T06:58:50+00:00\",\"author\":{\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#\/schema\/person\/990bda7c6fac1aa9c1ffde7745f42628\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/openwebsolutions.in\/blog\/why-kotlin-is-used-what-is-singleton-in-kotlin\/\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#\/schema\/person\/990bda7c6fac1aa9c1ffde7745f42628\",\"name\":\"Arindam Kundu\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1eea674a264b13f5b7c5895e36503137?s=96&r=g\",\"caption\":\"Arindam Kundu\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts\/1060"}],"collection":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/comments?post=1060"}],"version-history":[{"count":4,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts\/1060\/revisions"}],"predecessor-version":[{"id":1110,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts\/1060\/revisions\/1110"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/media\/1112"}],"wp:attachment":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/media?parent=1060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/categories?post=1060"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/tags?post=1060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}