Kotlin Tutorial: Getting Started
Kotlin Tutorial: Getting Started

Introduction

Kotlin tutorial getting started using REPL (Read-Eval-Print Loop) teaches you Kotlin Programming language with simple examples. You will learn the advantage of programming in Kotlin and install the IDE to practice. This Kotlin tutorial is mainly for the programmers who already know an object-oriented language and want to learn more about Kotlin.

If you are from C# or Java programming background, great! You will know how much more concise and readable your code you can write using Kotlin.

About Kotlin

Kotlin language is around 2011 and made as open source from 2012. Kotlin is designed to help programmers to write robust code. For example, Kotlin distinguishes between nullable and non-nullable data types, which helps catch more errors at compile time.

Are you from Java background? Good news, Kotlin code compiles so that you can use Java and Kotlin code side-by-side, and continue to use your favorite Java libraries.

Prerequisite

You should be familiar with:

  • The basics of a object-oriented programming language such as Java or C#.
  • Using an IDE such as IntelliJ IDEA, Android Studio, Eclipse, or Visual Studio.
  • How to declare variables, use types, program with classes, methods and handling exception.

What you'll learn

  • How to work with the Kotlin REPL (Read-Eval-Print Loop) interactive shell

What you'll do

  • Install the IntelliJ IDEA and get familiar with some feature.

Install IntelliJ IDEA

Download and install IntelliJ IDEA

Download IntelliJ IDEA for your operating system. Select the right download file based on your operating system.

Use Community version for trying it free.

Verify your IntelliJ IDEA installation

  • Start IntelliJ IDEA.
  • Install any updates and additional content you are prompted for.

Create Hello World Kotlin

Create a Kotlin project to let IntelliJ IDEA know that you are working in Kotlin.

I have installed the IntelliJ IDEA version "IntelliJ IDEA Community Edition 2020.3 x64".

Steps to follow

  • Create a new project from the IntelliJ IDEA welcome window.
  • From the New Project dialog, select Kotlin and provide the project name as "HelloWorld".
  • Select the build system as "Gradle Kotlin" and choose an SDK from the project SDK. If you are doing it the first time.
  • Click finish.
Kotlin getting started REPL (Read-Eval-Print Loop)

You can now run the application by clicking on Run from top right. Also, now you have access to REPL, (Read-Eval-Print Loop), Kotlin's interactive shell.

Select Tools > Kotlin > Kotlin REPL to open the REPL.

We have a simple program that prints "Hello World".

 
fun helloWorld() {
     println("Hello World!")
 }
 
 helloWorld()

The fun keyword designates a function, followed by the name. As with other programming languages, the parentheses are for function arguments.

There is no return type because the function doesn't return anything.

Click on Run button in the left side or by Control+Enter (Command+Enter on a Mac) to run it.

In Kotlin, no need to place semicolons at the end of lines.

Note: From Kotlin versions 1.3 and above, the main the function may or may not have a parameter of type Array<String>.

Kotlin getting started

Congratulations! You learned Kotlin tutorial getting started using REPL (Read-Eval-Print Loop). You have Installed the IntelliJ IDEA and got familiar with some features of IDE and Kotlin programming.

What's next? Kotlin Basic

Conclusion

In this post, you have learnt how to install IntelliJ IDEA and how to work with the Kotlin REPL (Read-Eval-Print Loop) interactive shell. That's all from this post. Next is to learn Kotlin Basics.

0 thoughts on “Kotlin Tutorial: Getting Started

  1. libero repudiandae optio velit a exercitationem dolor aut sit. quibusdam omnis sed corporis saepe enim id rerum deleniti. cumque distinctio sed enim earum voluptate ea vero sequi ullam facere asperiores id. alias quia repudiandae qui omnis et velit quibusdam et. et consequatur ut hic ut doloremque asperiores sunt praesentium.

Leave a Reply

Your email address will not be published. Required fields are marked *

Verified by MonsterInsights