0
0
Kotlinprogramming~20 mins

How Kotlin compiles to JVM bytecode - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Kotlin JVM Bytecode Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Kotlin code compiled to JVM bytecode
What is the output when this Kotlin code is compiled to JVM bytecode and run?
Kotlin
fun main() {
    val numbers = listOf(1, 2, 3)
    val doubled = numbers.map { it * 2 }
    println(doubled)
}
A[1, 4, 9]
B[1, 2, 3]
CCompilation error
D[2, 4, 6]
Attempts:
2 left
💡 Hint
Think about what the map function does to each element.
🧠 Conceptual
intermediate
1:30remaining
Kotlin compilation target for JVM
Which of the following best describes what Kotlin compiles into when targeting the JVM?
AJVM bytecode
BJavaScript code
CNative machine code
DJava source code
Attempts:
2 left
💡 Hint
Think about what the JVM runs directly.
🔧 Debug
advanced
2:00remaining
Identify the error in Kotlin bytecode generation
Given this Kotlin code snippet, what error will occur when compiling to JVM bytecode?
Kotlin
fun main() {
    val x: Int = "100"
    println(x)
}
ANo error, prints 100
BNull pointer exception at runtime
CType mismatch: inferred type is String but Int was expected
DSyntax error: missing semicolon
Attempts:
2 left
💡 Hint
Check the variable type and assigned value.
📝 Syntax
advanced
1:30remaining
Kotlin syntax for JVM bytecode compatibility
Which Kotlin syntax ensures the function is compiled as a static method in JVM bytecode?
A@JvmStatic fun funName() {}
Bstatic fun funName() {}
Cfun funName() static {}
Dfun static funName() {}
Attempts:
2 left
💡 Hint
Look for the correct annotation for JVM static methods.
🚀 Application
expert
2:30remaining
Effect of Kotlin inline functions on JVM bytecode
What is the main effect of using the 'inline' keyword on a Kotlin function when compiled to JVM bytecode?
AThe function is compiled as a separate class file
BThe function call is replaced by the function body to reduce overhead
CThe function is ignored during compilation
DThe function is compiled to native machine code
Attempts:
2 left
💡 Hint
Think about how inlining affects function calls.