NetRexx is an alternative language for the Java Virtual Machine (JVM). One of its most compelling benefits is its complete, syntax-less integration with JVM libraries. Whereas other JVM languages depend on new libraries to be written  with all the related problems like inventing new conventions  NetRexx integrates seamlessly with Java.

The NetRexx language processor can function as a pure scripting language and interpret source code, or it can compile to Java class files. In the compiled version, the right invocation is generated and there is no difference between using a NetRexx class or a Java class. NetRexx takes this integration to the extreme, by depending wholly on the JVM for I/O and other functions.

The benefit of such tight integration is that new developments in IT are available to NetRexx programmers as soon as they are available to the Java developers.

For example, when the Raspberry Pi first emerged  at least, when we could get our hands on one  a whole new world of turning on and off of LEDs and relays via GPIO pins was open to NetRexx. From the beginning, there were two class libraries that could perform the low-level I/O operations, such as with this:

import framboos. led = Outpin(0) led.setValue(1) Thread.currentThread().sleep(10000) led.setValue(0) led.close()

Note that this is the complete program, using the scripting mode of NetRexx, in which there is no need to set up class definitions, class constructors, or a main() method. This program will turn on an LED, wait 10 seconds, and turn it off.

While coding, you can use an edit-and-interpret cycle for rapid development; when the code is debugged and working, it can be compiled to a class file and stored in a JAR along with the other application classes.

A slightly larger example (Listing One) shows the use of NetRexx with the Eclipse Paho client for MQTT, the machine-to-machine messaging protocol for the Internet of Things (which is a good combination with a Raspberry, by the way  the mosquitto message broker does an excellent job offering a complete message broker in a small memory footprint).

Listing One: NetRexx written as a class.

import java.sql.Timestamp import org.eclipse.paho.client.mqttv3. class Publish implements MqttCallback method Publish() conOpt = MqttConnectOptions() conOpt.setCleanSession(0) tmpDir = System.getProperty("java.io.tmpdir") dataStore = MqttDefaultFilePersistence(tmpDir) clientId = MqttClient.generateClientId() topicName = "/world" payload = "hello".toString().getBytes() qos = 2 do broker = "localhost" port = "1883" brokerUrl = "tcp://"broker":"port client = MqttClient(brokerUrl,clientId, dataStore) client.setCallback(this) catch e=mqttException say e.getMessage() e.printStackTrace() end -- do client.connect() log("Connected to "brokerUrl" with client ID "client.getClientId()) -- Get an instance of the topic topic = client.getTopic(topicName) message = MqttMessage(payload) message.setQos(qos) -- Publish the message time = Timestamp(System.currentTimeMillis()).toString() log('Publishing at: 'time' to topic "'topicName'" with qos 'qos) token = topic.publish(message) -- Wait until the message has been delivered to the server token.waitForCompletion() -- Disconnect the client client.disconnect() log("Disconnected") method log(line) say line method messageArrived(t=MqttTopic,m=MqttMessage) method deliveryComplete(t=MqttDeliveryToken) log("Delivery Complete: " t) method connectionLost(t=Throwable) log("Connection Lost:" t.getMessage()) method main(args=String[]) static Publish()