260 likes | 276 Views
Explore the key syntax differences between Java and Kotlin, including final variables, bitwise operations, Null Safety, and Model Class implementation. Learn how Kotlin's features enhance code readability and efficiency.
E N D
Java vs Kotlin Syntax Java final int x; final int y = 1; int w; int z = 2; z = 3; w = 1; Kotlin val x: Int val y = 1 var w: Int var z = 2 z = 3 w = 1 https://fabiomsr.github.io/from-java-to-kotlin/
Bits Operations Java final intandResult = a & b; final intorResult = a | b; final intxorResult = a ^ b; final intrightShift = a >> 2; final intleftShift = a << 2; Kotlin valandResult = a and b valorResult = a or b valxorResult = a xor b valrightShift = a shr 2 valleftShift = a shl 2 Is As In Java if(x instanceof Integer){ } final String text = (String) other; if(x >= 0 && x <= 10 ){} Kotlin if (x is Int) { } val text = other as String if (x in 0..10) { }
Null Safety Kotlin val name: String? = null varlastName: String? lastName = null varfirstName: String firstName = null // Compilation error!! Java final String name = null; String lastName; lastName = null val length = b!!.length
Some Awesome stuffs Some Awesome stuffs https://kotlinlang.org/docs/tutorials/ https://try.kotlinlang.org/#/Kotlin%20Koans/Introduction/Hello,%20world!/Task.kt https://blog.mindorks.com/a-complete-guide-to-learn-kotlin-for-android-development-b1e5d23cc2d8 https://android-arsenal.com/tag/205?sort=created https://fabiomsr.github.io/from-java-to-kotlin/