Install Kotlin and use the command line |
The explanations below are for Windows. If you use Mac OSX or Linux, please check the remarks at the end of this page.
From the Windows menu, find the terminal program (under "Accessories"). Alternatively, press Windows+R and type cmd to start the terminal program.
Type java -version in your terminal. If your output indicates that you have Java 1.6 or higher installed, then you are done. Otherwise, you need to install Java. Click on Windows Online at www.java.com.
Restart your terminal program after the Java installation and check that Java is now on your computer.
Download the file kotlin-compiler-1.2.21.zip from the Kotlin download page. and save it to your desktop.
Please use exactly version 1.2.21 of the compiler, so that all CS109 students are running the exact same environment.
Extract the zip file to C:\Program Files. You need to add the kotlinc\bin directory to your command line path - the TAs will show you how.
Restart your terminal program, and check that you can start Kotlin by saying kotlinc.
Try some simple interactive Kotlin statements, such as
$ kotlinc Welcome to Kotlin version 1.2.21 (JRE 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12) Type :help for help, :quit for quit >>> 7 * 3 21 >>> 7 * Math.PI 21.991148575128552
Download cs109-additions.zip and extract the files in exactly the same place where you extracted the Kotlin archive.
This package contains:
Here are few checks you can perform to see if everything works:
$ ktc uitest1.kt $ kt Uitest1KtA new window should appear.
$ ktc Welcome to Kotlin version 1.2.21 (JRE 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12) Type :help for help, :quit for quit >>> import org.junit.Test
For a more complete test of junit, download the example test suite test1.kt, compile it, and run it:
$ ktc test1.kt $ kttest AdditionTest JUnit version 4.12 . Time: 0.003 OK (1 test)
The output should show that everything went alright and that all tests were passed.
You can use any editor you like for writing Kotlin programs. Perhaps you are already using VIM or Emacs—then keep using them.
Otherwise we recommend that you use Notepad++. Download and install:
Finally, download the file kotlin.xml and save it to your desktop. Start Notepad++, and select "User defined language" from the "Language" menu. Press the "Import" button, and select the kotlin.xml file. After the message "Import successful", terminate Notepad++.
When you start Notepad++ again, you should see "Kotlin" in the "Language" menu, and the language should automatically switch to Kotlin when you open a file with extension kt or kts.
Open your editor, and write the following small program:
println("Your arguments are:") for (i in 0 until args.size) { println("$i: ${args[i]}") }Save it as a file named args.kts.
Try running this program from the command line, with arguments, such as:
$ kts args.kts Hello World!
Finally, you may want to try running a larger program, such as mastermind.kts.
There are several ways to install Kotlin on Unix systems (including OSX), but I strongly recommend that you simply use the same zip file kotlin-compiler-1.2.21.zip linked above, to make sure that you have an environment compatible with the class environment (I have tested everything both on Linux and OSX).
To summarize:
You can use any editor you like (but don't use an integrated development environment like Eclipse or IntelliJ in this course).
Install Kotlin and use the command line |