Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Kotlin Quick Start Guide

You're reading from   Kotlin Quick Start Guide Core features to get you ready for developing applications

Arrow left icon
Product type Paperback
Published in Aug 2018
Publisher Packt
ISBN-13 9781789344189
Length 178 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Marko Devcic Marko Devcic
Author Profile Icon Marko Devcic
Marko Devcic
Arrow right icon
View More author details
Toc

Setting up the development environment

Although you could use a basic text editor for writing Kotlin source code and compile it using the command-line tools, you will make your life easier if you use an IDE for coding. IDE can provide code completion, syntax highlighting, stepping through code while debugging, refactoring, and more.

IntelliJ IDEA is probably the most popular IDE for Java today. The IDE comes from the same company that created Kotlin and, of course, Kotlin is a first class citizen inside IntelliJ. This book uses IntelliJ, and it is recommended that you use it as well. But other popular IDEs for Java could also work, such as Eclipse or NetBeans (a Kotlin plugin would be needed). The great thing about IntelliJ is that the latest versions already come with a Kotlin plugin pre-installed, so the IDE is ready for Kotin development out of the box. This plugin already has a Kotlin compiler and also enables Kotlin syntax highlighting inside the code editor.

Another benefit of using IntelliJ is that it comes with a Java to Kotlin converter. If you have some Java code, or you are working in a mixed (both Java and Kotlin) project, you can convert Java code to Kotlin with the click of a button. Some minor changes might be needed in the resulting Kotlin code but in general, this converter works reasonably well.

IntelliJ has a paid for Ultimate version and a free Community version. The Express version has everything needed for Kotlin development and can be downloaded from the JetBrains website https://www.jetbrains.com/idea/download/. It's available for all platforms (Mac, Linux, and Windows).

Finally, if you are just trying out the syntax or just getting a feel for the language, there is a free online compiler and IDE available at https://try.kotlinlang.org/.

What's great about this online IDE is that it has plenty of examples of Kotlin features. There is also a section called Koans which has smaller code problems with the goal of teaching Kotlin. So, it might be worth checking it out.

Now that we have an IDE installed, let's get the first taste of Kotlin. Inside Intellij, start a new project and select Kotlin from the bar on the left and then select the Kotlin/JVM option, as seen in the following screenshot:

On the next screen, enter your project name and select KotlinJavaRuntime in the Use library section.

This will be enough to compile and run Kotlin code from the IDE. For smaller examples, setting up Maven or Gradle would be an overkill. 

Now that we have a Kotlin project, let's add some Kotlin code: the standard Hello World printed to the console. Add a file named Main.kt inside the src folder.

Inside that file add the following code:

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

Now, there should be a little green icon in the gutter of the text editor and if you click it you should see "Hello World!" in the output.

You have been reading a chapter from
Kotlin Quick Start Guide
Published in: Aug 2018
Publisher: Packt
ISBN-13: 9781789344189
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image