The scijava-jupyter-kernel is polyglot which means you can use multiple languages in the same notebook. Available languages are :

  • Groovy
  • Python
  • BeanShell
  • Clojure
  • JavaScript
  • Scala

All those script languages are executed by the Scijava Scripting Mechanism. It means that any languages added to Scijava Script will work on scijava-jupyter-kernel.

You can specify a language per cell with the following shebang-like syntax : #!groovy. It needs to be on the first line of the cell. If nothing is specified, Groovy is the default language or the last selected language is used.


Now let's see some of the specific feature of the scripting languages.

Groovy


In [1]:
#!groovy
println "The Groovy version is " + GroovySystem.version


The Groovy version is 2.4.10
Out[1]:
No Outputs

In [2]:
class HelloWorld {
   def greet( name ){
      "Hello ${name}!"
   }
}

def hm = new HelloWorld()
println hm.greet("Groovy")


Hello Groovy!
Out[2]:
No Outputs

In [3]:
def pickEven(n, block) {
    for (int i=2; i <= n; i += 2) {
        block(i)
    }
}

pickEven(10) {
    println it
}


2
4
6
8
10
Out[3]:
No Outputs

Python


In [4]:
#!python
import sys
print(sys.version)


2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11) 
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)]
Out[4]:
No Outputs

In [5]:
# Code is from http://introtopython.org/classes.html

class Rocket(object):
    # Rocket simulates a rocket ship for a game,
    #  or a physics simulation.
    
    def __init__(self):
        # Each rocket has an (x,y) position.
        self.x = 0
        self.y = 0
        
    def move_up(self):
        # Increment the y-position of the rocket.
        self.y += 1
        
# Create a fleet of 5 rockets, and store them in a list.
my_rockets = [Rocket() for x in range(0,5)]

# Move the first rocket up.
my_rockets[0].move_up()

# Show that only the first rocket has moved.
for rocket in my_rockets:
    print("Rocket altitude:", rocket.y)


('Rocket altitude:', 1)
('Rocket altitude:', 0)
('Rocket altitude:', 0)
('Rocket altitude:', 0)
('Rocket altitude:', 0)
Out[5]:
No Outputs

Beanshell

!Beanshell

printBanner();

Hashtable hashtable = new Hashtable(); Date date = new Date(); hashtable.put( "today", date );

// Print the current clock value print( System.currentTimeMillis() );

// Loop for (int i=0; i<5; i++) print(i);

Clojure


In [2]:
#!clojure
(println *clojure-version*)


{:major 1, :minor 8, :incremental 0, :qualifier nil}
Out[2]:
No Outputs

In [14]:
(let [fn-list [+ - * /]]
    (println ((apply juxt fn-list) 1 2)))


[3 -1 2 1/2]
Out[14]:
No Outputs

Javascript


In [1]:
#!javascript
print("Hello World :-)");


Hello World :-)
Out[1]:
No Outputs

In [2]:
time = 18

if (time < 10) {
    greeting = "Good morning";
} else if (time < 20) {
    greeting = "Good day";
} else {
    greeting = "Good evening";
}

print(greeting)


Good day
Out[2]:
No Outputs

In [3]:
var cars = ["BMW", "Volvo", "Saab", "Ford"];
var text = "";

for (var i = 0; i < cars.length; i++) {
    text += cars[i] + "\n";
}

print(text);


BMW
Volvo
Saab
Ford

Out[3]:
No Outputs

Scala


In [4]:
#!scala
scala.util.Properties.versionMsg


Out[4]:
Scala library version 2.12.1 -- Copyright 2002-2016, LAMP/EPFL and Lightbend, Inc.

In [5]:
class Point(val xc: Int, val yc: Int) {
   var x: Int = xc
   var y: Int = yc
   
   def move(dx: Int, dy: Int) {
      x = x + dx
      y = y + dy
      println("Point x location : " + x);
      println("Point y location : " + y);
   }
}

val pt = new Point(10, 20);
// Move to a new location
pt.move(10, 10);


Out[5]:
No Outputs