What Is the LEGO Mindstorms NXT and How Does leJOS NXJ Run Java on It?

The LEGO Mindstorms NXT is a programmable robotics brick, and leJOS NXJ is a Java-based replacement firmware that lets you run Java programs on it instead of the stock firmware. You would choose NXJ when you want to write NXT robot logic in Java, using the leJOS NXJ API and PC API rather than the graphical or vendor-supplied programming tools. This article explains what NXT is, what NXJ is, how Java actually executes on the brick, and the basic workflow to get running.

What the NXT Is, and How It Differs from RCX and EV3

The NXT is one generation in LEGO's Mindstorms line of programmable robotics bricks. leJOS supports multiple generations, which is why the site lists separate firmware and API sets:

Brick generation leJOS firmware / API
RCX leJOS RCX (API, tutorial, downloads)
NXT leJOS NXJ (API, PC API, tutorial, downloads)
EV3 leJOS EV3 (separate releases, e.g. 0.9.1-beta)

The key distinction for a beginner: NXT is the hardware brick, while NXJ is the software layer that replaces its firmware so it can execute Java. RCX and EV3 are different bricks with their own leJOS variants, so NXJ instructions and APIs apply to the NXT, not to the others.

What leJOS NXJ Is

leJOS is described on the site as "a Java based replacement firmware for the Lego Mindstorms RCX microcontroller," and NXJ is "a Java based replacement firmware for the Lego Mindstorms NXT microcontroller." In other words, NXJ is the NXT-specific member of the leJOS family.

Practically, that means:

  • You replace the NXT's normal firmware with the NXJ firmware.
  • You program the brick in Java.
  • You use the leJOS NXJ API for on-brick robot behavior and the PC API for communication between a host computer and the NXT.

How Java Runs on the NXT: TinyVM and the Java VM

The NXT does not run a full desktop Java environment. leJOS NXJ relies on a small Java virtual machine — the site's keyword list includes TinyVM — so that Java bytecode can execute within the brick's limited resources.

The mechanism, in plain terms:

  1. You write Java source code on your PC.
  2. It is compiled to Java bytecode.
  3. The bytecode is uploaded to the NXT, where the leJOS NXJ firmware and its small VM execute it.

This is why NXJ is described as replacement firmware rather than just a library: the Java execution capability lives on the brick itself, not on the PC.

Basic Workflow: From Java Code to a Running NXT

The site points to NXJ tutorials and downloads as the starting resources. The general sequence is:

  1. Install the NXJ firmware on the NXT, following the leJOS NXJ tutorial and download instructions.
  2. Write Java code using the leJOS NXJ API for robot behavior.
  3. Compile the code on your PC.
  4. Upload the compiled program to the NXT.
  5. Run it on the brick.

If your program needs to talk to a PC — for example, sending commands or receiving sensor data — you use the PC API alongside the on-brick NXJ API.

A concrete task example

Suppose you want the NXT to drive forward until a sensor triggers, then report back to your PC. You would write the motor and sensor logic with the NXJ API, compile it, upload it to the NXT, and use the PC API on the host side to receive the report. The exact classes and methods are documented in the NXJ API and PC API references linked from the leJOS site.

Where to Go Next

The leJOS site organizes NXT material into these entry points:

  • leJOS NXJ API — classes for programming the brick.
  • PC API — classes for host-to-NXT communication.
  • Tutorial — guided setup and first programs.
  • Downloads — the NXJ firmware and related files.
  • FAQ and Forum — troubleshooting and community help.

For related questions, the site's own structure separates NXJ (the firmware and how it runs Java) from ICommand (how direct commands are sent to an NXT), so treat those as distinct topics when you search the documentation.

lejos.sourceforge.io
leJOS is a Java based replacement firmware for the Lego Mindstorms RCX microcontroller and NXJ is a Java based replacement firmware for the Lego Mind…