Kotlin Programming Introduction
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++.“Hello World” program in Kotlin
visit http://kotlinlang.org/ and TRYONLINE will help you write some sample programs online.
//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”)
}
3.From command line you can compile hello.kt using below command
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
4.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''
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')
String Datatype:
Strings are represented by the type String.
Strings are immutable
`val str = "hello world"`
6.Difference between val and var
val variables are immutable
var variables are mutable, means can be reassigned
Congratulations @naveendavisv! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
You published your First Post
You made your First Vote
You got a First Vote
You made your First Comment
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit