The NetRexx Tutorial
- Basic concepts
NetRexx Tutorial - Basic concepts

Basic concepts

In this chapter I'll try to give an overview of all the basic concepts which, in my opinion, are required to fully understand the following chapters.

If you're familiar with the concepts exposed here, you can just jump immediately to the next chapter.

The Java language

Java is an object-oriented programming language developed by Sun Microsystems (TM). A Java program might look like a C or C++ program, due to Java's similarities to those languages. Indeed, Java is not based on C, neither on C++. There has been no effort to make Java compatible with those two languages.

One important point to keep in mind is that Java was designed with the idea to allow execution of code across a network.

The main feature of Java is that the COMPILED code is platform independent. To achieve this, Java compiles to an intermediate form; Java byte-code. This code is then interpreted "on-the-fly" by a platform-dependent, Java interpreter.

  |            |
  | SOURCE     |
  |            |
       =     (compilation)
       =     javac
  |            |
  |JAVA BYTE   |
  |CODE        |

The Java Compiler creates a Java class file, which does not contain any instruction which is architecture dependent. You will not find Pentium, rs6000, MAC, etc. instructions in a class file: you will find code which is understood by a Java Virtual Machine: an interpreter which knows how to translate the Java byte-code into your machine's instructions.

  | JAVA BYTE CODE        | <- architecture independent
  | (class)               |
  |                       |
  | JAVA VIRTUAL MACHINE  | <- architecture dependent
  |                       |
  | MACHINE (PC,MAC,WS)   | <- your machine

So, the Java Virtual Machine is just a special interpreter, that "understands" a class file.

The idea is not new: it was available in UCSD Pascal, and the intermediate code was the so-called p-code.

When running code across a network, you must eliminate some of the language features which might allow any malicious code to gain access to your computer. Notably, Java's designers had to take away the concept of a "pointer", largely used in C and C++. Java programs cannot access arbitrary addresses in your machine memory.

Java and the WEB

The capability to interpret Java byte-code is available on most WWW browsers available today.

If an HTML document contains a <class> statement, the browser will fetch the class, (if you don't already have it on your machine) and execute the code. The important thing to stress is that the code, at this point, runs on YOUR machine, not on the server from where you downloaded the HTML document.


  WWW Browser                       http Daemon
  -----------                       -----------
  (client)                          (server)

              --(URL request)---->
              <--(HTML doc)------

   <class >
              --(class request)-->

   CLASS runs


Java adds local interaction to the WEB, and offloads processing from the server to the client.

What's the gain in such an approach? Why not run the code directly in the server side? (like you do whenever you issue a cgi-bin command)?

If your application manipulates data and displays it graphically, the Java approach is definitely more efficient, both in terms of reduced network traffic and perceived execution speed.

For example: suppose that your company wants to display several histograms on their WWW home page. You could have the pictures (in gif or jpg format) stored in the HTML daemon directory. Each time the document is requested, potentially hunders of kilobytes of data is transfered across the network. Using Java, you download the application that implements a histogram viewer, and the data to build the histogram to your machine; usually significantly less data than the pre-built images.


JDK is an acronym for Java Developer Kit. It is a set of programs that allows you to compile your java code and to execute it (using the Java Interpreter).

The JDK is distributed freely by Sun, and you can download it from Sun's site:

See the Appendix I for more details.

The JDK is made up by the following tools:

The JDK also includes all the Java class files that you need to compile and run your java programs.

The JDK is NOT a visual development environment, like Microsoft's J++ or Symatec's Cafe'. Sun's JDK has been defined as "primitive" [GREHAN, 1997] by some authors, since all the package's tools run from the command line. Other people [HAROLD, 1997] definitely prefer JDK's "minimalist" approach vs. more fancy products, sometimes still in beta test.

If you are an "old fashion" programmer like me, you'll probably prefer JDK's approach, which resembles the development process I followed on VM/370 and VS/COBOL; edit, compile, and run all from the command line.

For NetRexx there is no IDE at the moment, so you are forced to use JDK's approach anyway.

Java Classes

Like other languages; notably FORTRAN, Java is a relatively simple language. The power of these languages is derived, not from the language itself, but from the extensibility of the language. Without high level mathematical packages and functions in FORTRAN, you would not be able to do much of any significance. Java, without its Class Libraries is the same.


An application is, generally speaking, a stand-alone program which you launch from the command line. An application has unrestricted access to the host system. An application can read/write files on your system using your access privileges, it can open socket connections with any address, etc.

Technically, a NetRexx application is a NetRexx program that has a main() method, or no method at all (NetRexx will add the main() for you).


An applet is a program which is run in the context of an applet viewer or of a WEB browser. An applet has very limited access to the system where it runs; for example, an applet cannot read files, neither can it establish socket connections to systems other than the one from where the applet was downloaded.

Technically speaking, an applet is a NetRexx class which extends the Java class java.applet.Applet.


You might have found, in several WEB pages, portions of code that are executed by the browser. This code is written using javascript. To make it clear, javascript has nothing to do with java. The black beverage that you find in fast-foods has nothing to do with the nectar you drink at "La Tazza d'oro" (Via degli Orfani 82, in Rome). People ( not the same people, indeed) call both of them coffees, but that's the only thing they share. So Java and Javascript just share (a portion of) the name. "The intersection of Java and Javascript is the empty set." [VAN DER LINDEN, 1997].

Javascript was invented by Netscape Inc., and it is a simple scripting language, imbedded in HTML files. It offers loops and conditional tests.

As an example of Javascript, look at the following code:

| <HTML>                                                               |01
| <PRE>                                                                |02
| Here I snoop some info about you:                                    |03
|                                                                      |04
| <script language= "JavaScript">                                      |05
|   <!--                                                               |06
|   var where = document.referrer                                      |07
|   var name = navigator.appName                                       |08
|   var vers = navigator.appVersion                                    |09
|   document.writeln ("You came here from:'"+where+"'.")               |10
|   document.write ("You use:'"+name+"  "+vers+"'.")                   |11
|  // -->                                                              |12
| </script>                                                            |13
| </PRE>                                                               |14
| </HTML>                                                              |15

Just in time Compilers


JavaBeans is a public specification developed by Sun, in consultation with other vendors and with the Java community. JavaBeans is a component model, which lets you build and use Java-based components.

The beans is just a Java class with some additional descriptive information. Why this additional information? Because this information is used to make beans reusable software components, which can be manipulated by building tools. This allows non-programmers, using an authoring tool, to assemble an application using the provided components.

Additional sources of information


The "home" of Java is:


The first place is definitely

contains a good tutorial, and the specifications for JavaBeans 1.0.

You should then look at:

for the NetRexx implementation.

For more general informations, look at


File: nr_4.html.

The contents of this WEB page are Copyright © 1997 by Pierantonio Marchesini / ETH Zurich.

Last update was done on 18 May 1998 21:47:34(GMT +2).