scijava / scijava-jupyter-kernel

[RETIRED] Try IJava or BeakerX
Apache License 2.0
178 stars 42 forks source link

Documentation on Java features / support #95

Closed huntrods closed 5 years ago

huntrods commented 5 years ago

I've been revising an "introduction to programming - Java" course to use Jupyter Notebooks, and so far things are going very well. However, I'm having issues with some standard Java constructs that are not working (ERROR:NULL) in scijava-jupyter-kernel. Examples:

I know some (like command line arguments) are a bit beyond what could be expected from interpreted Java, but the do-while and array issues are real "show stoppers" for the course.

Where can I find documentation on what is and is not supported in scijava-jupyter-kernel in terms of "stock" Java?

Finally, who is the "keeper of the code" as I'd be willing to help if that would be of value. I can contact offline via email if you wish.

Thanks -R

ctrueden commented 5 years ago

@huntrods I maintain this repository together with @hadim. However: we are currently migrating all our notebooks over to the Groovy BeakerX kernel. The plan for this kernel (which is built on top of BeakerX as well) is to deprecate/retire it very soon in favor of the kernels that ship with BeakerX. That said, I would be very interested to know what things you need that SJJK does that BeakerX's other kernels cannot do otherwise. (E.g.: switching languages in the same notebook? Do you care about this?)

huntrods commented 5 years ago

I do apologize, but I know nothing at all of BeakerX. I'm revising a course as mentioned, and Jupyter Notebooks were suggested. I spent about a month learning about them, configuring a server (lovely, detailed, out-of-date documentation) to get to the point where I could build notebooks to create "Unit 1" of the course.

It was during that process I discovered the items I mentioned above.

So basically I am trying to combine traditional study guide, resources and working with code into a single notebook concept. Athabasca University is a 100% on-line university, so everything happens on-line. Our courses use a number of technologies at present including Moodle and Elgg, but programming courses always suffer from the disaster that is "now install the compiler". Having a Java environment that runs in a browser has been my goal since early this spring, but Jupyter and Sci-Java were the first to actually work, and work well.

So again, I don't even know what BeakerX is, as I'm approaching this from a somewhat different perspective, and have been doing all my own research to date.

To answer your question, What SJJK does ? It works. It works in Jupyter Notebooks, which were a dickens to get installed and running (Jupyter Hub, virtual servers, global packages/kernels, etc.). As to what BeakerX cannot do? I have no idea other than imply another huge learning curve for me trying to get it to work for me. Having spent a month fighting with Jupyter to get to this point, I'm somewhat hesitant to embark on another project.

Being able to switch languages is not an important issue for this course, but could well be awesome in other courses.

(and I'm still trying to get the C++ kernel working in Jupyter so it doesn't continuously crash as I have a C++ course revision in the wings for next year).

hadim commented 5 years ago

As @ctrueden said, SJJK is nothing more than BeakeX + some glue we added to make it play nicely with SciJava. Since this glue wasn't essential we decided recently to deprecate SJJK in favor of BeakerX.

So I would strongly suggest you switch to BeakerX since it's a much more active project. About the learning curve, it should not be too hard to make it work: https://github.com/twosigma/beakerx#build-and-install-linux-and-mac.

At least, you should give it a try and if it's really too complicated then keep SJJK.

ctrueden commented 5 years ago

@huntrods No worries, these technologies are evolving quickly, and this repository's README is not totally clear about the status of things, nor available alternatives.

My advice to you is as follows:

Once you have notebooks working locally, you can look into how best to host them. One option is Binder, which spins up instances on the cloud on demand for free. This is awesome, but if you want to run a class with 15+ students at once, there may be performance issues with that many concurrent instances. So then hosting your own JupyterHub instance somewhere is probably the way to go.

I'm having issues with some standard Java constructs that are not working

I wonder: were you using Groovy cells? (The default for SJJK.) Groovy is very much like Java, but differs syntactically in some small ways. Anyway, try the Java kernel of BeakerX and see how that works for you.

Happy to help answer any further questions to get you started! Using Java from Jupyter is very doable these days and I think you can run a very successful class this way!

huntrods commented 5 years ago

Curtis,

Thanks very much for the suggestion.

A couple of quick notes; conda create needs -c conda-forge to resolve the beakerx package, and conda wanted 'conda activate java-notebooks', but then it worked perfectly.

I installed as a user on a fresh install of Ubuntu 18.04.1 LTS using VirtualBox on a Windows 7 machine.

I can create Java notebooks and they work... sort-of. I entered a valid Java program

public class TestMe { public static void main(String[] args) { if(args.length < 1 || args[0].length() <= 0) { System.out.println("no arguments"); } else { System.out.println(args[0]); } } }

and when I run it, instead of "Hello World" I get

Out[6]: com.twosigma.beaher.javash.bkrd939cbfc.Hello

which is not what I expected.

Otherwise I'm not getting any errors.

Cheers,

-Richard

On 1/2/2019 7:43 AM, Curtis Rueden wrote:

@huntrodshttps://github.com/huntrods No worries, these technologies are evolving quickly, and this repository's README is not totally clear about the status of things, nor available alternatives.

My advice to you is as follows:

conda create -n java-notebooks beakerx

source activate java-notebooks

(Or on Windows, I believe this is instead activate java-notebooks.)

jupyter notebook

Once you have notebooks working locally, you can look into how best to host them. One option is Binderhttps://mybinder.org/, which spins up instances on the cloud on demand for free. This is awesome, but if you want to run a class with 15+ students at once, there may be performance issues with that many concurrent instances. So then hosting your own JupyterHub instance somewhere is probably the way to go.

I'm having issues with some standard Java constructs that are not working

I wonder: were you using Groovy cells? (The default for SJJK.) Groovy is very much like Java, but differs syntactically in some small ways. Anyway, try the Java kernel of BeakerX and see how that works for you.

Happy to help answer any further questions to get you started! Using Java from Jupyter is very doable these days and I think you can run a very successful class this way!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/scijava/scijava-jupyter-kernel/issues/95#issuecomment-450897404, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Ar3-U2qADkzJE8RROa27LpeuejitgQT7ks5u_NOlgaJpZM4ZjedH.

[https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif]https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient Virus-free. www.avast.comhttps://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient

This communication is intended for the use of the recipient to whom it is addressed, and may contain confidential, personal, and or privileged information. Please contact us immediately if you are not the intended recipient of this communication, and do not copy, distribute, or take action relying on it. Any communications received in error, or subsequent reply, should be deleted or destroyed.

huntrods commented 5 years ago

Curtis,

Apologies. Cut-and-paste didn't work properly.

The program I entered was

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

and when I run it, instead of "Hello World" I get

Out[6]: com.twosigma.beaher.javash.bkrd939cbfc.Hello

Sorry for the mistake/confusion.

Cheers,

-Richard

On 1/2/2019 7:43 AM, Curtis Rueden wrote:

@huntrodshttps://github.com/huntrods No worries, these technologies are evolving quickly, and this repository's README is not totally clear about the status of things, nor available alternatives.

My advice to you is as follows:

conda create -n java-notebooks beakerx

source activate java-notebooks

(Or on Windows, I believe this is instead activate java-notebooks.)

jupyter notebook

Once you have notebooks working locally, you can look into how best to host them. One option is Binderhttps://mybinder.org/, which spins up instances on the cloud on demand for free. This is awesome, but if you want to run a class with 15+ students at once, there may be performance issues with that many concurrent instances. So then hosting your own JupyterHub instance somewhere is probably the way to go.

I'm having issues with some standard Java constructs that are not working

I wonder: were you using Groovy cells? (The default for SJJK.) Groovy is very much like Java, but differs syntactically in some small ways. Anyway, try the Java kernel of BeakerX and see how that works for you.

Happy to help answer any further questions to get you started! Using Java from Jupyter is very doable these days and I think you can run a very successful class this way!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/scijava/scijava-jupyter-kernel/issues/95#issuecomment-450897404, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Ar3-U2qADkzJE8RROa27LpeuejitgQT7ks5u_NOlgaJpZM4ZjedH.

[https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif]https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient Virus-free. www.avast.comhttps://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient

This communication is intended for the use of the recipient to whom it is addressed, and may contain confidential, personal, and or privileged information. Please contact us immediately if you are not the intended recipient of this communication, and do not copy, distribute, or take action relying on it. Any communications received in error, or subsequent reply, should be deleted or destroyed.

huntrods commented 5 years ago

Curtis,

Some good news, and a few comments that may be of assistance to others...

I installed beakerx as per your instructions below (with the changes I noted in my prior email). I did this on a VirtualBox server - Ubuntu 18.04.1 LTS (desktop) on my local machine. It all worked although I'm having the issue with Java I noted in my last email. I'm sure it's nothing.

NEXT STEP - What I really need is beakerx + Java running on my "real" server, which is Ubuntu 18.04 Server (not desktop) running on a different PC and open to the world via my domain. That is the machine running JupyterHub as root, with everything "global" for all users.

I tried the steps below and it installed (as root), but the environment, though activated, was not global.

I started with a fresh copy of my server (I keep dated backups so I can just erase things that don't work and start again fresh), and this time I did the following:

conda install -c conda-forge beakerx.

Now one interesting thing is this server has anaconda3 installed, rather than miniconda. As a result, instead of installing many packages as part of beakerx, it only installed beakerx, py4j and maven. However, because it installed to /opt/anaconda3/share... I knew it should be globally available.

Indeed, as soon as I logged in to the JupyterHub server, I had all the "new" beakerx notebooks available under "new": Clojure, Groovy, Java, Kotlin, SQL and Scala - in addition to my existing Python3 and SciJava.

I shall now commence playing with BeakerX's Java and see what I shall see.

Thanks again!

-Richard

On 1/2/2019 7:43 AM, Curtis Rueden wrote:

@huntrodshttps://github.com/huntrods No worries, these technologies are evolving quickly, and this repository's README is not totally clear about the status of things, nor available alternatives.

My advice to you is as follows:

conda create -n java-notebooks beakerx

source activate java-notebooks

(Or on Windows, I believe this is instead activate java-notebooks.)

jupyter notebook

Once you have notebooks working locally, you can look into how best to host them. One option is Binderhttps://mybinder.org/, which spins up instances on the cloud on demand for free. This is awesome, but if you want to run a class with 15+ students at once, there may be performance issues with that many concurrent instances. So then hosting your own JupyterHub instance somewhere is probably the way to go.

I'm having issues with some standard Java constructs that are not working

I wonder: were you using Groovy cells? (The default for SJJK.) Groovy is very much like Java, but differs syntactically in some small ways. Anyway, try the Java kernel of BeakerX and see how that works for you.

Happy to help answer any further questions to get you started! Using Java from Jupyter is very doable these days and I think you can run a very successful class this way!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/scijava/scijava-jupyter-kernel/issues/95#issuecomment-450897404, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Ar3-U2qADkzJE8RROa27LpeuejitgQT7ks5u_NOlgaJpZM4ZjedH.

[https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif]https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient Virus-free. www.avast.comhttps://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient

This communication is intended for the use of the recipient to whom it is addressed, and may contain confidential, personal, and or privileged information. Please contact us immediately if you are not the intended recipient of this communication, and do not copy, distribute, or take action relying on it. Any communications received in error, or subsequent reply, should be deleted or destroyed.

huntrods commented 5 years ago

Hi Curtis,

Two last questions and I'll call it a night. :-)

I see that the BeakerX version of Java is indeed what I wanted. The array declaration and initialization works as it should, and the do-while loop also works.

My questions:

  1. How does one get Java to read input from the user (i.e. keyboard)?

  2. How does one invoke/run a complete Java program rather than a code fragment?

For example, this fragment works perfectly:

import java.text.; import java.util.;

    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
    String yyyymmddhhmmss = sdf.format(new Date());
    System.out.println("Date: " + yyyymmddhhmmss);

But make it a complete Java Class (program)

import java.text.; import java.util.;

public class JavaDateExample { public static void main(String[] args) { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss"); String yyyymmddhhmmss = sdf.format(new Date()); System.out.println("Date: " + yyyymmddhhmmss); } }

and it generates no output, only the following:

com.twosigma.beaker.javash.bkr8ff61783.JavaDateExample

I'm sure there's a way to run a java class / program, I just haven't found it yet.

Thanks, -Richard

ctrueden commented 5 years ago
  1. How does one get Java to read input from the user (i.e. keyboard)?

Stdin is not the dominant paradigm in a Jupyter notebook, because users just type input into cells. For example, at the top of a notebook, you can write some variable declarations, and instruct the user (either via comments, or using a Markdown cell prior to the code cell) to edit them as desired, reexecute the cell with ctrl+enter and see what happens.

That said, if you really want to use stdin, it appears to be supported somehow with BeakerX kernels; see twosigma/beakerx#1304. And it seems the Python kernel supports it too although I have never tried it.

  1. How does one invoke/run a complete Java program rather than a code fragment?

The reason you are seeing a weird string like com.twosigma.beaker.javash.bkr8ff61783.JavaDateExample is because Jupyter always prints the return value of the final line of the cell, as its output. This is a different thing than stdout. When you run a cell that executes print statements, you will see those as output before the Out: part, but then also you will see the final return value. Your "Hello world" example never actually executes the class you defined, however, so the "Hello world" output does not appear.

There is an example BeakerX Java notebook illustrating how the Java kernel works. It seems you need to define the class in one cell, then reference it in later cells. From the notebook: "One cell is equivalent to a Java compilation unit and can contain a single class, or a sequence of statements."

Since you got things working, I'll close this issue, but please feel free to follow up again if anything is still not clear!