Hello World in Java [] (Hello World in Java), Lektion, page 722578
https://www.purl.org/stefan_ram/pub/hello_world_java (permalink) is the canonical URI of this page.
Stefan Ram
Java Tutorial

>721002 Ein erstes Java -Programm

A first Java  program

Special characters

Java  programs sometimes contain some special characters, whose names will be given below.

»{« “left curly brace”

»}« “right curly brace”

»;« “semicolon” [ˌsɛ̣mi ˈkolə̣n]

»"« “quotation mark”

The first source code

A program of a programming language sometimes is called source code, when one wants to emphasize that it is the source for further processing.

⚠ The Line »Hello.java« in front of the rendition of the source code does not  form a part of the source code, but gives the name  under which the source code is to be stored as a file where necessary. The source code starts with the word »public« and ends with the text »}}«.

Hello.java
public final class Hello
{ public static void main( final java.lang.String[] args )
{ java.lang.System.out.println( "hello, world" ); }}
?    Counting the Lines
How many lines does the above source code have?

The meaning of all parts of the above program will be explained in the following lessons in exaggerating detail. In this lesson, below, follows a preliminary and somewhat simplified explanation.

The expected behavior of the program

When a computer is doing what a program demands, one also says that the computer is executing  the program or that the program is running. Causing a program to run is also known as starting  the program.

The program listed above will print »hello, world« into a writing field called the console [ˈkɔ:nsl] or (here) »java.lang.System.out« after it has been started.

java.lang.System.out
hello, world

Classes

A file that contains source code is called a source file ; the text contained in the file then also is called a translation unit. The source file »Hello.java« contains the specification of a class »Hello«, which is beginning with the source code »public final class Hello« and ends with the source code's final curly brace »}«.

Hello.java
public final class Hello
{
public static void main( final java.lang.String[] args )
{ java.lang.System.out.println( "hello, world" ); }}

For the time being, we can say that a class  is tantamount to a program. Therefore, we can say that our program is called »Hello«.

The name »Hello« at the end of the first line specifies the name of the class.

Hello.java
public final class Hello
{ public static void main( final java.lang.String[] args )
{ java.lang.System.out.println( "hello, world" ); }}

Methods

The program also contains the specification of a method »main«, that is starting with »public static void main( final java.lang.String[] args )« and ends with the source code's penultimate curly brace »}«. Put simply, a method  is the part of a class, that determines what this class is doing. Thus, this method determines what our program is doing.

Hello.java
public final class Hello
{ public static void main( final java.lang.String[] args )
{ java.lang.System.out.println( "hello, world" ); }}

Large programs often contain several classes, which in turn can contain several methods. Classes  and methods  allow to neatly arrange large programs into comprehensible units, just like chapters  and sections  can subdivide a book. Even if a program is so small that such a structuring is not necessary, Java  still requires it.

Statements

The last line of the program is well worth an explanation as it specifies what the program actually is supposed to do.

A statement  is a text that tells a computer what to do. (The observant reader might have noticed that this is the same definition as used for “program” above. This is correct. Programs and statements do not differ in this regard.)

The method »main« contains the statement »java.lang.System.out.println( "hello, world" );«, which requests the output of the text »hello, world«. So, this is what the program will do. The verb “print ” is used therein to mean any kind of output.

The many words in »java.lang.System.out.println« serve to specify exactly  which procedure is to be used for printing.

Hello.java
public final class Hello
{ public static void main( final java.lang.String[] args )
{ java.lang.System.out.println( "hello, world" ); }}

Variants of notation *

It is possible that the example programs from this course might look somewhat different than similar programs from other sources. This is so, because there are several possible ways to write a Java  program for a certain task, as will be explained later in more detail.

About this page, Impressum  |   Form for messages to the publisher regarding this page  |   "ram@zedat.fu-berlin.de" (without the quotation marks) is the email-address of Stefan Ram.   |   A link to the start page of Stefan Ram appears at the top of this page behind the text "Stefan Ram".)  |   Copyright 1998-2014 Stefan Ram, Berlin. All rights reserved. This page is a publication by Stefan Ram. relevant keywords describing this page: Stefan Ram Berlin slrprd slrprd stefanramberlin spellched stefanram722578 stefan_ram:722578 Hello World in Java Stefan Ram, Berlin, and, or, near, uni, online, slrprd, slrprdqxx, slrprddoc, slrprd722578, slrprddef722578, PbclevtugFgrsnaEnz Erklärung, Beschreibung, Info, Information, Hinweis,

Copyright 1998-2014 Stefan Ram, Berlin. All rights reserved. This page is a publication by Stefan Ram.
https://www.purl.org/stefan_ram/pub/hello_world_java