Kotlin Basics

tarun bhatt
4 min readSep 22, 2021
From my developer laptop

In my previous article, I provided an introduction to Kotlin. In this article, I will be writing on some basic features of Kotlin. Please go through my last article for a better understanding of the upcoming sections.

Classes

In my previous article, we executed code snippets in Kotlin without the need for a class. It worked well for small code snippets, but that isn’t an excellent option for production-ready applications. Let’s look into how to create a class in Kotlin.

I don’t need to create a new file for this purpose. Hence I will update the same HelloWorld.kt.

In Kotlin, we can initialize a class without the new() keyword (line number 5 & 8). Additionally, providing a class type while initializing is not mandatory, as you can see in the sample above.

Immutability: var vs val

Kotlin comes with specific keywords for mutable and immutable behaviors.

  • ‘var’ keyword means that the variable is mutable. i.e., the value can change.
  • ‘val’ keyword indicates that the…

--

--

tarun bhatt
tarun bhatt

Written by tarun bhatt

Learning to write and share. #ITNerd #MentalHealthAdvocate #MenRightsActivist #ToastMaster #PublicSpeaker

No responses yet