Run Kotlin interactively
IntelliJ IDEA provides several ways to execute code snippets outside a project. This is useful when you need to quickly evaluate some code fragment, test some scenario, or prototype an improvement.
Scratches
Scratches allow you to create a temporary file and execute it straight away. This is useful for testing and prototyping purposes.
Scratches are independent of projects. They can be accessed from any project, but you have to specify where to look for the classes in case you are using project-specific classes.
Create a scratch
In the main menu, go to Kotlin.
or press Ctrl+Alt+Shift+Insert, then select
Run a scratch
In the top-left corner of the editor, click
or press Ctrl+Alt+W.
The following options are available for running Kotlin scratches:
Use classpath of module (only applicable for scratches): specifies the module with your custom classes if you want to use them in a scratch.
Interactive mode: runs the code each time you stop typing.
Kotlin Notebook
Kotlin notebooks are interactive editors that integrate code, graphics, and text in a single environment.
You can create a notebook outside your project if you want to work with Kotlin without changing the dependencies in your project.
Learn more from Create a notebook.