Basics of Kotlin with examples

Kotlin is a JVM language which has not only become the de-facto programming language for developing Android applications but also is increasingly becoming very popular on the server side as well. So server side folks are also taking Kotlin very seriously because of so many cool features. Here I’ll summarise some of the basic features which have become really popular (remember Kotlin aims to make the code as compact and minimal as possible). If you look at each of the features below, they seem to be very logical way to make the Java syntax more concise but still readable and understandable.

	var data1 : String = text
	val data2:  String = text
	var letterBody: String = """
	    Dear ${letterRecipeint ?: "Recipent" }
	    This is to inform you that we have.....
	    You are receiving this letter on ${Date()}
	""".trimIndent()
	fun buildComputer(cpuTypeProvided: String = "i5",
			  ramSizeInGBProvided: Int = 8)
	    = Computer(cpuType = cpuTypeProvided,ramSize = ramSizeInGBProvided )

	buildComputer()
	buildComputer(cpuTypeProvided = "i9")
	buildComputer(cpuTypeProvided = "i9", ramSizeInGBProvided = 16)

In the above example, the function buildComputer is declared with default values for both the arguments. So as shown above, you can even invoke the same function without any argument and then it will take the default values of those arguments which were not specified. You can of course supply specific values in which case the default values will not be used.

		
		var text1 : String 
		var text2 : String?	

So text1 can’t contain null values. If you try to assign null values in it, the compiler will flag it as a compile time exception. However text2 can contain null values