go to previous page   go to home page   go to next page hear noise highlighting

Answer:


Between the Braces

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

The small Java programs in this chapter all look like this:

public class ClassName
{

}

Everything that a program does is described between the first brace and the final brace of a class. To start with, we will have only one class per source code file, but in later chapters there may be several classes per source code file.

The example program writes Hello World! to the monitor. It looks like a lot of program for such a little task! But, usually, programs are much longer and the details you see here help to keep them organized. The line

public static void main ( String[] args )

shows where the program starts running. The word main means that this is the main method — where the Java virtual machine starts running the program. The main method must start with this line, and all of its parts must be present. Wherever there is one space it is OK to have any number of spaces. The spaces surrounding the parentheses are not required. The fifth line shows parentheses not surrounded by spaces (but you could put them in).


QUESTION 4:

Is the following acceptable?

public    static void main(String[]  args   )

go to previous page   go to home page   go to next page