This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
id 'org.jetbrains.kotlin.multiplatform' | |
} | |
apply plugin: 'com.android.library' | |
apply plugin: 'kotlin-android-extensions' | |
apply plugin: 'maven-publish' | |
// Because the components are created only during the afterEvaluate phase, you must | |
// configure your publications using the afterEvaluate() lifecycle method. | |
afterEvaluate { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
sumOfTwoBytes() | |
} | |
/* | |
Why the answer is -16 when we expect the result in byte. Let's do that manually. We know that byte can store values | |
from -128 to 127 only. Here we want to store the 240 which is not possible. But how -16 is returned. | |
Binary value of 240 is 11110000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
println("Hello World") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
val a = 10 | |
//a = 11 //Error: val cannot be reassigned | |
// Line: 3 won't compile hence commented | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
// double declaration | |
val d = 1.234 // type is inferred | |
val doubleNotation = 1.2e10 | |
println(doubleNotation) | |
// float declaration | |
val floatValue = 123.23452F | |
val floatValueRoundedOff = 1.234278690234f |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
val escapeQuotes = "\"a\"" | |
println("\thello") | |
println('\n') | |
println(escapeQuotes) | |
println("\\h") | |
println('5'.code) // prints the ASCII code | |
println(56.toChar()) // prints 8 the value for ASCII code 56 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
val a: Int = 100 | |
val boxedA: Int? = a | |
val anotherBoxedA: Int? = a | |
// === means referential equality | |
println(boxedA === anotherBoxedA) // true | |
//JVM has predefined values for int between -128 to 127 hence above statement is true | |
val b: Int = 10000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
// assignment operators | |
var sum = 3 | |
sum += 3 | |
println(sum) | |
var sub = 13 | |
sub -= 3 | |
println(sub) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
// increment and decrement operators | |
var i = 0 | |
val j = i++ // post increment | |
var k = 0 | |
val l = ++k // pre increment | |
println("j:$j , l:$l") // prints j:0 , l:2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
val numbers = listOf<Int>(1, 2, 3, 4) | |
for(n in numbers) { | |
print(n) | |
} | |
println() | |
for (n in 1..5) { |