Jupyter Notebooks are an excellent tool, originally developed to help data scientists and engineers to simplify their work with data using python programming language. In fact, the interactive nature of notebooks makes them ideal for quickly seeing the code results without setting up a development environment, compiling, packaging and so on. This feature has been crucial for adoption in data science, machine learning, and statistical modeling where development skill was less essential than data manipulation expertise.
Below are some of the advantages of Jupyter notebook
Summarizing we can say that
Jupyter notebooks streamline the development process, from initial exploration to production-ready code, offering flexibility and real-time feedback.
Considering the advantages that offer Jupyter notebooks, would be great for software developers to use such notebook approach to develop, for example, USE CASE TESTS for projects or providing useful INTERACTIVE HOW-TO.
The question here is:
IS IT POSSIBLE TO USE A JUPYTER NOTEBOOK FOR PROGRAMMING LANGUAGE OTHER THAN PYTHON❓?
The answer is YES?.
The Jupyter tools have been architected to support multiple programming languages though the Kernel concept, see diagram below:
The kernel is how the Jupyter notebook server evaluates blocks of code written by the user inside the notebook document (.ipynb), so it is sufficient to have a kernel that can evaluate the code of the programming language of your choice to have it supported by Jupyter notebook.
Of course, it is easy to deduce that every potential programming language that a Jupyter Kernel can support should support Read–eval–print loop (REPL) feature.
The question becomes:
ARE THERE JUPYTER KERNEL OTHER THAN PYTHON ONE❓?
The answer is Yes?.
Lately I've been working on Langgraph4J which is a Java implementation of the more famous Langgraph.js which is a Javascript library used to create agent and multi-agent workflows by Langchain. Interesting note is that [Langchain.js] uses Javascript Jupyter notebooks powered by a DENO Jupiter Kernel to implement and document How-Tos.
So, I faced a dilemma on how to use (or possibly simulate) the same approach in Java and, without much hope, I started looking for a Jupyter Kernel that supported Java considering that, from the JDK 9 version, there was the introduction of JShell that enabled the REPL for Java.
After a bit of research (and a weird thought of trying to throw myself into a DIY implementation) I landed on rapaio-jupyter-kernel which is a Jupyter Kernel that supports Java ?. The project states:
Jupyter kernel for Java language based on JShell. It implements Jupyter message specification version 5.4, and it requires Java = 22.
It is amazing; I'm starting to use it and WOW!?. Take a look of some of its features, below I've summarized the most representative ones:
You can write normal Java.
var result = 2 2; result4
// including classes record Complex(double a, double b) { public Complex add(Complex c) { return new Complex(a c.a, b c.b); } } Complex x = new Complex(10,20); x.add(new Complex(1,1))Complex[a=11.0, b=21.0]
// methods can also be implemented int add(int a, int b) { return a b; } add(2,3)5
Magic commands
Besides Java code, a cell can contain special commands implemented by the kernel. These are called magic code and there are two types: magic lines and magic cells.
Magic lines are lines which are prefixed with %. After the prefix it is followed by the magic command and the optional parameters. Below is an example of magic line:// magic line which asks JShell to list the types defined in this notebook in this moment %jshell /types| record Complex
Magic commands interpolation
Sometimes there is a need to run a magic command in a more dynamic way. This can be done using magic interpolation.
Magic interpolation is the interpolation of marked content which starts with \{ and ends with }. Any content decorated with those markers is evaluated in jshell and the result is transformed in a String which replaces the decorated content in the magic command.String version = "1.0.2";
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3