Kotlin tutorial for Beginners – Kotlin Hello World

Kotlin Hello World – Your First Kotlin Program

In this article, you will learn to write Hello World program in Kotlin.

A “Hello, World!” is a simple program that outputs Hello, World! on the screen. Since it’s a very simple program, it’s often used to introduce a new programming language.

Let’s explore how “Hello, World!” program works in Kotlin.


Kotlin “Hello, World!” Program


// Hello World Program

fun main(args : Array<String>) {
    println("Hello, World!")
}

When you run the program, the output will be:

Hello, World!

How this program works?

  1. // Hello World ProgramAny line starting with // is a comment in Kotlin (similar to Java). Comments are ignored by the compiler. They are intended for person reading the code to better understand the intent and functionality of the program. To learn more, visit Kotlin comments.
  2. fun main(args : Array<String>) { ... }This is the main function, which is mandatory in every Kotlin application. The Kotlin compiler starts executing the code from the main function.The function takes array of strings as a parameter and returns Unit. You will learn about functions and parameters in later chapters.

    For now, just remember that main function is a mandatory function which is the entry point of every Kotlin program. The signature of main function is:

    fun main(args : Array<String>) {
        ... .. ...
    }
  3. println("Hello, World!")The println() function prints the given message inside the quotation marks and newline to the standard output stream. In this program, it prints Hello, World! and new line.

Comparison With Java “Hello, World!” program

As you know, Kotlin is 100% interoperable with Java.

// Hello World Program

class HelloWorldKt{
    public static void main(String[] args) {
        System.out.println("Hello, World!"); 
    }
}

Few Important Notes

  1. Unlike Java, it is not mandatory to create a class in every Kotlin program. It’s because the Kotlin compiler creates the class for us.If you are using IntelliJ IDEA, go to Run > Edit Configurations to view this class. If you named your Kotlin file HelloWorld.kt, the compiler creates HelloWorldKt class.
    Kotlin compiler creates class automatically
  2. The println() function calls System.out.println() internally.If you are using IntelliJ IDEA, put your mouse cursor next to println and go to Navigate > Declaration ( Shortcut: Ctrl + B . For Mac: Cmd + B), this will open Console.kt (declaration file). You can see that println() function is internally calling System.out.println().
    console.kt declaration file in Kotlin

 

 

Python Example for Beginners

Two Machine Learning Fields

There are two sides to machine learning:

  • Practical Machine Learning:This is about querying databases, cleaning data, writing scripts to transform data and gluing algorithm and libraries together and writing custom code to squeeze reliable answers from data to satisfy difficult and ill defined questions. It’s the mess of reality.
  • Theoretical Machine Learning: This is about math and abstraction and idealized scenarios and limits and beauty and informing what is possible. It is a whole lot neater and cleaner and removed from the mess of reality.

Data Science Resources: Data Science Recipes and Applied Machine Learning Recipes

Introduction to Applied Machine Learning & Data Science for Beginners, Business Analysts, Students, Researchers and Freelancers with Python & R Codes @ Western Australian Center for Applied Machine Learning & Data Science (WACAMLDS) !!!

Latest end-to-end Learn by Coding Recipes in Project-Based Learning:

Applied Statistics with R for Beginners and Business Professionals

Data Science and Machine Learning Projects in Python: Tabular Data Analytics

Data Science and Machine Learning Projects in R: Tabular Data Analytics

Python Machine Learning & Data Science Recipes: Learn by Coding

R Machine Learning & Data Science Recipes: Learn by Coding

Comparing Different Machine Learning Algorithms in Python for Classification (FREE)

Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause. The information presented here could also be found in public knowledge domains.