| title | Works on my machine |
|---|---|
| description | Necessary steps before trying the tutorials on your machine |
| date | 2019-07-31 17:00:00 -0700 |
| layout | default |
To try the code in these tutorials on your machine you'll need JDK 1.8 or later, available as per the operating system you use, and Jetbrains Intellij, the community edition of which can be downloaded for free from here. Kotlin's REPL can be used after you open a Java or Kotlin project in Intellij, and it will auto-import classes from dependencies declared in the project's pom.xml or build.gradle. So if you git clone and import in Intellij the (based on gradle) project of this github repository, it'd be easier to follow all tutorials on your machine:
- In Intellij go to File -> New -> Project from version control -> Git, and put this URL:
https://github.com/shadowmanos/explore-data-with-kotlin-repl.git
- After it's open, gradle has finished downloading half the internet and Intellij has done its thing, go the project view on the left pane, expand and highlight the main module inside the src folder and choose from menu Tools -> Kotlin -> Kotlin REPL. On the pane that opens, start typing code from the examples in this cookbook and (only) if you autocomplete the necessary classes will be auto imported while typing. Alternatively, there is a list of import statements at the first paragraph of each tutorial and if you copy and paste it into the REPL you can then copy and paste each line of code without bothering with autocomplete. For these import statements to work, you still need to highlight the main module in the left pane.
You may continue reading blog posts online on github or open the markdown files in the tutorials folder and Intellij will render them with its Markdown plugin. You can navigate to links by clicking if your are viewing in preview mode or Ctrl + Click in edit mode.
Tips:
- You may define a keyboard shortcut to bring up the REPL window.
- Hit Enter to type multi-line code in the REPL and Cmd+Enter or Ctrl+Enter to execute.
- To see all lines For multiline output move the cursor over a visible line (hover) and scroll upwards.
- A result number and type will appear if you don't assign the result to a variable e.g.
"a"+"b"
res1: kotlin.String = ab - You can avoid the above and get a somewhat cleaner output by using print e.g.
print("a"+"b")
ab - Assign a result to recall later by name e.g.
or you may recall a result by the auto-assigned name like
val text = "a" + "b"
res1 printlnin iterations doesn't seem to add a new line, so we'll use something likeprint("text\n")