Kotlin Tutorial – Learn Kotlin programming language to develop Desktop Applications and Android Applications with ease. Many example programs are presented with the concepts.
Kotlin is relatively a new statically-typed language by 2017, developed by JetBrains, that is targeted to run on Java Virtual Machine (JVM). Kotlin addresses most of the redundancies in Java programming language, and also new features have been added that could make application development faster and easier and most importantly lot of fun.
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 along side 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.
That being said, first stable version of Kotlin, Kotlin 1.0 has been released on 15th, Feb 2016. JetBrains would provide backwards 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 groups of audience, with and without Java Programming skills.
IDE (Integrated Development Environment)
Applications using Kotlin Language could be developed on IntelliJ IDEA. Eclipse or any editor could also be used along with a compiler to compile from the command line.
Android Applications could be developed using Kotlin from Android Studio verion 3.0. Android Studio has added Kotlin to its officially supported languages list, which already has Java and C++. Follow Android Kotlin Tutorial to develop Android Applications using Kotlin programming language.
In this Kotlin Tutorial, we shall learn Kotlin language from very basics.
Having setup our environment and a taste of Kotlin program, lets understand the basics of Kotlin.
- Kotlin main function – Kotlin Tutorial on the main entry point in a Kotlin program
- Kotlin Classes and Constructors – Kotlin Tutorial to understand about Kotlin Class and its structure, Kotlin Constructors – Kotlin Primary Constructor, Kotlin Secondary Constructor and Kotlin init block with examples
- Kotlin Data Classes – Kotlin Tutorial to understand the classes that are used to only store data with a simplified code.
- Kotlin Loops – Kotlin Tutorial to understand about various conditional loops available.
- Kotlin When expression – Kotlin Tutorial to learn about when expression (like a switch case statement in Java)
- Kotlin Extension Functions – Kotlin Tutorial on extension functions that help in extending the functionality of a Kotlin Class (even an inbuilt class).
- Kotlin Null Safety – Kotlin Tutorial on one of the powerful feature of Kotlin, Null Safety that provides lot of options to avoid traditional NullPointerException.
- Kotlin Enum Classes – Kotlin Tutorial to learn about Enum which is a special datatype that allows a variable to hold a value only from a set of predefined constants. Also learn to initialize Enums in Kotlin.
We have learnt the basics of Kotlin programming language. Now we shall see how to handle some of the errors that occur during the Kotlin application development.
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.
Working with Files in Kotlin
If your application requires working with files which needs 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 – Reading content of File
- Kotlin – Read content of a File as List of lines
- Kotlin – Writing content to File
- Kotlin – Append text to File
- Kotlin – Copy file to other location
- Kotlin – Iterate through all files in Directory
If you are interested in developing Android Applications, you may follow Kotlin Android Tutorial .
Kotlin Interfacing to Database
If your Kotlin Application needs interfacing to a database, following topics explain how to connect to different databases.
Kotlin Error Handling
- Handle Compilation Error
- Kotlin – Primary constructor call expected – Kotlin Tutorial to fix the error which occurs when primary constructor is not called from secondary constructor.
- Kotlin – Variable must be initialized – Kotlin Tutorial to fix the compilation error which occurs when a variable is declared but not initialized.
- Kotlin – Null cannot be a value of a non-null type – Kotlin Tutorial to fix the compilation error which occurs when a variable is declared but not initialized.
Reference – Kotlin Official Site .
By following these tutorials, we can successfully learn Kotlin basics and tools required to work with applications using Kotlin programming language.