JSDAI Introduction 


Hello World

Before going into SDAI let us first have a look to a simple Java program. The "look" of Java is very close to C/C++, however the way it works is rather different. To learn more on Java please take one of the many available books. We found the book "Just Java" from Peter van Linden very enlightened.

Example program

public class HelloWorld {                    // (1)
    public static void main(String argv[]) { // (2)
        String message = "Hello World";      // (3)
        message = message.toUpperCase();     // (4)
        System.out.println(message);         // (5)
    }
}
  1. Java encapsulate all code into classes.  The class HelloWorld is made public to be accessible from the outside.  A class may contain variables and methods.
  2. The method main() is public accessible. It is static because this method needs no object (instance) of type HelloWorld to be invoked.
  3. An object of type String is created. The object is referenced by the variable message. While the value of the variable message may change, the object itself can never change. When the object is no longer used (referenced) the Garbage Collection will take it away.
  4. The method toUpperCase() on the String object is invoked to create a new String object. Please note that we have now 2 String-objects; however the first one is no longer referenced.
  5. The static variable out in class System in of type class PrintStream. The method println of class PrintStream is invoked on out. Class System belongs to package "java.lang" and is imported by default.

Running the example

Using the free Java Development Kit (JDK) from Sun Microsystems from a DOS command prompt. Compiling the *.java" source with "javac" and running the resulting "*.class" file.

D:\LKSOFT\tutorial>javac HelloWorld.java

D:\LKSOFT\tutorial>dir HelloWorld.*
12/10/99  12:36p                   659 HelloWorld.class
12/10/99  12:35p                   259 HelloWorld.java

D:\LKSOFT\tutorial>java HelloWorld
HELLO WORLD



Copyright 1998-2003, LKSoftWare GmbH