Kotlin tutorials

Kotlin example for Beginners – Kotlin Program to Print an Integer (Entered by the User)

Kotlin Program to Print an Integer (Entered by the User) In this program, you’ll learn to print an integer entered by the user. The integer is stored in a variable and printed to the screen using nextInt() and println() functions respectively. Example 1: How to Print an Integer entered by an user in Kotlin using …

Kotlin tutorial for Beginners – Kotlin Extension Function

Kotlin Extension Function In this article, you will learn to extend a class with new functionality using extension functions. Suppose, you need to extend a class with new functionality. In most programming languages, you either derive a new class or use some kind of design pattern to do this. However, in Koltin, you can also use extension …

Kotlin tutorial for Beginners – Kotlin Companion Objects

Kotlin Companion Objects In this article, you will learn to create and use companion objects in your Kotlin program with the help of examples. Before taking about companion objects, let’s take an example to access members of a class. class Person{ fun callMe() = println(“I’m called.”) } fun main(args: Array<String>) { val p1 = Person() …

Kotlin tutorial for Beginners – Kotlin Object Declarations and Expressions

Kotlin Object Declarations and Expressions In this article, you will learn about object declarations (singletons) and object expressions with the help of examples. Object Declarations Singleton is an object-oriented pattern where a class can have only one instance (object). For example, you are working an application having SQL database backend. You want to create a …

Kotlin tutorial for Beginners – Kotlin Interfaces

Kotlin Interfaces In this article, you will learn about interfaces and how to implement it in Kotlin with the help of examples. Kotlin interfaces are similar to interfaces in Java 8. They can contain definitions of abstract methods as well as implementations of non-abstract methods. However, they cannot contain any state. Meaning, interface may have …

Kotlin tutorial for Beginners – Kotlin Abstract Class

Kotlin Abstract Class In this article, you will learn about abstract class and how to implement it in Kotlin (with the help of examples). Like Java, abstract keyword is used to declare abstract classes in Kotlin. An abstract class cannot be instantiated (you cannot create objects of an abstract class). However, you can inherit subclasses from …