Although Kotlin has a standalone compiler and can work with Eclipse, we are going to use Intellij IDEA.
A Kotlin project is structured much like a Java project. Following a standard Maven convention, you typically put your Kotlin source code in a /src/main/kotlin/
folder instead of a /src/main/java/
folder. The Kotlin source code is stored in text files with a .kt
extension instead of .java
. However, Kotlin files do not have to contain a class sharing the same name as the file.
In Intellij IDEA, import your Kotlin project, if you haven't already. Right-click on the /src/main/kotlin/
folder and navigate to New
|
Kotlin File/Class
,
as shown in the following figure:
Figure 12.1: Creating a new Kotlin file
In the following dialog, name the file Launcher
and then click on OK
. You should now see the Launcher.kt
file in the Project
pane. Double-click on it to open the editor. Write the following "Hello World"
Kotlin code, as shown here, and then run it by clicking...