0
0
Kotlinprogramming~5 mins

Calling Kotlin from Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
How do you call a Kotlin function from Java?
You call a Kotlin function from Java like a regular Java method. Kotlin compiles to JVM bytecode, so Java can use Kotlin classes and functions directly.
Click to reveal answer
beginner
What is the default Kotlin class name seen from Java if no @JvmName is used?
If you have top-level Kotlin functions in a file named Example.kt, Java sees them in a class named ExampleKt by default.
Click to reveal answer
intermediate
What annotation helps rename Kotlin functions or classes for Java callers?
The @JvmName annotation lets you specify a different name for Kotlin functions or classes when called from Java.
Click to reveal answer
intermediate
How do Kotlin properties appear when accessed from Java?
Kotlin properties appear as getter and setter methods in Java. For example, a Kotlin property 'val name' becomes 'getName()' in Java.
Click to reveal answer
intermediate
What is the purpose of the @JvmStatic annotation in Kotlin for Java callers?
@JvmStatic makes a Kotlin function or property static in the generated Java bytecode, so Java can call it without an instance.
Click to reveal answer
If you have a Kotlin file named Utils.kt with a top-level function, how do you call it from Java?
AUtilsKt.functionName()
BUtils.functionName()
Cnew Utils().functionName()
DYou cannot call it from Java
Which annotation changes the name of a Kotlin function for Java callers?
A@JvmStatic
B@JvmName
C@JvmOverloads
D@JvmField
How does a Kotlin 'val' property appear in Java?
AAs a public field
BAs a setter method
CAs a private field with no access
DAs a getter method
What does the @JvmStatic annotation do in Kotlin?
AMakes a function static in Java bytecode
BGenerates overloads
CChanges function visibility
DMakes a function inline
Can Java call Kotlin extension functions directly?
AYes, as instance methods
BNo, extension functions are invisible to Java
CYes, as static methods
DOnly if annotated with @JvmName
Explain how Kotlin top-level functions are accessed from Java and how you can customize their names.
Think about the file name and the default class name Java sees.
You got /3 concepts.
    Describe how Kotlin properties are represented in Java and how @JvmStatic affects calling Kotlin functions from Java.
    Consider how Java accesses fields and static methods.
    You got /3 concepts.