Monday 5 November 2018

Kotlin Basics Tutorial 1

Creating a main function in Kotlin and Java

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>){}


or we can add :Unit instead of void in java


fun main(args: Array<String>): Unit{}


For returning type int


fun main(args: Array<String>): Int{}


For printing just type

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

Facebook Twitter Delicious Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes