Difficulty: Beginner
Estimated Time: 5 min

Kotlin Interactive Tutorial

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sed sapien erat. Nunc et tellus eget nisl volutpat ultricies. Quisque dictum nibh et dui pellentesque mattis. Praesent consequat imperdiet tincidunt. Nullam fermentum porttitor quam, sit amet ultrices quam viverra sed. Etiam at faucibus augue. Mauris ultrices, ex et ornare rhoncus, lorem urna sodales magna, id semper lectus tortor et nunc. Sed eu metus vehicula, venenatis magna at, vestibulum sapien. Pellentesque vulputate at lacus a pellentesque.

About the Author

Ken Kousen is a Java Champion, Oracle Developer Champion, and Grails Rock Star whose books include Modern Java Recipes, Gradle Recipes for Android, and Making Java Groovy.

Kotlin Cookbook

Step 1 of 2

Use the Kotlin REPL

Problem

You want to run Kotlin in an interactive shell as a quick and easy way to evaluate Kotlin expressions without starting up a full integrated development environment (IDE).

Solution

Use the Kotlin REPL by typing kotlinc at the command line.

Discussion

Kotlin includes an interactive compiler session, known as a REPL (Read-Eval-Print-Loop) that is triggered by the kotlinc command with no arguments. Once inside the REPL, you can evaluate arbitrary Kotlin commands and see the results immediately.

TIP: The Kotlin REPL is also available inside Android Studio and IntelliJ IDEA as the Kotlin REPL entry under the Tools/Kotlin menu.

After running the kotlinc command, you will receive an interactive prompt.

kotlinc

Once you're logged in, try a command:

println("Hello, World!")

You can also do things like set variables:

var name = "Dolly"
println("Hello, $name!")

Finally, you can get help:

:help

When you're done, use the

:quit

command.

Oh -- I need this as the base image:

docker pull zenika/kotlin