Kotlin

Kotlin Set

In this tutorial, we will talk about Kotlin Set with the help of simple examples. Sets are: An unordered collection of elements. Duplicate elements are not allowed in sets. In Kotlin, we can have both a mutable set and an immutable set. Kotlin Immutable Set The immutable set also known as read-only set support only read-only access to the set. Immutable set …

Kotlin Set Read More »

Kotlin List

In this tutorial, we will talk about Kotlin List with the help of simple examples. List  An ordered collection of elements. The ordered is maintained through indices (same as arrays). Indices start from zero(the index of the first element) and go to lastIndex which is the (list.size – 1). An element (including null) can occur …

Kotlin List Read More »

Kotlin Null Safety

This tutorial is about Null Safety in Kotlin. Null Safety in Kotlin is to eliminate the risk of occurrence of NullPointerException from code. One of the most common pitfalls in many programming languages, including Java, is that accessing a member of a null reference will result in a null reference exception. In Java this would …

Kotlin Null Safety Read More »

Kotlin Data Classes

This tutorial is about Kotlin Data classes, requirements that data class must fulfill, and their standard functionalities. Data Classes Data classes  are classes whose main purpose is to hold data/state and contains standard functionalities. A data keyword is used to declare a class as a data class. Example: data class Student(val name: String, val age: Int) …

Kotlin Data Classes Read More »

Kotlin Object Declarations and Expressions

This tutorial is about object declarations (singletons) and object expressions with the help of examples. Object Declarations Object declarations defines singletons. Singleton is an object-oriented pattern where a class can have only one instance (object) at a time. Kotlin creates singletons with the object keyword. The object declaration can have functions, properties, and the init …

Kotlin Object Declarations and Expressions Read More »

Kotlin Companion objects

This tutorial is about companion objects in Kotlin with the help of examples. Kotlin doesn’t have a static keyword. Static members belong to a type, and not to an instance of a type. In kotlin to achieve this static feature, we make use of companion object. companion object An object declaration inside a class can be …

Kotlin Companion objects Read More »

Kotlin Getters and Setters

This tutorial is about how to use getters and setters in Kotlin with the help of simple example. Getters and Setters Getters are used for getting value of the property and Setters are used for setting the value of the property. Setters can have visibility modifiers but Getters always have the same visibility as the …

Kotlin Getters and Setters Read More »

Kotlin Visibility Modifiers

This post is about Access/Visibility modifiers in kotlin and how to use them. Access Modifiers In Kotlin, visibility modifiers are used to restrict the accessibility of Classes, objects, interfaces, constructors, functions, properties and their setters to a certain level. Getters always have the same visibility as the property. There are four visibility modifiers in Kotlin: public protected internal …

Kotlin Visibility Modifiers Read More »

Kotlin Interfaces(With Examples)

This article is about interfaces and how to implement it in Kotlin with the help of simple examples. Interfaces In Kotlin, Interfaces can contain declarations of abstract methods (have no body), as well as method implementation of non-abstract methods.  Interfaces can have properties but these need to be abstract or to provide accessor implementations. Creating …

Kotlin Interfaces(With Examples) Read More »