NetRexx at Once

Quick Guide for Java Developers


[Index] [Previous Chapter] [Next Chapter]

1. Basic Input-Output

1.1 SAY vs System.out.println

With NetRexx you can develop Java applications fast and easily. For example, consider the simplest application that says "Hello!" to the world. Compare the two chuncks of code:

Java
/* This is Hello.java */
class Hello {
  public static void main(String[] arg) {
    System.out.println("Hello! World.");
  }
}
NetRexx
/* This is Hello.nrx */
say 'Hello! World.'
--
--
--
--
notes
  • No class declaration needed.
  • No main method declaration needed.
  • No semicolon needed at the end of instructions.
  • SAY instruction instead of println method.
  • Both souce codes create a fully compatible Hello.class:
    Java with the command javac Hello.java
    NetRexx with the command java COM.ibm.netrexx.process.NetRexxC Hello

1.2 ASK vs System.in.read

If you need to get data from the standard input stream, code remains simple. This program asks your name and answers politely:

Java
/* This is HelloYou.java */
import java.io.IOException;
class HelloYou { // This is a comment
  public static void main(String[] arg) {
    String name = "";
    System.out.println("Who are you?");
    try {
      byte[] answer = new byte[30];
      int len = System.in.read(answer);
      name = new String(answer,0,len);
    } catch(IOException e) {
      name = "exception";
    }
    System.out.println("Hello! "+name);
  }
}
NetRexx
/* This is HelloYou.nrx */
say "Who are you?" -- This is a comment
name=ask
SAY 'Hello!' Name
--
--
--
--
--
--
--
--
--
--
--
--
notes
  • Import of the most used Java packages is automatic.
  • No input overhead with the ask keyword.
  • Simple String management: concatenation is implied and spaces between strings are significant.
  • No type of variable declaration needed.
  • Notice the different use of // and -- for comments at the end of a line.
  • Finally: you can use either " or ' for string literals and all the source code is case insensitive
    (exported names such as identifiers of public classes and methods are treated differently).

[Index] [Previous Chapter] [Next Chapter]


TETRACTYS Freeware Main Page hosted by GeoCities Get your own Free Home Page
Hosted by www.Geocities.ws

1