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

Answer:

  1. What should the source file be named?
    • AddUpNumbers.java
  2. What is the name of the bytecode file the compiler creates?
    • AddUpNumbers.class

Identifiers and Reserved Words

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

Most classes contain many more lines than this one. Everything that makes up a class is placed between the first brace  {  and its matching last brace  } .

The name of the class (and therefore the name of the file) is up to you. In programming, the name for something like a class is called an identifier. An identifier consists of alphabetical characters and digits. The first character must be alphabetical, the remaining characters can be mixed alphabetic characters and digits (plus the two characters '_' and '$' underscore and dollar sign). No spaces are allowed inside the name. Chapter nine discusses this in more detail.

Usually a class name starts with a capital letter, but this is not required. A source file should always end with .java in lower case.

A reserved word is a word like class that has a special meaning to the system. For example, class means that a definition of a class immediately follows. You must use reserved words only for their intended purpose. (For example, you can't use the word class for any other purpose than defining a class.)


QUESTION 3:

Which of the following look like good identifiers? (click on an identifier to verify your answer)

  1. ExcitingGame
  2. Lady Luck
  3. x32
  4. lastChance
  5. x/y