print something to the console in jjs

11 June 2015

Once I got jjs running I started with some pretty simple stuff. To print something to the console I found the following ways.

//javascript style
print("hello world"); // don't forget the parentheses here, otherwise jjs wont like you
//java style
var System = Java.type('java.lang.System');
System.out.println("hello world");
//of course there is an error out too
System.err.println("hello world");

Don’t forget to declare System as Variable, otherwise it will fail.

nashorn> System.out.println("hello world");
script error: ReferenceError: "System" is not defined in <STDIN> at line number 1