Kotlin Development Environment
$count++; if($count == 1) { include "../mobilemenu.php"; } if ($count == 2) { include "../sharemediasubfolder.php"; } ?>
Kotlin runs on JVM, so the first step to start developing in Kotlin is to download JDK.
Download and install JDK
Download and install JDK from the website of your choice. You can skip this step if you already have JDK already installed.
Download and extract Kotlin
Once done, please download Kotlin Compiler from git link given below.
Kotlin Compiler Git Link
The above link is as of writing this document. Please refer to the parent release folder in Git for the latest release. It is recommended to use the latest release.
Once downloaded, unzip the compiler and you should find a bin directory.
The bin directory contains all that is needed to compile a Kotlin program.
It is recommended to add bin directory to the classpath for easy compilation with your favorite editors.
Kotlin can be developed via IDEs Android Studio and above or IntelliJ IDEA with Kotlin plugin integrated.
However for beginners it is recommended to start programming via a text editor so that you can get a firm grasp of the concepts of the language.
For regular text editors, you can use the editor of your operating system.
Example:
Notepad in Windows.
TextEdit in Mac.
vi editor in Linux.
Alternatively you can download advanced editors like VSCode, Sublime Text or Notepad++. You can search them in your search engine and go to the download page.
Creating your first Kotlin file
When you use a Text editor, just create a new file, and add your Kotlin Code.
Once added, save the file to your favorite location. Make sure to save with extension ".kt".
Congrats! you are done.
In Kotlin you must first compile the file. In following example we created a sample file HelloWorld.kt. "main" function is the entry point into a Kotlin program. It takes an Array of strings, which we can use to pass any parameters to our Kotlin program. In the following example, we just printed a line.
Compiling via Kotlin compiler / Java Development Kit: Create a file HelloWorld.kt.
fun main(args: Array<String>)
{
println("The Quick Brown Fox Jumps Over The Lazy Dog")
}
Compiling Kotlin source code
To compile a file, say HelloWorld.kt we created above, you can use the following command.
kotlinc HelloWorld.kt -include-runtime -jar HelloWorld.jar
This will create a jar file HelloWorld.jar in the same directory. kotlinc is the compiler. -include-runtime ensures that kotlin runtime is included in the generated library, HelloWorld.jar, so that it will run standalone. Using jar option, we can specify the library location and name, in this case, it is HelloWorld.jar
Run your Kotlin program
You can run the file using the following command.
java -jar HelloWorld.jar
Output:
The Quick Brown Fox Jumps Over The Lazy Dog!
Android Studio
IntelliJ IDEA - Community Edition has Kotlin plugin
Editors for Kotlin:
Visual Studio Code
Sublime Text
Atom Editor
Please note that you may have to download additional plugins to editors for Kotlin support.