Java is fully compatible with Kotlin . So to call java code in kotlin first write following java and
kotlin code two separate file .
KotlinApplication.kt
fun main(args:Array<String>){
println("Kotlin Application Started ..... ")
}
fun navigateToKotlinApplication(){
println("Welcome in Kotlin Application ..... ")
}
JavaApplication.java
public class JavaApplication {
public static void main(String []args){
System.out.println("Java Application Started ...... ");
System.out.println("---------------------------------- ");
System.out.println("Navigating to Kotlin Application ......");
System.out.println("--------------------------------- ");
KotlinApplicationKt.navigateToKotlinApplication();
}
}
Commands to compile and run above two code
1 . First Compile KotlinApplication.kt file
kotlinc KotlinApplication.kt
Note :- After Compiling of KotlinApplication.kt kotlinc compiler conventionally generate KotlinApplicationKt.class by default kotlinc compiler append Kt in suffix of kotlin file name.
2 . Running KotlinApplicationKt.class file
kotlin KotlinApplicationKt
3 . Compiling Java code JavaApplication.java
javac JavaApplication.java
4 . Running Java Application
java JavaApplication
Output in Console.....
No comments:
Post a Comment