Kotlin Code Pills — Main Function

Tugce Konuklar Dogantekin
The Kotlin Chronicle
1 min readMar 27, 2019

I decide to start to write some small and quick code pills to help to understand how Kotlin works.

As you know, Kotlin works on JVM and most of developers are friendly with Java, that’s why I will use Java to help to show concept of Kotlin.

Let’s write main function to print Hello World.

Java :

Kotlin :

There are some the differences you can see on Kotlin:

  • Functions starts with fun words.
  • There is no static keyword
  • Class definition is not mandatory in Kotlin, because, default access modifier is public final , all functions can be reachable from all classes, thats why class definition is not mandatory , if you don’t restrict.
  • There is no semi column end of the code line -; This is not mandatory
  • Function variables are define with this formula
             (var/val <name>[: <type>][= initialiser])

Bonus Tips:

  • Default access modifier
                        Kotlin — public final                         Java — package private 

You can follow code pills in here.

See you on the next code pill.

--

--