Creating a main function in Kotlin and Java
Java
we need to create class then want to add following function
we don't need to create class,just add function
or we can add :Unit instead of void in java
For returning type int
For printing just type
/***************************************************************/
For printing Hello World in java ,we need first create a class in java then followed my main class
Java
In Kotlin we don't need to create class , just create function defining fun...and not need any semicolon for ending command, Kotlin compiler internally create class for function while running the program
Java
we need to create class then want to add following function
public static void main(String[] args){}Kotlin
we don't need to create class,just add function
fun main(args: Array<String>){}
fun main(args: Array<String>): Unit{}
fun main(args: Array<String>): Int{}
print("Hello World")
/***************************************************************/
For printing Hello World in java ,we need first create a class in java then followed my main class
Java
public class MyClass{
public static void main(String[] args){
System.out.println("Hello World");
}
}
In Kotlin we don't need to create class , just create function defining fun...and not need any semicolon for ending command, Kotlin compiler internally create class for function while running the program
fun main(args: Array<String>){print("Hello World")}
0 Comments:
Post a Comment