Learn Kotlin with me Part 1 — Understanding the basics

Hitesh Kohli
3 min readApr 12, 2024
Photo by Marc Reichelt on Unsplash

Kotlin is becoming more and more popular nowadays. Kotlin helps us build multiplatform apps for both IOS and Android. Also, we can use it with Ktor to make a backend for the apps. It means we can architect the whole structure of apps with one single language.

A lot of technologies use Java, which forms the basis of Kotlin. It opens up the opportunity of using Kotlin with Java. It is one of many features of the Kotlin language. Let’s take a look at the features of Kotlin.

Features of Kotlin :

  • Statically Typed Language
  • Strictly Typed Language
  • Follows OOPS concepts
  • Concise/Safe/Powerful
  • Open Source
  • 100% interoperable with Java

Statically Typed Language:

  • It means that variable types are defined on the compile time. In simple words, we need to define data types of variables when we use them. If we do not do so, the compiler will give us an error before the run time.
  • Let us look at an example
var name:String = "Hitesh"

Strictly Typed Language:

  • It is the same as Statically Typed Language.

Follows OOPS concepts:

  • It follows all the concepts of OOPS:
  • Abstraction
  • Polymorphism
  • Inheritance
  • Encapsulation

Concise/Safe/Powerful:

  • One more important concept of Kotlin language is null safety. Java can give a lot of null pointer exceptions. To prevent null pointer exceptions Kotlin introduced null safety.
  • Let’s take an example:
var name String? = "Hitesh"

Open Source:

  • Kotlin is an open-source language. So we can spot the code on GitHub. As a developer, we can learn a lot from how different programming languages function.
  • Github link -

100% interoperable with Java:

  • Kotlin can be used with Java. It means that old Java projects can use the new features of the Kotlin language without rewriting any code.

Now that we have studied the basics of Kotlin. Let’s explore the basics of variables in Kotlin.

Variables and Datatypes in Kotlin

We can declare variables in two ways:

  • Var
  • Val
  • We want to declare a mutable type of variable. We use “var” to declare variables. Mutable means that variables can be changed or re-assigned.
  • We want to declare an immutable type of variable. We use “val” to declare variables. Immutable means that variables can not be changed or reassigned.

Kotlin can dynamically detect the data type of the variable. It means that we don’t have to declare the datatype of variables. Kotlin automatically assigns the data type to the variables.

Here is an example:

var name:String = "hitesh"
var age:Int = 23

Let’s take a look at data types in Kotlin:

  • String
  • Int
  • Boolean
  • Short
  • Long
  • Char
  • Byte

Functions in Kotlin

Let’s try to explore some functions in Kotlin. Functions are a set of reusable instructions. We declare a function like this:

fun printMyName(){

println("My name is Hitesh")

}

Functions usually start with a main function. It’s a starting point of code execution.

fun main(){
printMyName()
}

Let’s try to print my name with a function.

fun printMyName(name:String, age:Int){

println("My name is $name and my age is $age")

}

printMyName("Hitesh", 23)

-> OUTPUT -->

My name is Hitesh and my age is 23

I hope this makes the Kotlin more clear. We will explore the rest in upcoming blogs. Thank you for reading.

If I have written something wrong, please forgive me. I hope you enjoyed reading.

Thank you,

Your Captain (the commute)

Hitesh Kohli.

--

--

Hitesh Kohli

I will help you build distribution with apps |Building and Designing apps| Writing Newsletters 📩| Building @Developcommute & Niwa