Kotlin Tutorial
Welcome to Kotlin Tutorial! Kotlin has become popular with Android. If you would like to learn Kotlin programming language, this is a good start.
This Kotlin Tutorial provides a detailed introduction to Kotlin programming language, its basics, and examples to understand basic functional programming statements, object-oriented concepts, file operations, string operations, etc.
What is Kotlin?
Basically, Kotlin is a programming language. It can be used to develop modern multi-platform applications for Desktop, Android, Web, etc.
Kotlin runs on Java Virtual Machine like other programming languages: Scala, Groovy, Kawa, etc.
Why Kotlin has become popular?
If the word Kotlin has been buzzing around for quite some time, all the credit goes to Google Android, because Google had brought this language to lime light. Once Google Android declared that Kotlin will be one of the officially supported language for Android App development, Kotlin’s popularity had surged. And Kotlin has become popular with the existing Android community and also the emerging.
Kotlin programming language can be used to develop Desktop Applications and Android Applications with ease. These tutorials have been designed to present you the basics and new idiomatic approach.
A little introduction to Kotlin’s history
Kotlin is relatively a new statically-typed language by 2017, developed by JetBrains. Kotlin is targeted to run on the Java Virtual Machine (JVM). Kotlin addresses most of the redundancies present in Java programming language, and also new features have been added that could make application development faster and easier.
There are other new languages with new features that could run on JVM, but Kotlin excels in the reduced compile time (comparable to the time taken by Java Compiler) when compared to other languages.
Also, Kotlin is concise and expressive while maintaining a good compatibility with existing Java stack. And Kotlin could be written alongside Java or we could convert existing Java classes to Kotlin files or classes using IntelliJ IDEA. All these features make it easy for a Java developer to get started with Kotlin quickly.
That being said, the first stable version of Kotlin, Kotlin 1.0 has been released on 15th, Feb 2016. JetBrains would provide backward compatibility for Kotlin 1.0 for a long time. Also, Google added Kotlin as an officially supported language for Android Application development, which is available from Android Studio 3.0.
Prerequisites for this Kotlin Tutorial
Understanding of Java Basics would help a lot in learning Kotlin quickly. However this Kotlin Tutorial is designed to address both beginners and advanced developers.
IDE for Kotlin Development
Applications using Kotlin Language could be developed on IntelliJ IDEA and is recommended. Eclipse or any editor could also be used along with a compiler to compile from the command line.
Android Studio
Android Applications could be developed using Kotlin from Android Studio version 3.0.
Refer Kotlin Android Tutorial to develop Android Applications using Kotlin programming language.
Kotlin Tutorials Index
The following tutorials help you get started with Kotlin development.
Kotlin Environment Setup
First and foremost thing to do is, setting up your environment to work with Kotlin.
Having set up our environment and a peek of Kotlin program, let us understand the basics of Kotlin.
Kotlin Variables and Datatypes
Variables are storage containers for data. And datatype of a variable determines the type of data stored in the variable. The following tutorials cover variables, and different datatypes in Kotlin.
Kotlin Conditional Statements
Conditional Statements are those which can execute a block of code based on the result of a condition. The following tutorials cover the basic conditional statements in Kotlin, followed by some of typically scenarios with conditional statements.
Kotlin Loops
Kotlin loop statements are used to execute a block of code multiple times based on a condition. In the following tutorials, we start with an introduction to loops in Kotlin programming. Then we dive deep into each of the looping statements in Kotlin, and some of typical scenarios where these looping statements are used.
Kotlin Exception Handling
Exception Handling is a must known tool to every developer for any programming language. The following tutorials start with a basic try-catch statement, and then about explicitly throwing an exception, or writing our own Exceptions, etc.
Kotlin Object Oriented Concepts
Kotlin supports object oriented programming. The following tutorials get us introduced to different object oriented concepts, and about each of them in detail.
- Kotlin Object Oriented
- Kotlin Classes and Constructors
- Kotlin Sealed Classes
- Kotlin Data Classes
- Kotlin Inheritance
- Kotlin Abstraction
- Kotlin Abstract Class
- Kotlin Interfaces
Kotlin Array
An array is an ordered collection of similar type of elements. In the following tutorials, we start with an introductory tutorial to basics of Array in Kotlin, and then some of the mostly used function of Array class in Kotlin, followed by regularly used use-cases.
Kotlin Array Properties
Kotlin Array CRUD Operations
- Kotlin – Get Element at Given Index in Array
- Kotlin – Set Element at Given Index in Array
- Kotlin – Iterate over Array Elements
- Kotlin – Array forEach
- Kotlin – Replace All Occurrences of an Element in Array
- Kotlin – Delete All Elements in Array
Kotlin Array Checks
- Kotlin – Check if Array is Empty
- Kotlin – Check if Element is present in Array
Kotlin Array Transformations
- Kotlin – Apply Function on Each Element of Array
- Kotlin – Filter Array
- Kotlin – Find Unique Elements in Array
- Kotlin – Join Arrays
- Koltin – Reverse Array
- Kotlin – Shuffle Array
- Kotlin – Slice Array
- Kotlin – Sort Array
Kotlin Array Conversions
- Kotlin – Convert Array to List
- Kotlin – Convert Array to ArrayList
- Kotlin – Convert Array to Set
- Kotlin – Convert Array to String
- Kotlin – Convert Array to Map
- Kotlin – Convert Array to
- Kotlin – Convert Array to
- Kotlin – Convert Array to
- Kotlin – Convert Array to
Other Kotlin Array Functions
- Kotlin – Array Average
Kotlin Basics
- Kotlin main function
- Kotlin Extension Functions – Kotlin extension functions actually help in extending the functionality of a class without actually inheriting the class.
- Kotlin Null Safety – Null Safety can used to eliminate the risk of NullPointerException in real time.
- Kotlin Enum Classes – Kotlin Tutorial about how Enum class allows a variable to hold a value only from a set of predefined constants.
- Kotlin use function – In Kotlin, use is a keyword, used to execute a given block function on this resource.
- Kotlin Ranges – Kotlin Tutorial on how to express a series of numbers defined as a range and different scenarios where ranges can be used.
Kotlin String Operations
It is very necessary to know about String Operations in programming applications. Following topics take you through some of the String Operations that are commonly used.
- Kotlin – Check if Two Strings are Equal
- Kotlin – Check if String contains Specified Substring
- Kotlin – Check if String Starts with Specified Character
- Kotlin – Check if String Ends with Specified String
- Kotlin – Compare Strings
- Kotlin – Filter Characters of String
- Kotlin – Get Character at Specific Index in String
- Kotlin – Remove First N Characters from String
- Kotlin – Remove Last N Characters from String
- Kotlin – Split String to Lines
- Kotlin – Substring
- Kotlin – Iterate over Each Character in String
Kotlin File Operations
If our application requires working with files which need operations like reading, writing, modifying and appending content in a file or moving files from one location to another and such, following are the tutorials that help you with file operations.
- Kotlin – Read File
- Kotlin – Read File as List of lines
- Kotlin – Write to File
- Kotlin – Append Text to File
- Kotlin – Copy File
- Kotlin – Iterate through all Files in Directory
Kotlin Interfacing to Database
If our Kotlin Application needs interfacing to a database, following topics explain how to connect to different databases.
Kotlin Error Handling
This section of tutorials focuses on how to handle most frequently occurring errors during programming in Kotlin.
- Kotlin Error: Primary Constructor call expected
- Kotlin Error: Variable must be initialized
- Kotlin Error: Null cannot be a value of a non-null type
- Kotlin Error: Cannot create an instance of abstract class
Interview Questions & Answers
Find the mostly asked Interview Questions and respective answers for Kotlin programming.
Conclusion
By following these Kotlin Tutorials, you would definitely learn Kotlin basics and tools required to work with Desktop applications and Android Applications.