Setting up a Kotlin project with IntelliJ

The process of setting up a Kotlin project with IntelliJ is straightforward:

  1. Start the IntelliJ IDE application.
  2. Click Create New Project.
  1. Select Java from the available project options on the left-hand side of the newly opened window.
  2. Add Kotlin/JVM as an additional library to the project.
  3. Pick a project SDK from the drop-down list in the window.
  4. Click Next.
  5. Select a template if you wish to use one, then continue to the next screen.
  6. Provide a project name in the input field provided. Name the project HelloWorld for now.
  7. Set a project location in the input field.
  8. Click Finish.

Your project will be created and you will be presented with the IDE window:

To the left of the window, you will immediately see the project view. This view shows the logical structure of your project files.

Two folders are present. These are:

  • .idea: This contains IntelliJ's project-specific settings files.
  • src: This is the source folder of your project. You will place your program files in this folder.

Now that the project is set up, we will write a simple program. Add a file named hello.kt to the source folder (right-click the src folder, select New | Kotlin File/Class, and name the file hello). Copy and paste the following code into the file:

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

To run the program, click the Kotlin logo adjacent to the main function and select Run HelloKt:

The project will be built and run, after which, Hello world! will be printed to the standard system output.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.195.111