Basics of Kotlin


Kotlin - Basic Syntax

Kotlin Program Entry point

The main () function is an entry point for a Kotlin application. A function can be defined as a block of code designed to perform a specific task.

Entry point with parameters

Another form of the main () function adopts a variable number of string arguments.

print () vs. println ()

The print () is a function in Kotlin that prints its argument to the standard output; similarly, println () is another function that prints its argument into the standard output, but it adds a line break to the output.

Both functions (print () and println ()) can be used to print numbers and strings.

A semicolon (;) in Kotlin

Unlike other programming languages such as Java, C ++, and C #, Kotlin statements do not require a semicolon (;) to terminate a statement.

The Kotlin program can be compiled and executed with or without semicolons.

So as a good programming practice, it is not recommended to add a semicolon to the end of a Kotlin statement.

Packages in Kotlin

Although the package specification is optional, the Kotlin code is usually defined in the package. If the package is not specified in a source file, its contents will go to the default package.