Kotlin is a statically typed programming language that runs on the Java Virtual Machine and can also compile to JavaScript. It was announced by Google in 2017 as an officially supported language for Android development alongside Java and C++. The document provides an introduction to Kotlin and covers topics like data types, variables, arrays, strings, and the difference between val and var. It also includes a "Hello World" example program written in Kotlin.
3. Kotlin Android Development
Introduction to Kotlin programming Language:
● Google announced Kotlin as officially supported language for Android.
● Kotlin is a great fit for developing server-side applications, allowing to write concise and
expressive code
●
● Kotlin provides ability to target javascript
● Kotlin is a statically typed programming language that runs on Java virtual machine(JVM)
and also can be compiled to Javascript source code.
● Google I/O 2017 it was declared as one of the official programming languages to develop
Android applications along with Java and C++.
4. Kotlin Android Development
“Hello World” program in Kotlin
visit http://kotlinlang.org/ and TRYONLINE will help you write
some sample programs online.
//there will be a main function for every project.
//save the file as hello.kt
package demo //package is optional
fun main(args:Array<strings){
/*fun keyword shows its a function and args is argument of type array of strings*/
println(“hello world”)
}
–
5. Kotlin Android Development
From command line you can compile hello.kt using below
command.
$kotlinc hello.kt -include-runtime -d hello.jar
The -d option indicates what we want the output of the compiler to be called and may be either a
directory name for class files or a .jar file name. The -include-runtime option makes the resulting .jar file self-
contained and runnable by including the Kotlin runtime library in it.
Run the application.
$java -jar hello.jar
7. Kotlin Android Development
Basic data types in Kotlin are :
Double = 64bit,Float=32bit,Long=64bit,Int=32bit,Short = 16bit,Byte=8bit
Variable declaration and Initialization:
val a: Int = 100
Char type
val b:Char = 'b'
8. Kotlin Android Development
Basic data types in Kotlin are :
Array type
Arrays in Kotlin are represented by the Array class,
that has get and set functions
Method1:
val arr = arrayOf(1,2,3)
Method2:
val arr:IntArray = intArrayOf(1,2,3)
val x:CharArray = charArrayOf('a','b','c')
9. Kotlin Android Development
String Datatype:
Strings are represented by the type String.
Strings are immutable
val str = "hello world"
–