Skip to main content


Showing posts from March 31, 2019

Kotlin - Variables and Type Inference

Greetings! Unlike Java, Kotlin uses special keywords to declare variables. var - for the values that change, mutable. val - for the values that do not change, immutable. Java String name = "Java"; int age = 20; Kotlin val name = "Kotlin" val age = 4 It is best practice to use val because immutability guarantees safety. We can use variable type when we declare it. If we initialize it, we can remove the type. But if we do not initialize, we should declare the variable type. val name = "Jon Snow" val role: String role = "King in the north" Constant If the value is a truly constant we can const keyword when declaring. Though this needs to use companion object. const val THE_END = "All men must die" Type inference Kotlin is a strongly typed language. Compiler can deduce the type by the context eliminating boilerplate code. Compiler is smart enough to identify the variable type. val helpUs = "Save Wilpattu&

Kotlin - Introduction

Greetings! I'm going to talk about Kotlin as a Java developer. There are many languages looming and Kotlin is one of them. Since it is another JVM based language it will be easier to grasp. Why another language? Java is more than 20 years old mature, widely used language. The problem of being old is it lacks modern techniques. Even though Java adapted to functional programming with Java 8, I believe it is somewhat late for the game. Considering modern day language features, difficulties they have faced using Java, Jetbrains created Kotlin. Being the one of the best IDE providers they know what they are doing. With InteliJ Idea Kotlin has the best IDE support with it. What is Kotlin Kotlin is a cross-platform, statically typed, general-purpose programming language with type inference. Kotlin is designed to interoperate fully with Java, and the JVM version of its standard library depends on the Java Class Library, but type inference allows its syntax to be more concise.