Hello World in J
Your first J program - the classic Hello World example with Docker setup
Every programming journey starts with Hello World. In J, this is remarkably concise—just a string expression that outputs to the screen.
The Code
Create a file named hello.ijs:
| |
That’s it—one line that writes our greeting to standard output.
Understanding the Code
Let’s break down this concise expression:
'Hello, World!'- A character string (called a “literal” in J)1!:2- A “foreign conjunction” for file output (the1class handles files,:2means write)(2)- File descriptor 2 represents standard output (screen)
In J, !: is the foreign conjunction that provides access to system functions. The 1!:2 specifically means “write to file,” and file number 2 is standard output.
Alternative Approaches
J offers several ways to output text:
| |
The NB. is J’s comment marker (“Nota Bene” - Latin for “note well”).
Running with Docker
The easiest way to run J without installing anything locally:
| |
Command Line Options Explained
--entrypoint /usr/bin/ijconsole-9.03- Use the J console interpreter-v $(pwd):/app- Mount current directory into the container-w /app- Set working directory inside containerhello.ijs- The script file to execute
Running Locally
If you have J installed locally:
| |
Installing J
All Platforms:
Download from Jsoftware.com - J is available for Windows, macOS, Linux, and Raspberry Pi.
Linux (from source):
| |
Expected Output
Hello, World!
Interactive J
J is particularly powerful in interactive mode. Start a J session:
| |
Then type expressions and see immediate results:
| |
The three-space indent shows user input in J’s interactive mode.
To exit, type exit '' or press Ctrl+D.
Going Beyond Hello World
J’s power becomes apparent with array operations. Even in a “Hello World” tutorial, we can glimpse this:
| |
The single character |. reverses the entire string—no loops, no indexing.
| |
The # verb counts the elements (characters in a string).
| |
The $ (reshape) verb rearranges our string into a 3×4 matrix.
A Note on J Syntax
J’s ASCII-based syntax uses punctuation creatively:
| Symbol | Meaning | Example |
|---|---|---|
+ | Add | 2 + 3 → 5 |
- | Subtract/Negate | 5 - 3 → 2, - 5 → _5 |
* | Multiply/Sign | 2 * 3 → 6 |
% | Divide | 6 % 2 → 3 |
# | Count/Copy | # 'hi' → 2 |
$ | Shape/Reshape | $ 'hi' → 2 |
i. | Integers | i. 5 → 0 1 2 3 4 |
!: | Foreign (system) | 1!:2 = file write |
Notice that J uses % for division (not /) and _ for negative numbers (not -).
Key Concepts
- ASCII-only - J uses standard keyboard characters, unlike APL
- Foreign conjunctions -
m!:nprovides system-level operations - Right-to-left evaluation - No operator precedence except right-to-left
- Arrays are fundamental - A string is a character array
- Verbs work on arrays - No explicit iteration needed
Historical Note
J was created by Kenneth Iverson and Roger Hui in 1989-1990 as a modernization of APL. The switch from APL’s special characters to ASCII was revolutionary—suddenly APL’s powerful array programming was accessible on any computer with any keyboard.
The name “J” follows naturally from APL’s influence: APL stands for “A Programming Language,” and J is simply the next letter after I (Iverson).
Next Steps
Continue to Variables and Data Types to learn about J’s array-oriented data model.
Running Today
All examples can be run using Docker:
docker pull nesachirou/jlang:latest