Skip to content

Instantly share code, notes, and snippets.

@tueda
Last active February 21, 2024 04:56
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save tueda/a200b3f747d0fc864be8b4dd09be5a1e to your computer and use it in GitHub Desktop.
Save tueda/a200b3f747d0fc864be8b4dd09be5a1e to your computer and use it in GitHub Desktop.
Java-Colab.ipynb
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@seanbenhur
Copy link

How to read inputs!?, when I try to read inputs it doesn't show any input form!

@tueda
Copy link
Author

tueda commented Jan 5, 2021

You mean reading inputs from console? The following code works to me:

var scanner = new java.util.Scanner(System.in);
var str = scanner.nextLine();

@davisjm4
Copy link

davisjm4 commented Mar 5, 2022

I'm getting the following error.

NameError Traceback (most recent call last)
in ()
----> 1 System.out.println("Hello world!");

NameError: name 'System' is not defined

@tueda
Copy link
Author

tueda commented Mar 9, 2022

@davisjm4 I can't reproduce your error when I follow the instruction in the notebook. Your kernel looks like Python, not Java; it seems that the page was not successfully refreshed.

@davisjm4
Copy link

davisjm4 commented Mar 9, 2022 via email

@jmmanipadam
Copy link

followed theinstructions, the code i pasted is running but no output seen. Why?

@tueda
Copy link
Author

tueda commented Nov 14, 2022

@jmmanipadam You need to open the notebook file in Colab (copy&paste code doesn't work), because you need to switch the Jupyter Kernel type to "java" (impossible from the Colab UI, saved in the .ipynb file). That is why I made this template notebook.

@benrobideau
Copy link

Does this still currently work? I've been running into the issue of a never-ending "Connecting...". I've been troubleshooting for about a day with no luck.

@tueda
Copy link
Author

tueda commented Dec 13, 2022

Oh, now the Java Kernel actually seems to stop at "Connecting"...

SpencerPark/IJava#138
googlecolab/colabtools#3267

@tueda
Copy link
Author

tueda commented Dec 21, 2022

@tueda
Copy link
Author

tueda commented Feb 21, 2024

For reference, nowadays the easiest way to run Java on Colab would be:

  1. Copy and paste 4 lines in https://github.com/jupyter-java#installing-in-online-jupyter-notebooks, and run them.
  2. Change runtime type to java (IJava/j!).

Then the above examples work well (including %maven ...).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment