Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Your first program

Save the following as hello.j:

# hello.j
use io;

def x as int init 21;
io.printf($x + $x);

Run it:

./jennifer run hello.j

You should see 42.

What just happened

  1. use io; makes Jennifer’s standard library functions available.
  2. def x as int init 21; declares an integer variable named x and initializes it to 21. Notice that using a variable requires the $ prefix.
  3. io.printf($x + $x) calls the standard library function with the result of 21 + 21.

Top-level statements run in source order - there is no required entry-point method. You can still group reusable code into methods (def) and call them explicitly.