Kotlin is a relatively new programming language developed by JetBrains for modern multiplatform applications. Nowadays, Kotlin is widely used for Android development instead of Java. It is because Kotlin is safe, concise, and fun to read and write.
Why Kotlin?
Statically typed, object-oriented, Modern programming language
Properties and extensions for classes
Created by the developer for developers
Concise, much less boilerplate code than some other languages
Increased null safety with nullable and non-nullable data types
Open sourced
Supports lambdas and higher-order functions
Fully compatible with Java language, so that you can migrate over time and continue using your favorite libraries
Officially supported for Android development, and included with IntelliJ and Android Studio
Features of Kotlin Programming
- Open Source
Kotlin is distributed under Apache License, Version 2.0. The Kompiler (Kotlin Compiler), IntelliJ IDEA plugin, enhancements to basic Java libraries and build tools all are open source.
- Interoperable
Kotlin is 100 percent interoperable with Java. This means all your current Java/Android code works seamlessly with Kotlin.
- Concise and Expressive
Compared to Java, Kotlin codes are much more concise. Also, Kotlin code is much more expressive (easier to understand and write).
- Tool-friendly
Kotlin is developed by JetBrains, a company renowned for creating development tools. You can choose any Java IDE to write Kotlin code.
- Easy to Learn
Learning Kotlin is easy if you know other programming languages like Java, Scala, Groovy, C#, JavaScript, and Gosu.
- Safe
Kotlin is a statically typed language. Hence, the type checking occurs at compile-time as opposed to run-time, and trivial bugs are caught at an early stage.
Kotlin Hello World: Your First Kotlin Programming
A “Hello, World!” is a simple program that outputs Hello, World! on the screen. Since it’s a very simple program, it’s often used to introduce a new programming language.
When you run the program, the output will be:
Hello, World!
How does this program work?
1. // Hello World Program
Any line starting with // is a comment in Kotlin (Similar to Java). Comments are ignored by the compiler. They are intended for the person reading the code to better understand the intent and functionality of the program.
2. fun main (args : Array <String>) { ….. }
This is the main function, which is mandatory in every Kotlin application. The Kotlin compiler starts executing the code from the main function.
The function takes an array of strings as a parameter and returns a Unit. Just remember that the main function is a mandatory function which is the entry point of every Kotlin program. The signature of the main function is:
fun main (args : Array<String>) {
… .. …
}
3. println (“Hello, World!”)
The println ( ) function prints the given message inside the quotation marks and newlines to the standard output stream. In this program, it prints Hello, World! and new line.
Thank You!