Skip to content

Instantly share code, notes, and snippets.

View kalaiselvan369's full-sized avatar
🎯
Focusing

Kalaiselvan kalaiselvan369

🎯
Focusing
View GitHub Profile
@kalaiselvan369
kalaiselvan369 / mpp-build.gradle
Last active April 24, 2020 12:31
Build gradle for MPP
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 {
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
@kalaiselvan369
kalaiselvan369 / entry_point.kt
Last active June 7, 2023 07:55
Kotlin Basics
fun main() {
println("Hello World")
}
@kalaiselvan369
kalaiselvan369 / val_immutable.kt
Last active June 8, 2023 14:23
val & var difference
fun main() {
val a = 10
//a = 11 //Error: val cannot be reassigned
// Line: 3 won't compile hence commented
}
@kalaiselvan369
kalaiselvan369 / numbers.kt
Created June 8, 2023 11:12
Various notation in double, float and literal constants
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
@kalaiselvan369
kalaiselvan369 / characters.kt
Last active June 8, 2023 11:43
usage of 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
@kalaiselvan369
kalaiselvan369 / jvm_number_representation.kt
Created June 8, 2023 11:16
JVM representation for primitive types
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
fun main() {
// assignment operators
var sum = 3
sum += 3
println(sum)
var sub = 13
sub -= 3
println(sub)
@kalaiselvan369
kalaiselvan369 / increment_decrement.kt
Created June 8, 2023 11:18
Increment and Decrement
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
fun main() {
val numbers = listOf<Int>(1, 2, 3, 4)
for(n in numbers) {
print(n)
}
println()
for (n in 1..5) {