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

Answer:

  1. ExcitingGame     OK: mixed upper and lower case is allowed
  2. Lady Luck     BAD: no spaces allowed inside an identifier
  3. x32     OK: identifiers must start with an alphabetical character, but the rest can be digits.
  4. lastChance     OK: class names usually start with a capital, but identifiers don't have to.
  5. x/y     BAD: the slash is not allowed inside an identifier

Between the Braces

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

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

class Hello
{

}

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 )