DEV Community

Cover image for How to Use Kotlin Notebook for Free
Aldo Wachyudi
Aldo Wachyudi

Posted on

How to Use Kotlin Notebook for Free

Kotlin Notebook is a fun way to experiment with Kotlin, whether you’re testing out Kotlin syntax or exploring libraries. But, to use the Kotlin Notebook Plugin in IntelliJ or Android Studio, you need an Ultimate Subscription, which makes it less accessible for those who want to use it for free. Here’s the good news: you can actually use the Kotlin Notebook kernel to run Kotlin Notebooks for free!


Yes, you can use Kotlin Notebook for free!

Since the kernel is free and Kotlin Notebook is one of the kernels available for Jupyter Notebooks, you can use it just like any other Python Notebook. This means you can run it in your browser using Jupyter Lab or in Visual Studio Code.


Which one do you prefer, JupyterLab or Visual Studio Code?

Installation

All you need to do is install the Kotlin kernel by running the command pip install kotlin-jupyter-kernel. Then, choose Kotlin as the kernel in your Jupyter Kernel.


Changing Kernel in VS Code

That’s it! But, in case you’re using Jupyter Notebook for the first time, head over to the appendix section.


Changing Kernel in Jupyter Notebook.

To make this article more complete, I’ve created three code examples to demonstrate various features of Kotlin Notebook in different scenarios.

Example 1 — Basic Features

The code: basic-kotlin-notebook.ipynb

I’ve created an example that uses MessageDigest, Base64, Sequence, and Stream. This example also showcases basic Notebook features like using variables or functions from other cells.


Notice that I don’t define numbers in the bottom cell.

Example 2 — Using Dependencies

The code: external-lib-retrofit.ipynb

This example demonstrates how you can use dependencies and transitive dependencies in Kotlin Notebook, using Retrofit as an example.


HTTP Get using Retrofit in Kotlin Notebook

Example 3 — Kotlin Notebook & Ollama

The code: external-lib-langchain4j.ipynb

Ollama is an easy-to-use LLM provider that allows us to communicate with large language models for free, without relying on commercial LLM services. LangChain4j, on the other hand, is a library that helps us write LLM-based applications in Java/Kotlin.


Ollama & LangChain4j in Action

Summary

Kotlin Notebook provides a convenient way to experiment with Kotlin code and libraries. While the IntelliJ Plugin requires an Ultimate Subscription, you can use Kotlin Notebook for free by using the Kotlin Jupyter kernel. This method allows you to run Kotlin notebooks in Jupyter Lab or Visual Studio Code, making it accessible to everyone.


Appendix — Installation

If this is your first time using Jupyter Notebook, I recommend installing the necessary tools in the following order:

  1. Install PyEnv: This tool makes it easy to manage different Python versions, which is important since Jupyter Notebook and the Kotlin-Jupyter kernel rely on Python. You can install PyEnv using Homebrew with the following command: brew install pyenv

  2. Install JupyterLab or Jupyter Notebook: Once PyEnv is set up, install JupyterLab or Jupyter Notebook. You can do this using pip, for example: pip install notebook

  3. Install the Kotlin Kernel: Next, install the Kotlin-Jupyter kernel to enable Kotlin support in your notebooks: pip install kotlin-jupyter-kernel

  4. Install Ollama: To use Ollama, you can simply drag and drop the app from the Ollama website. After installing, pull the necessary images used in the examples: ollama pull tinyllama and ollama pull gemma2:2b


Cover Photo by Mike Tinnion on Unsplash

Top comments (0)