Hello World!

class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello world!");
  }
}

Was heißt das?

class HelloWorld

deklariert die Klasse HelloWorld.

public static void main(String[] args)

deklariert die Funktion main, die ein Array von %JAVADOC{java.lang.String}%-Objekten als Argument erwartet, nichts ("void") zurückgibt und mit den Attributen "public" und "static" gekennzeichnet ist.

System.out.println("Hello world!");

ruft die Methode println des Objekts %JAVADOC{java.lang.System}%.out mit einem %JAVADOC{java.lang.String}%-Objekt als Argument auf.

Kompilieren und ausführen

Die Klasse HelloWorld wird in der Datei HelloWorld.java gespeichert.

Dann wird der Java Compiler aufgerufen mit javac HelloWorld.java. Dieser erzeugt die Datei HelloWorld.class im gleichen Verzeichnis.

Diese kann nun durch java HelloWorld aufgerufen werden.

-- Main.christo - 05 Nov 2003
Topic revision: r6 - 2003-11-14, VolkerRWSchaa
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding GSI Wiki? Send feedback | Legal notice | Privacy Policy (german)