The main() Function
Learn about the special main function as the entry point into your program.
We'll cover the following
Every application requires an entry point where program execution is started. In most languages, including Kotlin, this is called the main
function.
Kotlin also allows writing script files (
.kts
file ending) which don’t require an explicitmain
function, similar to Bash or Python scripts. When talking about an “application” above, such scripts are excluded.
In fact, even the code listings here on Educative require a main
function, although you have not seen one yet. Up until this point, a main
function was always hidden in code surrounding the code you saw in the listings. This is what enabled the code examples to run.
Anatomy of a main
Function #
The main
function in Kotlin is simple:
Get hands-on with 1200+ tech skills courses.