49

I've used the Jupyter notebook quite a lot for my Python projects, but now I have to work on something in Java. So I was wondering if I could get Jupyter to work with Java?

After some searching I think I understand that you can install different kernels for other languages, with a list of kernels here. But I don't see one for Java there. The reason I think there is a working solution is this notebook, showing of a Java 9 notebook. Does anyone know how to set this up?

I'm on macOS Sierra if it matters.

4
  • There seems to be a kernel around, but apparently it's currently not functional. See: github.com/Bachmann1234/java9_kernel Commented Dec 1, 2016 at 18:09
  • @cel I found that too, but figured it was outdated due to the not functional part. And it hasn't been updated in a bit either, so it doesn't seem likely that it will be fixed... But is that really all there is? Commented Dec 1, 2016 at 18:11
  • Scijava fails if you use scanner or try to define an array. No help with the problem either, I suggest you try something else. Wish I knew what, but java on jupyterlab seems like a lost cause. Commented Feb 16, 2019 at 20:05
  • Hi I'm currently working on the task about turning parts of the logic in Java source codes into JupyterNotebook, can these Kernals help? Commented Feb 4, 2020 at 12:09

6 Answers 6

34

IJava available at https://github.com/SpencerPark/IJava requires JDK 9. The build process for my iMac (MacOS 10.13.5) worked like a charm and within 10 minutes, I could start programming interactively in Java within Jupyter.

Sign up to request clarification or add additional context in comments.

2 Comments

This still works well, even though the last GitHub commit was a03ad77 on 9 Dec 2019 (as of 19 Jan 22)
after installing the kernel, is there a way to select it in VSCode?
12

While doing a similar search, I found an option that may meet your needs:

SciJava Jupyter Kernel https://github.com/scijava/scijava-jupyter-kernel

I have not actually run Java against this kernel yet, but it's documentation claims to support Java among a number of other scripting languages.

It is constructed to run ImageJ ("an open source Java image processing program"): https://imagej.net/Scripting#Supported_languages

Jupyter Kernels List (reference): https://github.com/jupyter/jupyter/wiki/Jupyter-kernels

1 Comment

Co-maintainer of SciJava Jupyter Kernel here. Just a heads up that we have retired support for this kernel. I recommend using IJava instead.
8

You can use Zeppelin notebook instead. Apache Zeppelin is build on the JVM.

1 Comment

I've tried Zeppelin for Java and found it limited compared to support for Kotlin and Scala. For example, you cannot pass values from one cell to the next when using Java. ZeppelinContext search in Zeppelin GitHub and Apache Zeppelin Context z.put() share data between cells in Java notebook
-1
  1. Verify Java is installed java -version

  2. Download the IJava zip from GitHub https://github.com/SpencerPark/IJava/releases/download/v1.3.0/ijava-1.3.0.zip Extract to a folder, e.g. D:\IJava.

  3. Install the kernel using the install script Open terminal inside the extracted folder and run: cd D:\IJava python install.py This installs the Java kernel into Jupyter (creates a kernel folder under C:\ProgramData\jupyter\kernels\java by default).

  4. VS Code blocked the kernel as “untrusted” Error shown: The kernel 'Java' was not started as it is located in an insecure location 'C:\ProgramData\jupyter\kernels\java\kernel.json'. Two ways to fix that:

    1. Trust that specific kernel folder in VS Code settings (jupyter.kernels.trusted) — add the ProgramData path. (this did not work for me)
    2. Move the kernel folder into your user Roaming path (what you did) so VS Code trusts it automatically. So I moved the folder: From: C:\ProgramData\jupyter\kernels\java To: C:\Users\Admin\AppData\Roaming\jupyter\kernels\java
  5. Fix the kernel.json path (critical) After moving, the kernel still pointed to the old jar path, so Jupyter tried to run a jar that no longer existed. Open: C:\Users\Admin\AppData\Roaming\jupyter\kernels\java\kernel.json Edit the "argv" entry so the -jar path points to the new location. Example final content we used:

{
  "argv": [
    "java",
    "-jar",
    "C:\\Users\\Admin\\AppData\\Roaming\\jupyter\\kernels\\java\\ijava-1.3.0.jar",
    "{connection_file}"
  ],
  "display_name": "Java",
  "language": "java"
}

Make sure the jar filename and full path exactly match what’s in that folder.

  1. Restart VS Code completely (Not just reload — close and re-open). This makes VS Code pick up the updated kernel.

  2. Select the Java kernel in the notebook

New contributor
Amruta Pawar is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Comments

-2

In the list of kernels, there is also a Scala kernel, which is based on Java.

2 Comments

I guess that's nice - if you use Scala. Not much help that it is based on Java when it can't run Java code...
Scala can run java code. They both compile down to byte code
-2

You can integrate Visual Studio Code with Anaconda-Navigator. After installing anaconda, run this command in cmd: 'conda install ipykernel'. This should solve your problem.

2 Comments

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
Hi Vihaan, your answer helps in doing the set-up needed to use Jupyter notebooks for python programming, not for java programming, which is what this question was asking about.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.