Java program outputs nothing when run using Jupyter

I installed the iJava kernel for Jupyter and am able to execute standalone java statements in the notebook and lab, but when I run simple programs, nothing happens - no error, no output!

System.out.println(“Hello World!”); when run in a cell works fine, but a simple class with a main() function doesn’t !

Is there any issue with environment setup?

Could you solve this issue? I have had the same problem… :frowning:

There seems to be a fundamental misunderstanding with how Jupyter’s interactive execution works vs. how I suspect running a Java .class file from the command line. Having a main() method within a Jupyter cell doesn’t automatically trigger its execution in the same way as a standalone Java program.

What you are describing is very similar to the issue in the post ‘How do I print a value on a console in a jupyter notebook?’. There the kernel was for a C++ notebook; however, the issue seems very similar and so does the necessary approach to invoke executing the code.

Did you try adding to the bottom of that cell something like the following as the last line of the cell:

Hello.main(null);

Or something along that line to indicate you want to invoke using that class’s main method?

This would be the single cell content with the code all together:

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello, world!");
    }
}
Hello.main(null);

Since I used it to test my idea, I’ll point out there is a repo here, ‘ijava-binder’ that lets you launch temporary sessions on remote systems with the iJava kernel all set up via the MyBinder system.

There is in fact, a more advanced notebook entitled ’ 3rd Party Dependencies in an IJava Notebook’ that looks like something you may want to check out to get more insight into working with the iJava kernel in Jupyter.